Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / OPC_AABBCollider.h
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 code for an AABB collider.
21  *      \file           OPC_AABBCollider.h
22  *      \author         Pierre Terdiman
23  *      \date           January, 1st, 2002
24  */
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 // Include Guard
29 #ifndef __OPC_AABBCOLLIDER_H__
30 #define __OPC_AABBCOLLIDER_H__
31
32         struct OPCODE_API AABBCache : VolumeCache
33         {
34                                                 AABBCache() : FatCoeff(1.1f)
35                                                 {
36                                                         FatBox.mCenter.Zero();
37                                                         FatBox.mExtents.Zero();
38                                                 }
39
40                 // Cached faces signature
41                 CollisionAABB   FatBox;         //!< Box used when performing the query resulting in cached faces
42                 // User settings
43                 float                   FatCoeff;       //!< mRadius2 multiplier used to create a fat sphere
44         };
45
46         class OPCODE_API AABBCollider : public VolumeCollider
47         {
48                 public:
49                 // Constructor / Destructor
50                                                                                         AABBCollider();
51                 virtual                                                         ~AABBCollider();
52
53                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54                 /**
55                  *      Generic collision query for generic OPCODE models. After the call, access the results:
56                  *      - with GetContactStatus()
57                  *      - with GetNbTouchedPrimitives()
58                  *      - with GetTouchedPrimitives()
59                  *
60                  *      \param          cache                   [in/out] a box cache
61                  *      \param          box                             [in] collision AABB in world space
62                  *      \param          model                   [in] Opcode model to collide with
63                  *      \return         true if success
64                  *      \warning        SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
65                  */
66                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67                                                         bool                    Collide(AABBCache& cache, const CollisionAABB& box, const Model& model);
68                 //
69                                                         bool                    Collide(AABBCache& cache, const CollisionAABB& box, const AABBTree* tree);
70                 protected:
71                                                         CollisionAABB   mBox;                   //!< Query box in (center, extents) form
72                                                         Point                   mMin;                   //!< Query box min point
73                                                         Point                   mMax;                   //!< Query box max point
74                 // Leaf description
75                                                         Point                   mLeafVerts[3];  //!< Triangle vertices
76                 // Internal methods
77                                                         void                    _Collide(const AABBCollisionNode* node);
78                                                         void                    _Collide(const AABBNoLeafNode* node);
79                                                         void                    _Collide(const AABBQuantizedNode* node);
80                                                         void                    _Collide(const AABBQuantizedNoLeafNode* node);
81                                                         void                    _Collide(const AABBTreeNode* node);
82                                                         void                    _CollideNoPrimitiveTest(const AABBCollisionNode* node);
83                                                         void                    _CollideNoPrimitiveTest(const AABBNoLeafNode* node);
84                                                         void                    _CollideNoPrimitiveTest(const AABBQuantizedNode* node);
85                                                         void                    _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node);
86                         // Overlap tests
87                 inline_                         BOOL                    AABBContainsBox(const Point& bc, const Point& be);
88                 inline_                         BOOL                    AABBAABBOverlap(const Point& b, const Point& Pb);
89                 inline_                         BOOL                    TriBoxOverlap();
90                         // Init methods
91                                                         BOOL                    InitQuery(AABBCache& cache, const CollisionAABB& box);
92         };
93
94         class OPCODE_API HybridAABBCollider : public AABBCollider
95         {
96                 public:
97                 // Constructor / Destructor
98                                                                                         HybridAABBCollider();
99                 virtual                                                         ~HybridAABBCollider();
100
101                                                         bool                    Collide(AABBCache& cache, const CollisionAABB& box, const HybridModel& model);
102                 protected:
103                                                         Container               mTouchedBoxes;
104         };
105
106 #endif // __OPC_AABBCOLLIDER_H__