]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/builddeps/linux64/ode/include/ode/common.h
Move libraries into subdirectories for better selectivity when building.
[xonotic/xonotic.git] / misc / builddeps / linux64 / ode / include / ode / common.h
1 /*************************************************************************
2  *                                                                       *
3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
4  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
5  *                                                                       *
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     *
12  *       file LICENSE.TXT.                                               *
13  *   (2) The BSD-style license that is included with this library in     *
14  *       the file LICENSE-BSD.TXT.                                       *
15  *                                                                       *
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.                     *
20  *                                                                       *
21  *************************************************************************/
22
23 #ifndef _ODE_COMMON_H_
24 #define _ODE_COMMON_H_
25 #include <ode/odeconfig.h>
26 #include <ode/error.h>
27 #include <math.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 #define PURE_INLINE static __inline
35
36
37 /* configuration stuff */
38
39 /* constants */
40
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)
43  */
44
45 #ifndef M_PI
46 #define M_PI REAL(3.1415926535897932384626433832795029)
47 #endif
48 #ifndef M_SQRT1_2
49 #define M_SQRT1_2 REAL(0.7071067811865475244008443621048490)
50 #endif
51
52
53 /* debugging:
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)"
59  *            is printed.
60  *   DEBUGMSG just prints out a message
61  */
62
63 #  if defined(__STDC__) && __STDC_VERSION__ >= 199901L
64 #    define __FUNCTION__ __func__
65 #  endif
66 #ifndef dNODEBUG
67 #  ifdef __GNUC__
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__); }
81 #  endif
82 #  define dIVERIFY(a) dIASSERT(a)
83 #else
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))
88 #endif
89
90 #  ifdef __GNUC__
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; } }
96 #  endif
97
98 // Argument assert is a special case of user assert
99 #define dAASSERT(a) dUASSERT(a,"Bad argument(s)")
100
101 /* floating point data type, vector, matrix and quaternion types */
102
103 #if defined(dSINGLE)
104 typedef float dReal;
105 #ifdef dDOUBLE
106 #error You can only #define dSINGLE or dDOUBLE, not both.
107 #endif // dDOUBLE
108 #elif defined(dDOUBLE)
109 typedef double dReal;
110 #else
111 #error You must #define dSINGLE or dDOUBLE
112 #endif
113
114 // Detect if we've got both trimesh engines enabled.
115 #if dTRIMESH_ENABLED
116 #if dTRIMESH_OPCODE && dTRIMESH_GIMPACT
117 #error You can only #define dTRIMESH_OPCODE or dTRIMESH_GIMPACT, not both.
118 #endif
119 #endif // dTRIMESH_ENABLED
120
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
124 #if dTRIMESH_GIMPACT
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
132
133 /* round an integer up to a multiple of 4, except that 0 and 1 are unmodified
134  * (used to compute matrix leading dimensions)
135  */
136 #define dPAD(a) (((a) > 1) ? ((((a)-1)|3)+1) : (a))
137
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];
145
146
147 /* precision dependent scalar math functions */
148
149 #if defined(dSINGLE)
150
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 */
164
165 #if defined(_ODE__NEXTAFTERF_REQUIRED)
166 float _nextafterf(float x, float y);
167 #endif
168
169 #ifdef HAVE___ISNANF
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))
175 #else
176   /*
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
183      back to a default
184   */
185 #define dIsNan(x) (_isnan(x))
186 #endif
187
188 #elif defined(dDOUBLE)
189
190 #define REAL(x) (x)
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)
203
204 #undef _ODE__NEXTAFTERF_REQUIRED
205
206 #ifdef HAVE___ISNAN
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))
212 #else
213 #define dIsNan(x) (_isnan(x))
214 #endif
215
216 #else
217 #error You must #define dSINGLE or dDOUBLE
218 #endif
219
220 /* internal object types (all prefixed with `dx') */
221
222 struct dxWorld;         /* dynamics world */
223 struct dxSpace;         /* collision space */
224 struct dxBody;          /* rigid body (dynamics object) */
225 struct dxGeom;          /* geometry (collision object) */
226 struct dxJoint;
227 struct dxJointNode;
228 struct dxJointGroup;
229 struct dxWorldProcessThreadingManager;
230
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;
238
239 /* error numbers */
240
241 enum {
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 */
246 };
247
248
249 /* joint type numbers */
250
251 typedef enum {
252   dJointTypeNone = 0,           /* or "unknown" */
253   dJointTypeBall,
254   dJointTypeHinge,
255   dJointTypeSlider,
256   dJointTypeContact,
257   dJointTypeUniversal,
258   dJointTypeHinge2,
259   dJointTypeFixed,
260   dJointTypeNull,
261   dJointTypeAMotor,
262   dJointTypeLMotor,
263   dJointTypePlane2D,
264   dJointTypePR,
265   dJointTypePU,
266   dJointTypePiston
267 } dJointType;
268
269
270 /* an alternative way of setting joint parameters, using joint parameter
271  * structures and member constants. we don't actually do this yet.
272  */
273
274 /*
275 typedef struct dLimot {
276   int mode;
277   dReal lostop, histop;
278   dReal vel, fmax;
279   dReal fudge_factor;
280   dReal bounce, soft;
281   dReal suspension_erp, suspension_cfm;
282 } dLimot;
283
284 enum {
285   dLimotLoStop          = 0x0001,
286   dLimotHiStop          = 0x0002,
287   dLimotVel             = 0x0004,
288   dLimotFMax            = 0x0008,
289   dLimotFudgeFactor     = 0x0010,
290   dLimotBounce          = 0x0020,
291   dLimotSoft            = 0x0040
292 };
293 */
294
295
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.
301  */
302
303 #define D_ALL_PARAM_NAMES(start) \
304   /* parameters for limits and motors */ \
305   dParamLoStop = start, \
306   dParamHiStop, \
307   dParamVel, \
308   dParamFMax, \
309   dParamFudgeFactor, \
310   dParamBounce, \
311   dParamCFM, \
312   dParamStopERP, \
313   dParamStopCFM, \
314   /* parameters for suspension */ \
315   dParamSuspensionERP, \
316   dParamSuspensionCFM, \
317   dParamERP, \
318
319   //////////////////////////////////////////////////////////////////////////////
320   /// \enum  D_ALL_PARAM_NAMES_X
321   ///
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, \
331   dParamHiStop ## x, \
332   dParamVel ## x, \
333   dParamFMax ## x, \
334   dParamFudgeFactor ## x, \
335   dParamBounce ## x, \
336   dParamCFM ## x, \
337   dParamStopERP ## x, \
338   dParamStopCFM ## x, \
339   /* parameters for suspension */ \
340   dParamSuspensionERP ## x, \
341   dParamSuspensionCFM ## x, \
342   dParamERP ## x,
343
344 enum {
345   D_ALL_PARAM_NAMES(0)
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)
350
351   /* add a multiple of this constant to the basic parameter numbers to get
352    * the parameters for the second, third etc axes.
353    */
354   dParamGroup=0x100
355 };
356
357
358 /* angular motor mode numbers */
359
360 enum {
361   dAMotorUser = 0,
362   dAMotorEuler = 1
363 };
364
365
366 /* joint force feedback information */
367
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 */
373 } dJointFeedback;
374
375
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.
381  */
382
383 void dGeomMoved (dGeomID);
384 dGeomID dGeomGetBodyNext (dGeomID);
385
386 /**
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:
391  *
392  * ODE
393  * ODE_single_precision
394  * ODE_double_precision
395  * ODE_EXT_no_debug
396  * ODE_EXT_trimesh
397  * ODE_EXT_opcode
398  * ODE_EXT_gimpact
399  * ODE_EXT_malloc_not_alloca
400  * ODE_EXT_gyroscopic
401  * ODE_OPC_16bit_indices
402  * ODE_OPC_new_collider
403 */
404 ODE_API const char* dGetConfiguration (void);
405
406 /**
407  * Helper to check for a token in the ODE configuration string.
408  * Caution, this function is case sensitive.
409  *
410  * @param token A configuration token, see dGetConfiguration for details
411  *
412  * @return 1 if exact token is present, 0 if not present
413  */
414 ODE_API int dCheckConfiguration( const char* token );
415
416 #ifdef __cplusplus
417 }
418 #endif
419
420 #endif