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

#include <OPC_OBBCollider.h>

Inheritance diagram for OBBCollider:
VolumeCollider Collider HybridOBBCollider

Public Member Functions

 OBBCollider ()
 
virtual ~OBBCollider ()
 
bool Collide (OBBCache &cache, const OBB &box, const Model &model, const Matrix4x4 *worldb=null, const Matrix4x4 *worldm=null)
 
inline_ void SetFullBoxBoxTest (bool flag)
 
 override (Collider) const char *ValidateSettings()
 
- Public Member Functions inherited from VolumeCollider
 VolumeCollider ()
 
virtual ~VolumeCollider ()=0
 
inline_ udword GetNbTouchedPrimitives () const
 
inline_ const udwordGetTouchedPrimitives () const
 
inline_ udword GetNbVolumeBVTests () const
 
inline_ udword GetNbVolumePrimTests () 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 *node)
 
void _Collide (const AABBNoLeafNode *node)
 
void _Collide (const AABBQuantizedNode *node)
 
void _Collide (const AABBQuantizedNoLeafNode *node)
 
void _CollideNoPrimitiveTest (const AABBCollisionNode *node)
 
void _CollideNoPrimitiveTest (const AABBNoLeafNode *node)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNode *node)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNoLeafNode *node)
 
inline_ bool OBBContainsBox (const Point &bc, const Point &be)
 
inline_ bool BoxBoxOverlap (const Point &extents, const Point &center)
 A dedicated version when one box is constant. More...
 
inline_ bool TriBoxOverlap ()
 A dedicated version where the box is constant. More...
 
bool InitQuery (OBBCache &cache, const OBB &box, const Matrix4x4 *worldb=null, const Matrix4x4 *worldm=null)
 
- Protected Member Functions inherited from VolumeCollider
void _Dump (const AABBCollisionNode *node)
 
void _Dump (const AABBNoLeafNode *node)
 
void _Dump (const AABBQuantizedNode *node)
 
void _Dump (const AABBQuantizedNoLeafNode *node)
 
 override (Collider) inline_ void InitQuery()
 
inline_ BOOL IsCacheValid (VolumeCache &cache)
 
- Protected Member Functions inherited from Collider
inline_ BOOL Setup (const BaseModel *model)
 
virtual inline_ void InitQuery ()
 

Protected Attributes

Matrix3x3 mAR
 Absolute rotation matrix. More...
 
Matrix3x3 mRModelToBox
 Rotation from model space to obb space. More...
 
Matrix3x3 mRBoxToModel
 Rotation from obb space to model space. More...
 
Point mTModelToBox
 Translation from model space to obb space. More...
 
Point mTBoxToModel
 Translation from obb space to model space. More...
 
Point mBoxExtents
 
Point mB0
 
Point mB1
 
float mBBx1
 
float mBBy1
 
float mBBz1
 
float mBB_1
 
float mBB_2
 
float mBB_3
 
float mBB_4
 
float mBB_5
 
float mBB_6
 
float mBB_7
 
float mBB_8
 
float mBB_9
 
Point mLeafVerts [3]
 Triangle vertices. More...
 
bool mFullBoxBoxTest
 Perform full BV-BV tests (true) or SAT-lite tests (false) More...
 
- Protected Attributes inherited from VolumeCollider
ContainermTouchedPrimitives
 List of touched primitives. More...
 
Point mCenterCoeff
 
Point mExtentsCoeff
 
udword mNbVolumeBVTests
 Number of Volume-BV tests. More...
 
udword mNbVolumePrimTests
 Number of Volume-Primitive tests. 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 OBB-vs-tree collider.

Author
Pierre Terdiman
Version
1.3
Date
January, 1st, 2002

Definition at line 38 of file OPC_OBBCollider.h.

Constructor & Destructor Documentation

OBBCollider::OBBCollider ( )
virtual OBBCollider::~OBBCollider ( )
virtual

Member Function Documentation

void OBBCollider::_Collide ( const AABBCollisionNode node)
protected
void OBBCollider::_Collide ( const AABBNoLeafNode node)
protected
void OBBCollider::_Collide ( const AABBQuantizedNode node)
protected
void OBBCollider::_Collide ( const AABBQuantizedNoLeafNode node)
protected
void OBBCollider::_CollideNoPrimitiveTest ( const AABBCollisionNode node)
protected
void OBBCollider::_CollideNoPrimitiveTest ( const AABBNoLeafNode node)
protected
void OBBCollider::_CollideNoPrimitiveTest ( const AABBQuantizedNode node)
protected
void OBBCollider::_CollideNoPrimitiveTest ( const AABBQuantizedNoLeafNode node)
protected
inline_ bool OBBCollider::BoxBoxOverlap ( const Point extents,
const Point center 
)
protected

A dedicated version when one box is constant.

Definition at line 68 of file OPC_BoxBoxOverlap.h.

References FALSE, GREATER, Matrix3x3::m, mAR, mBB_1, mBB_2, mBB_3, mBB_4, mBB_5, mBB_6, mBB_7, mBB_8, mBB_9, mBBx1, mBBy1, mBBz1, mBoxExtents, mFullBoxBoxTest, VolumeCollider::mNbVolumeBVTests, mRBoxToModel, mTBoxToModel, TRUE, Point::x, Point::y, and Point::z.

69 {
70  // Stats
72 
73  float t,t2;
74 
75  // Class I : A's basis vectors
76  float Tx = mTBoxToModel.x - center.x; t = extents.x + mBBx1; if(GREATER(Tx, t)) return FALSE;
77  float Ty = mTBoxToModel.y - center.y; t = extents.y + mBBy1; if(GREATER(Ty, t)) return FALSE;
78  float Tz = mTBoxToModel.z - center.z; t = extents.z + mBBz1; if(GREATER(Tz, t)) return FALSE;
79 
80  // Class II : B's basis vectors
81  t = Tx*mRBoxToModel.m[0][0] + Ty*mRBoxToModel.m[0][1] + Tz*mRBoxToModel.m[0][2];
82  t2 = extents.x*mAR.m[0][0] + extents.y*mAR.m[0][1] + extents.z*mAR.m[0][2] + mBoxExtents.x;
83  if(GREATER(t, t2)) return FALSE;
84 
85  t = Tx*mRBoxToModel.m[1][0] + Ty*mRBoxToModel.m[1][1] + Tz*mRBoxToModel.m[1][2];
86  t2 = extents.x*mAR.m[1][0] + extents.y*mAR.m[1][1] + extents.z*mAR.m[1][2] + mBoxExtents.y;
87  if(GREATER(t, t2)) return FALSE;
88 
89  t = Tx*mRBoxToModel.m[2][0] + Ty*mRBoxToModel.m[2][1] + Tz*mRBoxToModel.m[2][2];
90  t2 = extents.x*mAR.m[2][0] + extents.y*mAR.m[2][1] + extents.z*mAR.m[2][2] + mBoxExtents.z;
91  if(GREATER(t, t2)) return FALSE;
92 
93  // Class III : 9 cross products
94  // Cool trick: always perform the full test for first level, regardless of settings.
95  // That way pathological cases (such as the pencils scene) are quickly rejected anyway !
97  {
98  t = Tz*mRBoxToModel.m[0][1] - Ty*mRBoxToModel.m[0][2]; t2 = extents.y*mAR.m[0][2] + extents.z*mAR.m[0][1] + mBB_1; if(GREATER(t, t2)) return FALSE; // L = A0 x B0
99  t = Tz*mRBoxToModel.m[1][1] - Ty*mRBoxToModel.m[1][2]; t2 = extents.y*mAR.m[1][2] + extents.z*mAR.m[1][1] + mBB_2; if(GREATER(t, t2)) return FALSE; // L = A0 x B1
100  t = Tz*mRBoxToModel.m[2][1] - Ty*mRBoxToModel.m[2][2]; t2 = extents.y*mAR.m[2][2] + extents.z*mAR.m[2][1] + mBB_3; if(GREATER(t, t2)) return FALSE; // L = A0 x B2
101  t = Tx*mRBoxToModel.m[0][2] - Tz*mRBoxToModel.m[0][0]; t2 = extents.x*mAR.m[0][2] + extents.z*mAR.m[0][0] + mBB_4; if(GREATER(t, t2)) return FALSE; // L = A1 x B0
102  t = Tx*mRBoxToModel.m[1][2] - Tz*mRBoxToModel.m[1][0]; t2 = extents.x*mAR.m[1][2] + extents.z*mAR.m[1][0] + mBB_5; if(GREATER(t, t2)) return FALSE; // L = A1 x B1
103  t = Tx*mRBoxToModel.m[2][2] - Tz*mRBoxToModel.m[2][0]; t2 = extents.x*mAR.m[2][2] + extents.z*mAR.m[2][0] + mBB_6; if(GREATER(t, t2)) return FALSE; // L = A1 x B2
104  t = Ty*mRBoxToModel.m[0][0] - Tx*mRBoxToModel.m[0][1]; t2 = extents.x*mAR.m[0][1] + extents.y*mAR.m[0][0] + mBB_7; if(GREATER(t, t2)) return FALSE; // L = A2 x B0
105  t = Ty*mRBoxToModel.m[1][0] - Tx*mRBoxToModel.m[1][1]; t2 = extents.x*mAR.m[1][1] + extents.y*mAR.m[1][0] + mBB_8; if(GREATER(t, t2)) return FALSE; // L = A2 x B1
106  t = Ty*mRBoxToModel.m[2][0] - Tx*mRBoxToModel.m[2][1]; t2 = extents.x*mAR.m[2][1] + extents.y*mAR.m[2][0] + mBB_9; if(GREATER(t, t2)) return FALSE; // L = A2 x B2
107  }
108  return TRUE;
109 }
bool OBBCollider::Collide ( OBBCache cache,
const OBB box,
const Model model,
const Matrix4x4 worldb = null,
const Matrix4x4 worldm = null 
)

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

Parameters
cache[in/out] a box cache
box[in] collision OBB in local space
model[in] Opcode model to collide with
worldb[in] OBB's world matrix, or null
worldm[in] model's world matrix, or null
Returns
true if success
Warning
SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
bool OBBCollider::InitQuery ( OBBCache cache,
const OBB box,
const Matrix4x4 worldb = null,
const Matrix4x4 worldm = null 
)
protected
inline_ bool OBBCollider::OBBContainsBox ( const Point bc,
const Point be 
)
protected
OBBCollider::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
inline_ void OBBCollider::SetFullBoxBoxTest ( bool  flag)
inline

Settings: select 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

Definition at line 71 of file OPC_OBBCollider.h.

71 { mFullBoxBoxTest = flag; }
inline_ bool OBBCollider::TriBoxOverlap ( )
protected

A dedicated version where the box is constant.

Definition at line 198 of file OPC_TriBoxOverlap.h.

References d, FALSE, FINDMINMAX, IMPLEMENT_CLASS3_TESTS, max(), mBoxExtents, min(), mLeafVerts, VolumeCollider::mNbVolumePrimTests, planeBoxOverlap(), TRUE, Point::x, Point::y, and Point::z.

199 {
200  // Stats
202 
203  // Hook
204  const Point& extents = mBoxExtents;
205  const Point& v0 = mLeafVerts[0];
206  const Point& v1 = mLeafVerts[1];
207  const Point& v2 = mLeafVerts[2];
208 
209  // use separating axis theorem to test overlap between triangle and box
210  // need to test for overlap in these directions:
211  // 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle
212  // we do not even need to test these)
213  // 2) normal of the triangle
214  // 3) crossproduct(edge from tri, {x,y,z}-directin)
215  // this gives 3x3=9 more tests
216 
217  // Box center is already in (0,0,0)
218 
219  // First, test overlap in the {x,y,z}-directions
220 #ifdef OPC_USE_FCOMI
221  // find min, max of the triangle in x-direction, and test for overlap in X
222  if(FCMin3(v0.x, v1.x, v2.x)>mBoxExtents.x) return FALSE;
223  if(FCMax3(v0.x, v1.x, v2.x)<-mBoxExtents.x) return FALSE;
224 
225  if(FCMin3(v0.y, v1.y, v2.y)>mBoxExtents.y) return FALSE;
226  if(FCMax3(v0.y, v1.y, v2.y)<-mBoxExtents.y) return FALSE;
227 
228  if(FCMin3(v0.z, v1.z, v2.z)>mBoxExtents.z) return FALSE;
229  if(FCMax3(v0.z, v1.z, v2.z)<-mBoxExtents.z) return FALSE;
230 #else
231  float min,max;
232  // Find min, max of the triangle in x-direction, and test for overlap in X
233  FINDMINMAX(v0.x, v1.x, v2.x, min, max);
234  if(min>mBoxExtents.x || max<-mBoxExtents.x) return FALSE;
235 
236  FINDMINMAX(v0.y, v1.y, v2.y, min, max);
237  if(min>mBoxExtents.y || max<-mBoxExtents.y) return FALSE;
238 
239  FINDMINMAX(v0.z, v1.z, v2.z, min, max);
240  if(min>mBoxExtents.z || max<-mBoxExtents.z) return FALSE;
241 #endif
242  // 2) Test if the box intersects the plane of the triangle
243  // compute plane equation of triangle: normal*x+d=0
244  // ### could be precomputed since we use the same leaf triangle several times
245  const Point e0 = v1 - v0;
246  const Point e1 = v2 - v1;
247  const Point normal = e0 ^ e1;
248  const float d = -normal|v0;
249  if(!planeBoxOverlap(normal, d, mBoxExtents)) return FALSE;
250 
251  // 3) "Class III" tests - here we always do full tests since the box is a primitive (not a BV)
252  {
254  }
255  return TRUE;
256 }

Member Data Documentation

Matrix3x3 OBBCollider::mAR
protected

Absolute rotation matrix.

Definition at line 85 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

Point OBBCollider::mB0
protected
  • mTModelToBox + mBoxExtents

Definition at line 92 of file OPC_OBBCollider.h.

Point OBBCollider::mB1
protected
  • mTModelToBox - mBoxExtents

Definition at line 93 of file OPC_OBBCollider.h.

float OBBCollider::mBB_1
protected

Definition at line 99 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_2
protected

Definition at line 100 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_3
protected

Definition at line 101 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_4
protected

Definition at line 102 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_5
protected

Definition at line 103 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_6
protected

Definition at line 104 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_7
protected

Definition at line 105 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_8
protected

Definition at line 106 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBB_9
protected

Definition at line 107 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBBx1
protected

Definition at line 95 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBBy1
protected

Definition at line 96 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

float OBBCollider::mBBz1
protected

Definition at line 97 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

Point OBBCollider::mBoxExtents
protected

Definition at line 91 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap(), and TriBoxOverlap().

bool OBBCollider::mFullBoxBoxTest
protected

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

Definition at line 112 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

Point OBBCollider::mLeafVerts[3]
protected

Triangle vertices.

Definition at line 110 of file OPC_OBBCollider.h.

Referenced by TriBoxOverlap().

Matrix3x3 OBBCollider::mRBoxToModel
protected

Rotation from obb space to model space.

Definition at line 87 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

Matrix3x3 OBBCollider::mRModelToBox
protected

Rotation from model space to obb space.

Definition at line 86 of file OPC_OBBCollider.h.

Point OBBCollider::mTBoxToModel
protected

Translation from obb space to model space.

Definition at line 89 of file OPC_OBBCollider.h.

Referenced by BoxBoxOverlap().

Point OBBCollider::mTModelToBox
protected

Translation from model space to obb space.

Definition at line 88 of file OPC_OBBCollider.h.


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