| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 |
/* |
| 3 |
* OPCODE - Optimized Collision Detection |
| 4 |
* Copyright (C) 2001 Pierre Terdiman |
| 5 |
* Homepage: http://www.codercorner.com/Opcode.htm |
| 6 |
*/ |
| 7 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 8 |
|
| 9 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 10 |
/** |
| 11 |
* Contains code for a planes collider. |
| 12 |
* \file OPC_PlanesCollider.h |
| 13 |
* \author Pierre Terdiman |
| 14 |
* \date January, 1st, 2002 |
| 15 |
*/ |
| 16 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 17 |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 19 |
// Include Guard |
| 20 |
#ifndef __OPC_PLANESCOLLIDER_H__ |
| 21 |
#define __OPC_PLANESCOLLIDER_H__ |
| 22 |
|
| 23 |
struct OPCODE_API PlanesCache : VolumeCache |
| 24 |
{ |
| 25 |
PlanesCache() |
| 26 |
{ |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
class OPCODE_API PlanesCollider : public VolumeCollider |
| 31 |
{ |
| 32 |
public: |
| 33 |
// Constructor / Destructor |
| 34 |
PlanesCollider(); |
| 35 |
virtual ~PlanesCollider(); |
| 36 |
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 |
/** |
| 39 |
* Generic collision query for generic OPCODE models. After the call, access the results: |
| 40 |
* - with GetContactStatus() |
| 41 |
* - with GetNbTouchedPrimitives() |
| 42 |
* - with GetTouchedPrimitives() |
| 43 |
* |
| 44 |
* \param cache [in/out] a planes cache |
| 45 |
* \param planes [in] list of planes in world space |
| 46 |
* \param nb_planes [in] number of planes |
| 47 |
* \param model [in] Opcode model to collide with |
| 48 |
* \param worldm [in] model's world matrix, or null |
| 49 |
* \return true if success |
| 50 |
* \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only. |
| 51 |
*/ |
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 |
bool Collide(PlanesCache& cache, const Plane* planes, udword nb_planes, const Model& model, const Matrix4x4* worldm=null); |
| 54 |
|
| 55 |
// Mutant box-with-planes collision queries |
| 56 |
inline_ bool Collide(PlanesCache& cache, const OBB& box, const Model& model, const Matrix4x4* worldb=null, const Matrix4x4* worldm=null) |
| 57 |
{ |
| 58 |
Plane PL[6]; |
| 59 |
|
| 60 |
if(worldb) |
| 61 |
{ |
| 62 |
// Create a new OBB in world space |
| 63 |
OBB WorldBox; |
| 64 |
box.Rotate(*worldb, WorldBox); |
| 65 |
// Compute planes from the sides of the box |
| 66 |
WorldBox.ComputePlanes(PL); |
| 67 |
} |
| 68 |
else |
| 69 |
{ |
| 70 |
// Compute planes from the sides of the box |
| 71 |
box.ComputePlanes(PL); |
| 72 |
} |
| 73 |
|
| 74 |
// Collide with box planes |
| 75 |
return Collide(cache, PL, 6, model, worldm); |
| 76 |
} |
| 77 |
// Settings |
| 78 |
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 80 |
/** |
| 81 |
* Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider. |
| 82 |
* \return null if everything is ok, else a string describing the problem |
| 83 |
*/ |
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 |
override(Collider) const char* ValidateSettings(); |
| 86 |
|
| 87 |
protected: |
| 88 |
// Planes in model space |
| 89 |
udword mNbPlanes; |
| 90 |
Plane* mPlanes; |
| 91 |
// Leaf description |
| 92 |
VertexPointers mVP; |
| 93 |
ConversionArea mVC; |
| 94 |
// Internal methods |
| 95 |
void _Collide(const AABBCollisionNode* node, udword clip_mask); |
| 96 |
void _Collide(const AABBNoLeafNode* node, udword clip_mask); |
| 97 |
void _Collide(const AABBQuantizedNode* node, udword clip_mask); |
| 98 |
void _Collide(const AABBQuantizedNoLeafNode* node, udword clip_mask); |
| 99 |
void _CollideNoPrimitiveTest(const AABBCollisionNode* node, udword clip_mask); |
| 100 |
void _CollideNoPrimitiveTest(const AABBNoLeafNode* node, udword clip_mask); |
| 101 |
void _CollideNoPrimitiveTest(const AABBQuantizedNode* node, udword clip_mask); |
| 102 |
void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node, udword clip_mask); |
| 103 |
// Overlap tests |
| 104 |
inline_ BOOL PlanesAABBOverlap(const Point& center, const Point& extents, udword& out_clip_mask, udword in_clip_mask); |
| 105 |
inline_ BOOL PlanesTriOverlap(udword in_clip_mask); |
| 106 |
// Init methods |
| 107 |
BOOL InitQuery(PlanesCache& cache, const Plane* planes, udword nb_planes, const Matrix4x4* worldm=null); |
| 108 |
}; |
| 109 |
|
| 110 |
class OPCODE_API HybridPlanesCollider : public PlanesCollider |
| 111 |
{ |
| 112 |
public: |
| 113 |
// Constructor / Destructor |
| 114 |
HybridPlanesCollider(); |
| 115 |
virtual ~HybridPlanesCollider(); |
| 116 |
|
| 117 |
bool Collide(PlanesCache& cache, const Plane* planes, udword nb_planes, const HybridModel& model, const Matrix4x4* worldm=null); |
| 118 |
protected: |
| 119 |
Container mTouchedBoxes; |
| 120 |
}; |
| 121 |
|
| 122 |
#endif // __OPC_PLANESCOLLIDER_H__ |