My Project: dynamics.mod/NewtonDynamics/source/physics/dgContact.h Source File

My Project

dgContact.h
Go to the documentation of this file.
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 #ifndef __DGCONTACT_H__
23 #define __DGCONTACT_H__
24
25
26 #include "dgConstraint.h"
27
28 class dgBody;
29 class dgWorld;
30 class dgContact;
31 class dgContactPoint;
32 class dgContactMaterial;
33 class dgPolygonMeshDesc;
34 class dgCollisionInstance;
35
36
37 #define DG_MAX_CONTATCS 128
38 #define DG_RESTING_CONTACT_PENETRATION dgFloat32 (1.0f / 256.0f)
39
40 class dgActiveContacts: public dgList<dgContact*>
41 {
42 public:
43 dgActiveContacts (dgMemoryAllocator* const allocator)
44 :dgList<dgContact*>(allocator)
45 {
46 }
47 };
48
49 class dgCollidingPairCollector
50 {
51 public:
52 class dgPair
53 {
54 public:
55 dgContact* m_contact;
56 dgContactPoint* m_contactBuffer;
57 dgFloat32 m_timeOfImpact;
58 dgInt32 m_contactCount : 16;
59 dgInt32 m_isDeformable : 1;
60 dgInt32 m_cacheIsValid : 1;
61 };
62
63
64 dgCollidingPairCollector ();
65 ~dgCollidingPairCollector ();
66
67 void Init ();
68 void AddPair (dgContact* const contatJoint, dgInt32 threadIndex);
69
70 dgInt32 m_count;
71 dgInt32 m_maxSize;
72 dgBody* m_sentinel;
73 dgThread::dgCriticalSection m_lock;
74 };
75
76
77 DG_MSC_VECTOR_ALIGMENT
78 class dgContactPoint
79 {
80 public:
81 dgVector m_point;
82 dgVector m_normal;
83 const dgBody* m_body0;
84 const dgBody* m_body1;
85 const dgCollisionInstance* m_collision0;
86 const dgCollisionInstance* m_collision1;
87 dgInt64 m_shapeId0;
88 dgInt64 m_shapeId1;
89 dgFloat32 m_penetration;
90 }DG_GCC_VECTOR_ALIGMENT;
91
92 DG_MSC_VECTOR_ALIGMENT
93 class dgCollisionParamProxy
94 {
95 public:
96 dgCollisionParamProxy(dgContact* const contact, dgContactPoint* const contactBuffer, dgInt32 threadIndex, bool ccdMode, bool intersectionTestOnly)
97 :m_contactJoint(contact)
98 ,m_contacts(contactBuffer)
99 ,m_polyMeshData(NULL)
100 ,m_threadIndex(threadIndex)
101 ,m_continueCollision(ccdMode)
102 ,m_intersectionTestOnly(intersectionTestOnly)
103 {
104 }
105
106 dgMatrix m_matrix;
107 dgVector m_normal;
108 dgVector m_closestPointBody0;
109 dgVector m_closestPointBody1;
110 dgUnsigned64 m_shapeFaceID;
111 dgContact* m_contactJoint;
112 dgBody* m_floatingBody;
113 dgBody* m_referenceBody;
114 dgCollisionInstance* m_floatingCollision;
115 dgCollisionInstance* m_referenceCollision;
116 dgContactPoint* m_contacts;
117 dgPolygonMeshDesc* m_polyMeshData;
118
119 dgFloat32 m_timestep;
120 dgFloat32 m_skinThickness;
121 dgInt32 m_threadIndex;
122 dgInt32 m_maxContacts;
123 bool m_continueCollision;
124 bool m_intersectionTestOnly;
125
126 }DG_GCC_VECTOR_ALIGMENT;
127
128
129 class dgClothPatchMaterial
130 {
131 public:
132 dgFloat32 m_damper;
133 dgFloat32 m_stiffness;
134 };
135
136
137 DG_MSC_VECTOR_ALIGMENT
138 class dgContactMaterial: public dgContactPoint
139 {
140 public:
141
142 enum {
143 m_collisionEnable = 1<<0,
144 m_friction0Enable = 1<<1,
145 m_friction1Enable = 1<<2,
146 m_override0Accel = 1<<3,
147 m_override1Accel = 1<<4,
148 m_overrideNormalAccel = 1<<5,
149 };
150
151 typedef void (dgApi *OnContactCallback) (dgContact& contactJoint, dgFloat32 timestep, dgInt32 threadIndex);
152 typedef bool (dgApi *OnAABBOverlap) (const dgContactMaterial& material, const dgBody& body0, const dgBody& body1, dgInt32 threadIndex);
153 typedef bool (dgApi *OnCompoundCollisionPrefilter) (const dgContactMaterial& material, const dgBody* bodyA, const void* collisionNodeA, const dgBody* bodyB, const void* collisionNodeB, dgInt32 threadIndex);
154
155 dgContactMaterial();
156 void* GetUserData () const;
157 void SetUserData (void* const userData);
158 void SetCollisionCallback (OnAABBOverlap abbOvelap, OnContactCallback callback);
159 void SetCompoundCollisionCallback (OnCompoundCollisionPrefilter abbCompounndOvelap);
160
161 dgVector m_dir0;
162 dgVector m_dir1;
163 dgForceImpactPair m_normal_Force;
164 dgForceImpactPair m_dir0_Force;
165 dgForceImpactPair m_dir1_Force;
166 dgFloat32 m_softness;
167 dgFloat32 m_restitution;
168 dgFloat32 m_staticFriction0;
169 dgFloat32 m_staticFriction1;
170 dgFloat32 m_dynamicFriction0;
171 dgFloat32 m_dynamicFriction1;
172 dgFloat32 m_skinThickness;
173 dgInt32 m_flags;
174
175 private:
176 void *m_userData;
177 OnAABBOverlap m_aabbOverlap;
178 OnContactCallback m_contactPoint;
179 OnCompoundCollisionPrefilter m_compoundAABBOverlap;
180
181 friend class dgWorld;
182 friend class dgBroadPhase;
183 friend class dgCollisionScene;
184 friend class dgCollisionCompound;
185 friend class dgWorldDynamicUpdate;
186 friend class dgSolverWorlkerThreads;
187 friend class dgCollidingPairCollector;
188 friend class dgBroadPhaseMaterialCallbackWorkerThread;
189
190 }DG_GCC_VECTOR_ALIGMENT;
191
192
193
194 DG_MSC_VECTOR_ALIGMENT
195 class dgContact: public dgConstraint, public dgList<dgContactMaterial>
196 {
197 public:
198 dgFloat32 GetClosestDistance() const;
199 dgFloat32 GetTimeOfImpact() const;
200 void SetTimeOfImpact(dgFloat32 timetoImpact);
201 const dgContactMaterial* GetMaterial() const;
202
203 protected:
204 dgContact(dgWorld* const world, const dgContactMaterial* const material);
205 virtual ~dgContact();
206
207 DG_CLASS_ALLOCATOR(allocator)
208
209 virtual void ResetMaxDOF();
210 virtual void GetInfo (dgConstraintInfo* const info) const;
211 virtual dgUnsigned32 JacobianDerivative (dgContraintDescritor& params);
212 virtual void JointAccelerations (dgJointAccelerationDecriptor* const params);
213 virtual void JointVelocityCorrection(dgJointAccelerationDecriptor* const params);
214
215 virtual bool IsDeformable() const ;
216 virtual void SetDestructorCallback (OnConstraintDestroy destructor);
217
218 void JacobianContactDerivative (dgContraintDescritor& params, const dgContactMaterial& contact, dgInt32 normalIndex, dgInt32& frictionIndex);
219 void CalculatePointDerivative (dgInt32 index, dgContraintDescritor& desc, const dgVector& dir, const dgPointParam& param) const;
220
221 void AppendToActiveList();
222 void SwapBodies();
223
224 dgVector m_positAcc;
225 dgQuaternion m_rotationAcc;
226 dgVector m_separtingVector;
227 dgFloat32 m_closestDistance;
228 dgFloat32 m_timeOfImpact;
229 dgWorld* m_world;
230 const dgContactMaterial* m_material;
231 dgActiveContacts::dgListNode* m_contactNode;
232 dgUnsigned32 m_broadphaseLru;
233 dgUnsigned32 m_isNewContact : 1;
234
235
236 friend class dgBody;
237 friend class dgWorld;
238 friend class dgBroadPhase;
239 friend class dgContactSolver;
240 friend class dgActiveContacts;
241 friend class dgCollisionScene;
242 friend class dgCollisionConvex;
243 friend class dgCollisionCompound;
244 friend class dgWorldDynamicUpdate;
245 friend class dgSolverWorlkerThreads;
246 friend class dgCollisionConvexPolygon;
247 friend class dgCollidingPairCollector;
248 }DG_GCC_VECTOR_ALIGMENT;
249
250 inline void dgContactMaterial::SetCollisionCallback (OnAABBOverlap aabbOverlap, OnContactCallback contact)
251 {
252 m_aabbOverlap = aabbOverlap;
253 m_contactPoint = contact;
254 }
255
256 inline void dgContactMaterial::SetCompoundCollisionCallback (OnCompoundCollisionPrefilter aabbOverlap)
257 {
258 m_compoundAABBOverlap = aabbOverlap;
259 }
260
261 inline void* dgContactMaterial::GetUserData () const
262 {
263 return m_userData;
264 }
265
266 inline void dgContactMaterial::SetUserData (void* const userData)
267 {
268 m_userData = userData;
269 }
270
271
272 inline bool dgContact::IsDeformable() const
273 {
274 return false;
275 }
276
277 inline void dgContact::SetDestructorCallback (OnConstraintDestroy destructor)
278 {
279 }
280
281 inline const dgContactMaterial* dgContact::GetMaterial() const
282 {
283 return m_material;
284 }
285
286 inline void dgContact::SetTimeOfImpact(dgFloat32 timetoImpact)
287 {
288 m_timeOfImpact = timetoImpact;
289 }
290
291 inline dgFloat32 dgContact::GetTimeOfImpact() const
292 {
293 return m_timeOfImpact;
294 }
295
296 inline dgFloat32 dgContact::GetClosestDistance() const
297 {
298 return m_closestDistance;
299 }
300
301 inline void dgContact::ResetMaxDOF()
302 {
303 m_maxDOF = 0;
304 }
305
306 #endif
307
dgContactPoint::m_penetration
dgFloat32 m_penetration
Definition: dgContact.h:89
dgList< dgContact *>::dgListNode
friend class dgListNode
Definition: dgList.h:249
dgContact::m_positAcc
dgVector m_positAcc
Definition: dgContact.h:224
dgApi
#define dgApi
Definition: dgTypes.h:263
dgInt64
long long dgInt64
Definition: dgTypes.h:222
dgUnsigned64
unsigned long long dgUnsigned64
Definition: dgTypes.h:223
dgContactPoint::m_normal
dgVector m_normal
Definition: dgContact.h:82
dgCollisionParamProxy::m_referenceBody
dgBody * m_referenceBody
Definition: dgContact.h:113
dgContact
Definition: dgContact.h:195
dgCollisionParamProxy::m_timestep
dgFloat32 m_timestep
Definition: dgContact.h:119
dgCollidingPairCollector::dgPair
Definition: dgContact.h:52
dgCollidingPairCollector
Definition: dgContact.h:49
dgContact::SetDestructorCallback
virtual void SetDestructorCallback(OnConstraintDestroy destructor)
Definition: dgContact.h:277
dgContactMaterial::SetUserData
void SetUserData(void *const userData)
Definition: dgContact.h:266
dgContactPoint::m_body0
const dgBody * m_body0
Definition: dgContact.h:83
dgForceImpactPair
Definition: dgConstraint.h:73
dgCollisionParamProxy::m_contactJoint
dgContact * m_contactJoint
Definition: dgContact.h:111
dgBody
Definition: dgBody.h:44
dgContactMaterial::m_flags
dgInt32 m_flags
Definition: dgContact.h:173
dgContact::GetClosestDistance
dgFloat32 GetClosestDistance() const
Definition: dgContact.h:296
userData
void *const userData
Definition: dgBroadPhase.h:35
dgClothPatchMaterial
Definition: dgContact.h:129
dgContactMaterial::m_dir0_Force
dgForceImpactPair m_dir0_Force
Definition: dgContact.h:164
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgCollisionParamProxy::m_intersectionTestOnly
bool m_intersectionTestOnly
Definition: dgContact.h:124
void
typedef void(dgApi *ConstraintsForceFeeback)(const dgConstraint &me
dgPolygonMeshDesc
Definition: dgCollisionMesh.h:42
dgVector
Definition: dgVector.h:639
dgContactMaterial::m_dir1_Force
dgForceImpactPair m_dir1_Force
Definition: dgContact.h:165
dgContact::GetMaterial
const dgContactMaterial * GetMaterial() const
Definition: dgContact.h:281
dgCollisionParamProxy::m_continueCollision
bool m_continueCollision
Definition: dgContact.h:123
dgContactMaterial::m_dir1
dgVector m_dir1
Definition: dgContact.h:162
dgCollisionParamProxy::m_maxContacts
dgInt32 m_maxContacts
Definition: dgContact.h:122
dgContactMaterial::m_staticFriction1
dgFloat32 m_staticFriction1
Definition: dgContact.h:169
dgContactPoint::m_shapeId1
dgInt64 m_shapeId1
Definition: dgContact.h:88
dgContact::SetTimeOfImpact
void SetTimeOfImpact(dgFloat32 timetoImpact)
Definition: dgContact.h:286
dgContactMaterial::m_skinThickness
dgFloat32 m_skinThickness
Definition: dgContact.h:172
DG_CLASS_ALLOCATOR
#define DG_CLASS_ALLOCATOR(allocator)
Definition: dgMemory.h:60
dgContactPoint::m_shapeId0
dgInt64 m_shapeId0
Definition: dgContact.h:87
dgCollidingPairCollector::m_lock
dgThread::dgCriticalSection m_lock
Definition: dgContact.h:73
dgCollisionConvexPolygon
Definition: dgCollisionConvexPolygon.h:31
dgQuaternion
Definition: dgQuaternion.h:31
dgContact::m_rotationAcc
dgQuaternion m_rotationAcc
Definition: dgContact.h:225
dgContraintDescritor
Definition: dgConstraint.h:118
dgList
Definition: dgList.h:33
dgCollisionParamProxy::m_polyMeshData
dgPolygonMeshDesc * m_polyMeshData
Definition: dgContact.h:117
dgCollidingPairCollector::dgPair::m_contactBuffer
dgContactPoint * m_contactBuffer
Definition: dgContact.h:56
dgConstraint.h
dgContactPoint::m_body1
const dgBody * m_body1
Definition: dgContact.h:84
dgContact::m_separtingVector
dgVector m_separtingVector
Definition: dgContact.h:226
dgConstraintInfo
Definition: dgConstraint.h:46
dgContactPoint
Definition: dgContact.h:78
dgContactPoint::m_point
dgVector m_point
Definition: dgContact.h:81
dgCollidingPairCollector::dgPair::m_contact
dgContact * m_contact
Definition: dgContact.h:55
dgWorldDynamicUpdate
Definition: dgWorldDynamicUpdate.h:252
dgClothPatchMaterial::m_stiffness
dgFloat32 m_stiffness
Definition: dgContact.h:133
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgContactMaterial::SetCompoundCollisionCallback
void SetCompoundCollisionCallback(OnCompoundCollisionPrefilter abbCompounndOvelap)
Definition: dgContact.h:256
dgJointCallbackParam
Definition: dgConstraint.h:63
dgContactMaterial::GetUserData
void * GetUserData() const
Definition: dgContact.h:261
dgBroadPhase
Definition: dgBroadPhase.h:65
dgContactMaterial::m_normal_Force
dgForceImpactPair m_normal_Force
Definition: dgContact.h:163
dgCollisionParamProxy::m_closestPointBody0
dgVector m_closestPointBody0
Definition: dgContact.h:108
dgContactMaterial::m_softness
dgFloat32 m_softness
Definition: dgContact.h:166
dgCollidingPairCollector::dgPair::m_timeOfImpact
dgFloat32 m_timeOfImpact
Definition: dgContact.h:57
dgCollisionInstance
Definition: dgCollisionInstance.h:30
dgCollisionParamProxy::m_threadIndex
dgInt32 m_threadIndex
Definition: dgContact.h:121
dgActiveContacts
Definition: dgContact.h:40
dgContactMaterial::m_dir0
dgVector m_dir0
Definition: dgContact.h:161
dgCollisionParamProxy::m_referenceCollision
dgCollisionInstance * m_referenceCollision
Definition: dgContact.h:115
OnConstraintDestroy
void(dgApi * OnConstraintDestroy)(dgConstraint &me)
Definition: dgConstraint.h:136
dgContactMaterial::m_restitution
dgFloat32 m_restitution
Definition: dgContact.h:167
dgCollidingPairCollector::m_maxSize
dgInt32 m_maxSize
Definition: dgContact.h:71
dgConstraint::dgPointParam
Definition: dgConstraint.h:183
dgCollisionScene
Definition: dgCollisionScene.h:31
dgContact::m_broadphaseLru
dgUnsigned32 m_broadphaseLru
Definition: dgContact.h:232
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgCollidingPairCollector::m_sentinel
dgBody * m_sentinel
Definition: dgContact.h:72
dgContact::m_closestDistance
dgFloat32 m_closestDistance
Definition: dgContact.h:227
dgCollisionParamProxy::m_contacts
dgContactPoint * m_contacts
Definition: dgContact.h:116
dgCollisionConvex
Definition: dgCollisionConvex.h:42
dgContact::IsDeformable
virtual bool IsDeformable() const
Definition: dgContact.h:272
dgCollisionParamProxy::m_closestPointBody1
dgVector m_closestPointBody1
Definition: dgContact.h:109
dgContact::m_timeOfImpact
dgFloat32 m_timeOfImpact
Definition: dgContact.h:228
dgContactMaterial
Definition: dgContact.h:138
threadIndex
dgFloat32 dgInt32 threadIndex
Definition: dgConstraint.h:44
timestep
dgFloat32 timestep
Definition: dgBallConstraint.h:34
dgContactPoint::m_collision0
const dgCollisionInstance * m_collision0
Definition: dgContact.h:85
dgContact::ResetMaxDOF
virtual void ResetMaxDOF()
Definition: dgContact.h:301
dgContact::GetTimeOfImpact
dgFloat32 GetTimeOfImpact() const
Definition: dgContact.h:291
dgContactMaterial::SetCollisionCallback
void SetCollisionCallback(OnAABBOverlap abbOvelap, OnContactCallback callback)
Definition: dgContact.h:250
dgCollisionParamProxy::m_shapeFaceID
dgUnsigned64 m_shapeFaceID
Definition: dgContact.h:110
dgMatrix
Definition: dgMatrix.h:40
dgMemoryAllocator
Definition: dgMemory.h:73
dgClothPatchMaterial::m_damper
dgFloat32 m_damper
Definition: dgContact.h:132
dgActiveContacts::dgActiveContacts
dgActiveContacts(dgMemoryAllocator *const allocator)
Definition: dgContact.h:43
dgContact::m_contactNode
dgActiveContacts::dgListNode * m_contactNode
Definition: dgContact.h:231
DG_GCC_VECTOR_ALIGMENT
DG_MSC_VECTOR_ALIGMENT class dgContactPoint DG_GCC_VECTOR_ALIGMENT
dgCollisionParamProxy::dgCollisionParamProxy
dgCollisionParamProxy(dgContact *const contact, dgContactPoint *const contactBuffer, dgInt32 threadIndex, bool ccdMode, bool intersectionTestOnly)
Definition: dgContact.h:96
dgCollisionParamProxy::m_normal
dgVector m_normal
Definition: dgContact.h:107
dgCollisionParamProxy::m_skinThickness
dgFloat32 m_skinThickness
Definition: dgContact.h:120
dgConstraint
Definition: dgConstraint.h:140
dgContact::m_world
dgWorld * m_world
Definition: dgContact.h:229
dgCollisionParamProxy::m_floatingCollision
dgCollisionInstance * m_floatingCollision
Definition: dgContact.h:114
dgWorld
Definition: dgWorld.h:129
dgJointAccelerationDecriptor
Definition: dgConstraint.h:106
dgThread::dgCriticalSection
Definition: dgThread.h:35
dgContactMaterial::m_staticFriction0
dgFloat32 m_staticFriction0
Definition: dgContact.h:168
dgCollisionParamProxy::m_matrix
dgMatrix m_matrix
Definition: dgContact.h:106
dgContactPoint::m_collision1
const dgCollisionInstance * m_collision1
Definition: dgContact.h:86
dgCollidingPairCollector::m_count
dgInt32 m_count
Definition: dgContact.h:70
dgContactMaterial::m_dynamicFriction0
dgFloat32 m_dynamicFriction0
Definition: dgContact.h:170
dgCollisionParamProxy::m_floatingBody
dgBody * m_floatingBody
Definition: dgContact.h:112
dgContactMaterial::m_dynamicFriction1
dgFloat32 m_dynamicFriction1
Definition: dgContact.h:171
dgContact::m_material
const dgContactMaterial * m_material
Definition: dgContact.h:230
dgCollisionCompound
Definition: dgCollisionCompound.h:35
dgCollisionParamProxy
Definition: dgContact.h:93