1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3 * OPCODE - Optimized Collision Detection
4 * Copyright (C) 2001 Pierre Terdiman
5 * Homepage: http://www.codercorner.com/Opcode.htm
7 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11 * Contains code for a sphere collider.
12 * \file OPC_SphereCollider.h
13 * \author Pierre Terdiman
16 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20 #ifndef __OPC_SPHERECOLLIDER_H__
21 #define __OPC_SPHERECOLLIDER_H__
23 struct OPCODE_API SphereCache
: VolumeCache
25 SphereCache() : Center(0.0f
,0.0f
,0.0f
), FatRadius2(0.0f
), FatCoeff(1.1f
) {}
28 // Cached faces signature
29 Point Center
; //!< Sphere used when performing the query resulting in cached faces
30 float FatRadius2
; //!< Sphere used when performing the query resulting in cached faces
32 float FatCoeff
; //!< mRadius2 multiplier used to create a fat sphere
35 class OPCODE_API SphereCollider
: public VolumeCollider
38 // Constructor / Destructor
40 virtual ~SphereCollider();
42 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 * Generic collision query for generic OPCODE models. After the call, access the results:
45 * - with GetContactStatus()
46 * - with GetNbTouchedPrimitives()
47 * - with GetTouchedPrimitives()
49 * \param cache [in/out] a sphere cache
50 * \param sphere [in] collision sphere in local space
51 * \param model [in] Opcode model to collide with
52 * \param worlds [in] sphere's world matrix, or null
53 * \param worldm [in] model's world matrix, or null
54 * \return true if success
55 * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
57 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 bool Collide(SphereCache
& cache
, const Sphere
& sphere
, const Model
& model
, const Matrix4x4
* worlds
=null
, const Matrix4x4
* worldm
=null
);
61 bool Collide(SphereCache
& cache
, const Sphere
& sphere
, const AABBTree
* tree
);
63 // Sphere in model space
64 Point mCenter
; //!< Sphere center
65 float mRadius2
; //!< Sphere radius squared
67 void _Collide(const AABBCollisionNode
* node
);
68 void _Collide(const AABBNoLeafNode
* node
);
69 void _Collide(const AABBQuantizedNode
* node
);
70 void _Collide(const AABBQuantizedNoLeafNode
* node
);
71 void _Collide(const AABBTreeNode
* node
);
72 void _CollideNoPrimitiveTest(const AABBCollisionNode
* node
);
73 void _CollideNoPrimitiveTest(const AABBNoLeafNode
* node
);
74 void _CollideNoPrimitiveTest(const AABBQuantizedNode
* node
);
75 void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode
* node
);
77 inline_ BOOL
SphereContainsBox(const Point
& bc
, const Point
& be
);
78 inline_ BOOL
SphereAABBOverlap(const Point
& center
, const Point
& extents
);
79 BOOL
SphereTriOverlap(const Point
& vert0
, const Point
& vert1
, const Point
& vert2
);
81 BOOL
InitQuery(SphereCache
& cache
, const Sphere
& sphere
, const Matrix4x4
* worlds
=null
, const Matrix4x4
* worldm
=null
);
84 class OPCODE_API HybridSphereCollider
: public SphereCollider
87 // Constructor / Destructor
88 HybridSphereCollider();
89 virtual ~HybridSphereCollider();
91 bool Collide(SphereCache
& cache
, const Sphere
& sphere
, const HybridModel
& model
, const Matrix4x4
* worlds
=null
, const Matrix4x4
* worldm
=null
);
93 Container mTouchedBoxes
;
96 #endif // __OPC_SPHERECOLLIDER_H__