1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21 *************************************************************************/
23 #ifndef _ODE_COMMON_H_
24 #define _ODE_COMMON_H_
26 #include <ode/odeconfig.h>
27 #include <ode/error.h>
35 /* configuration stuff */
39 /* pi and 1/sqrt(2) are defined here if necessary because they don't get
40 * defined in <math.h> on some platforms (like MS-Windows)
44 #define M_PI REAL(3.1415926535897932384626433832795029)
47 #define M_PI_2 REAL(1.5707963267948966192313216916398)
50 #define M_SQRT1_2 REAL(0.7071067811865475244008443621048490)
54 /* floating point data type, vector, matrix and quaternion types */
59 #error You can only #define dSINGLE or dDOUBLE, not both.
61 #elif defined(dDOUBLE)
64 #error You must #define dSINGLE or dDOUBLE
67 /* Detect if we've got both trimesh engines enabled. */
69 #if dTRIMESH_OPCODE && dTRIMESH_GIMPACT
70 #error You can only #define dTRIMESH_OPCODE or dTRIMESH_GIMPACT, not both.
72 #endif /* dTRIMESH_ENABLED */
75 * Define a type for indices, either 16 or 32 bit, based on build option
76 * TODO: Currently GIMPACT only supports 32 bit indices.
78 #if dTRIMESH_16BIT_INDICES
80 typedef duint32 dTriIndex;
81 #else /* dTRIMESH_GIMPACT */
82 typedef duint16 dTriIndex;
83 #endif /* dTRIMESH_GIMPACT */
84 #else /* dTRIMESH_16BIT_INDICES */
85 typedef duint32 dTriIndex;
86 #endif /* dTRIMESH_16BIT_INDICES */
88 /* round an integer up to a multiple of 4, except that 0 and 1 are unmodified
89 * (used to compute matrix leading dimensions)
91 #define dPAD(a) (((a) > 1) ? (((a) + 3) & (int)(~3)) : (a))
106 dMD_LINEAR = dMD__MIN,
115 dDA__L_MIN = dDA__MIN + dMD_LINEAR * dSA__MAX,
117 dDA_LX = dDA__L_MIN + dSA_X,
118 dDA_LY = dDA__L_MIN + dSA_Y,
119 dDA_LZ = dDA__L_MIN + dSA_Z,
121 dDA__L_MAX = dDA__L_MIN + dSA__MAX,
123 dDA__A_MIN = dDA__MIN + dMD_ANGULAR * dSA__MAX,
125 dDA_AX = dDA__A_MIN + dSA_X,
126 dDA_AY = dDA__A_MIN + dSA_Y,
127 dDA_AZ = dDA__A_MIN + dSA_Z,
129 dDA__A_MAX = dDA__A_MIN + dSA__MAX,
131 dDA__MAX = dDA__MIN + dMD__MAX * dSA__MAX,
137 dV3E__AXES_MIN = dV3E__MIN,
139 dV3E_X = dV3E__AXES_MIN + dSA_X,
140 dV3E_Y = dV3E__AXES_MIN + dSA_Y,
141 dV3E_Z = dV3E__AXES_MIN + dSA_Z,
143 dV3E__AXES_MAX = dV3E__AXES_MIN + dSA__MAX,
145 dV3E_PAD = dV3E__AXES_MAX,
149 dV3E__AXES_COUNT = dV3E__AXES_MAX - dV3E__AXES_MIN,
155 dV4E_X = dV4E__MIN + dSA_X,
156 dV4E_Y = dV4E__MIN + dSA_Y,
157 dV4E_Z = dV4E__MIN + dSA_Z,
158 dV4E_O = dV4E__MIN + dSA__MAX,
166 dM3E__X_MIN = dM3E__MIN + dSA_X * dV3E__MAX,
168 dM3E__X_AXES_MIN = dM3E__X_MIN + dV3E__AXES_MIN,
170 dM3E_XX = dM3E__X_MIN + dV3E_X,
171 dM3E_XY = dM3E__X_MIN + dV3E_Y,
172 dM3E_XZ = dM3E__X_MIN + dV3E_Z,
174 dM3E__X_AXES_MAX = dM3E__X_MIN + dV3E__AXES_MAX,
176 dM3E_XPAD = dM3E__X_MIN + dV3E_PAD,
178 dM3E__X_MAX = dM3E__X_MIN + dV3E__MAX,
180 dM3E__Y_MIN = dM3E__MIN + dSA_Y * dV3E__MAX,
182 dM3E__Y_AXES_MIN = dM3E__Y_MIN + dV3E__AXES_MIN,
184 dM3E_YX = dM3E__Y_MIN + dV3E_X,
185 dM3E_YY = dM3E__Y_MIN + dV3E_Y,
186 dM3E_YZ = dM3E__Y_MIN + dV3E_Z,
188 dM3E__Y_AXES_MAX = dM3E__Y_MIN + dV3E__AXES_MAX,
190 dM3E_YPAD = dM3E__Y_MIN + dV3E_PAD,
192 dM3E__Y_MAX = dM3E__Y_MIN + dV3E__MAX,
194 dM3E__Z_MIN = dM3E__MIN + dSA_Z * dV3E__MAX,
196 dM3E__Z_AXES_MIN = dM3E__Z_MIN + dV3E__AXES_MIN,
198 dM3E_ZX = dM3E__Z_MIN + dV3E_X,
199 dM3E_ZY = dM3E__Z_MIN + dV3E_Y,
200 dM3E_ZZ = dM3E__Z_MIN + dV3E_Z,
202 dM3E__Z_AXES_MAX = dM3E__Z_MIN + dV3E__AXES_MAX,
204 dM3E_ZPAD = dM3E__Z_MIN + dV3E_PAD,
206 dM3E__Z_MAX = dM3E__Z_MIN + dV3E__MAX,
208 dM3E__MAX = dM3E__MIN + dSA__MAX * dV3E__MAX,
214 dM4E__X_MIN = dM4E__MIN + dV4E_X * dV4E__MAX,
216 dM4E_XX = dM4E__X_MIN + dV4E_X,
217 dM4E_XY = dM4E__X_MIN + dV4E_Y,
218 dM4E_XZ = dM4E__X_MIN + dV4E_Z,
219 dM4E_XO = dM4E__X_MIN + dV4E_O,
221 dM4E__X_MAX = dM4E__X_MIN + dV4E__MAX,
223 dM4E__Y_MIN = dM4E__MIN + dV4E_Y * dV4E__MAX,
225 dM4E_YX = dM4E__Y_MIN + dV4E_X,
226 dM4E_YY = dM4E__Y_MIN + dV4E_Y,
227 dM4E_YZ = dM4E__Y_MIN + dV4E_Z,
228 dM4E_YO = dM4E__Y_MIN + dV4E_O,
230 dM4E__Y_MAX = dM4E__Y_MIN + dV4E__MAX,
232 dM4E__Z_MIN = dM4E__MIN + dV4E_Z * dV4E__MAX,
234 dM4E_ZX = dM4E__Z_MIN + dV4E_X,
235 dM4E_ZY = dM4E__Z_MIN + dV4E_Y,
236 dM4E_ZZ = dM4E__Z_MIN + dV4E_Z,
237 dM4E_ZO = dM4E__Z_MIN + dV4E_O,
239 dM4E__Z_MAX = dM4E__Z_MIN + dV4E__MAX,
241 dM4E__O_MIN = dM4E__MIN + dV4E_O * dV4E__MAX,
243 dM4E_OX = dM4E__O_MIN + dV4E_X,
244 dM4E_OY = dM4E__O_MIN + dV4E_Y,
245 dM4E_OZ = dM4E__O_MIN + dV4E_Z,
246 dM4E_OO = dM4E__O_MIN + dV4E_O,
248 dM4E__O_MAX = dM4E__O_MIN + dV4E__MAX,
250 dM4E__MAX = dM4E__MIN + dV4E__MAX * dV4E__MAX,
260 dQUE_I = dQUE__AXIS_MIN + dSA_X,
261 dQUE_J = dQUE__AXIS_MIN + dSA_Y,
262 dQUE_K = dQUE__AXIS_MIN + dSA_Z,
264 dQUE__AXIS_MAX = dQUE__AXIS_MIN + dSA__MAX,
266 dQUE__MAX = dQUE__AXIS_MAX,
269 /* these types are mainly just used in headers */
270 typedef dReal dVector3[dV3E__MAX];
271 typedef dReal dVector4[dV4E__MAX];
272 typedef dReal dMatrix3[dM3E__MAX];
273 typedef dReal dMatrix4[dM4E__MAX];
274 typedef dReal dMatrix6[(dMD__MAX * dV3E__MAX) * (dMD__MAX * dSA__MAX)];
275 typedef dReal dQuaternion[dQUE__MAX];
278 /* precision dependent scalar math functions */
282 #define REAL(x) (x##f) /* form a constant */
283 #define dRecip(x) ((1.0f/(x))) /* reciprocal */
284 #define dSqrt(x) (sqrtf(x)) /* square root */
285 #define dRecipSqrt(x) ((1.0f/sqrtf(x))) /* reciprocal square root */
286 #define dSin(x) (sinf(x)) /* sine */
287 #define dCos(x) (cosf(x)) /* cosine */
288 #define dFabs(x) (fabsf(x)) /* absolute value */
289 #define dAtan2(y,x) (atan2f(y,x)) /* arc tangent with 2 args */
290 #define dAsin(x) (asinf(x))
291 #define dAcos(x) (acosf(x))
292 #define dFMod(a,b) (fmodf(a,b)) /* modulo */
293 #define dFloor(x) floorf(x) /* floor */
294 #define dCeil(x) ceilf(x) /* ceil */
295 #define dCopySign(a,b) _ode_copysignf(a, b) /* copy value sign */
296 #define dNextAfter(x, y) _ode_nextafterf(x, y) /* next value after */
299 #define dIsNan(x) (__isnanf(x))
300 #elif defined(HAVE__ISNANF)
301 #define dIsNan(x) (_isnanf(x))
302 #elif defined(HAVE_ISNANF)
303 #define dIsNan(x) (isnanf(x))
306 fall back to _isnan which is the VC way,
307 this may seem redundant since we already checked
308 for _isnan before, but if isnan is detected by
309 configure but is not found during compilation
310 we should always make sure we check for __isnanf,
311 _isnanf and isnanf in that order before falling
314 #define dIsNan(x) (_isnan(x))
317 #elif defined(dDOUBLE)
320 #define dRecip(x) (1.0/(x))
321 #define dSqrt(x) sqrt(x)
322 #define dRecipSqrt(x) (1.0/sqrt(x))
323 #define dSin(x) sin(x)
324 #define dCos(x) cos(x)
325 #define dFabs(x) fabs(x)
326 #define dAtan2(y,x) atan2((y),(x))
327 #define dAsin(x) asin(x)
328 #define dAcos(x) acos(x)
329 #define dFMod(a,b) (fmod((a),(b)))
330 #define dFloor(x) floor(x)
331 #define dCeil(x) ceil(x)
332 #define dCopySign(a,b) _ode_copysign(a, b)
333 #define dNextAfter(x, y) _ode_nextafter(x, y)
336 #define dIsNan(x) (__isnan(x))
337 #elif defined(HAVE__ISNAN)
338 #define dIsNan(x) (_isnan(x))
339 #elif defined(HAVE_ISNAN)
340 #define dIsNan(x) (isnan(x))
342 #define dIsNan(x) (_isnan(x))
346 #error You must #define dSINGLE or dDOUBLE
349 ODE_PURE_INLINE dReal dMin(dReal x, dReal y) { return x <= y ? x : y; }
350 ODE_PURE_INLINE dReal dMax(dReal x, dReal y) { return x <= y ? y : x; }
353 /* internal object types (all prefixed with `dx') */
355 struct dxWorld; /* dynamics world */
356 struct dxSpace; /* collision space */
357 struct dxBody; /* rigid body (dynamics object) */
358 struct dxGeom; /* geometry (collision object) */
359 struct dxJoint; /* joint */
360 struct dxJointGroup;/* joint group */
363 typedef struct dxWorld *dWorldID;
364 typedef struct dxSpace *dSpaceID;
365 typedef struct dxBody *dBodyID;
366 typedef struct dxGeom *dGeomID;
367 typedef struct dxJoint *dJointID;
368 typedef struct dxJointGroup *dJointGroupID;
374 d_ERR_UNKNOWN = 0, /* unknown error */
375 d_ERR_IASSERT, /* internal assertion failed */
376 d_ERR_UASSERT, /* user assertion failed */
377 d_ERR_LCP /* user assertion failed */
381 /* joint type numbers */
384 dJointTypeNone = 0, /* or "unknown" */
401 dJointTypeTransmission,
405 /* an alternative way of setting joint parameters, using joint parameter
406 * structures and member constants. we don't actually do this yet.
410 typedef struct dLimot {
412 dReal lostop, histop;
416 dReal suspension_erp, suspension_cfm;
420 dLimotLoStop = 0x0001,
421 dLimotHiStop = 0x0002,
424 dLimotFudgeFactor = 0x0010,
425 dLimotBounce = 0x0020,
431 /* standard joint parameter names. why are these here? - because we don't want
432 * to include all the joint function definitions in joint.cpp. hmmmm.
433 * MSVC complains if we call D_ALL_PARAM_NAMES_X with a blank second argument,
434 * which is why we have the D_ALL_PARAM_NAMES macro as well. please copy and
435 * paste between these two.
438 #define D_ALL_PARAM_NAMES(start) \
439 /* parameters for limits and motors */ \
440 dParamLoStop = start, \
451 /* parameters for suspension */ \
452 dParamSuspensionERP, \
453 dParamSuspensionCFM, \
457 * \enum D_ALL_PARAM_NAMES_X
459 * \var dParamGroup This is the starting value of the different group
460 * (i.e. dParamGroup1, dParamGroup2, dParamGroup3)
461 * It also helps in the use of parameter
462 * (dParamGroup2 | dParamFMax) == dParamFMax2
464 #define D_ALL_PARAM_NAMES_X(start,x) \
465 dParamGroup ## x = start, \
466 /* parameters for limits and motors */ \
467 dParamLoStop ## x = start, \
473 dParamFudgeFactor ## x, \
476 dParamStopERP ## x, \
477 dParamStopCFM ## x, \
478 /* parameters for suspension */ \
479 dParamSuspensionERP ## x, \
480 dParamSuspensionCFM ## x, \
485 dParamsInGroup, /* < Number of parameter in a group */
486 D_ALL_PARAM_NAMES_X(0x000,1)
487 D_ALL_PARAM_NAMES_X(0x100,2)
488 D_ALL_PARAM_NAMES_X(0x200,3)
490 /* add a multiple of this constant to the basic parameter numbers to get
491 * the parameters for the second, third etc axes.
497 /* angular motor mode numbers */
504 /* transmission joint mode numbers */
507 dTransmissionParallelAxes = 0,
508 dTransmissionIntersectingAxes = 1,
509 dTransmissionChainDrive = 2
513 /* joint force feedback information */
515 typedef struct dJointFeedback {
516 dVector3 f1; /* force applied to body 1 */
517 dVector3 t1; /* torque applied to body 1 */
518 dVector3 f2; /* force applied to body 2 */
519 dVector3 t2; /* torque applied to body 2 */
523 /* private functions that must be implemented by the collision library:
524 * (1) indicate that a geom has moved, (2) get the next geom in a body list.
525 * these functions are called whenever the position of geoms connected to a
526 * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or
527 * when the ODE step function updates the body state.
530 void dGeomMoved (dGeomID);
531 dGeomID dGeomGetBodyNext (dGeomID);
534 * dGetConfiguration returns the specific ODE build configuration as
535 * a string of tokens. The string can be parsed in a similar way to
536 * the OpenGL extension mechanism, the naming convention should be
537 * familiar too. The following extensions are reported:
540 * ODE_single_precision
541 * ODE_double_precision
546 * ODE_OPC_16bit_indices
547 * ODE_OPC_new_collider
548 * ODE_EXT_mt_collisions
550 * ODE_THR_builtin_impl
552 ODE_API const char* dGetConfiguration (void);
555 * Helper to check for a token in the ODE configuration string.
556 * Caution, this function is case sensitive.
558 * @param token A configuration token, see dGetConfiguration for details
560 * @return 1 if exact token is present, 0 if not present
562 ODE_API int dCheckConfiguration( const char* token );