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 base volume collider class. |
---|
12 | * \file OPC_VolumeCollider.h |
---|
13 | * \author Pierre Terdiman |
---|
14 | * \date June, 2, 2001 |
---|
15 | */ |
---|
16 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
17 | |
---|
18 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
19 | // Include Guard |
---|
20 | #ifndef __OPC_VOLUMECOLLIDER_H__ |
---|
21 | #define __OPC_VOLUMECOLLIDER_H__ |
---|
22 | |
---|
23 | struct OPCODE_API VolumeCache |
---|
24 | { |
---|
25 | VolumeCache() : Model(null) {} |
---|
26 | ~VolumeCache() {} |
---|
27 | |
---|
28 | Container TouchedPrimitives; //!< Indices of touched primitives |
---|
29 | const BaseModel* Model; //!< Owner |
---|
30 | }; |
---|
31 | |
---|
32 | class OPCODE_API VolumeCollider : public Collider |
---|
33 | { |
---|
34 | public: |
---|
35 | // Constructor / Destructor |
---|
36 | VolumeCollider(); |
---|
37 | virtual ~VolumeCollider() = 0; |
---|
38 | |
---|
39 | // Collision report |
---|
40 | |
---|
41 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
42 | /** |
---|
43 | * Gets the number of touched primitives after a collision query. |
---|
44 | * \see GetContactStatus() |
---|
45 | * \see GetTouchedPrimitives() |
---|
46 | * \return the number of touched primitives |
---|
47 | */ |
---|
48 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
49 | inline_ udword GetNbTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetNbEntries() : 0; } |
---|
50 | |
---|
51 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
52 | /** |
---|
53 | * Gets the list of touched primitives after a collision query. |
---|
54 | * \see GetContactStatus() |
---|
55 | * \see GetNbTouchedPrimitives() |
---|
56 | * \return the list of touched primitives (primitive indices) |
---|
57 | */ |
---|
58 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
59 | inline_ const udword* GetTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetEntries() : null; } |
---|
60 | |
---|
61 | // Stats |
---|
62 | |
---|
63 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
64 | /** |
---|
65 | * Stats: gets the number of Volume-BV overlap tests after a collision query. |
---|
66 | * \see GetNbVolumePrimTests() |
---|
67 | * \return the number of Volume-BV tests performed during last query |
---|
68 | */ |
---|
69 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
70 | inline_ udword GetNbVolumeBVTests() const { return mNbVolumeBVTests; } |
---|
71 | |
---|
72 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
73 | /** |
---|
74 | * Stats: gets the number of Volume-Triangle overlap tests after a collision query. |
---|
75 | * \see GetNbVolumeBVTests() |
---|
76 | * \return the number of Volume-Triangle tests performed during last query |
---|
77 | */ |
---|
78 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
79 | inline_ udword GetNbVolumePrimTests() const { return mNbVolumePrimTests; } |
---|
80 | |
---|
81 | // Settings |
---|
82 | |
---|
83 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
84 | /** |
---|
85 | * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider. |
---|
86 | * \return null if everything is ok, else a string describing the problem |
---|
87 | */ |
---|
88 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
89 | override(Collider) const char* ValidateSettings(); |
---|
90 | |
---|
91 | protected: |
---|
92 | // Touched primitives |
---|
93 | Container* mTouchedPrimitives; //!< List of touched primitives |
---|
94 | |
---|
95 | // Dequantization coeffs |
---|
96 | Point mCenterCoeff; |
---|
97 | Point mExtentsCoeff; |
---|
98 | // Stats |
---|
99 | udword mNbVolumeBVTests; //!< Number of Volume-BV tests |
---|
100 | udword mNbVolumePrimTests; //!< Number of Volume-Primitive tests |
---|
101 | // Internal methods |
---|
102 | void _Dump(const AABBCollisionNode* node); |
---|
103 | void _Dump(const AABBNoLeafNode* node); |
---|
104 | void _Dump(const AABBQuantizedNode* node); |
---|
105 | void _Dump(const AABBQuantizedNoLeafNode* node); |
---|
106 | |
---|
107 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
108 | /** |
---|
109 | * Initializes a query |
---|
110 | */ |
---|
111 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
112 | override(Collider) inline_ void InitQuery() |
---|
113 | { |
---|
114 | // Reset stats & contact status |
---|
115 | mNbVolumeBVTests = 0; |
---|
116 | mNbVolumePrimTests = 0; |
---|
117 | Collider::InitQuery(); |
---|
118 | } |
---|
119 | |
---|
120 | inline_ BOOL IsCacheValid(VolumeCache& cache) |
---|
121 | { |
---|
122 | // We're going to do a volume-vs-model query. |
---|
123 | if(cache.Model!=mCurrentModel) |
---|
124 | { |
---|
125 | // Cached list was for another model so we can't keep it |
---|
126 | // Keep track of new owner and reset cache |
---|
127 | cache.Model = mCurrentModel; |
---|
128 | return FALSE; |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | // Same models, no problem |
---|
133 | return TRUE; |
---|
134 | } |
---|
135 | } |
---|
136 | }; |
---|
137 | |
---|
138 | #endif // __OPC_VOLUMECOLLIDER_H__ |
---|