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
AABBTreeCollider Class Reference

#include <OPC_TreeCollider.h>

Inheritance diagram for AABBTreeCollider:
Collider

Public Member Functions

 AABBTreeCollider ()
 
virtual ~AABBTreeCollider ()
 
bool Collide (BVTCache &cache, const Matrix4x4 *world0=null, const Matrix4x4 *world1=null)
 
bool Collide (const AABBCollisionTree *tree0, const AABBCollisionTree *tree1, const Matrix4x4 *world0=null, const Matrix4x4 *world1=null, Pair *cache=null)
 
bool Collide (const AABBNoLeafTree *tree0, const AABBNoLeafTree *tree1, const Matrix4x4 *world0=null, const Matrix4x4 *world1=null, Pair *cache=null)
 
bool Collide (const AABBQuantizedTree *tree0, const AABBQuantizedTree *tree1, const Matrix4x4 *world0=null, const Matrix4x4 *world1=null, Pair *cache=null)
 
bool Collide (const AABBQuantizedNoLeafTree *tree0, const AABBQuantizedNoLeafTree *tree1, const Matrix4x4 *world0=null, const Matrix4x4 *world1=null, Pair *cache=null)
 
inline_ void SetFullBoxBoxTest (bool flag)
 
void SetFullPrimBoxTest (bool flag)
 
inline_ udword GetNbBVBVTests () const
 
inline_ udword GetNbPrimPrimTests () const
 
inline_ udword GetNbBVPrimTests () const
 
inline_ udword GetNbPairs () const
 
inline_ const PairGetPairs () const
 
 override (Collider) const char *ValidateSettings()
 
- Public Member Functions inherited from Collider
 Collider ()
 
virtual ~Collider ()
 
inline_ BOOL GetContactStatus () const
 
inline_ BOOL FirstContactEnabled () const
 
inline_ BOOL TemporalCoherenceEnabled () const
 
inline_ BOOL ContactFound () const
 
inline_ BOOL TemporalHit () const
 
inline_ BOOL SkipPrimitiveTests () const
 
inline_ void SetFirstContact (bool flag)
 
inline_ void SetTemporalCoherence (bool flag)
 
inline_ void SetPrimitiveTests (bool flag)
 
virtual const char * ValidateSettings ()=0
 

Protected Member Functions

void _Collide (const AABBCollisionNode *b0, const AABBCollisionNode *b1)
 
void _Collide (const AABBQuantizedNode *b0, const AABBQuantizedNode *b1, const Point &a, const Point &Pa, const Point &b, const Point &Pb)
 
void _CollideTriBox (const AABBNoLeafNode *b)
 
void _CollideBoxTri (const AABBNoLeafNode *b)
 
void _Collide (const AABBNoLeafNode *a, const AABBNoLeafNode *b)
 
void _CollideTriBox (const AABBQuantizedNoLeafNode *b)
 
void _CollideBoxTri (const AABBQuantizedNoLeafNode *b)
 
void _Collide (const AABBQuantizedNoLeafNode *a, const AABBQuantizedNoLeafNode *b)
 
void PrimTest (udword id0, udword id1)
 
inline_ void PrimTestTriIndex (udword id1)
 
inline_ void PrimTestIndexTri (udword id0)
 
inline_ bool BoxBoxOverlap (const Point &ea, const Point &ca, const Point &eb, const Point &cb)
 
inline_ bool TriBoxOverlap (const Point &center, const Point &extents)
 
inline_ bool TriTriOverlap (const Point &V0, const Point &V1, const Point &V2, const Point &U0, const Point &U1, const Point &U2)
 
void InitQuery (const Matrix4x4 *world0=null, const Matrix4x4 *world1=null)
 
bool CheckTemporalCoherence (Pair *cache)
 
inline_ bool Setup (const MeshInterface *mi0, const MeshInterface *mi1)
 
- Protected Member Functions inherited from Collider
inline_ BOOL Setup (const BaseModel *model)
 
virtual inline_ void InitQuery ()
 

Protected Attributes

Container mPairs
 Pairs of colliding primitives. More...
 
const MeshInterfacemIMesh0
 User-defined mesh interface for object0. More...
 
const MeshInterfacemIMesh1
 User-defined mesh interface for object1. More...
 
udword mNbBVBVTests
 Number of BV-BV tests. More...
 
udword mNbPrimPrimTests
 Number of Primitive-Primitive tests. More...
 
udword mNbBVPrimTests
 Number of BV-Primitive tests. More...
 
Matrix3x3 mAR
 Absolute rotation matrix. More...
 
Matrix3x3 mR0to1
 Rotation from object0 to object1. More...
 
Matrix3x3 mR1to0
 Rotation from object1 to object0. More...
 
Point mT0to1
 Translation from object0 to object1. More...
 
Point mT1to0
 Translation from object1 to object0. More...
 
Point mCenterCoeff0
 
Point mExtentsCoeff0
 
Point mCenterCoeff1
 
Point mExtentsCoeff1
 
Point mLeafVerts [3]
 Triangle vertices. More...
 
udword mLeafIndex
 Triangle index. More...
 
bool mFullBoxBoxTest
 Perform full BV-BV tests (true) or SAT-lite tests (false) More...
 
bool mFullPrimBoxTest
 Perform full Primitive-BV tests (true) or SAT-lite tests (false) More...
 
- Protected Attributes inherited from Collider
udword mFlags
 Bit flags. More...
 
const BaseModelmCurrentModel
 Current model for collision query (owner of touched faces) More...
 
const MeshInterfacemIMesh
 User-defined mesh interface. More...
 

Detailed Description

Contains an AABB tree collider. This class performs a collision test between two AABB trees.

Author
Pierre Terdiman
Version
1.3
Date
March, 20, 2001

Definition at line 69 of file OPC_TreeCollider.h.

Constructor & Destructor Documentation

AABBTreeCollider::AABBTreeCollider ( )
virtual AABBTreeCollider::~AABBTreeCollider ( )
virtual

Member Function Documentation

void AABBTreeCollider::_Collide ( const AABBCollisionNode b0,
const AABBCollisionNode b1 
)
protected
void AABBTreeCollider::_Collide ( const AABBQuantizedNode b0,
const AABBQuantizedNode b1,
const Point a,
const Point Pa,
const Point b,
const Point Pb 
)
protected
void AABBTreeCollider::_Collide ( const AABBNoLeafNode a,
const AABBNoLeafNode b 
)
protected
void AABBTreeCollider::_Collide ( const AABBQuantizedNoLeafNode a,
const AABBQuantizedNoLeafNode b 
)
protected
void AABBTreeCollider::_CollideBoxTri ( const AABBNoLeafNode b)
protected
void AABBTreeCollider::_CollideBoxTri ( const AABBQuantizedNoLeafNode b)
protected
void AABBTreeCollider::_CollideTriBox ( const AABBNoLeafNode b)
protected
void AABBTreeCollider::_CollideTriBox ( const AABBQuantizedNoLeafNode b)
protected
inline_ bool AABBTreeCollider::BoxBoxOverlap ( const Point ea,
const Point ca,
const Point eb,
const Point cb 
)
protected

OBB-OBB overlap test using the separating axis theorem.

  • original code by Gomez / Gamasutra (similar to Gottschalk's one in RAPID)
  • optimized for AABB trees by computing the rotation matrix once (SOLID-fashion)
  • the fabs matrix is precomputed as well and epsilon-tweaked (RAPID-style, we found this almost mandatory)
  • Class III axes can be disabled... (SOLID & Intel fashion)
  • ...or enabled to perform some profiling
  • CPU comparisons used when appropriate
  • lazy evaluation sometimes saves some work in case of early exits (unlike SOLID)
Parameters
ea[in] extents from box A
ca[in] center from box A
eb[in] extents from box B
cb[in] center from box B
Returns
true if boxes overlap

Definition at line 19 of file OPC_BoxBoxOverlap.h.

20 {
21  // Stats
22  mNbBVBVTests++;
23 
24  float t,t2;
25 
26  // Class I : A's basis vectors
27  float Tx = (mR1to0.m[0][0]*cb.x + mR1to0.m[1][0]*cb.y + mR1to0.m[2][0]*cb.z) + mT1to0.x - ca.x;
28  t = ea.x + eb.x*mAR.m[0][0] + eb.y*mAR.m[1][0] + eb.z*mAR.m[2][0];
29  if(GREATER(Tx, t)) return FALSE;
30 
31  float Ty = (mR1to0.m[0][1]*cb.x + mR1to0.m[1][1]*cb.y + mR1to0.m[2][1]*cb.z) + mT1to0.y - ca.y;
32  t = ea.y + eb.x*mAR.m[0][1] + eb.y*mAR.m[1][1] + eb.z*mAR.m[2][1];
33  if(GREATER(Ty, t)) return FALSE;
34 
35  float Tz = (mR1to0.m[0][2]*cb.x + mR1to0.m[1][2]*cb.y + mR1to0.m[2][2]*cb.z) + mT1to0.z - ca.z;
36  t = ea.z + eb.x*mAR.m[0][2] + eb.y*mAR.m[1][2] + eb.z*mAR.m[2][2];
37  if(GREATER(Tz, t)) return FALSE;
38 
39  // Class II : B's basis vectors
40  t = Tx*mR1to0.m[0][0] + Ty*mR1to0.m[0][1] + Tz*mR1to0.m[0][2]; t2 = ea.x*mAR.m[0][0] + ea.y*mAR.m[0][1] + ea.z*mAR.m[0][2] + eb.x;
41  if(GREATER(t, t2)) return FALSE;
42 
43  t = Tx*mR1to0.m[1][0] + Ty*mR1to0.m[1][1] + Tz*mR1to0.m[1][2]; t2 = ea.x*mAR.m[1][0] + ea.y*mAR.m[1][1] + ea.z*mAR.m[1][2] + eb.y;
44  if(GREATER(t, t2)) return FALSE;
45 
46  t = Tx*mR1to0.m[2][0] + Ty*mR1to0.m[2][1] + Tz*mR1to0.m[2][2]; t2 = ea.x*mAR.m[2][0] + ea.y*mAR.m[2][1] + ea.z*mAR.m[2][2] + eb.z;
47  if(GREATER(t, t2)) return FALSE;
48 
49  // Class III : 9 cross products
50  // Cool trick: always perform the full test for first level, regardless of settings.
51  // That way pathological cases (such as the pencils scene) are quickly rejected anyway !
53  {
54  t = Tz*mR1to0.m[0][1] - Ty*mR1to0.m[0][2]; t2 = ea.y*mAR.m[0][2] + ea.z*mAR.m[0][1] + eb.y*mAR.m[2][0] + eb.z*mAR.m[1][0]; if(GREATER(t, t2)) return FALSE; // L = A0 x B0
55  t = Tz*mR1to0.m[1][1] - Ty*mR1to0.m[1][2]; t2 = ea.y*mAR.m[1][2] + ea.z*mAR.m[1][1] + eb.x*mAR.m[2][0] + eb.z*mAR.m[0][0]; if(GREATER(t, t2)) return FALSE; // L = A0 x B1
56  t = Tz*mR1to0.m[2][1] - Ty*mR1to0.m[2][2]; t2 = ea.y*mAR.m[2][2] + ea.z*mAR.m[2][1] + eb.x*mAR.m[1][0] + eb.y*mAR.m[0][0]; if(GREATER(t, t2)) return FALSE; // L = A0 x B2
57  t = Tx*mR1to0.m[0][2] - Tz*mR1to0.m[0][0]; t2 = ea.x*mAR.m[0][2] + ea.z*mAR.m[0][0] + eb.y*mAR.m[2][1] + eb.z*mAR.m[1][1]; if(GREATER(t, t2)) return FALSE; // L = A1 x B0
58  t = Tx*mR1to0.m[1][2] - Tz*mR1to0.m[1][0]; t2 = ea.x*mAR.m[1][2] + ea.z*mAR.m[1][0] + eb.x*mAR.m[2][1] + eb.z*mAR.m[0][1]; if(GREATER(t, t2)) return FALSE; // L = A1 x B1
59  t = Tx*mR1to0.m[2][2] - Tz*mR1to0.m[2][0]; t2 = ea.x*mAR.m[2][2] + ea.z*mAR.m[2][0] + eb.x*mAR.m[1][1] + eb.y*mAR.m[0][1]; if(GREATER(t, t2)) return FALSE; // L = A1 x B2
60  t = Ty*mR1to0.m[0][0] - Tx*mR1to0.m[0][1]; t2 = ea.x*mAR.m[0][1] + ea.y*mAR.m[0][0] + eb.y*mAR.m[2][2] + eb.z*mAR.m[1][2]; if(GREATER(t, t2)) return FALSE; // L = A2 x B0
61  t = Ty*mR1to0.m[1][0] - Tx*mR1to0.m[1][1]; t2 = ea.x*mAR.m[1][1] + ea.y*mAR.m[1][0] + eb.x*mAR.m[2][2] + eb.z*mAR.m[0][2]; if(GREATER(t, t2)) return FALSE; // L = A2 x B1
62  t = Ty*mR1to0.m[2][0] - Tx*mR1to0.m[2][1]; t2 = ea.x*mAR.m[2][1] + ea.y*mAR.m[2][0] + eb.x*mAR.m[1][2] + eb.y*mAR.m[0][2]; if(GREATER(t, t2)) return FALSE; // L = A2 x B2
63  }
64  return TRUE;
65 }
bool AABBTreeCollider::CheckTemporalCoherence ( Pair cache)
protected
bool AABBTreeCollider::Collide ( BVTCache cache,
const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null 
)

Generic collision query for generic OPCODE models. After the call, access the results with:

Parameters
cache[in] collision cache for model pointers and a colliding pair of primitives
world0[in] world matrix for first object, or null
world1[in] world matrix for second object, or null
Returns
true if success
Warning
SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
bool AABBTreeCollider::Collide ( const AABBCollisionTree tree0,
const AABBCollisionTree tree1,
const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null,
Pair cache = null 
)
bool AABBTreeCollider::Collide ( const AABBNoLeafTree tree0,
const AABBNoLeafTree tree1,
const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null,
Pair cache = null 
)
bool AABBTreeCollider::Collide ( const AABBQuantizedTree tree0,
const AABBQuantizedTree tree1,
const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null,
Pair cache = null 
)
bool AABBTreeCollider::Collide ( const AABBQuantizedNoLeafTree tree0,
const AABBQuantizedNoLeafTree tree1,
const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null,
Pair cache = null 
)
inline_ udword AABBTreeCollider::GetNbBVBVTests ( ) const
inline

Stats: gets the number of BV-BV overlap tests after a collision query.

See Also
GetNbPrimPrimTests()
GetNbBVPrimTests()
Returns
the number of BV-BV tests performed during last query

Definition at line 128 of file OPC_TreeCollider.h.

128 { return mNbBVBVTests; }
inline_ udword AABBTreeCollider::GetNbBVPrimTests ( ) const
inline

Stats: gets the number of BV-Triangle overlap tests after a collision query.

See Also
GetNbBVBVTests()
GetNbPrimPrimTests()
Returns
the number of BV-Triangle tests performed during last query

Definition at line 148 of file OPC_TreeCollider.h.

148 { return mNbBVPrimTests; }
inline_ udword AABBTreeCollider::GetNbPairs ( ) const
inline

Gets the number of contacts after a collision query.

See Also
GetContactStatus()
GetPairs()
Returns
the number of contacts / colliding pairs.

Definition at line 160 of file OPC_TreeCollider.h.

160 { return mPairs.GetNbEntries()>>1; }
inline_ udword AABBTreeCollider::GetNbPrimPrimTests ( ) const
inline

Stats: gets the number of Triangle-Triangle overlap tests after a collision query.

See Also
GetNbBVBVTests()
GetNbBVPrimTests()
Returns
the number of Triangle-Triangle tests performed during last query

Definition at line 138 of file OPC_TreeCollider.h.

138 { return mNbPrimPrimTests; }
inline_ const Pair* AABBTreeCollider::GetPairs ( ) const
inline

Gets the pairs of colliding triangles after a collision query.

See Also
GetContactStatus()
GetNbPairs()
Returns
the list of colliding pairs (triangle indices)

Definition at line 170 of file OPC_TreeCollider.h.

170 { return (const Pair*)mPairs.GetEntries(); }
void AABBTreeCollider::InitQuery ( const Matrix4x4 world0 = null,
const Matrix4x4 world1 = null 
)
protected
AABBTreeCollider::override ( Collider  ) const

Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider.

Returns
null if everything is ok, else a string describing the problem
void AABBTreeCollider::PrimTest ( udword  id0,
udword  id1 
)
protected
inline_ void AABBTreeCollider::PrimTestIndexTri ( udword  id0)
protected
inline_ void AABBTreeCollider::PrimTestTriIndex ( udword  id1)
protected
inline_ void AABBTreeCollider::SetFullBoxBoxTest ( bool  flag)
inline

Settings: selects between full box-box tests or "SAT-lite" tests (where Class III axes are discarded)

Parameters
flag[in] true for full tests, false for coarse tests
See Also
SetFullPrimBoxTest(bool flag)

Definition at line 107 of file OPC_TreeCollider.h.

107 { mFullBoxBoxTest = flag; }
void AABBTreeCollider::SetFullPrimBoxTest ( bool  flag)
inline

Settings: selects between full triangle-box tests or "SAT-lite" tests (where Class III axes are discarded)

Parameters
flag[in] true for full tests, false for coarse tests
See Also
SetFullBoxBoxTest(bool flag)

Definition at line 116 of file OPC_TreeCollider.h.

116 { mFullPrimBoxTest = flag; }
inline_ bool AABBTreeCollider::Setup ( const MeshInterface mi0,
const MeshInterface mi1 
)
inlineprotected

Definition at line 233 of file OPC_TreeCollider.h.

References FALSE, and TRUE.

234  {
235  mIMesh0 = mi0;
236  mIMesh1 = mi1;
237 
238  if(!mIMesh0 || !mIMesh1) return FALSE;
239 
240  return TRUE;
241  }
inline_ bool AABBTreeCollider::TriBoxOverlap ( const Point center,
const Point extents 
)
protected

Triangle-Box overlap test using the separating axis theorem. This is the code from Tomas Möller, a bit optimized:

  • with some more lazy evaluation (faster path on PC)
  • with a tiny bit of assembly
  • with "SAT-lite" applied if needed
  • and perhaps with some more minor modifs...
Parameters
center[in] box center
extents[in] box extents
Returns
true if triangle & box overlap

Definition at line 118 of file OPC_TriBoxOverlap.h.

119 {
120  // Stats
121  mNbBVPrimTests++;
122 
123  // use separating axis theorem to test overlap between triangle and box
124  // need to test for overlap in these directions:
125  // 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle
126  // we do not even need to test these)
127  // 2) normal of the triangle
128  // 3) crossproduct(edge from tri, {x,y,z}-directin)
129  // this gives 3x3=9 more tests
130 
131  // move everything so that the boxcenter is in (0,0,0)
132  Point v0, v1, v2;
133  v0.x = mLeafVerts[0].x - center.x;
134  v1.x = mLeafVerts[1].x - center.x;
135  v2.x = mLeafVerts[2].x - center.x;
136 
137  // First, test overlap in the {x,y,z}-directions
138 #ifdef OPC_USE_FCOMI
139  // find min, max of the triangle in x-direction, and test for overlap in X
140  if(FCMin3(v0.x, v1.x, v2.x)>extents.x) return FALSE;
141  if(FCMax3(v0.x, v1.x, v2.x)<-extents.x) return FALSE;
142 
143  // same for Y
144  v0.y = mLeafVerts[0].y - center.y;
145  v1.y = mLeafVerts[1].y - center.y;
146  v2.y = mLeafVerts[2].y - center.y;
147 
148  if(FCMin3(v0.y, v1.y, v2.y)>extents.y) return FALSE;
149  if(FCMax3(v0.y, v1.y, v2.y)<-extents.y) return FALSE;
150 
151  // same for Z
152  v0.z = mLeafVerts[0].z - center.z;
153  v1.z = mLeafVerts[1].z - center.z;
154  v2.z = mLeafVerts[2].z - center.z;
155 
156  if(FCMin3(v0.z, v1.z, v2.z)>extents.z) return FALSE;
157  if(FCMax3(v0.z, v1.z, v2.z)<-extents.z) return FALSE;
158 #else
159  float min,max;
160  // Find min, max of the triangle in x-direction, and test for overlap in X
161  FINDMINMAX(v0.x, v1.x, v2.x, min, max);
162  if(min>extents.x || max<-extents.x) return FALSE;
163 
164  // Same for Y
165  v0.y = mLeafVerts[0].y - center.y;
166  v1.y = mLeafVerts[1].y - center.y;
167  v2.y = mLeafVerts[2].y - center.y;
168 
169  FINDMINMAX(v0.y, v1.y, v2.y, min, max);
170  if(min>extents.y || max<-extents.y) return FALSE;
171 
172  // Same for Z
173  v0.z = mLeafVerts[0].z - center.z;
174  v1.z = mLeafVerts[1].z - center.z;
175  v2.z = mLeafVerts[2].z - center.z;
176 
177  FINDMINMAX(v0.z, v1.z, v2.z, min, max);
178  if(min>extents.z || max<-extents.z) return FALSE;
179 #endif
180  // 2) Test if the box intersects the plane of the triangle
181  // compute plane equation of triangle: normal*x+d=0
182  // ### could be precomputed since we use the same leaf triangle several times
183  const Point e0 = v1 - v0;
184  const Point e1 = v2 - v1;
185  const Point normal = e0 ^ e1;
186  const float d = -normal|v0;
187  if(!planeBoxOverlap(normal, d, extents)) return FALSE;
188 
189  // 3) "Class III" tests
190  if(mFullPrimBoxTest)
191  {
193  }
194  return TRUE;
195 }
inline_ bool AABBTreeCollider::TriTriOverlap ( const Point V0,
const Point V1,
const Point V2,
const Point U0,
const Point U1,
const Point U2 
)
protected

Triangle/triangle intersection test routine, by Tomas Moller, 1997. See article "A Fast Triangle-Triangle Intersection Test", Journal of Graphics Tools, 2(2), 1997

Updated June 1999: removed the divisions – a little faster now! Updated October 1999: added {} to CROSS and SUB macros

int NoDivTriTriIsect(float V0[3],float V1[3],float V2[3], float U0[3],float U1[3],float U2[3])

Parameters
V0[in] triangle 0, vertex 0
V1[in] triangle 0, vertex 1
V2[in] triangle 0, vertex 2
U0[in] triangle 1, vertex 0
U1[in] triangle 1, vertex 1
U2[in] triangle 1, vertex 2
Returns
true if triangles overlap

Definition at line 179 of file OPC_TriTriOverlap.h.

180 {
181  // Stats
183 
184  // Compute plane equation of triangle(V0,V1,V2)
185  Point E1 = V1 - V0;
186  Point E2 = V2 - V0;
187  const Point N1 = E1 ^ E2;
188  const float d1 =-N1 | V0;
189  // Plane equation 1: N1.X+d1=0
190 
191  // Put U0,U1,U2 into plane equation 1 to compute signed distances to the plane
192  float du0 = (N1|U0) + d1;
193  float du1 = (N1|U1) + d1;
194  float du2 = (N1|U2) + d1;
195 
196  // Coplanarity robustness check
197 #ifdef OPC_TRITRI_EPSILON_TEST
198  if(fabsf(du0)<LOCAL_EPSILON) du0 = 0.0f;
199  if(fabsf(du1)<LOCAL_EPSILON) du1 = 0.0f;
200  if(fabsf(du2)<LOCAL_EPSILON) du2 = 0.0f;
201 #endif
202  const float du0du1 = du0 * du1;
203  const float du0du2 = du0 * du2;
204 
205  if(du0du1>0.0f && du0du2>0.0f) // same sign on all of them + not equal 0 ?
206  return FALSE; // no intersection occurs
207 
208  // Compute plane of triangle (U0,U1,U2)
209  E1 = U1 - U0;
210  E2 = U2 - U0;
211  const Point N2 = E1 ^ E2;
212  const float d2=-N2 | U0;
213  // plane equation 2: N2.X+d2=0
214 
215  // put V0,V1,V2 into plane equation 2
216  float dv0 = (N2|V0) + d2;
217  float dv1 = (N2|V1) + d2;
218  float dv2 = (N2|V2) + d2;
219 
220 #ifdef OPC_TRITRI_EPSILON_TEST
221  if(fabsf(dv0)<LOCAL_EPSILON) dv0 = 0.0f;
222  if(fabsf(dv1)<LOCAL_EPSILON) dv1 = 0.0f;
223  if(fabsf(dv2)<LOCAL_EPSILON) dv2 = 0.0f;
224 #endif
225 
226  const float dv0dv1 = dv0 * dv1;
227  const float dv0dv2 = dv0 * dv2;
228 
229  if(dv0dv1>0.0f && dv0dv2>0.0f) // same sign on all of them + not equal 0 ?
230  return FALSE; // no intersection occurs
231 
232  // Compute direction of intersection line
233  const Point D = N1^N2;
234 
235  // Compute and index to the largest component of D
236  float max=fabsf(D[0]);
237  short index=0;
238  float bb=fabsf(D[1]);
239  float cc=fabsf(D[2]);
240  if(bb>max) max=bb,index=1;
241  if(cc>max) max=cc,index=2;
242 
243  // This is the simplified projection onto L
244  const float vp0 = V0[index];
245  const float vp1 = V1[index];
246  const float vp2 = V2[index];
247 
248  const float up0 = U0[index];
249  const float up1 = U1[index];
250  const float up2 = U2[index];
251 
252  // Compute interval for triangle 1
253  float a,b,c,x0,x1;
254  NEWCOMPUTE_INTERVALS(vp0,vp1,vp2,dv0,dv1,dv2,dv0dv1,dv0dv2,a,b,c,x0,x1);
255 
256  // Compute interval for triangle 2
257  float d,e,f,y0,y1;
258  NEWCOMPUTE_INTERVALS(up0,up1,up2,du0,du1,du2,du0du1,du0du2,d,e,f,y0,y1);
259 
260  const float xx=x0*x1;
261  const float yy=y0*y1;
262  const float xxyy=xx*yy;
263 
264  float isect1[2], isect2[2];
265 
266  float tmp=a*xxyy;
267  isect1[0]=tmp+b*x1*yy;
268  isect1[1]=tmp+c*x0*yy;
269 
270  tmp=d*xxyy;
271  isect2[0]=tmp+e*xx*y1;
272  isect2[1]=tmp+f*xx*y0;
273 
274  SORT(isect1[0],isect1[1]);
275  SORT(isect2[0],isect2[1]);
276 
277  if(isect1[1]<isect2[0] || isect2[1]<isect1[0]) return FALSE;
278  return TRUE;
279 }

Member Data Documentation

Matrix3x3 AABBTreeCollider::mAR
protected

Absolute rotation matrix.

Definition at line 191 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mCenterCoeff0
protected

Definition at line 197 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mCenterCoeff1
protected

Definition at line 199 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mExtentsCoeff0
protected

Definition at line 198 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mExtentsCoeff1
protected

Definition at line 200 of file OPC_TreeCollider.h.

bool AABBTreeCollider::mFullBoxBoxTest
protected

Perform full BV-BV tests (true) or SAT-lite tests (false)

Definition at line 205 of file OPC_TreeCollider.h.

bool AABBTreeCollider::mFullPrimBoxTest
protected

Perform full Primitive-BV tests (true) or SAT-lite tests (false)

Definition at line 206 of file OPC_TreeCollider.h.

const MeshInterface* AABBTreeCollider::mIMesh0
protected

User-defined mesh interface for object0.

Definition at line 184 of file OPC_TreeCollider.h.

const MeshInterface* AABBTreeCollider::mIMesh1
protected

User-defined mesh interface for object1.

Definition at line 185 of file OPC_TreeCollider.h.

udword AABBTreeCollider::mLeafIndex
protected

Triangle index.

Definition at line 203 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mLeafVerts[3]
protected

Triangle vertices.

Definition at line 202 of file OPC_TreeCollider.h.

udword AABBTreeCollider::mNbBVBVTests
protected

Number of BV-BV tests.

Definition at line 187 of file OPC_TreeCollider.h.

udword AABBTreeCollider::mNbBVPrimTests
protected

Number of BV-Primitive tests.

Definition at line 189 of file OPC_TreeCollider.h.

udword AABBTreeCollider::mNbPrimPrimTests
protected

Number of Primitive-Primitive tests.

Definition at line 188 of file OPC_TreeCollider.h.

Container AABBTreeCollider::mPairs
protected

Pairs of colliding primitives.

Definition at line 182 of file OPC_TreeCollider.h.

Matrix3x3 AABBTreeCollider::mR0to1
protected

Rotation from object0 to object1.

Definition at line 192 of file OPC_TreeCollider.h.

Matrix3x3 AABBTreeCollider::mR1to0
protected

Rotation from object1 to object0.

Definition at line 193 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mT0to1
protected

Translation from object0 to object1.

Definition at line 194 of file OPC_TreeCollider.h.

Point AABBTreeCollider::mT1to0
protected

Translation from object1 to object0.

Definition at line 195 of file OPC_TreeCollider.h.


The documentation for this class was generated from the following files: