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 an AABB collider.
12 * \file OPC_AABBCollider.h
13 * \author Pierre Terdiman
14 * \date January, 1st, 2002
16 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20 #ifndef __OPC_AABBCOLLIDER_H__
21 #define __OPC_AABBCOLLIDER_H__
23 struct OPCODE_API AABBCache
: VolumeCache
25 AABBCache() : FatCoeff(1.1f
)
27 FatBox
.mCenter
.Zero();
28 FatBox
.mExtents
.Zero();
31 // Cached faces signature
32 CollisionAABB FatBox
; //!< Box used when performing the query resulting in cached faces
34 float FatCoeff
; //!< mRadius2 multiplier used to create a fat sphere
37 class OPCODE_API AABBCollider
: public VolumeCollider
40 // Constructor / Destructor
42 virtual ~AABBCollider();
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 * Generic collision query for generic OPCODE models. After the call, access the results:
47 * - with GetContactStatus()
48 * - with GetNbTouchedPrimitives()
49 * - with GetTouchedPrimitives()
51 * \param cache [in/out] a box cache
52 * \param box [in] collision AABB in world space
53 * \param model [in] Opcode model to collide with
54 * \return true if success
55 * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
57 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 bool Collide(AABBCache
& cache
, const CollisionAABB
& box
, const Model
& model
);
60 bool Collide(AABBCache
& cache
, const CollisionAABB
& box
, const AABBTree
* tree
);
62 CollisionAABB mBox
; //!< Query box in (center, extents) form
63 Point mMin
; //!< Query box min point
64 Point mMax
; //!< Query box max point
66 Point mLeafVerts
[3]; //!< Triangle vertices
68 void _Collide(const AABBCollisionNode
* node
);
69 void _Collide(const AABBNoLeafNode
* node
);
70 void _Collide(const AABBQuantizedNode
* node
);
71 void _Collide(const AABBQuantizedNoLeafNode
* node
);
72 void _Collide(const AABBTreeNode
* node
);
73 void _CollideNoPrimitiveTest(const AABBCollisionNode
* node
);
74 void _CollideNoPrimitiveTest(const AABBNoLeafNode
* node
);
75 void _CollideNoPrimitiveTest(const AABBQuantizedNode
* node
);
76 void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode
* node
);
78 inline_ BOOL
AABBContainsBox(const Point
& bc
, const Point
& be
);
79 inline_ BOOL
AABBAABBOverlap(const Point
& b
, const Point
& Pb
);
80 inline_ BOOL
TriBoxOverlap();
82 BOOL
InitQuery(AABBCache
& cache
, const CollisionAABB
& box
);
85 class OPCODE_API HybridAABBCollider
: public AABBCollider
88 // Constructor / Destructor
90 virtual ~HybridAABBCollider();
92 bool Collide(AABBCache
& cache
, const CollisionAABB
& box
, const HybridModel
& model
);
94 Container mTouchedBoxes
;
97 #endif // __OPC_AABBCOLLIDER_H__