OPC_RayCollider.h
Go to the documentation of this file.
1 /*
3  * OPCODE - Optimized Collision Detection
4  * Copyright (C) 2001 Pierre Terdiman
5  * Homepage: http://www.codercorner.com/Opcode.htm
6  */
8 
10 
16 
19 // Include Guard
20 #ifndef __OPC_RAYCOLLIDER_H__
21 #define __OPC_RAYCOLLIDER_H__
22 
24  {
25  public:
30 
32  float mDistance;
33  float mU, mV;
34  };
35 
37  {
38  public:
43 
44  inline_ udword GetNbFaces() const { return GetNbEntries()>>2; }
45  inline_ const CollisionFace* GetFaces() const { return (const CollisionFace*)GetEntries(); }
46 
48 
49  inline_ void AddFace(const CollisionFace& face) { Add(face.mFaceID).Add(face.mDistance).Add(face.mU).Add(face.mV); }
50  };
51 
52 #ifdef OPC_RAYHIT_CALLBACK
53 
59  typedef void (*HitCallback) (const CollisionFace& hit, void* user_data);
61 #endif
62 
64  {
65  public:
66  // Constructor / Destructor
67  RayCollider();
68  virtual ~RayCollider();
69 
71 
83  bool Collide(const Ray& world_ray, const Model& model, const Matrix4x4* world=null, udword* cache=null);
85  //
86  bool Collide(const Ray& world_ray, const AABBTree* tree, Container& box_indices);
87  // Settings
88 
89 #ifndef OPC_RAYHIT_CALLBACK
90 
98  inline_ void SetClosestHit(bool flag) { mClosestHit = flag; }
100 #endif
101 
109  inline_ void SetCulling(bool flag) { mCulling = flag; }
111 
113 
120  inline_ void SetMaxDist(float max_dist=MAX_FLOAT) { mMaxDist = max_dist; }
122 
123 #ifdef OPC_RAYHIT_CALLBACK
124  inline_ void SetHitCallback(HitCallback cb) { mHitCallback = cb; }
125  inline_ void SetUserData(void* user_data) { mUserData = user_data; }
126 #else
127 
135  inline_ void SetDestination(CollisionFaces* cf) { mStabbedFaces = cf; }
137 #endif
138  // Stats
140 
146  inline_ udword GetNbRayBVTests() const { return mNbRayBVTests; }
148 
150 
156  inline_ udword GetNbRayPrimTests() const { return mNbRayPrimTests; }
158 
159  // In-out test
161 
167  inline_ udword GetNbIntersections() const { return mNbIntersections; }
169 
171 
175  override(Collider) const char* ValidateSettings();
177 
178  protected:
179  // Ray in local space
183  Point mData, mData2;
184  // Stabbed faces
186 #ifdef OPC_RAYHIT_CALLBACK
187  HitCallback mHitCallback;
188  void* mUserData;
189 #else
191 #endif
192  // Stats
195  // In-out test
197  // Dequantization coeffs
200  // Settings
201  float mMaxDist;
202 #ifndef OPC_RAYHIT_CALLBACK
203  bool mClosestHit;
204 #endif
205  bool mCulling;
206  // Internal methods
207  void _SegmentStab(const AABBCollisionNode* node);
208  void _SegmentStab(const AABBNoLeafNode* node);
209  void _SegmentStab(const AABBQuantizedNode* node);
210  void _SegmentStab(const AABBQuantizedNoLeafNode* node);
211  void _SegmentStab(const AABBTreeNode* node, Container& box_indices);
212  void _RayStab(const AABBCollisionNode* node);
213  void _RayStab(const AABBNoLeafNode* node);
214  void _RayStab(const AABBQuantizedNode* node);
215  void _RayStab(const AABBQuantizedNoLeafNode* node);
216  void _RayStab(const AABBTreeNode* node, Container& box_indices);
217  // Overlap tests
218  inline_ BOOL RayAABBOverlap(const Point& center, const Point& extents);
219  inline_ BOOL SegmentAABBOverlap(const Point& center, const Point& extents);
220  inline_ BOOL RayTriOverlap(const Point& vert0, const Point& vert1, const Point& vert2);
221  // Init methods
222  BOOL InitQuery(const Ray& world_ray, const Matrix4x4* world=null, udword* face_id=null);
223  };
224 
225 #endif // __OPC_RAYCOLLIDER_H__
CollisionFace::mU
float mU
Definition: OPC_RayCollider.h:33
RayCollider::mNbRayBVTests
udword mNbRayBVTests
Number of Ray-BV tests.
Definition: OPC_RayCollider.h:193
RayCollider::mStabbedFace
CollisionFace mStabbedFace
Current stabbed face.
Definition: OPC_RayCollider.h:185
Matrix4x4
Definition: IceMatrix4x4.h:21
CollisionFaces
Definition: OPC_RayCollider.h:36
RayCollider::mDir
Point mDir
Ray direction (normalized)
Definition: OPC_RayCollider.h:181
RayCollider::mNbRayPrimTests
udword mNbRayPrimTests
Number of Ray-Primitive tests.
Definition: OPC_RayCollider.h:194
Container
Definition: IceContainer.h:25
Collider::InitQuery
virtual inline_ void InitQuery()
Definition: OPC_Collider.h:173
udword
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
CollisionFaces::GetFaces
const inline_ CollisionFace * GetFaces() const
Definition: OPC_RayCollider.h:45
BOOL
int BOOL
Another boolean type.
Definition: IceTypes.h:102
CollisionFace::~CollisionFace
inline_ ~CollisionFace()
Destructor.
Definition: OPC_RayCollider.h:29
CollisionFace
Definition: OPC_RayCollider.h:23
Collider::ValidateSettings
virtual const char * ValidateSettings()=0
CollisionFace::mFaceID
udword mFaceID
Index of touched face.
Definition: OPC_RayCollider.h:31
Collider::Collider
Collider()
Definition: OPC_Collider.cpp:40
CollisionFace::mDistance
float mDistance
Distance from collider to hitpoint.
Definition: OPC_RayCollider.h:32
AABBTreeNode
Definition: OPC_AABBTree.h:83
AABBCollisionNode
Definition: OPC_OptimizedTree.h:76
AABBNoLeafNode
Definition: OPC_OptimizedTree.h:116
CollisionFace::CollisionFace
inline_ CollisionFace()
Constructor.
Definition: OPC_RayCollider.h:27
RayCollider::mMaxDist
float mMaxDist
Valid segment on the ray.
Definition: OPC_RayCollider.h:201
RayCollider::mOrigin
Point mOrigin
Ray origin.
Definition: OPC_RayCollider.h:180
RayCollider::mNbIntersections
udword mNbIntersections
Number of valid intersections.
Definition: OPC_RayCollider.h:196
AABBTree
Definition: OPC_AABBTree.h:113
RayCollider::mClosestHit
bool mClosestHit
Report closest hit only.
Definition: OPC_RayCollider.h:203
Collider
Definition: OPC_Collider.h:37
RayCollider::mFDir
Point mFDir
fabsf(mDir)
Definition: OPC_RayCollider.h:182
AABBQuantizedNoLeafNode
Definition: OPC_OptimizedTree.h:121
Container::Add
inline_ Container & Add(udword entry)
Definition: IceContainer.h:47
RayCollider::mData2
Point mData2
Definition: OPC_RayCollider.h:183
Ray
Definition: IceRay.h:15
CollisionFace::mV
float mV
Impact barycentric coordinates.
Definition: OPC_RayCollider.h:33
RayCollider::mExtentsCoeff
Point mExtentsCoeff
Definition: OPC_RayCollider.h:199
RayCollider::mCulling
bool mCulling
Stab culled faces or not.
Definition: OPC_RayCollider.h:205
Model
Definition: OPC_Model.h:23
CollisionFaces::CollisionFaces
CollisionFaces()
Constructor.
Definition: OPC_RayCollider.h:40
CollisionFaces::GetNbFaces
inline_ udword GetNbFaces() const
Definition: OPC_RayCollider.h:44
MAX_FLOAT
#define MAX_FLOAT
max possible float value
Definition: IceTypes.h:130
CollisionFaces::Reset
inline_ void Reset()
Definition: OPC_RayCollider.h:47
OPCODE_API
#define OPCODE_API
Definition: Opcode.h:68
void
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
RayCollider::mStabbedFaces
CollisionFaces * mStabbedFaces
List of stabbed faces.
Definition: OPC_RayCollider.h:190
Point
Definition: IcePoint.h:25
AABBQuantizedNode
Definition: OPC_OptimizedTree.h:100
CollisionFaces::AddFace
inline_ void AddFace(const CollisionFace &face)
Definition: OPC_RayCollider.h:49
RayCollider::mCenterCoeff
Point mCenterCoeff
Definition: OPC_RayCollider.h:198
RayCollider
Definition: OPC_RayCollider.h:63
flag
png_infop png_uint_32 flag
Definition: png.h:2156
inline_
#define inline_
Definition: IcePreprocessor.h:103
CollisionFaces::~CollisionFaces
~CollisionFaces()
Destructor.
Definition: OPC_RayCollider.h:42
Container::Reset
inline_ void Reset()
Definition: IceContainer.h:125


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:04