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 an AABB collider. |
---|
12 | * \file OPC_AABBCollider.h |
---|
13 | * \author Pierre Terdiman |
---|
14 | * \date January, 1st, 2002 |
---|
15 | */ |
---|
16 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
17 | |
---|
18 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
19 | // Include Guard |
---|
20 | #ifndef __OPC_AABBCOLLIDER_H__ |
---|
21 | #define __OPC_AABBCOLLIDER_H__ |
---|
22 | |
---|
23 | struct OPCODE_API AABBCache : VolumeCache |
---|
24 | { |
---|
25 | AABBCache() : FatCoeff(1.1f) |
---|
26 | { |
---|
27 | FatBox.mCenter.Zero(); |
---|
28 | FatBox.mExtents.Zero(); |
---|
29 | } |
---|
30 | |
---|
31 | // Cached faces signature |
---|
32 | CollisionAABB FatBox; //!< Box used when performing the query resulting in cached faces |
---|
33 | // User settings |
---|
34 | float FatCoeff; //!< mRadius2 multiplier used to create a fat sphere |
---|
35 | }; |
---|
36 | |
---|
37 | class OPCODE_API AABBCollider : public VolumeCollider |
---|
38 | { |
---|
39 | public: |
---|
40 | // Constructor / Destructor |
---|
41 | AABBCollider(); |
---|
42 | virtual ~AABBCollider(); |
---|
43 | |
---|
44 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
45 | /** |
---|
46 | * Generic collision query for generic OPCODE models. After the call, access the results: |
---|
47 | * - with GetContactStatus() |
---|
48 | * - with GetNbTouchedPrimitives() |
---|
49 | * - with GetTouchedPrimitives() |
---|
50 | * |
---|
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. |
---|
56 | */ |
---|
57 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
58 | bool Collide(AABBCache& cache, const CollisionAABB& box, const Model& model); |
---|
59 | // |
---|
60 | bool Collide(AABBCache& cache, const CollisionAABB& box, const AABBTree* tree); |
---|
61 | protected: |
---|
62 | CollisionAABB mBox; //!< Query box in (center, extents) form |
---|
63 | Point mMin; //!< Query box min point |
---|
64 | Point mMax; //!< Query box max point |
---|
65 | // Leaf description |
---|
66 | Point mLeafVerts[3]; //!< Triangle vertices |
---|
67 | // Internal methods |
---|
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); |
---|
77 | // Overlap tests |
---|
78 | inline_ BOOL AABBContainsBox(const Point& bc, const Point& be); |
---|
79 | inline_ BOOL AABBAABBOverlap(const Point& b, const Point& Pb); |
---|
80 | inline_ BOOL TriBoxOverlap(); |
---|
81 | // Init methods |
---|
82 | BOOL InitQuery(AABBCache& cache, const CollisionAABB& box); |
---|
83 | }; |
---|
84 | |
---|
85 | class OPCODE_API HybridAABBCollider : public AABBCollider |
---|
86 | { |
---|
87 | public: |
---|
88 | // Constructor / Destructor |
---|
89 | HybridAABBCollider(); |
---|
90 | virtual ~HybridAABBCollider(); |
---|
91 | |
---|
92 | bool Collide(AABBCache& cache, const CollisionAABB& box, const HybridModel& model); |
---|
93 | protected: |
---|
94 | Container mTouchedBoxes; |
---|
95 | }; |
---|
96 | |
---|
97 | #endif // __OPC_AABBCOLLIDER_H__ |
---|