Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / OPC_VolumeCollider.cpp
1 /*
2  *      OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
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:
12
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.
16 */
17
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19 /**
20  *      Contains base volume collider class.
21  *      \file           OPC_VolumeCollider.cpp
22  *      \author         Pierre Terdiman
23  *      \date           June, 2, 2001
24  */
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 /**
29  *      Contains the abstract class for volume colliders.
30  *
31  *      \class          VolumeCollider
32  *      \author         Pierre Terdiman
33  *      \version        1.3
34  *      \date           June, 2, 2001
35 */
36 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37
38 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39 // Precompiled Header
40 #include "Stdafx.h"
41
42 using namespace Opcode;
43
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45 /**
46  *      Constructor.
47  */
48 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 VolumeCollider::VolumeCollider() :
50         mTouchedPrimitives      (null),
51         mNbVolumeBVTests        (0),
52         mNbVolumePrimTests      (0)
53 {
54 }
55
56 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 /**
58  *      Destructor.
59  */
60 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 VolumeCollider::~VolumeCollider()
62 {
63         mTouchedPrimitives = null;
64 }
65
66 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 /**
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
70  */
71 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72 const char* VolumeCollider::ValidateSettings()
73 {
74         return null;
75 }
76
77 // Pretty dumb way to dump - to do better - one day...
78
79 #define IMPLEMENT_NOLEAFDUMP(type)                                                                                              \
80 void VolumeCollider::_Dump(const type* node)                                                                    \
81 {                                                                                                                                                               \
82         if(node->HasPosLeaf())  mTouchedPrimitives->Add(node->GetPosPrimitive());       \
83         else                                    _Dump(node->GetPos());                                                          \
84                                                                                                                                                                 \
85         if(ContactFound()) return;                                                                                                      \
86                                                                                                                                                                 \
87         if(node->HasNegLeaf())  mTouchedPrimitives->Add(node->GetNegPrimitive());       \
88         else                                    _Dump(node->GetNeg());                                                          \
89 }
90
91 #define IMPLEMENT_LEAFDUMP(type)                                                \
92 void VolumeCollider::_Dump(const type* node)                    \
93 {                                                                                                               \
94         if(node->IsLeaf())                                                                      \
95         {                                                                                                       \
96                 mTouchedPrimitives->Add(node->GetPrimitive());  \
97         }                                                                                                       \
98         else                                                                                            \
99         {                                                                                                       \
100                 _Dump(node->GetPos());                                                  \
101                                                                                                                 \
102                 if(ContactFound()) return;                                              \
103                                                                                                                 \
104                 _Dump(node->GetNeg());                                                  \
105         }                                                                                                       \
106 }
107
108 IMPLEMENT_NOLEAFDUMP(AABBNoLeafNode)
109 IMPLEMENT_NOLEAFDUMP(AABBQuantizedNoLeafNode)
110
111 IMPLEMENT_LEAFDUMP(AABBCollisionNode)
112 IMPLEMENT_LEAFDUMP(AABBQuantizedNode)