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 code for an LSS collider.
21 * \file OPC_LSSCollider.h
22 * \author Pierre Terdiman
23 * \date December, 28, 2002
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_LSSCOLLIDER_H__
30 #define __OPC_LSSCOLLIDER_H__
32 struct OPCODE_API LSSCache : VolumeCache
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;
42 // Cached faces signature
43 LSS Previous; //!< LSS used when performing the query resulting in cached faces
45 float FatCoeff; //!< mRadius2 multiplier used to create a fat LSS
48 class OPCODE_API LSSCollider : public VolumeCollider
51 // Constructor / Destructor
53 virtual ~LSSCollider();
55 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 * Generic collision query for generic OPCODE models. After the call, access the results:
58 * - with GetContactStatus()
59 * - with GetNbTouchedPrimitives()
60 * - with GetTouchedPrimitives()
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.
70 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
71 bool Collide(LSSCache& cache, const LSS& lss, const Model& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
73 bool Collide(LSSCache& cache, const LSS& lss, const AABBTree* tree);
76 Segment mSeg; //!< Segment
77 float mRadius2; //!< LSS radius squared
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);
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);
93 BOOL InitQuery(LSSCache& cache, const LSS& lss, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
96 class OPCODE_API HybridLSSCollider : public LSSCollider
99 // Constructor / Destructor
101 virtual ~HybridLSSCollider();
103 bool Collide(LSSCache& cache, const LSS& lss, const HybridModel& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
105 Container mTouchedBoxes;
108 #endif // __OPC_LSSCOLLIDER_H__