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

My Project

dgConstraint.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 #if !defined(AFX_DGCONSTRAINT_H__F9EC24E0_6E0F_4CD5_909E_A5F5E1AC7C0B_H)
23 #define AFX_DGCONSTRAINT_H__F9EC24E0_6E0F_4CD5_909E_A5F5E1AC7C0B_H
24
25 #include "dgBodyMasterList.h"
26
27 #define DG_MAX_BOUND dgFloat32 (1.0e15f)
28 #define DG_MIN_BOUND (-DG_MAX_BOUND)
29
30
31 #define DG_BILATERAL_CONSTRAINT -1
32 #define DG_NORMAL_CONSTRAINT -2
33 #define DG_BILATERAL_FRICTION_CONSTRAINT -3
34
35 #define DG_CONSTRAINT_MAX_ROWS (3 * 16)
36
37 #define MIN_JOINT_PIN_LENGTH dgFloat32 (50.0f)
38
39 class dgBody;
40 class dgWorld;
41 class dgConstraint;
42 class dgBilateralBounds;
43
44 typedef void (dgApi *ConstraintsForceFeeback) (const dgConstraint& me, dgFloat32 timestep, dgInt32 threadIndex);
45
46 class dgConstraintInfo
47 {
48 public:
49 dgMatrix m_attachMatrix_0;
50 dgMatrix m_attachMatrix_1;
51 dgFloat32 m_minLinearDof[3];
52 dgFloat32 m_maxLinearDof[3];
53 dgFloat32 m_minAngularDof[3];
54 dgFloat32 m_maxAngularDof[3];
55 dgBody* m_attachBody_0;
56 dgBody* m_attachBody_1;
57 dgFloat32 m_extraParameters[64];
58 dgInt32 m_collideCollisionOn;
59 char m_discriptionType[64];
60 };
61
62
63 class dgJointCallbackParam
64 {
65 public:
66 dgFloat32 m_accel;
67 dgFloat32 m_minFriction;
68 dgFloat32 m_maxFriction;
69 dgFloat32 m_timestep;
70 };
71
72
73 class dgForceImpactPair
74 {
75 public:
76 dgFloat32 m_force;
77 dgFloat32 m_impact;
78 };
79
80 class dgBilateralBounds
81 {
82 public:
83 dgFloat32 m_low;
84 dgFloat32 m_upper;
85 dgInt32 m_normalIndex;
86 dgForceImpactPair* m_jointForce;
87 };
88
89 DG_MSC_VECTOR_ALIGMENT
90 class dgJacobian
91 {
92 public:
93 dgVector m_linear;
94 dgVector m_angular;
95 } DG_GCC_VECTOR_ALIGMENT;
96
97 DG_MSC_VECTOR_ALIGMENT
98 class dgJacobianPair
99 {
100 public:
101 dgJacobian m_jacobianM0;
102 dgJacobian m_jacobianM1;
103 } DG_GCC_VECTOR_ALIGMENT;
104
105 class dgJacobianMatrixElement;
106 class dgJointAccelerationDecriptor
107 {
108 public:
109 dgInt32 m_rowsCount;
110 dgFloat32 m_timeStep;
111 dgFloat32 m_invTimeStep;
112 dgFloat32 m_firstPassCoefFlag;
113 dgJacobianMatrixElement *m_rowMatrix;
114 };
115
116
117 DG_MSC_VECTOR_ALIGMENT
118 class dgContraintDescritor
119 {
120 public:
121 dgJacobianPair m_jacobian[DG_CONSTRAINT_MAX_ROWS];
122 dgBilateralBounds m_forceBounds[DG_CONSTRAINT_MAX_ROWS];
123 dgFloat32 m_jointAccel[DG_CONSTRAINT_MAX_ROWS];
124 dgFloat32 m_jointStiffness[DG_CONSTRAINT_MAX_ROWS];
125 dgFloat32 m_restitution[DG_CONSTRAINT_MAX_ROWS];
126 dgFloat32 m_penetration[DG_CONSTRAINT_MAX_ROWS];
127 dgFloat32 m_penetrationStiffness[DG_CONSTRAINT_MAX_ROWS];
128 bool m_isMotor[DG_CONSTRAINT_MAX_ROWS];
129 dgWorld* m_world;
130 dgInt32 m_threadIndex;
131 dgFloat32 m_timestep;
132 dgFloat32 m_invTimestep;
133 } DG_GCC_VECTOR_ALIGMENT;
134
135
136 typedef void (dgApi *OnConstraintDestroy) (dgConstraint& me);
137
138 //DG_MSC_VECTOR_ALIGMENT
139 DG_MSC_VECTOR_ALIGMENT
140 class dgConstraint
141 {
142 public:
143 DG_CLASS_ALLOCATOR(allocator)
144
145 enum dgConstraintID
146 {
147 m_ballConstraint,
148 m_hingeConstraint,
149 m_sliderConstraint,
150 m_contactConstraint,
151 m_upVectorConstraint,
152 m_universalConstraint,
153 m_corkScrewConstraint,
154 m_unknownConstraint
155 };
156
157
158 dgUnsigned32 GetId () const;
159 dgBody* GetBody0 () const;
160 dgBody* GetBody1 () const;
161
162 void SetBodies (dgBody* const body0, dgBody* const body1);
163
164 dgBodyMasterListRow::dgListNode* GetLink0() const;
165 dgBodyMasterListRow::dgListNode* GetLink1() const;
166 void* GetUserData () const;
167
168 bool IsActive() const;
169 bool IsCollidable () const;
170
171 virtual void ResetMaxDOF();
172 dgInt32 GetMaxDOF() const;
173
174 void SetUserData (void *userData);
175 void SetCollidable (bool state);
176 virtual void SetDestructorCallback (OnConstraintDestroy destructor) = 0;
177
178 virtual dgFloat32 GetStiffness() const;
179 virtual void SetStiffness(dgFloat32 stiffness);
180 virtual void GetInfo (dgConstraintInfo* const info) const;
181
182
183 class dgPointParam
184 {
185 public:
186 dgVector m_r0;
187 dgVector m_r1;
188 dgVector m_posit0;
189 dgVector m_posit1;
190 dgVector m_veloc0;
191 dgVector m_veloc1;
192 dgVector m_centripetal0;
193 dgVector m_centripetal1;
194 dgFloat32 m_stiffness;
195 };
196
197
198 protected:
199 dgConstraint();
200 virtual ~dgConstraint();
201
202 virtual bool IsBilateral () const;
203
204
205 virtual dgUnsigned32 JacobianDerivative (dgContraintDescritor& params) = 0;
206
207 virtual void JointAccelerations(dgJointAccelerationDecriptor* const params) = 0;
208 virtual void JointVelocityCorrection(dgJointAccelerationDecriptor* const params) = 0;
209
210 void SetUpdateFeedbackFunction (ConstraintsForceFeeback function);
211 void InitPointParam (dgPointParam& param, dgFloat32 stiffness, const dgVector& p0Global, const dgVector& p1Global) const;
212
213
214 void InitInfo (dgConstraintInfo* const info) const;
215
216 void* m_userData;
217 dgBody* m_body0;
218 dgBody* m_body1;
219 dgBodyMasterListRow::dgListNode* m_link0;
220 dgBodyMasterListRow::dgListNode* m_link1;
221 ConstraintsForceFeeback m_updaFeedbackCallback;
222 dgUnsigned32 m_dynamicsLru;
223 dgUnsigned32 m_index;
224
225 dgUnsigned32 m_maxDOF : 6;
226 dgUnsigned32 m_constId : 6;
227 dgUnsigned32 m_enableCollision : 1;
228 dgUnsigned32 m_useExactSolver : 1;
229 dgUnsigned32 m_solverActive : 1;
230 dgUnsigned32 m_contactActive : 1;
231
232 friend class dgWorld;
233 friend class dgAmpInstance;
234 friend class dgJacobianMemory;
235 friend class dgBodyMasterList;
236 friend class dgWorldDynamicUpdate;
237 friend class dgParallelSolverJointAcceleration;
238 friend class dgParallelSolverInitFeedbackUpdate;
239 friend class dgParallelSolverBuildJacobianMatrix;
240 friend class dgBroadPhaseMaterialCallbackWorkerThread;
241 } DG_GCC_VECTOR_ALIGMENT;
242
243 inline dgConstraint::dgConstraint()
244 :m_userData(NULL)
245 ,m_body0(NULL)
246 ,m_body1(NULL)
247 ,m_link0(NULL)
248 ,m_link1(NULL)
249 ,m_updaFeedbackCallback(NULL)
250 ,m_dynamicsLru(0)
251 ,m_index(0)
252 ,m_maxDOF(6)
253 ,m_constId(m_unknownConstraint)
254 ,m_enableCollision(false)
255 ,m_useExactSolver(false)
256 ,m_solverActive(false)
257 ,m_contactActive(false)
258 {
259 dgAssert ((((dgUnsigned64) this) & 15) == 0);
260 }
261
262 inline dgConstraint::~dgConstraint()
263 {
264 }
265
266 inline void dgConstraint::SetUpdateFeedbackFunction (ConstraintsForceFeeback function)
267 {
268 m_updaFeedbackCallback = function;
269 }
270
271 inline bool dgConstraint::IsCollidable () const
272 {
273 return m_enableCollision ? true : false;
274 }
275
276 inline void dgConstraint::SetCollidable (bool state)
277 {
278 m_enableCollision = dgUnsigned32 (state);
279 }
280
281 inline dgUnsigned32 dgConstraint::GetId () const
282 {
283 return m_constId;
284 }
285
286 inline dgBody* dgConstraint::GetBody0 () const
287 {
288 return m_body0;
289 }
290
291 inline dgBody* dgConstraint::GetBody1 () const
292 {
293 return m_body1;
294 }
295
296 inline void dgConstraint::SetBodies (dgBody* const body0, dgBody* const body1)
297 {
298 m_body0 = body0;
299 m_body1 = body1;
300 }
301
302
303 inline dgBodyMasterListRow::dgListNode* dgConstraint::GetLink0() const
304 {
305 return m_link0;
306 }
307 inline dgBodyMasterListRow::dgListNode* dgConstraint::GetLink1() const
308 {
309 return m_link1;
310 }
311
312
313 inline dgFloat32 dgConstraint::GetStiffness() const
314 {
315 return dgFloat32 (1.0f);
316 }
317
318 inline void dgConstraint::SetStiffness(dgFloat32 stiffness)
319 {
320 }
321
322
323 inline void dgConstraint::ResetMaxDOF()
324 {
325 }
326
327 inline dgInt32 dgConstraint::GetMaxDOF() const
328 {
329 return dgInt32 (m_maxDOF);
330 }
331
332 inline bool dgConstraint::IsActive() const
333 {
334 return m_contactActive ? true : false;
335 }
336
337 #endif // !defined(AFX_DGCONSTRAINT_H__F9EC24E0_6E0F_4CD5_909E_A5F5E1AC7C0B_H)
338
dgList< dgBodyMasterListCell >::dgListNode
friend class dgListNode
Definition: dgList.h:249
dgConstraint::m_userData
void * m_userData
Definition: dgConstraint.h:216
dgApi
#define dgApi
Definition: dgTypes.h:263
dgUnsigned64
unsigned long long dgUnsigned64
Definition: dgTypes.h:223
dgForceImpactPair::m_impact
dgFloat32 m_impact
Definition: dgConstraint.h:77
dgAmpInstance
Definition: dgAmpInstance.h:143
dgBodyMasterList
Definition: dgBodyMasterList.h:57
dgConstraint::GetMaxDOF
dgInt32 GetMaxDOF() const
Definition: dgConstraint.h:327
dgConstraint::m_index
dgUnsigned32 m_index
Definition: dgConstraint.h:223
dgConstraintInfo::m_minAngularDof
dgFloat32 m_minAngularDof[3]
Definition: dgConstraint.h:53
dgForceImpactPair
Definition: dgConstraint.h:73
dgConstraint::dgPointParam::m_veloc0
dgVector m_veloc0
Definition: dgConstraint.h:190
dgBody
Definition: dgBody.h:44
DG_GCC_VECTOR_ALIGMENT
DG_MSC_VECTOR_ALIGMENT class dgJacobian DG_GCC_VECTOR_ALIGMENT
dgConstraintInfo::m_attachMatrix_0
dgMatrix m_attachMatrix_0
Definition: dgConstraint.h:49
userData
void *const userData
Definition: dgBroadPhase.h:35
timestep
dgFloat32 timestep
Definition: dgConstraint.h:44
dgAssert
#define dgAssert(x)
Definition: dgTypes.h:158
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
void
typedef void(dgApi *ConstraintsForceFeeback)(const dgConstraint &me
dgConstraint::m_hingeConstraint
Definition: dgConstraint.h:148
dgConstraint::dgPointParam::m_r1
dgVector m_r1
Definition: dgConstraint.h:187
dgJointAccelerationDecriptor::m_invTimeStep
dgFloat32 m_invTimeStep
Definition: dgConstraint.h:111
dgJacobianMemory
Definition: dgWorldDynamicUpdate.h:242
dgConstraint::m_body1
dgBody * m_body1
Definition: dgConstraint.h:218
dgConstraint::m_enableCollision
dgUnsigned32 m_enableCollision
Definition: dgConstraint.h:227
dgVector
Definition: dgVector.h:639
dgConstraintInfo::m_discriptionType
char m_discriptionType[64]
Definition: dgConstraint.h:59
dgConstraint::GetLink1
dgBodyMasterListRow::dgListNode * GetLink1() const
Definition: dgConstraint.h:307
dgConstraint::m_contactActive
dgUnsigned32 m_contactActive
Definition: dgConstraint.h:230
dgConstraint::m_corkScrewConstraint
Definition: dgConstraint.h:153
dgConstraint::dgConstraint
dgConstraint()
Definition: dgConstraint.h:243
dgJointCallbackParam::m_maxFriction
dgFloat32 m_maxFriction
Definition: dgConstraint.h:68
dgBilateralBounds::m_upper
dgFloat32 m_upper
Definition: dgConstraint.h:84
dgConstraint::m_constId
dgUnsigned32 m_constId
Definition: dgConstraint.h:226
dgConstraint::~dgConstraint
virtual ~dgConstraint()
Definition: dgConstraint.h:262
dgConstraint::dgPointParam::m_stiffness
dgFloat32 m_stiffness
Definition: dgConstraint.h:194
dgJacobianPair::m_jacobianM0
dgJacobian m_jacobianM0
Definition: dgConstraint.h:101
dgConstraint::ResetMaxDOF
virtual void ResetMaxDOF()
Definition: dgConstraint.h:323
DG_CLASS_ALLOCATOR
#define DG_CLASS_ALLOCATOR(allocator)
Definition: dgMemory.h:60
dgConstraint::SetBodies
void SetBodies(dgBody *const body0, dgBody *const body1)
Definition: dgConstraint.h:296
dgConstraint::m_universalConstraint
Definition: dgConstraint.h:152
dgContraintDescritor
Definition: dgConstraint.h:118
dgConstraint::dgPointParam::m_centripetal1
dgVector m_centripetal1
Definition: dgConstraint.h:193
dgConstraintInfo::m_minLinearDof
dgFloat32 m_minLinearDof[3]
Definition: dgConstraint.h:51
dgConstraint::m_body0
dgBody * m_body0
Definition: dgConstraint.h:217
dgConstraintInfo
Definition: dgConstraint.h:46
dgJointCallbackParam::m_accel
dgFloat32 m_accel
Definition: dgConstraint.h:66
dgConstraint::SetCollidable
void SetCollidable(bool state)
Definition: dgConstraint.h:276
dgWorldDynamicUpdate
Definition: dgWorldDynamicUpdate.h:252
dgConstraint::SetStiffness
virtual void SetStiffness(dgFloat32 stiffness)
Definition: dgConstraint.h:318
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgJointCallbackParam
Definition: dgConstraint.h:63
dgConstraint::dgPointParam::m_posit0
dgVector m_posit0
Definition: dgConstraint.h:188
dgConstraintInfo::m_extraParameters
dgFloat32 m_extraParameters[64]
Definition: dgConstraint.h:57
dgConstraint::IsCollidable
bool IsCollidable() const
Definition: dgConstraint.h:271
dgConstraint::dgPointParam::m_veloc1
dgVector m_veloc1
Definition: dgConstraint.h:191
dgJacobian::m_linear
dgVector m_linear
Definition: dgConstraint.h:93
dgJacobian
Definition: dgConstraint.h:90
dgJacobianPair
Definition: dgConstraint.h:98
dgJointCallbackParam::m_minFriction
dgFloat32 m_minFriction
Definition: dgConstraint.h:67
dgConstraint::m_updaFeedbackCallback
ConstraintsForceFeeback m_updaFeedbackCallback
Definition: dgConstraint.h:221
OnConstraintDestroy
void(dgApi * OnConstraintDestroy)(dgConstraint &me)
Definition: dgConstraint.h:136
dgConstraint::m_link1
dgBodyMasterListRow::dgListNode * m_link1
Definition: dgConstraint.h:220
dgConstraint::m_maxDOF
dgUnsigned32 m_maxDOF
Definition: dgConstraint.h:225
dgConstraint::dgPointParam
Definition: dgConstraint.h:183
dgBilateralBounds::m_normalIndex
dgInt32 m_normalIndex
Definition: dgConstraint.h:85
dgJointAccelerationDecriptor::m_rowsCount
dgInt32 m_rowsCount
Definition: dgConstraint.h:109
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgConstraint::m_link0
dgBodyMasterListRow::dgListNode * m_link0
Definition: dgConstraint.h:219
dgConstraintInfo::m_maxAngularDof
dgFloat32 m_maxAngularDof[3]
Definition: dgConstraint.h:54
dgConstraintInfo::m_attachBody_1
dgBody * m_attachBody_1
Definition: dgConstraint.h:56
dgConstraint::IsActive
bool IsActive() const
Definition: dgConstraint.h:332
dgJacobianMatrixElement
Definition: dgWorldDynamicUpdate.h:214
dgBilateralBounds
Definition: dgConstraint.h:80
dgJointCallbackParam::m_timestep
dgFloat32 m_timestep
Definition: dgConstraint.h:69
dgContraintDescritor::m_timestep
dgFloat32 m_timestep
Definition: dgConstraint.h:131
dgConstraint::GetId
dgUnsigned32 GetId() const
Definition: dgConstraint.h:281
threadIndex
dgFloat32 dgInt32 threadIndex
Definition: dgConstraint.h:44
dgContraintDescritor::m_threadIndex
dgInt32 m_threadIndex
Definition: dgConstraint.h:130
DG_CONSTRAINT_MAX_ROWS
#define DG_CONSTRAINT_MAX_ROWS
Definition: dgConstraint.h:35
dgConstraint::m_sliderConstraint
Definition: dgConstraint.h:149
dgConstraint::m_dynamicsLru
dgUnsigned32 m_dynamicsLru
Definition: dgConstraint.h:222
dgConstraint::GetBody0
dgBody * GetBody0() const
Definition: dgConstraint.h:286
dgMatrix
Definition: dgMatrix.h:40
dgConstraint::m_upVectorConstraint
Definition: dgConstraint.h:151
dgConstraint::GetLink0
dgBodyMasterListRow::dgListNode * GetLink0() const
Definition: dgConstraint.h:303
dgConstraintInfo::m_attachMatrix_1
dgMatrix m_attachMatrix_1
Definition: dgConstraint.h:50
dgJointAccelerationDecriptor::m_firstPassCoefFlag
dgFloat32 m_firstPassCoefFlag
Definition: dgConstraint.h:112
dgConstraint::dgPointParam::m_centripetal0
dgVector m_centripetal0
Definition: dgConstraint.h:192
dgConstraint
Definition: dgConstraint.h:140
dgJointAccelerationDecriptor::m_rowMatrix
dgJacobianMatrixElement * m_rowMatrix
Definition: dgConstraint.h:113
dgConstraint::dgPointParam::m_posit1
dgVector m_posit1
Definition: dgConstraint.h:189
dgConstraintInfo::m_collideCollisionOn
dgInt32 m_collideCollisionOn
Definition: dgConstraint.h:58
dgConstraint::dgPointParam::m_r0
dgVector m_r0
Definition: dgConstraint.h:186
dgConstraintInfo::m_attachBody_0
dgBody * m_attachBody_0
Definition: dgConstraint.h:55
dgJacobianPair::m_jacobianM1
dgJacobian m_jacobianM1
Definition: dgConstraint.h:102
dgWorld
Definition: dgWorld.h:129
dgConstraint::dgConstraintID
dgConstraintID
Definition: dgConstraint.h:145
dgJointAccelerationDecriptor::m_timeStep
dgFloat32 m_timeStep
Definition: dgConstraint.h:110
dgConstraint::m_ballConstraint
Definition: dgConstraint.h:147
dgBilateralBounds::m_low
dgFloat32 m_low
Definition: dgConstraint.h:83
dgBilateralBounds::m_jointForce
dgForceImpactPair * m_jointForce
Definition: dgConstraint.h:86
dgContraintDescritor::m_invTimestep
dgFloat32 m_invTimestep
Definition: dgConstraint.h:132
dgJointAccelerationDecriptor
Definition: dgConstraint.h:106
dgConstraintInfo::m_maxLinearDof
dgFloat32 m_maxLinearDof[3]
Definition: dgConstraint.h:52
dgForceImpactPair::m_force
dgFloat32 m_force
Definition: dgConstraint.h:76
dgConstraint::SetUpdateFeedbackFunction
void SetUpdateFeedbackFunction(ConstraintsForceFeeback function)
Definition: dgConstraint.h:266
dgJacobian::m_angular
dgVector m_angular
Definition: dgConstraint.h:94
dgConstraint::GetBody1
dgBody * GetBody1() const
Definition: dgConstraint.h:291
dgConstraint::GetStiffness
virtual dgFloat32 GetStiffness() const
Definition: dgConstraint.h:313
dgBodyMasterList.h
dgConstraint::m_contactConstraint
Definition: dgConstraint.h:150
dgContraintDescritor::m_world
dgWorld * m_world
Definition: dgConstraint.h:129