Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
30  {
33  {
34  ResetCache();
35  ResetCountDown();
36  }
37 
38  void ResetCache()
39  {
40  Model0 = null;
41  Model1 = null;
42  id0 = 0;
43  id1 = 1;
44 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
45  HullTest = true;
46  SepVector.pid = 0;
47  SepVector.qid = 0;
48  SepVector.SV = Point(1.0f, 0.0f, 0.0f);
49 #endif // __MESHMERIZER_H__
50  }
51 
53  {
54 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
55  CountDown = 50;
56 #endif // __MESHMERIZER_H__
57  }
58 
59  const Model* Model0;
60  const Model* Model1;
61 
62 #ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
63  SVCache SepVector;
64  udword CountDown;
65  bool HullTest;
66 #endif // __MESHMERIZER_H__
67  };
68 
70  {
71  public:
72  // Constructor / Destructor
74  virtual ~AABBTreeCollider();
75  // Generic collision query
76 
78 
90  bool Collide(BVTCache& cache, const Matrix4x4* world0=null, const Matrix4x4* world1=null);
92 
93  // Collision queries
94  bool Collide(const AABBCollisionTree* tree0, const AABBCollisionTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
95  bool Collide(const AABBNoLeafTree* tree0, const AABBNoLeafTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
96  bool Collide(const AABBQuantizedTree* tree0, const AABBQuantizedTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
97  bool Collide(const AABBQuantizedNoLeafTree* tree0, const AABBQuantizedNoLeafTree* tree1, const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
98  // Settings
99 
101 
106  inline_ void SetFullBoxBoxTest(bool flag) { mFullBoxBoxTest = flag; }
108 
110 
115  void SetFullPrimBoxTest(bool flag) { mFullPrimBoxTest = flag; }
117 
118  // Stats
119 
121 
127  inline_ udword GetNbBVBVTests() const { return mNbBVBVTests; }
129 
131 
137  inline_ udword GetNbPrimPrimTests() const { return mNbPrimPrimTests; }
139 
141 
147  inline_ udword GetNbBVPrimTests() const { return mNbBVPrimTests; }
149 
150  // Data access
151 
153 
159  inline_ udword GetNbPairs() const { return mPairs.GetNbEntries()>>1; }
161 
163 
169  inline_ const Pair* GetPairs() const { return (const Pair*)mPairs.GetEntries(); }
171 
173 
177  override(Collider) const char* ValidateSettings();
179 
180  protected:
181  // Colliding pairs
183  // User mesh interfaces
186  // Stats
190  // Precomputed data
196  // Dequantization coeffs
201  // Leaf description
202  Point mLeafVerts[3];
204  // Settings
207  // Internal methods
208 
209  // Standard AABB trees
210  void _Collide(const AABBCollisionNode* b0, const AABBCollisionNode* b1);
211  // Quantized AABB trees
212  void _Collide(const AABBQuantizedNode* b0, const AABBQuantizedNode* b1, const Point& a, const Point& Pa, const Point& b, const Point& Pb);
213  // No-leaf AABB trees
214  void _CollideTriBox(const AABBNoLeafNode* b);
215  void _CollideBoxTri(const AABBNoLeafNode* b);
216  void _Collide(const AABBNoLeafNode* a, const AABBNoLeafNode* b);
217  // Quantized no-leaf AABB trees
218  void _CollideTriBox(const AABBQuantizedNoLeafNode* b);
219  void _CollideBoxTri(const AABBQuantizedNoLeafNode* b);
220  void _Collide(const AABBQuantizedNoLeafNode* a, const AABBQuantizedNoLeafNode* b);
221  // Overlap tests
222  void PrimTest(udword id0, udword id1);
223  inline_ void PrimTestTriIndex(udword id1);
224  inline_ void PrimTestIndexTri(udword id0);
225 
226  inline_ bool BoxBoxOverlap(const Point& ea, const Point& ca, const Point& eb, const Point& cb);
227  inline_ bool TriBoxOverlap(const Point& center, const Point& extents);
228  inline_ bool TriTriOverlap(const Point& V0, const Point& V1, const Point& V2, const Point& U0, const Point& U1, const Point& U2);
229  // Init methods
230  void InitQuery(const Matrix4x4* world0=null, const Matrix4x4* world1=null);
231  bool CheckTemporalCoherence(Pair* cache);
232 
233  inline_ bool Setup(const MeshInterface* mi0, const MeshInterface* mi1)
234  {
235  mIMesh0 = mi0;
236  mIMesh1 = mi1;
237 
238  if(!mIMesh0 || !mIMesh1) return FALSE;
239 
240  return TRUE;
241  }
242  };
243 
244 #endif // __OPC_TREECOLLIDER_H__