ScummVM API documentation
dgCollisionCompound.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2  *
3  * This software is provided 'as-is', without any express or implied
4  * warranty. In no event will the authors be held liable for any damages
5  * arising from the use of this software.
6  *
7  * Permission is granted to anyone to use this software for any purpose,
8  * including commercial applications, and to alter it and redistribute it
9  * freely, subject to the following restrictions:
10  *
11  * 1. The origin of this software must not be misrepresented; you must not
12  * claim that you wrote the original software. If you use this software
13  * in a product, an acknowledgment in the product documentation would be
14  * appreciated but is not required.
15  *
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  *
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #if !defined(AFX_DGCOLLISIONCOMPOUND_H__E164CA46_D0ED_46EE_8130_46C4004940BA__INCLUDED_)
23 #define AFX_DGCOLLISIONCOMPOUND_H__E164CA46_D0ED_46EE_8130_46C4004940BA__INCLUDED_
24 
25 #include "dgCollision.h"
26 #include "dgContact.h"
27 class dgCollisionConvex;
28 
29 #define DG_COMPOUND_STACK_DEPTH 256
30 
32 protected:
33  enum dgNodeType {
34  m_leaf,
35  m_node,
36  };
37 
38  class OOBBTestData {
39  public:
40  OOBBTestData(const dgMatrix &matrix);
41  OOBBTestData(const dgMatrix &matrix, const dgVector &p0, const dgVector &p1);
42 
43  dgMatrix m_matrix;
44  dgMatrix m_absMatrix;
45  dgVector m_origin;
46  dgVector m_size;
47  dgVector m_localP0;
48  dgVector m_localP1;
49  dgVector m_aabbP0;
50  dgVector m_aabbP1;
51  dgVector m_crossAxis[3][3];
52  dgVector m_crossAxisAbs[3][3];
53  dgVector m_crossAxisDotAbs[3][3];
54  dgVector m_extends[3][3];
55  };
56 
57  DG_MSC_VECTOR_ALIGMENT
58  class dgNodeBase {
59  public:
60  DG_CLASS_ALLOCATOR(allocator)
61  dgNodeBase();
62  dgNodeBase(dgCollisionConvex *const m_shape, dgInt32 id);
63  dgNodeBase(dgNodeBase *const left, dgNodeBase *const right, dgInt32 id);
64  ~dgNodeBase();
65  void reset();
66  bool BoxTest(const OOBBTestData &data) const;
67  bool BoxTest(const OOBBTestData &data, const dgNodeBase *const otherNode) const;
68 
69  dgFloat32 BoxClosestDistance(const dgVector *const points, dgInt32 count) const;
70 
71  dgVector m_p0;
72  dgVector m_p1;
73  dgVector m_size;
74  dgVector m_origin;
75  dgInt32 m_type;
76  dgInt32 m_id;
77  dgFloat32 m_area;
78  dgNodeBase *m_left;
79  dgNodeBase *m_right;
80  dgNodeBase *m_parent;
81  dgCollisionConvex *m_shape;
82  } DG_GCC_VECTOR_ALIGMENT;
83 
85  public:
86  dgInt32 m_nodeA;
87  dgInt32 m_nodeB;
88  };
89 
90 public:
93  dgCollisionCompound(dgInt32 count, dgCollisionConvex *const shapeArray[], dgWorld *world);
94  dgCollisionCompound(dgWorld *const world, dgDeserialize deserialization, void *const userData);
95  virtual ~dgCollisionCompound();
96 
97  void AddCollision(dgCollisionConvex *part);
98  // void RemoveCollision (dgCollisionConvex* part);
99  void RemoveCollision(dgNodeBase *node);
100 
101 protected:
102  void Init(dgInt32 count, dgCollisionConvex *const shapeArray[]);
103  virtual dgFloat32 GetVolume() const;
104  virtual dgFloat32 GetBoxMinRadius() const;
105  virtual dgFloat32 GetBoxMaxRadius() const;
106 
107  virtual dgVector SupportVertex(const dgVector &dir) const;
108  virtual void CalcAABB(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
109  virtual void CalcAABBSimd(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
110  virtual bool OOBBTest(const dgMatrix &matrix, const dgCollisionConvex *const shape, void *const cacheOrder) const;
111 
112  virtual void DebugCollision(const dgMatrix &matrix, OnDebugCollisionMeshCallback callback, void *const userData) const;
113  virtual void CalculateInertia(dgVector &inertia, dgVector &origin) const;
114  virtual dgVector CalculateVolumeIntegral(const dgMatrix &globalMatrix, GetBuoyancyPlane bouyancyPlane, void *const context) const;
115  virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
116  virtual dgFloat32 RayCastSimd(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
117 
118  dgNodeBase *BuildTree(dgInt32 count, dgCollisionConvex *const shapeArray[]);
119 
120  virtual dgInt32 CalculateSignature() const;
121  virtual void SetCollisionBBox(const dgVector &p0, const dgVector &p1);
122  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
123  virtual void Serialize(dgSerialize callback, void *const userData) const;
124  void LinkParentNodes();
125 
126  dgInt32 CalculateContacts(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
127  dgInt32 CalculateContactsToSingle(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
128  dgInt32 CalculateContactsToCompound(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
129  dgInt32 CalculateContactsToCollisionTree(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
130  dgInt32 CalculateContactsToHeightField(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
131  dgInt32 CalculateContactsBruteForce(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy, dgInt32 useSimd) const;
132 
133  dgInt32 ClosestDitance(dgBody *const bodyA, dgTriplex &contactA, dgBody *const bodyB, dgTriplex &contactB, dgTriplex &normalAB) const;
134 
135 #ifdef _DEBUG
136  dgVector IntenalSupportVertex(const dgVector &dir) const;
137 #endif
138 
139 protected:
140  // dgInt32 GetAxis (dgNodeBase** const proxiArray, dgInt32 boxCount) const;
141  // static dgInt32 CompareBox (const dgNodeBase* const boxA, const dgNodeBase* const boxB, void* const context);
142  // dgNodeBase* BuildBottomUpTree(dgInt32 count, dgNodeBase** const proxiArray);
143 
144  void ImproveNodeFitness(dgNodeBase *const node) const;
145  dgNodeBase *BuildTopDownTree(dgInt32 count, dgNodeBase **const proxiArray, dgInt32 &id);
146  void PushNodes(dgNodeBase *const root, dgNodeBase **const proxiArray, dgInt32 &index) const;
147  dgFloat32 CalculateSurfaceArea(dgNodeBase *const node0, dgNodeBase *const node1, dgVector &minBox, dgVector &maxBox) const;
148 
149  dgInt32 m_count;
150  dgFloat32 m_boxMinRadius;
151  dgFloat32 m_boxMaxRadius;
152  dgWorld *m_world;
153  dgNodeBase *m_root;
154  dgCollisionConvex **m_array;
155  OnCompoundCollisionPrefilter *m_preCollisionFilter;
156  friend class dgBody;
157  friend class dgWorld;
158 };
159 
160 #endif
Definition: dgCollision.h:73
Definition: dgBody.h:85
Definition: dgCollisionCompound.h:84
Definition: dgVector.h:86
Definition: dgCollisionCompound.h:38
Definition: dgContact.h:88
Definition: dgCollisionConvex.h:39
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgCollisionCompound.h:58
Definition: dgWorld.h:118
Definition: dgTypes.h:70
Definition: dgContact.h:53
Definition: dgCollisionCompound.h:31
Definition: dgContact.h:102