ScummVM API documentation
dgContact.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_DGCONTACT_H__BDE5B2AC_5834_46FD_A994_65D855788F69__INCLUDED_)
23 #define AFX_DGCONTACT_H__BDE5B2AC_5834_46FD_A994_65D855788F69__INCLUDED_
24 
25 
26 #include "dgConstraint.h"
27 
28 
29 class dgBody;
30 class dgWorld;
31 class dgContact;
32 class dgCollision;
33 class dgContactPoint;
34 class dgContactMaterial;
35 class dgPolygonMeshDesc;
36 
37 
38 #define DG_MAX_CONTATCS 128
39 #define DG_CACHE_PAIR_BUFFER 256
40 
41 typedef int(dgApi *OnAABBOverlap)(const NewtonMaterial *const material, const NewtonBody *const body0, const NewtonBody *const body1, int32 threadIndex);
42 typedef void(dgApi *OnContactCallback)(const NewtonJoint *const contact, dFloat timestep, int32 threadIndex);
43 
44 class dgActiveContacts: public dgList<dgContact *> {
45 public:
46  dgActiveContacts(dgMemoryAllocator *const allocator)
47  : dgList<dgContact*>(allocator) {
48  }
49 };
50 
52 public:
53  struct dgPair {
54  dgBody *m_body0;
55  dgBody *m_body1;
56  dgContact *m_contact;
57  const dgContactMaterial *m_material;
58  dgContactPoint *m_contactBuffer;
59  dgInt16 m_contactCount;
60  dgInt16 m_isTrigger;
61  };
62 
64  dgInt32 m_count;
65  dgPair m_chacheBuffer[DG_CACHE_PAIR_BUFFER];
66  };
67  dgThreadPairCache *m_chacheBuffers[DG_MAXIMUN_THREADS];
68 
69 
72 
73  void Init();
74  void SetCaches(dgThreadPairCache *const chaches);
75  void FlushChache(dgThreadPairCache *const chache);
76  void AddPair(dgBody *const body0, dgBody *const body1, dgInt32 threadIndex);
77 
78 
79  dgPair *m_pairs;
80  dgInt32 m_count;
81  dgInt32 m_maxSize;
82  dgBody *m_sentinel;
83 };
84 
85 
86 
87 DG_MSC_VECTOR_ALIGMENT
89 public:
90  dgVector m_point;
91  dgVector m_normal;
92  dgBody *m_body0;
93  dgBody *m_body1;
94  dgCollision *m_collision0;
95  dgCollision *m_collision1;
96  dgInt64 m_userId;
97  dgFloat32 m_penetration;
98  dgInt32 m_isEdgeContact;
99 } DG_GCC_VECTOR_ALIGMENT;
100 
101 DG_MSC_VECTOR_ALIGMENT
103 public:
104  dgBody *m_floatingBody;
105  dgBody *m_referenceBody;
106  dgCollision *m_floatingCollision;
107  dgCollision *m_referenceCollision;
108  dgMatrix m_floatingMatrix;
109  dgMatrix m_referenceMatrix;
110  dgFloat32 m_timestep;
111  dgFloat32 m_penetrationPadding;
112  dgInt32 m_continueCollision;
113  dgInt32 m_unconditionalCast;
114  dgInt32 m_threadIndex;
115  dgInt32 m_maxContacts;
116  dgContactPoint *m_contacts;
117 
118  // used but Mink solver
119  const dgMatrix *m_localMatrixInv;
120  const dgPolygonMeshDesc *m_polyMeshData;
121 
122  dgUnsigned32 m_isTriggerVolume : 1;
123  dgUnsigned32 m_inTriggerVolume : 1;
124 
125 
126  dgCollisionParamProxy(dgInt32 threadIndex) {
127  m_threadIndex = threadIndex;
128  m_polyMeshData = NULL;
129  m_localMatrixInv = NULL;
130 // m_projectContinueCollisionContacts = 1;
131  }
132 
133 } DG_GCC_VECTOR_ALIGMENT;
134 
135 
136 
137 DG_MSC_VECTOR_ALIGMENT
139 public:
140 
141  enum {
142  m_collisionEnable__ = 1 << 0,
143  m_friction0Enable__ = 1 << 1,
144  m_friction1Enable__ = 1 << 2,
145  m_override0Accel__ = 1 << 3,
146  m_override1Accel__ = 1 << 4,
147  m_overrideNormalAccel__ = 1 << 5,
148  m_collisionContinueCollisionEnable__ = 1 << 6,
149  };
150 
152  void *GetUserData() const;
153  void SetUserData(void *const userData);
154  void SetCollisionCallback(OnAABBOverlap abbOvelap, OnContactCallback callback);
155  void SetCompoundCollisionCallback(OnAABBOverlap abbOvelap);
156 
157  dgVector m_dir0;
158  dgVector m_dir1;
159  dgFloat32 m_normal_Force;
160  dgFloat32 m_dir0_Force;
161  dgFloat32 m_dir1_Force;
162  dgFloat32 m_softness;
163  dgFloat32 m_restitution;
164  dgFloat32 m_staticFriction0;
165  dgFloat32 m_staticFriction1;
166  dgFloat32 m_dynamicFriction0;
167  dgFloat32 m_dynamicFriction1;
168  dgFloat32 m_penetrationPadding;
169  dgInt32 m_flags;
170 // union {
171 // dgInt32 m_flags;
172 // struct {
173 // dgUnsigned32 m_collisionEnable : 1;
174 // dgUnsigned32 m_friction0Enable : 1;
175 // dgUnsigned32 m_friction1Enable : 1;
176 // dgUnsigned32 m_override0Accel : 1;
177 // dgUnsigned32 m_override1Accel : 1;
178 // dgUnsigned32 m_overrideNormalAccel : 1;
179 // dgUnsigned32 m_collisionContinueCollisionEnable : 1;
180 // };
181 // };
182 
183 private:
184  void *m_userData;
185  OnAABBOverlap m_aabbOverlap;
186  OnContactCallback m_contactPoint;
187  OnAABBOverlap m_compoundAABBOverlap;
188 
189  friend class dgWorld;
190  friend class dgCollisionCompound;
191  friend class dgBroadPhaseCollision;
192  friend class dgSolverWorlkerThreads;
193  friend class dgCollidingPairCollector;
195 
196 } DG_GCC_VECTOR_ALIGMENT;
197 
198 
199 
200 DG_MSC_VECTOR_ALIGMENT
201 class dgContact:
202  public dgConstraint,
203  public dgList<dgContactMaterial> {
204 
205  dgContact(dgWorld *world);
206  virtual ~dgContact();
207 
208  DG_CLASS_ALLOCATOR(allocator)
209 
210  virtual void GetInfo(dgConstraintInfo *const info) const;
211  virtual dgUnsigned32 JacobianDerivative(dgContraintDescritor &params);
212  virtual void JointAccelerations(const dgJointAccelerationDecriptor &params);
213  virtual void JointAccelerationsSimd(const dgJointAccelerationDecriptor &params);
214  virtual void JointVelocityCorrection(const dgJointAccelerationDecriptor &params);
215 
216  virtual void SetDestructorCallback(OnConstraintDestroy destructor);
217 
218  void JacobianContactDerivative(dgContraintDescritor &params, dgContactMaterial &contact, dgInt32 normalIndex, dgInt32 &frictionIndex);
219  void CalculatePointDerivative(dgInt32 index, dgContraintDescritor &desc, const dgVector &dir, const dgPointParam &param) const;
220 
221 
222  dgVector m_prevPosit0;
223  dgVector m_prevPosit1;
224  dgQuaternion m_prevRotation0;
225  dgQuaternion m_prevRotation1;
226 
227  dgWorld *m_world;
228  dgActiveContacts::dgListNode *m_contactNode;
229  const dgContactMaterial *m_myCacheMaterial;
230  dgInt32 m_broadphaseLru;
231 
232  friend class dgWorld;
233  friend class dgActiveContacts;
234  friend class dgTireCollision;
235  friend class dgBroadPhaseCollision;
236  friend class dgSolverWorlkerThreads;
237  friend class dgCollidingPairCollector;
238 } DG_GCC_VECTOR_ALIGMENT;
239 
240 inline void dgContactMaterial::SetCollisionCallback(OnAABBOverlap aabbOverlap, OnContactCallback contact) {
241  m_aabbOverlap = aabbOverlap;
242  m_contactPoint = contact;
243 }
244 
245 inline void dgContactMaterial::SetCompoundCollisionCallback(OnAABBOverlap aabbOverlap) {
246  m_compoundAABBOverlap = aabbOverlap;
247 }
248 
249 inline void *dgContactMaterial::GetUserData() const {
250  return m_userData;
251 }
252 
253 inline void dgContactMaterial::SetUserData(void *const userData) {
254  m_userData = userData;
255 }
256 
257 
258 
259 inline void dgContact::SetDestructorCallback(OnConstraintDestroy destructor) {
260 }
261 
262 #endif
Definition: dgWorldDynamicUpdate.h:101
Definition: dgContact.h:201
Definition: dgContact.h:51
Definition: dgBroadPhaseCollision.h:170
Definition: dgBody.h:85
Definition: dgCollisionMesh.h:39
Definition: dgVector.h:86
Definition: dgQuaternion.h:31
Definition: dgConstraint.h:137
Definition: dgList.h:33
Definition: dgConstraint.h:48
Definition: dgBroadPhaseCollision.h:158
Definition: dgContact.h:88
Definition: dgContact.h:44
Definition: dgConstraint.h:191
Definition: dgContact.h:138
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgMemory.h:80
Definition: dgConstraint.h:169
Definition: dgWorld.h:118
Definition: dgConstraint.h:116
Definition: dgContact.h:53
Definition: dgCollisionCompound.h:31
Definition: dgContact.h:102