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