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 AABB collider.
21 * \file OPC_AABBCollider.h
22 * \author Pierre Terdiman
23 * \date January, 1st, 2002
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_AABBCOLLIDER_H__
30 #define __OPC_AABBCOLLIDER_H__
32 struct OPCODE_API AABBCache : VolumeCache
34 AABBCache() : FatCoeff(1.1f)
36 FatBox.mCenter.Zero();
37 FatBox.mExtents.Zero();
40 // Cached faces signature
41 CollisionAABB FatBox; //!< Box used when performing the query resulting in cached faces
43 float FatCoeff; //!< mRadius2 multiplier used to create a fat sphere
46 class OPCODE_API AABBCollider : public VolumeCollider
49 // Constructor / Destructor
51 virtual ~AABBCollider();
53 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55 * Generic collision query for generic OPCODE models. After the call, access the results:
56 * - with GetContactStatus()
57 * - with GetNbTouchedPrimitives()
58 * - with GetTouchedPrimitives()
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.
66 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 bool Collide(AABBCache& cache, const CollisionAABB& box, const Model& model);
69 bool Collide(AABBCache& cache, const CollisionAABB& box, const AABBTree* tree);
71 CollisionAABB mBox; //!< Query box in (center, extents) form
72 Point mMin; //!< Query box min point
73 Point mMax; //!< Query box max point
75 Point mLeafVerts[3]; //!< Triangle vertices
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);
87 inline_ BOOL AABBContainsBox(const Point& bc, const Point& be);
88 inline_ BOOL AABBAABBOverlap(const Point& b, const Point& Pb);
89 inline_ BOOL TriBoxOverlap();
91 BOOL InitQuery(AABBCache& cache, const CollisionAABB& box);
94 class OPCODE_API HybridAABBCollider : public AABBCollider
97 // Constructor / Destructor
99 virtual ~HybridAABBCollider();
101 bool Collide(AABBCache& cache, const CollisionAABB& box, const HybridModel& model);
103 Container mTouchedBoxes;
106 #endif // __OPC_AABBCOLLIDER_H__