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__
inline_ const CollisionFace * GetFaces() const
inline_ void AddFace(const CollisionFace &face)
udword mNbRayPrimTests
Number of Ray-Primitive tests.
#define null
our own NULL pointer
Definition: IceTypes.h:57
udword mFaceID
Index of touched face.
#define inline_
CollisionFaces()
Constructor.
Point mDir
Ray direction (normalized)
Definition: IcePoint.h:25
virtual inline_ void InitQuery()
Definition: OPC_Collider.h:173
#define OPCODE_API
Definition: Opcode.h:68
int BOOL
Another boolean type.
Definition: IceTypes.h:102
float mMaxDist
Valid segment on the ray.
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
virtual const char * ValidateSettings()=0
inline_ udword GetNbFaces() const
Point mFDir
fabsf(mDir)
float mV
Impact barycentric coordinates.
inline_ void Reset()
inline_ Container & Add(udword entry)
Definition: IceContainer.h:47
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
~CollisionFaces()
Destructor.
#define MAX_FLOAT
max possible float value
Definition: IceTypes.h:130
bool mCulling
Stab culled faces or not.
Definition: IceRay.h:15
Point mOrigin
Ray origin.
inline_ void Reset()
Definition: IceContainer.h:125
udword mNbIntersections
Number of valid intersections.
bool mClosestHit
Report closest hit only.
inline_ CollisionFace()
Constructor.
float mDistance
Distance from collider to hitpoint.
void(* HitCallback)(const CollisionFace &hit, void *user_data)
Definition: Opcode.h:61
CollisionFaces * mStabbedFaces
List of stabbed faces.
inline_ ~CollisionFace()
Destructor.
inline_ udword GetNbEntries() const
Returns the current number of entries.
Definition: IceContainer.h:170
inline_ udword * GetEntries() const
Returns the list of entries.
Definition: IceContainer.h:172
CollisionFace mStabbedFace
Current stabbed face.
png_infop png_uint_32 flag
Definition: png.h:2159
udword mNbRayBVTests
Number of Ray-BV tests.


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:39