aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/include/ode/common.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ode-0.9/include/ode/common.h388
1 files changed, 388 insertions, 0 deletions
diff --git a/libraries/ode-0.9/include/ode/common.h b/libraries/ode-0.9/include/ode/common.h
new file mode 100644
index 0000000..7f0a12d
--- /dev/null
+++ b/libraries/ode-0.9/include/ode/common.h
@@ -0,0 +1,388 @@
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/config.h>
26#include <ode/error.h>
27#include <math.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33
34/* configuration stuff */
35
36/* the efficient alignment. most platforms align data structures to some
37 * number of bytes, but this is not always the most efficient alignment.
38 * for example, many x86 compilers align to 4 bytes, but on a pentium it
39 * is important to align doubles to 8 byte boundaries (for speed), and
40 * the 4 floats in a SIMD register to 16 byte boundaries. many other
41 * platforms have similar behavior. setting a larger alignment can waste
42 * a (very) small amount of memory. NOTE: this number must be a power of
43 * two. this is set to 16 by default.
44 */
45#define EFFICIENT_ALIGNMENT 16
46
47
48/* constants */
49
50/* pi and 1/sqrt(2) are defined here if necessary because they don't get
51 * defined in <math.h> on some platforms (like MS-Windows)
52 */
53
54#ifndef M_PI
55#define M_PI REAL(3.1415926535897932384626433832795029)
56#endif
57#ifndef M_SQRT1_2
58#define M_SQRT1_2 REAL(0.7071067811865475244008443621048490)
59#endif
60
61
62/* debugging:
63 * IASSERT is an internal assertion, i.e. a consistency check. if it fails
64 * we want to know where.
65 * UASSERT is a user assertion, i.e. if it fails a nice error message
66 * should be printed for the user.
67 * AASSERT is an arguments assertion, i.e. if it fails "bad argument(s)"
68 * is printed.
69 * DEBUGMSG just prints out a message
70 */
71
72#ifndef dNODEBUG
73#ifdef __GNUC__
74#define dIASSERT(a) if (!(a)) dDebug (d_ERR_IASSERT, \
75 "assertion \"" #a "\" failed in %s() [%s]",__FUNCTION__,__FILE__);
76#define dUASSERT(a,msg) if (!(a)) dDebug (d_ERR_UASSERT, \
77 msg " in %s()", __FUNCTION__);
78#define dDEBUGMSG(msg) dMessage (d_ERR_UASSERT, \
79msg " in %s() File %s Line %d", __FUNCTION__, __FILE__,__LINE__);
80#else
81#define dIASSERT(a) if (!(a)) dDebug (d_ERR_IASSERT, \
82 "assertion \"" #a "\" failed in %s:%d",__FILE__,__LINE__);
83#define dUASSERT(a,msg) if (!(a)) dDebug (d_ERR_UASSERT, \
84 msg " (%s:%d)", __FILE__,__LINE__);
85#define dDEBUGMSG(msg) dMessage (d_ERR_UASSERT, \
86 msg " (%s:%d)", __FILE__,__LINE__);
87#endif
88#else
89#define dIASSERT(a) ;
90#define dUASSERT(a,msg) ;
91#define dDEBUGMSG(msg) ;
92#endif
93#define dAASSERT(a) dUASSERT(a,"Bad argument(s)")
94
95// Macro used to suppress unused variable warning
96#define dVARIABLEUSED(a) ((void)a)
97
98/* floating point data type, vector, matrix and quaternion types */
99
100#if defined(dSINGLE)
101typedef float dReal;
102#ifdef dDOUBLE
103#error You can only #define dSINGLE or dDOUBLE, not both.
104#endif // dDOUBLE
105#elif defined(dDOUBLE)
106typedef double dReal;
107#else
108#error You must #define dSINGLE or dDOUBLE
109#endif
110
111// Detect if we've got both trimesh engines enabled.
112#if dTRIMESH_ENABLED
113#if dTRIMESH_OPCODE && dTRIMESH_GIMPACT
114#error You can only #define dTRIMESH_OPCODE or dTRIMESH_GIMPACT, not both.
115#endif
116#endif // dTRIMESH_ENABLED
117
118/* round an integer up to a multiple of 4, except that 0 and 1 are unmodified
119 * (used to compute matrix leading dimensions)
120 */
121#define dPAD(a) (((a) > 1) ? ((((a)-1)|3)+1) : (a))
122
123/* these types are mainly just used in headers */
124typedef dReal dVector3[4];
125typedef dReal dVector4[4];
126typedef dReal dMatrix3[4*3];
127typedef dReal dMatrix4[4*4];
128typedef dReal dMatrix6[8*6];
129typedef dReal dQuaternion[4];
130
131
132/* precision dependent scalar math functions */
133
134#if defined(dSINGLE)
135
136#define REAL(x) (x ## f) /* form a constant */
137#define dRecip(x) ((1.0f/(x))) /* reciprocal */
138#define dSqrt(x) (sqrtf(x)) /* square root */
139#define dRecipSqrt(x) ((1.0f/sqrtf(x))) /* reciprocal square root */
140#define dSin(x) (sinf(x)) /* sine */
141#define dCos(x) (cosf(x)) /* cosine */
142#define dFabs(x) (fabsf(x)) /* absolute value */
143#define dAtan2(y,x) (atan2f(y,x)) /* arc tangent with 2 args */
144#define dFMod(a,b) (fmodf(a,b)) /* modulo */
145#define dFloor(x) floorf(x) /* floor */
146
147#ifdef HAVE___ISNANF
148#define dIsNan(x) (__isnanf(x))
149#elif defined(HAVE__ISNANF)
150#define dIsNan(x) (_isnanf(x))
151#elif defined(HAVE_ISNANF)
152#define dIsNan(x) (isnanf(x))
153#else
154 /*
155 fall back to _isnan which is the VC way,
156 this may seem redundant since we already checked
157 for _isnan before, but if isnan is detected by
158 configure but is not found during compilation
159 we should always make sure we check for __isnanf,
160 _isnanf and isnanf in that order before falling
161 back to a default
162 */
163#define dIsNan(x) (_isnan(x))
164#endif
165
166#define dCopySign(a,b) ((dReal)copysignf(a,b))
167
168#elif defined(dDOUBLE)
169
170#define REAL(x) (x)
171#define dRecip(x) (1.0/(x))
172#define dSqrt(x) sqrt(x)
173#define dRecipSqrt(x) (1.0/sqrt(x))
174#define dSin(x) sin(x)
175#define dCos(x) cos(x)
176#define dFabs(x) fabs(x)
177#define dAtan2(y,x) atan2((y),(x))
178#define dFMod(a,b) (fmod((a),(b)))
179#define dFloor(x) floor(x)
180
181#ifdef HAVE___ISNAN
182#define dIsNan(x) (__isnan(x))
183#elif defined(HAVE__ISNAN)
184#define dIsNan(x) (_isnan(x))
185#elif defined(HAVE_ISNAN)
186#define dIsNan(x) (isnan(x))
187#else
188#define dIsNan(x) (_isnan(x))
189#endif
190
191#define dCopySign(a,b) (copysign((a),(b)))
192
193#else
194#error You must #define dSINGLE or dDOUBLE
195#endif
196
197
198/* utility */
199
200
201/* round something up to be a multiple of the EFFICIENT_ALIGNMENT */
202
203#define dEFFICIENT_SIZE(x) ((((x)-1)|(EFFICIENT_ALIGNMENT-1))+1)
204
205
206/* alloca aligned to the EFFICIENT_ALIGNMENT. note that this can waste
207 * up to 15 bytes per allocation, depending on what alloca() returns.
208 */
209
210#define dALLOCA16(n) \
211 ((char*)dEFFICIENT_SIZE(((size_t)(alloca((n)+(EFFICIENT_ALIGNMENT-1))))))
212
213
214// Use the error-checking memory allocation system. Because this system uses heap
215// (malloc) instead of stack (alloca), it is slower. However, it allows you to
216// simulate larger scenes, as well as handle out-of-memory errors in a somewhat
217// graceful manner
218
219// #define dUSE_MALLOC_FOR_ALLOCA
220
221#ifdef dUSE_MALLOC_FOR_ALLOCA
222enum {
223 d_MEMORY_OK = 0, /* no memory errors */
224 d_MEMORY_OUT_OF_MEMORY /* malloc failed due to out of memory error */
225};
226
227#endif
228
229
230
231/* internal object types (all prefixed with `dx') */
232
233struct dxWorld; /* dynamics world */
234struct dxSpace; /* collision space */
235struct dxBody; /* rigid body (dynamics object) */
236struct dxGeom; /* geometry (collision object) */
237struct dxJoint;
238struct dxJointNode;
239struct dxJointGroup;
240
241typedef struct dxWorld *dWorldID;
242typedef struct dxSpace *dSpaceID;
243typedef struct dxBody *dBodyID;
244typedef struct dxGeom *dGeomID;
245typedef struct dxJoint *dJointID;
246typedef struct dxJointGroup *dJointGroupID;
247
248
249/* error numbers */
250
251enum {
252 d_ERR_UNKNOWN = 0, /* unknown error */
253 d_ERR_IASSERT, /* internal assertion failed */
254 d_ERR_UASSERT, /* user assertion failed */
255 d_ERR_LCP /* user assertion failed */
256};
257
258
259/* joint type numbers */
260
261enum {
262 dJointTypeNone = 0, /* or "unknown" */
263 dJointTypeBall,
264 dJointTypeHinge,
265 dJointTypeSlider,
266 dJointTypeContact,
267 dJointTypeUniversal,
268 dJointTypeHinge2,
269 dJointTypeFixed,
270 dJointTypeNull,
271 dJointTypeAMotor,
272 dJointTypeLMotor,
273 dJointTypePlane2D,
274 dJointTypePR
275};
276
277
278/* an alternative way of setting joint parameters, using joint parameter
279 * structures and member constants. we don't actually do this yet.
280 */
281
282/*
283typedef struct dLimot {
284 int mode;
285 dReal lostop, histop;
286 dReal vel, fmax;
287 dReal fudge_factor;
288 dReal bounce, soft;
289 dReal suspension_erp, suspension_cfm;
290} dLimot;
291
292enum {
293 dLimotLoStop = 0x0001,
294 dLimotHiStop = 0x0002,
295 dLimotVel = 0x0004,
296 dLimotFMax = 0x0008,
297 dLimotFudgeFactor = 0x0010,
298 dLimotBounce = 0x0020,
299 dLimotSoft = 0x0040
300};
301*/
302
303
304/* standard joint parameter names. why are these here? - because we don't want
305 * to include all the joint function definitions in joint.cpp. hmmmm.
306 * MSVC complains if we call D_ALL_PARAM_NAMES_X with a blank second argument,
307 * which is why we have the D_ALL_PARAM_NAMES macro as well. please copy and
308 * paste between these two.
309 */
310
311#define D_ALL_PARAM_NAMES(start) \
312 /* parameters for limits and motors */ \
313 dParamLoStop = start, \
314 dParamHiStop, \
315 dParamVel, \
316 dParamFMax, \
317 dParamFudgeFactor, \
318 dParamBounce, \
319 dParamCFM, \
320 dParamStopERP, \
321 dParamStopCFM, \
322 /* parameters for suspension */ \
323 dParamSuspensionERP, \
324 dParamSuspensionCFM, \
325 dParamERP, \
326
327#define D_ALL_PARAM_NAMES_X(start,x) \
328 /* parameters for limits and motors */ \
329 dParamLoStop ## x = start, \
330 dParamHiStop ## x, \
331 dParamVel ## x, \
332 dParamFMax ## x, \
333 dParamFudgeFactor ## x, \
334 dParamBounce ## x, \
335 dParamCFM ## x, \
336 dParamStopERP ## x, \
337 dParamStopCFM ## x, \
338 /* parameters for suspension */ \
339 dParamSuspensionERP ## x, \
340 dParamSuspensionCFM ## x, \
341 dParamERP ## x,
342
343enum {
344 D_ALL_PARAM_NAMES(0)
345 D_ALL_PARAM_NAMES_X(0x100,2)
346 D_ALL_PARAM_NAMES_X(0x200,3)
347
348 /* add a multiple of this constant to the basic parameter numbers to get
349 * the parameters for the second, third etc axes.
350 */
351 dParamGroup=0x100
352};
353
354
355/* angular motor mode numbers */
356
357enum{
358 dAMotorUser = 0,
359 dAMotorEuler = 1
360};
361
362
363/* joint force feedback information */
364
365typedef struct dJointFeedback {
366 dVector3 f1; /* force applied to body 1 */
367 dVector3 t1; /* torque applied to body 1 */
368 dVector3 f2; /* force applied to body 2 */
369 dVector3 t2; /* torque applied to body 2 */
370} dJointFeedback;
371
372
373/* private functions that must be implemented by the collision library:
374 * (1) indicate that a geom has moved, (2) get the next geom in a body list.
375 * these functions are called whenever the position of geoms connected to a
376 * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or
377 * when the ODE step function updates the body state.
378 */
379
380void dGeomMoved (dGeomID);
381dGeomID dGeomGetBodyNext (dGeomID);
382
383
384#ifdef __cplusplus
385}
386#endif
387
388#endif