2 * OPCODE - Optimized Collision Detection
3 * http://www.codercorner.com/Opcode.htm
5 * Copyright (c) 2001-2008 Pierre Terdiman, pierre@codercorner.com
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it freely,
11 subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20 * Contains base volume collider class.
21 * \file OPC_VolumeCollider.h
22 * \author Pierre Terdiman
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_VOLUMECOLLIDER_H__
30 #define __OPC_VOLUMECOLLIDER_H__
32 struct OPCODE_API VolumeCache
34 VolumeCache() : Model(null) {}
37 Container TouchedPrimitives; //!< Indices of touched primitives
38 const BaseModel* Model; //!< Owner
41 class OPCODE_API VolumeCollider : public Collider
44 // Constructor / Destructor
46 virtual ~VolumeCollider() = 0;
50 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52 * Gets the number of touched primitives after a collision query.
53 * \see GetContactStatus()
54 * \see GetTouchedPrimitives()
55 * \return the number of touched primitives
57 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 inline_ udword GetNbTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetNbEntries() : 0; }
60 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 * Gets the list of touched primitives after a collision query.
63 * \see GetContactStatus()
64 * \see GetNbTouchedPrimitives()
65 * \return the list of touched primitives (primitive indices)
67 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68 inline_ const udword* GetTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetEntries() : null; }
72 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74 * Stats: gets the number of Volume-BV overlap tests after a collision query.
75 * \see GetNbVolumePrimTests()
76 * \return the number of Volume-BV tests performed during last query
78 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
79 inline_ udword GetNbVolumeBVTests() const { return mNbVolumeBVTests; }
81 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 * Stats: gets the number of Volume-Triangle overlap tests after a collision query.
84 * \see GetNbVolumeBVTests()
85 * \return the number of Volume-Triangle tests performed during last query
87 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 inline_ udword GetNbVolumePrimTests() const { return mNbVolumePrimTests; }
92 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider.
95 * \return null if everything is ok, else a string describing the problem
97 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98 override(Collider) const char* ValidateSettings();
101 // Touched primitives
102 Container* mTouchedPrimitives; //!< List of touched primitives
104 // Dequantization coeffs
108 udword mNbVolumeBVTests; //!< Number of Volume-BV tests
109 udword mNbVolumePrimTests; //!< Number of Volume-Primitive tests
111 void _Dump(const AABBCollisionNode* node);
112 void _Dump(const AABBNoLeafNode* node);
113 void _Dump(const AABBQuantizedNode* node);
114 void _Dump(const AABBQuantizedNoLeafNode* node);
116 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118 * Initializes a query
120 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121 override(Collider) inline_ void InitQuery()
123 // Reset stats & contact status
124 mNbVolumeBVTests = 0;
125 mNbVolumePrimTests = 0;
126 Collider::InitQuery();
129 inline_ BOOL IsCacheValid(VolumeCache& cache)
131 // We're going to do a volume-vs-model query.
132 if(cache.Model!=mCurrentModel)
134 // Cached list was for another model so we can't keep it
135 // Keep track of new owner and reset cache
136 cache.Model = mCurrentModel;
141 // Same models, no problem
147 #endif // __OPC_VOLUMECOLLIDER_H__