122 #define SET_CONTACT(prim_index, flag) \ 123 mNbIntersections++; \ 127 mStabbedFace.mFaceID = prim_index; 129 #ifdef OPC_RAYHIT_CALLBACK 131 #define HANDLE_CONTACT(prim_index, flag) \ 132 SET_CONTACT(prim_index, flag) \ 134 if(mHitCallback) (mHitCallback)(mStabbedFace, mUserData); 136 #define UPDATE_CACHE \ 137 if(cache && GetContactStatus()) \ 139 *cache = mStabbedFace.mFaceID; \ 143 #define HANDLE_CONTACT(prim_index, flag) \ 144 SET_CONTACT(prim_index, flag) \ 150 if(!mClosestHit || !mStabbedFaces->GetNbFaces()) \ 152 mStabbedFaces->AddFace(mStabbedFace); \ 157 CollisionFace* Current = const_cast<CollisionFace*>(mStabbedFaces->GetFaces()); \ 158 if(Current && mStabbedFace.mDistance<Current->mDistance) \ 160 *Current = mStabbedFace; \ 165 #define UPDATE_CACHE \ 166 if(cache && GetContactStatus() && mStabbedFaces) \ 168 const CollisionFace* Current = mStabbedFaces->GetFaces(); \ 169 if(Current) *cache = Current->mFaceID; \ 170 else *cache = INVALID_ID; \ 174 #define SEGMENT_PRIM(prim_index, flag) \ 176 VertexPointers VP; mIMesh->GetTriangle(VP, prim_index); \ 179 if(RayTriOverlap(*VP.Vertex[0], *VP.Vertex[1], *VP.Vertex[2])) \ 183 if(IR(mStabbedFace.mDistance)<IR(mMaxDist)) \ 185 HANDLE_CONTACT(prim_index, flag) \ 189 #define RAY_PRIM(prim_index, flag) \ 191 VertexPointers VP; mIMesh->GetTriangle(VP, prim_index); \ 194 if(RayTriOverlap(*VP.Vertex[0], *VP.Vertex[1], *VP.Vertex[2])) \ 196 HANDLE_CONTACT(prim_index, flag) \ 210 mStabbedFaces (
null),
214 mNbIntersections (0),
240 if(
mMaxDist<0.0
f)
return "Higher distance bound must be positive!";
242 #ifndef OPC_RAYHIT_CALLBACK 243 if(mClosestHit &&
FirstContactEnabled())
return "Closest hit doesn't work with ""First contact"" mode!";
246 if(
SkipPrimitiveTests())
return "SkipPrimitiveTests not possible for RayCollider ! (not implemented)";
267 if(!
Setup(&model))
return false;
270 if(
InitQuery(world_ray, world, cache))
return true;
346 #ifndef OPC_RAYHIT_CALLBACK 347 if(mStabbedFaces) mStabbedFaces->Reset();
387 #ifndef OPC_RAYHIT_CALLBACK 408 #ifndef OPC_RAYHIT_CALLBACK 475 if(!tree)
return false;
555 if(node->HasPosLeaf())
563 if(node->HasNegLeaf())
586 if(node->HasPosLeaf())
594 if(node->HasNegLeaf())
611 Point Center, Extents;
612 node->GetAABB()->GetCenter(Center);
613 node->GetAABB()->GetExtents(Extents);
636 if(!
RayAABBOverlap(node->mAABB.mCenter, node->mAABB.mExtents))
return;
691 if(!
RayAABBOverlap(node->mAABB.mCenter, node->mAABB.mExtents))
return;
693 if(node->HasPosLeaf())
701 if(node->HasNegLeaf())
724 if(node->HasPosLeaf())
732 if(node->HasNegLeaf())
749 Point Center, Extents;
750 node->GetAABB()->GetCenter(Center);
751 node->GetAABB()->GetExtents(Extents);
761 _RayStab(node->GetPos(), box_indices);
762 _RayStab(node->GetNeg(), box_indices);
inline_ BOOL FirstContactEnabled() const
const MeshInterface * mIMesh
User-defined mesh interface.
#define IR(x)
Integer representation of a floating-point value.
virtual inline_ void InitQuery()
#define IEEE_MAX_FLOAT
integer representation of MAX_FLOAT
#define null
our own NULL pointer
inline_ udword GetNbPrimitives() const
const BaseModel * mCurrentModel
Current model for collision query (owner of touched faces)
void _SegmentStab(const AABBCollisionNode *node)
bool Collide(const Ray &world_ray, const Model &model, const Matrix4x4 *world=null, udword *cache=null)
inline_ BOOL RayTriOverlap(const Point &vert0, const Point &vert1, const Point &vert2)
uword mExtents[3]
Quantized extents.
udword mNbRayPrimTests
Number of Ray-Primitive tests.
sword mCenter[3]
Quantized center.
#define OPC_RAYHIT_CALLBACK
Use a callback in the ray collider.
inline_ const udword * GetPrimitives() const
virtual const char * ValidateSettings()=0
int BOOL
Another boolean type.
unsigned int udword
sizeof(udword) must be 4
inline_ BOOL GetContactStatus() const
CollisionFace mStabbedFace
Current stabbed face.
inline_ BOOL ContactFound() const
inline_ BOOL Setup(const BaseModel *model)
#define RAY_PRIM(prim_index, flag)
inline_ Container & Add(udword entry)
#define MAX_FLOAT
max possible float value
inline_ BOOL RayAABBOverlap(const Point ¢er, const Point &extents)
inline_ void GetTriangle(VertexPointers &vp, udword index) const
Final contact status after a collision query.
inline_ BOOL SkipPrimitiveTests() const
float mDistance
Distance from collider to hitpoint.
float mMaxDist
Valid segment on the ray.
#define SEGMENT_PRIM(prim_index, flag)
ICEMATHS_API void InvertPRMatrix(Matrix4x4 &dest, const Matrix4x4 &src)
udword mNbRayBVTests
Number of Ray-BV tests.
udword mFaceID
Index of touched face.
void _RayStab(const AABBCollisionNode *node)
#define INVALID_ID
Invalid dword ID (counterpart of null pointers)
inline_ BOOL IsQuantized() const
Point mDir
Normalized direction.
inline_ BOOL TemporalCoherenceEnabled() const
inline_ BOOL HasSingleNode() const
inline_ BOOL HasLeafNodes() const
Point mDir
Ray direction (normalized)
udword mNbIntersections
Number of valid intersections.
inline_ const AABBOptimizedTree * GetTree() const
inline_ BOOL SegmentAABBOverlap(const Point ¢er, const Point &extents)