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 a planes collider.
21 * \file OPC_PlanesCollider.h
22 * \author Pierre Terdiman
23 * \date January, 1st, 2002
25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 #ifndef __OPC_PLANESCOLLIDER_H__
30 #define __OPC_PLANESCOLLIDER_H__
32 struct OPCODE_API PlanesCache : VolumeCache
39 class OPCODE_API PlanesCollider : public VolumeCollider
42 // Constructor / Destructor
44 virtual ~PlanesCollider();
46 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48 * Generic collision query for generic OPCODE models. After the call, access the results:
49 * - with GetContactStatus()
50 * - with GetNbTouchedPrimitives()
51 * - with GetTouchedPrimitives()
53 * \param cache [in/out] a planes cache
54 * \param planes [in] list of planes in world space
55 * \param nb_planes [in] number of planes
56 * \param model [in] Opcode model to collide with
57 * \param worldm [in] model's world matrix, or null
58 * \return true if success
59 * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
61 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 bool Collide(PlanesCache& cache, const Plane* planes, udword nb_planes, const Model& model, const Matrix4x4* worldm=null);
64 // Mutant box-with-planes collision queries
65 inline_ bool Collide(PlanesCache& cache, const OBB& box, const Model& model, const Matrix4x4* worldb=null, const Matrix4x4* worldm=null)
71 // Create a new OBB in world space
73 box.Rotate(*worldb, WorldBox);
74 // Compute planes from the sides of the box
75 WorldBox.ComputePlanes(PL);
79 // Compute planes from the sides of the box
80 box.ComputePlanes(PL);
83 // Collide with box planes
84 return Collide(cache, PL, 6, model, worldm);
88 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 * Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider.
91 * \return null if everything is ok, else a string describing the problem
93 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 override(Collider) const char* ValidateSettings();
97 // Planes in model space
103 void _Collide(const AABBCollisionNode* node, udword clip_mask);
104 void _Collide(const AABBNoLeafNode* node, udword clip_mask);
105 void _Collide(const AABBQuantizedNode* node, udword clip_mask);
106 void _Collide(const AABBQuantizedNoLeafNode* node, udword clip_mask);
107 void _CollideNoPrimitiveTest(const AABBCollisionNode* node, udword clip_mask);
108 void _CollideNoPrimitiveTest(const AABBNoLeafNode* node, udword clip_mask);
109 void _CollideNoPrimitiveTest(const AABBQuantizedNode* node, udword clip_mask);
110 void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node, udword clip_mask);
112 inline_ BOOL PlanesAABBOverlap(const Point& center, const Point& extents, udword& out_clip_mask, udword in_clip_mask);
113 inline_ BOOL PlanesTriOverlap(udword in_clip_mask);
115 BOOL InitQuery(PlanesCache& cache, const Plane* planes, udword nb_planes, const Matrix4x4* worldm=null);
118 class OPCODE_API HybridPlanesCollider : public PlanesCollider
121 // Constructor / Destructor
122 HybridPlanesCollider();
123 virtual ~HybridPlanesCollider();
125 bool Collide(PlanesCache& cache, const Plane* planes, udword nb_planes, const HybridModel& model, const Matrix4x4* worldm=null);
127 Container mTouchedBoxes;
130 #endif // __OPC_PLANESCOLLIDER_H__