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_
25 #include <ode/odeconfig.h>
26 #include <ode/error.h>
34 #define PURE_INLINE static __inline
37 /* configuration stuff */
41 /* pi and 1/sqrt(2) are defined here if necessary because they don't get
42 * defined in <math.h> on some platforms (like MS-Windows)
46 #define M_PI REAL(3.1415926535897932384626433832795029)
49 #define M_SQRT1_2 REAL(0.7071067811865475244008443621048490)
54 * IASSERT is an internal assertion, i.e. a consistency check. if it fails
55 * we want to know where.
56 * UASSERT is a user assertion, i.e. if it fails a nice error message
57 * should be printed for the user.
58 * AASSERT is an arguments assertion, i.e. if it fails "bad argument(s)"
60 * DEBUGMSG just prints out a message
63 # if defined(__STDC__) && __STDC_VERSION__ >= 199901L
64 # define __FUNCTION__ __func__
68 # define dIASSERT(a) { if (!(a)) { dDebug (d_ERR_IASSERT, \
69 "assertion \"" #a "\" failed in %s() [%s:%u]",__FUNCTION__,__FILE__,__LINE__); } }
70 # define dUASSERT(a,msg) { if (!(a)) { dDebug (d_ERR_UASSERT, \
71 msg " in %s()", __FUNCTION__); } }
72 # define dDEBUGMSG(msg) { dMessage (d_ERR_UASSERT, \
73 msg " in %s() [%s:%u]", __FUNCTION__,__FILE__,__LINE__); }
74 # else // not __GNUC__
75 # define dIASSERT(a) { if (!(a)) { dDebug (d_ERR_IASSERT, \
76 "assertion \"" #a "\" failed in %s:%u",__FILE__,__LINE__); } }
77 # define dUASSERT(a,msg) { if (!(a)) { dDebug (d_ERR_UASSERT, \
78 msg " (%s:%u)", __FILE__,__LINE__); } }
79 # define dDEBUGMSG(msg) { dMessage (d_ERR_UASSERT, \
80 msg " (%s:%u)", __FILE__,__LINE__); }
82 # define dIVERIFY(a) dIASSERT(a)
84 # define dIASSERT(a) ((void)0)
85 # define dUASSERT(a,msg) ((void)0)
86 # define dDEBUGMSG(msg) ((void)0)
87 # define dIVERIFY(a) ((void)(a))
91 # define dICHECK(a) { if (!(a)) { dDebug (d_ERR_IASSERT, \
92 "assertion \"" #a "\" failed in %s() [%s:%u]",__FUNCTION__,__FILE__,__LINE__); *(int *)0 = 0; } }
93 # else // not __GNUC__
94 # define dICHECK(a) { if (!(a)) { dDebug (d_ERR_IASSERT, \
95 "assertion \"" #a "\" failed in %s:%u",__FILE__,__LINE__); *(int *)0 = 0; } }
98 // Argument assert is a special case of user assert
99 #define dAASSERT(a) dUASSERT(a,"Bad argument(s)")
101 /* floating point data type, vector, matrix and quaternion types */
106 #error You can only #define dSINGLE or dDOUBLE, not both.
108 #elif defined(dDOUBLE)
109 typedef double dReal;
111 #error You must #define dSINGLE or dDOUBLE
114 // Detect if we've got both trimesh engines enabled.
116 #if dTRIMESH_OPCODE && dTRIMESH_GIMPACT
117 #error You can only #define dTRIMESH_OPCODE or dTRIMESH_GIMPACT, not both.
119 #endif // dTRIMESH_ENABLED
121 // Define a type for indices, either 16 or 32 bit, based on build option
122 // TODO: Currently GIMPACT only supports 32 bit indices.
123 #if dTRIMESH_16BIT_INDICES
125 typedef uint32 dTriIndex;
126 #else // dTRIMESH_GIMPACT
127 typedef uint16 dTriIndex;
128 #endif // dTRIMESH_GIMPACT
129 #else // dTRIMESH_16BIT_INDICES
130 typedef uint32 dTriIndex;
131 #endif // dTRIMESH_16BIT_INDICES
133 /* round an integer up to a multiple of 4, except that 0 and 1 are unmodified
134 * (used to compute matrix leading dimensions)
136 #define dPAD(a) (((a) > 1) ? ((((a)-1)|3)+1) : (a))
138 /* these types are mainly just used in headers */
139 typedef dReal dVector3[4];
140 typedef dReal dVector4[4];
141 typedef dReal dMatrix3[4*3];
142 typedef dReal dMatrix4[4*4];
143 typedef dReal dMatrix6[8*6];
144 typedef dReal dQuaternion[4];
147 /* precision dependent scalar math functions */
151 #define REAL(x) (x ## f) /* form a constant */
152 #define dRecip(x) ((1.0f/(x))) /* reciprocal */
153 #define dSqrt(x) (sqrtf(x)) /* square root */
154 #define dRecipSqrt(x) ((1.0f/sqrtf(x))) /* reciprocal square root */
155 #define dSin(x) (sinf(x)) /* sine */
156 #define dCos(x) (cosf(x)) /* cosine */
157 #define dFabs(x) (fabsf(x)) /* absolute value */
158 #define dAtan2(y,x) (atan2f(y,x)) /* arc tangent with 2 args */
159 #define dFMod(a,b) (fmodf(a,b)) /* modulo */
160 #define dFloor(x) floorf(x) /* floor */
161 #define dCeil(x) ceilf(x) /* floor */
162 #define dCopySign(a,b) ((dReal)copysignf(a,b)) /* copy value sign */
163 #define dNextAfter(x, y) nextafterf(x, y) /* next value after */
165 #if defined(_ODE__NEXTAFTERF_REQUIRED)
166 float _nextafterf(float x, float y);
170 #define dIsNan(x) (__isnanf(x))
171 #elif defined(HAVE__ISNANF)
172 #define dIsNan(x) (_isnanf(x))
173 #elif defined(HAVE_ISNANF)
174 #define dIsNan(x) (isnanf(x))
177 fall back to _isnan which is the VC way,
178 this may seem redundant since we already checked
179 for _isnan before, but if isnan is detected by
180 configure but is not found during compilation
181 we should always make sure we check for __isnanf,
182 _isnanf and isnanf in that order before falling
185 #define dIsNan(x) (_isnan(x))
188 #elif defined(dDOUBLE)
191 #define dRecip(x) (1.0/(x))
192 #define dSqrt(x) sqrt(x)
193 #define dRecipSqrt(x) (1.0/sqrt(x))
194 #define dSin(x) sin(x)
195 #define dCos(x) cos(x)
196 #define dFabs(x) fabs(x)
197 #define dAtan2(y,x) atan2((y),(x))
198 #define dFMod(a,b) (fmod((a),(b)))
199 #define dFloor(x) floor(x)
200 #define dCeil(x) ceil(x)
201 #define dCopySign(a,b) (copysign((a),(b)))
202 #define dNextAfter(x, y) nextafter(x, y)
204 #undef _ODE__NEXTAFTERF_REQUIRED
207 #define dIsNan(x) (__isnan(x))
208 #elif defined(HAVE__ISNAN)
209 #define dIsNan(x) (_isnan(x))
210 #elif defined(HAVE_ISNAN)
211 #define dIsNan(x) (isnan(x))
213 #define dIsNan(x) (_isnan(x))
217 #error You must #define dSINGLE or dDOUBLE
220 /* internal object types (all prefixed with `dx') */
222 struct dxWorld; /* dynamics world */
223 struct dxSpace; /* collision space */
224 struct dxBody; /* rigid body (dynamics object) */
225 struct dxGeom; /* geometry (collision object) */
229 struct dxWorldProcessThreadingManager;
231 typedef struct dxWorld *dWorldID;
232 typedef struct dxSpace *dSpaceID;
233 typedef struct dxBody *dBodyID;
234 typedef struct dxGeom *dGeomID;
235 typedef struct dxJoint *dJointID;
236 typedef struct dxJointGroup *dJointGroupID;
237 typedef struct dxWorldProcessThreadingManager *dWorldStepThreadingManagerID;
242 d_ERR_UNKNOWN = 0, /* unknown error */
243 d_ERR_IASSERT, /* internal assertion failed */
244 d_ERR_UASSERT, /* user assertion failed */
245 d_ERR_LCP /* user assertion failed */
249 /* joint type numbers */
252 dJointTypeNone = 0, /* or "unknown" */
270 /* an alternative way of setting joint parameters, using joint parameter
271 * structures and member constants. we don't actually do this yet.
275 typedef struct dLimot {
277 dReal lostop, histop;
281 dReal suspension_erp, suspension_cfm;
285 dLimotLoStop = 0x0001,
286 dLimotHiStop = 0x0002,
289 dLimotFudgeFactor = 0x0010,
290 dLimotBounce = 0x0020,
296 /* standard joint parameter names. why are these here? - because we don't want
297 * to include all the joint function definitions in joint.cpp. hmmmm.
298 * MSVC complains if we call D_ALL_PARAM_NAMES_X with a blank second argument,
299 * which is why we have the D_ALL_PARAM_NAMES macro as well. please copy and
300 * paste between these two.
303 #define D_ALL_PARAM_NAMES(start) \
304 /* parameters for limits and motors */ \
305 dParamLoStop = start, \
314 /* parameters for suspension */ \
315 dParamSuspensionERP, \
316 dParamSuspensionCFM, \
319 //////////////////////////////////////////////////////////////////////////////
320 /// \enum D_ALL_PARAM_NAMES_X
322 /// \var dParamGroup This is the starting value of the different group
323 /// (i.e. dParamGroup1, dParamGroup2, dParamGroup3)
324 /// It also helps in the use of parameter
325 /// (dParamGroup2 | dParamFMax) == dParamFMax2
326 //////////////////////////////////////////////////////////////////////////////
327 #define D_ALL_PARAM_NAMES_X(start,x) \
328 dParamGroup ## x = start, \
329 /* parameters for limits and motors */ \
330 dParamLoStop ## x = start, \
334 dParamFudgeFactor ## x, \
337 dParamStopERP ## x, \
338 dParamStopCFM ## x, \
339 /* parameters for suspension */ \
340 dParamSuspensionERP ## x, \
341 dParamSuspensionCFM ## x, \
346 dParamsInGroup, ///< Number of parameter in a group
347 D_ALL_PARAM_NAMES_X(0x000,1)
348 D_ALL_PARAM_NAMES_X(0x100,2)
349 D_ALL_PARAM_NAMES_X(0x200,3)
351 /* add a multiple of this constant to the basic parameter numbers to get
352 * the parameters for the second, third etc axes.
358 /* angular motor mode numbers */
366 /* joint force feedback information */
368 typedef struct dJointFeedback {
369 dVector3 f1; /* force applied to body 1 */
370 dVector3 t1; /* torque applied to body 1 */
371 dVector3 f2; /* force applied to body 2 */
372 dVector3 t2; /* torque applied to body 2 */
376 /* private functions that must be implemented by the collision library:
377 * (1) indicate that a geom has moved, (2) get the next geom in a body list.
378 * these functions are called whenever the position of geoms connected to a
379 * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or
380 * when the ODE step function updates the body state.
383 void dGeomMoved (dGeomID);
384 dGeomID dGeomGetBodyNext (dGeomID);
387 * dGetConfiguration returns the specific ODE build configuration as
388 * a string of tokens. The string can be parsed in a similar way to
389 * the OpenGL extension mechanism, the naming convention should be
390 * familiar too. The following extensions are reported:
393 * ODE_single_precision
394 * ODE_double_precision
399 * ODE_EXT_malloc_not_alloca
401 * ODE_OPC_16bit_indices
402 * ODE_OPC_new_collider
404 ODE_API const char* dGetConfiguration (void);
407 * Helper to check for a token in the ODE configuration string.
408 * Caution, this function is case sensitive.
410 * @param token A configuration token, see dGetConfiguration for details
412 * @return 1 if exact token is present, 0 if not present
414 ODE_API int dCheckConfiguration( const char* token );