Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / OPC_LSSCollider.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 LSS collider.
21  *      \file           OPC_LSSCollider.h
22  *      \author         Pierre Terdiman
23  *      \date           December, 28, 2002
24  */
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 // Include Guard
29 #ifndef __OPC_LSSCOLLIDER_H__
30 #define __OPC_LSSCOLLIDER_H__
31
32         struct OPCODE_API LSSCache : VolumeCache
33         {
34                                         LSSCache()
35                                         {
36                                                 Previous.mP0 = Point(0.0f, 0.0f, 0.0f);
37                                                 Previous.mP1 = Point(0.0f, 0.0f, 0.0f);
38                                                 Previous.mRadius = 0.0f;
39                                                 FatCoeff = 1.1f;
40                                         }
41
42                 // Cached faces signature
43                 LSS                     Previous;       //!< LSS used when performing the query resulting in cached faces
44                 // User settings
45                 float           FatCoeff;       //!< mRadius2 multiplier used to create a fat LSS
46         };
47
48         class OPCODE_API LSSCollider : public VolumeCollider
49         {
50                 public:
51                 // Constructor / Destructor
52                                                                                         LSSCollider();
53                 virtual                                                         ~LSSCollider();
54
55                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56                 /**
57                  *      Generic collision query for generic OPCODE models. After the call, access the results:
58                  *      - with GetContactStatus()
59                  *      - with GetNbTouchedPrimitives()
60                  *      - with GetTouchedPrimitives()
61                  *
62                  *      \param          cache                   [in/out] an lss cache
63                  *      \param          lss                             [in] collision lss in local space
64                  *      \param          model                   [in] Opcode model to collide with
65                  *      \param          worldl                  [in] lss world matrix, or null
66                  *      \param          worldm                  [in] model's world matrix, or null
67                  *      \return         true if success
68                  *      \warning        SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
69                  */
70                 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
71                                                         bool                    Collide(LSSCache& cache, const LSS& lss, const Model& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
72                 // 
73                                                         bool                    Collide(LSSCache& cache, const LSS& lss, const AABBTree* tree);
74                 protected:
75                 // LSS in model space
76                                                         Segment                 mSeg;                   //!< Segment
77                                                         float                   mRadius2;               //!< LSS radius squared
78                 // Internal methods
79                                                         void                    _Collide(const AABBCollisionNode* node);
80                                                         void                    _Collide(const AABBNoLeafNode* node);
81                                                         void                    _Collide(const AABBQuantizedNode* node);
82                                                         void                    _Collide(const AABBQuantizedNoLeafNode* node);
83                                                         void                    _Collide(const AABBTreeNode* node);
84                                                         void                    _CollideNoPrimitiveTest(const AABBCollisionNode* node);
85                                                         void                    _CollideNoPrimitiveTest(const AABBNoLeafNode* node);
86                                                         void                    _CollideNoPrimitiveTest(const AABBQuantizedNode* node);
87                                                         void                    _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node);
88                         // Overlap tests
89                 inline_                         BOOL                    LSSContainsBox(const Point& bc, const Point& be);
90                 inline_                         BOOL                    LSSAABBOverlap(const Point& center, const Point& extents);
91                 inline_                         BOOL                    LSSTriOverlap(const Point& vert0, const Point& vert1, const Point& vert2);
92                         // Init methods
93                                                         BOOL                    InitQuery(LSSCache& cache, const LSS& lss, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
94         };
95
96         class OPCODE_API HybridLSSCollider : public LSSCollider
97         {
98                 public:
99                 // Constructor / Destructor
100                                                                                         HybridLSSCollider();
101                 virtual                                                         ~HybridLSSCollider();
102
103                                                         bool                    Collide(LSSCache& cache, const LSS& lss, const HybridModel& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
104                 protected:
105                                                         Container               mTouchedBoxes;
106         };
107
108 #endif // __OPC_LSSCOLLIDER_H__