OPC_TreeCollider.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_TREECOLLIDER_H__
21 #define __OPC_TREECOLLIDER_H__
22 
23 #include"../config.h"
31  {
34  {
35  ResetCache();
36  ResetCountDown();
37  }
38 
39  void ResetCache()
40  {
41  Model0 = null;
42  Model1 = null;
43  id0 = 0;
44  id1 = 1;
45 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
46  HullTest = true;
47  SepVector.pid = 0;
48  SepVector.qid = 0;
49  SepVector.SV = Point(1.0f, 0.0f, 0.0f);
50 #endif // __MESHMERIZER_H__
51  }
52 
54  {
55 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
56  CountDown = 50;
57 #endif // __MESHMERIZER_H__
58  }
59 
60  const Model* Model0;
61  const Model* Model1;
62 
63 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
64  SVCache SepVector;
65  udword CountDown;
66  bool HullTest;
67 #endif // __MESHMERIZER_H__
68  };
69 
71  {
72  public:
73  // Constructor / Destructor
75  virtual ~AABBTreeCollider();
76 
77  inline void setCollisionPairInserter(hrp::CollisionPairInserterBase* collisionPairInserter) {
78  this->collisionPairInserter = collisionPairInserter;
79  }
80 
81 
82  // Generic collision query
83 
85 
97  bool Collide(BVTCache& cache, const Matrix4x4* world0=null, const Matrix4x4* world1=null);
99 
100  // Collision queries
101  bool Collide(const AABBCollisionTree* tree0, const AABBCollisionTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
102  bool Collide(const AABBNoLeafTree* tree0, const AABBNoLeafTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
103  bool Collide(const AABBQuantizedTree* tree0, const AABBQuantizedTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
104  bool Collide(const AABBQuantizedNoLeafTree* tree0, const AABBQuantizedNoLeafTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
105  // Settings
106 
108 
113  inline_ void SetFullBoxBoxTest(bool flag) { mFullBoxBoxTest = flag; }
115 
117 
122  inline_ void SetFullPrimBoxTest(bool flag) { mFullPrimBoxTest = flag; }
124 
125  // Stats
126 
128 
134  inline_ udword GetNbBVBVTests() const { return mNbBVBVTests; }
136 
138 
144  inline_ udword GetNbPrimPrimTests() const { return mNbPrimPrimTests; }
146 
148 
154  inline_ udword GetNbBVPrimTests() const { return mNbBVPrimTests; }
156 
157  // Data access
158 
160 
166  inline_ udword GetNbPairs() const { return mPairs.GetNbEntries()>>1; }
168 
170 
176  inline_ const Pair* GetPairs() const { return (const Pair*)mPairs.GetEntries(); }
178 
180 
184  override(Collider) HRP_COLLISION_EXPORT const char* ValidateSettings();
186 
187  protected:
188  // Colliding pairs
190  // User mesh interfaces
193  // Stats
197  // Precomputed data
203  // Dequantization coeffs
208  // Modified!!
209  // For normal vector detection
214  // Leaf description
215  Point mLeafVerts[3];
217  // Settings
221  // Internal methods
222 
223  // Standard AABB trees
224  void _Collide(const AABBCollisionNode* b0, const AABBCollisionNode* b1);
225  // Quantized AABB trees
226  void _Collide(const AABBQuantizedNode* b0, const AABBQuantizedNode* b1, const Point& a, const Point& Pa, const Point& b, const Point& Pb);
227  // No-leaf AABB trees
228  void _CollideTriBox(const AABBNoLeafNode* b);
229  void _CollideBoxTri(const AABBNoLeafNode* b);
230  void _Collide(const AABBNoLeafNode* a, const AABBNoLeafNode* b);
231  // Quantized no-leaf AABB trees
232  void _CollideTriBox(const AABBQuantizedNoLeafNode* b);
233  void _CollideBoxTri(const AABBQuantizedNoLeafNode* b);
234  void _Collide(const AABBQuantizedNoLeafNode* a, const AABBQuantizedNoLeafNode* b);
235  // Overlap tests
236  void PrimTest(udword id0, udword id1);
237  inline_ void PrimTestTriIndex(udword id1);
238  inline_ void PrimTestIndexTri(udword id0);
239 
240  inline_ BOOL BoxBoxOverlap(const Point& ea, const Point& ca, const Point& eb, const Point& cb);
241  inline_ BOOL TriBoxOverlap(const Point& center, const Point& extents);
242  BOOL TriTriOverlap(const Point& V0, const Point& V1, const Point& V2, const Point& U0, const Point& U1, const Point& U2);
243  // Init methods
244  HRP_COLLISION_EXPORT void InitQuery(const Matrix4x4* world0=null, const Matrix4x4* world1=null);
245  bool CheckTemporalCoherence(Pair* cache);
246 
247  inline_ BOOL Setup(const MeshInterface* mi0, const MeshInterface* mi1)
248  {
249  mIMesh0 = mi0;
250  mIMesh1 = mi1;
251 
252  if(!mIMesh0 || !mIMesh1) return FALSE;
253 
254  return TRUE;
255  }
256  };
257 
258 #endif // __OPC_TREECOLLIDER_H__
void setCollisionPairInserter(hrp::CollisionPairInserterBase *collisionPairInserter)
const AABBCollisionNode * mNowNode0
#define FALSE
Definition: OPC_IceHook.h:9
void ResetCache()
#define null
our own NULL pointer
Definition: IceTypes.h:57
bool mFullPrimBoxTest
Perform full Primitive-BV tests (true) or SAT-lite tests (false)
#define TRUE
Definition: OPC_IceHook.h:13
udword mNbPrimPrimTests
Number of Primitive-Primitive tests.
hrp::CollisionPairInserterBase * collisionPairInserter
bool mFullBoxBoxTest
Perform full BV-BV tests (true) or SAT-lite tests (false)
udword mNbBVBVTests
Number of BV-BV tests.
#define inline_
Definition: IcePoint.h:25
inline_ BVTCache()
Constructor.
long b
Definition: jpegint.h:371
virtual inline_ void InitQuery()
Definition: OPC_Collider.h:173
#define OPCODE_API
Definition: Opcode.h:68
Matrix3x3 mAR
Absolute rotation matrix.
const MeshInterface * mIMesh0
User-defined mesh interface for object0.
int BOOL
Another boolean type.
Definition: IceTypes.h:102
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
Container mPairs
Pairs of colliding primitives.
Point mT0to1
Translation from object0 to object1.
virtual const char * ValidateSettings()=0
inline_ void ResetCountDown()
udword mLeafIndex
Triangle index.
#define HRP_COLLISION_EXPORT
Definition: Opcode.h:27
const AABBCollisionNode * mNowNode1
udword mNbBVPrimTests
Number of BV-Primitive tests.
Matrix3x3 mR0to1
Rotation from object0 to object1.
Point mT1to0
Translation from object1 to object0.
const MeshInterface * mIMesh1
User-defined mesh interface for object1.
Matrix3x3 mR1to0
Rotation from object1 to object0.
const Model * Model1
Model for second object.
png_infop png_uint_32 flag
Definition: png.h:2159
inline_ BOOL Setup(const MeshInterface *mi0, const MeshInterface *mi1)
A generic couple structure.
Definition: IcePairs.h:16
const Model * Model0
Model for first object.


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:40