Merged in alexvaillancourt_cmakeInstallPdb (pull request #17)
[ode.git] / OPCODE / OPC_AABBCollider.h
blob315d2d3366ea4df895d0433d8f77fa80009f07aa
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /*
3 * OPCODE - Optimized Collision Detection
4 * Copyright (C) 2001 Pierre Terdiman
5 * Homepage: http://www.codercorner.com/Opcode.htm
6 */
7 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 /**
11 * Contains code for an AABB collider.
12 * \file OPC_AABBCollider.h
13 * \author Pierre Terdiman
14 * \date January, 1st, 2002
16 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19 // Include Guard
20 #ifndef __OPC_AABBCOLLIDER_H__
21 #define __OPC_AABBCOLLIDER_H__
23 struct OPCODE_API AABBCache : VolumeCache
25 AABBCache() : FatCoeff(1.1f)
27 FatBox.mCenter.Zero();
28 FatBox.mExtents.Zero();
31 // Cached faces signature
32 CollisionAABB FatBox; //!< Box used when performing the query resulting in cached faces
33 // User settings
34 float FatCoeff; //!< mRadius2 multiplier used to create a fat sphere
37 class OPCODE_API AABBCollider : public VolumeCollider
39 public:
40 // Constructor / Destructor
41 AABBCollider();
42 virtual ~AABBCollider();
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45 /**
46 * Generic collision query for generic OPCODE models. After the call, access the results:
47 * - with GetContactStatus()
48 * - with GetNbTouchedPrimitives()
49 * - with GetTouchedPrimitives()
51 * \param cache [in/out] a box cache
52 * \param box [in] collision AABB in world space
53 * \param model [in] Opcode model to collide with
54 * \return true if success
55 * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
57 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 bool Collide(AABBCache& cache, const CollisionAABB& box, const Model& model);
60 bool Collide(AABBCache& cache, const CollisionAABB& box, const AABBTree* tree);
61 protected:
62 CollisionAABB mBox; //!< Query box in (center, extents) form
63 Point mMin; //!< Query box min point
64 Point mMax; //!< Query box max point
65 // Leaf description
66 Point mLeafVerts[3]; //!< Triangle vertices
67 // Internal methods
68 void _Collide(const AABBCollisionNode* node);
69 void _Collide(const AABBNoLeafNode* node);
70 void _Collide(const AABBQuantizedNode* node);
71 void _Collide(const AABBQuantizedNoLeafNode* node);
72 void _Collide(const AABBTreeNode* node);
73 void _CollideNoPrimitiveTest(const AABBCollisionNode* node);
74 void _CollideNoPrimitiveTest(const AABBNoLeafNode* node);
75 void _CollideNoPrimitiveTest(const AABBQuantizedNode* node);
76 void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node);
77 // Overlap tests
78 inline_ BOOL AABBContainsBox(const Point& bc, const Point& be);
79 inline_ BOOL AABBAABBOverlap(const Point& b, const Point& Pb);
80 inline_ BOOL TriBoxOverlap();
81 // Init methods
82 BOOL InitQuery(AABBCache& cache, const CollisionAABB& box);
85 class OPCODE_API HybridAABBCollider : public AABBCollider
87 public:
88 // Constructor / Destructor
89 HybridAABBCollider();
90 virtual ~HybridAABBCollider();
92 bool Collide(AABBCache& cache, const CollisionAABB& box, const HybridModel& model);
93 protected:
94 Container mTouchedBoxes;
97 #endif // __OPC_AABBCOLLIDER_H__