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.cpp
22 * \author Pierre Terdiman
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 * Contains the abstract class for volume colliders.
31 * \class VolumeCollider
32 * \author Pierre Terdiman
36 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42 using namespace Opcode;
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 VolumeCollider::VolumeCollider() :
50 mTouchedPrimitives (null),
52 mNbVolumePrimTests (0)
56 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 VolumeCollider::~VolumeCollider()
63 mTouchedPrimitives = null;
66 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68 * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider.
69 * \return null if everything is ok, else a string describing the problem
71 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72 const char* VolumeCollider::ValidateSettings()
77 // Pretty dumb way to dump - to do better - one day...
79 #define IMPLEMENT_NOLEAFDUMP(type) \
80 void VolumeCollider::_Dump(const type* node) \
82 if(node->HasPosLeaf()) mTouchedPrimitives->Add(node->GetPosPrimitive()); \
83 else _Dump(node->GetPos()); \
85 if(ContactFound()) return; \
87 if(node->HasNegLeaf()) mTouchedPrimitives->Add(node->GetNegPrimitive()); \
88 else _Dump(node->GetNeg()); \
91 #define IMPLEMENT_LEAFDUMP(type) \
92 void VolumeCollider::_Dump(const type* node) \
96 mTouchedPrimitives->Add(node->GetPrimitive()); \
100 _Dump(node->GetPos()); \
102 if(ContactFound()) return; \
104 _Dump(node->GetNeg()); \
108 IMPLEMENT_NOLEAFDUMP(AABBNoLeafNode)
109 IMPLEMENT_NOLEAFDUMP(AABBQuantizedNoLeafNode)
111 IMPLEMENT_LEAFDUMP(AABBCollisionNode)
112 IMPLEMENT_LEAFDUMP(AABBQuantizedNode)