source: OGRE/trunk/ogre_dependencies/Dependencies/include/ode/common.h @ 692

Revision 692, 9.7 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
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
26#include <ode/config.h>
27#include <ode/error.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, \
79  msg " in %s()", __FUNCTION__);
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/* floating point data type, vector, matrix and quaternion types */
96
97#if defined(dSINGLE)
98typedef float dReal;
99#elif defined(dDOUBLE)
100typedef double dReal;
101#else
102#error You must #define dSINGLE or dDOUBLE
103#endif
104
105
106/* round an integer up to a multiple of 4, except that 0 and 1 are unmodified
107 * (used to compute matrix leading dimensions)
108 */
109#define dPAD(a) (((a) > 1) ? ((((a)-1)|3)+1) : (a))
110
111/* these types are mainly just used in headers */
112typedef dReal dVector3[4];
113typedef dReal dVector4[4];
114typedef dReal dMatrix3[4*3];
115typedef dReal dMatrix4[4*4];
116typedef dReal dMatrix6[8*6];
117typedef dReal dQuaternion[4];
118
119
120/* precision dependent scalar math functions */
121
122#if defined(dSINGLE)
123
124#define REAL(x) (x ## f)                                        /* form a constant */
125#define dRecip(x) ((float)(1.0f/(x)))                           /* reciprocal */
126#define dSqrt(x) ((float)sqrtf(float(x)))                       /* square root */
127#define dRecipSqrt(x) ((float)(1.0f/sqrtf(float(x))))           /* reciprocal square root */
128#define dSin(x) ((float)sinf(float(x)))                         /* sine */
129#define dCos(x) ((float)cosf(float(x)))                         /* cosine */
130#define dFabs(x) ((float)fabsf(float(x)))                       /* absolute value */
131#define dAtan2(y,x) ((float)atan2f(float(y),float(x)))          /* arc tangent with 2 args */
132#define dFMod(a,b) ((float)fmodf(float(a),float(b)))            /* modulo */
133#define dCopySign(a,b) ((float)copysignf(float(a),float(b)))
134
135#elif defined(dDOUBLE)
136
137#define REAL(x) (x)
138#define dRecip(x) (1.0/(x))
139#define dSqrt(x) sqrt(x)
140#define dRecipSqrt(x) (1.0/sqrt(x))
141#define dSin(x) sin(x)
142#define dCos(x) cos(x)
143#define dFabs(x) fabs(x)
144#define dAtan2(y,x) atan2((y),(x))
145#define dFMod(a,b) (fmod((a),(b)))
146#define dCopySign(a,b) (copysign((a),(b)))
147
148#else
149#error You must #define dSINGLE or dDOUBLE
150#endif
151
152
153/* utility */
154
155
156/* round something up to be a multiple of the EFFICIENT_ALIGNMENT */
157
158#define dEFFICIENT_SIZE(x) ((((x)-1)|(EFFICIENT_ALIGNMENT-1))+1)
159
160
161/* alloca aligned to the EFFICIENT_ALIGNMENT. note that this can waste
162 * up to 15 bytes per allocation, depending on what alloca() returns.
163 */
164
165#define dALLOCA16(n) \
166  ((char*)dEFFICIENT_SIZE(((size_t)(alloca((n)+(EFFICIENT_ALIGNMENT-1))))))
167
168
169/* internal object types (all prefixed with `dx') */
170
171struct dxWorld;         /* dynamics world */
172struct dxSpace;         /* collision space */
173struct dxBody;          /* rigid body (dynamics object) */
174struct dxGeom;          /* geometry (collision object) */
175struct dxJoint;
176struct dxJointNode;
177struct dxJointGroup;
178
179typedef struct dxWorld *dWorldID;
180typedef struct dxSpace *dSpaceID;
181typedef struct dxBody *dBodyID;
182typedef struct dxGeom *dGeomID;
183typedef struct dxJoint *dJointID;
184typedef struct dxJointGroup *dJointGroupID;
185
186
187/* error numbers */
188
189enum {
190  d_ERR_UNKNOWN = 0,            /* unknown error */
191  d_ERR_IASSERT,                /* internal assertion failed */
192  d_ERR_UASSERT,                /* user assertion failed */
193  d_ERR_LCP                     /* user assertion failed */
194};
195
196
197/* joint type numbers */
198
199enum {
200  dJointTypeNone = 0,           /* or "unknown" */
201  dJointTypeBall,
202  dJointTypeHinge,
203  dJointTypeSlider,
204  dJointTypeContact,
205  dJointTypeUniversal,
206  dJointTypeHinge2,
207  dJointTypeFixed,
208  dJointTypeNull,
209  dJointTypeAMotor,
210  // Plane2D change
211  dJointTypePlane2D
212};
213
214
215/* an alternative way of setting joint parameters, using joint parameter
216 * structures and member constants. we don't actually do this yet.
217 */
218
219/*
220typedef struct dLimot {
221  int mode;
222  dReal lostop, histop;
223  dReal vel, fmax;
224  dReal fudge_factor;
225  dReal bounce, soft;
226  dReal suspension_erp, suspension_cfm;
227} dLimot;
228
229enum {
230  dLimotLoStop          = 0x0001,
231  dLimotHiStop          = 0x0002,
232  dLimotVel             = 0x0004,
233  dLimotFMax            = 0x0008,
234  dLimotFudgeFactor     = 0x0010,
235  dLimotBounce          = 0x0020,
236  dLimotSoft            = 0x0040
237};
238*/
239
240
241/* standard joint parameter names. why are these here? - because we don't want
242 * to include all the joint function definitions in joint.cpp. hmmmm.
243 * MSVC complains if we call D_ALL_PARAM_NAMES_X with a blank second argument,
244 * which is why we have the D_ALL_PARAM_NAMES macro as well. please copy and
245 * paste between these two.
246 */
247
248#define D_ALL_PARAM_NAMES(start) \
249  /* parameters for limits and motors */ \
250  dParamLoStop = start, \
251  dParamHiStop, \
252  dParamVel, \
253  dParamFMax, \
254  dParamFudgeFactor, \
255  dParamBounce, \
256  dParamCFM, \
257  dParamStopERP, \
258  dParamStopCFM, \
259  /* parameters for suspension */ \
260  dParamSuspensionERP, \
261  dParamSuspensionCFM,
262
263#define D_ALL_PARAM_NAMES_X(start,x) \
264  /* parameters for limits and motors */ \
265  dParamLoStop ## x = start, \
266  dParamHiStop ## x, \
267  dParamVel ## x, \
268  dParamFMax ## x, \
269  dParamFudgeFactor ## x, \
270  dParamBounce ## x, \
271  dParamCFM ## x, \
272  dParamStopERP ## x, \
273  dParamStopCFM ## x, \
274  /* parameters for suspension */ \
275  dParamSuspensionERP ## x, \
276  dParamSuspensionCFM ## x,
277
278enum {
279  D_ALL_PARAM_NAMES(0)
280  D_ALL_PARAM_NAMES_X(0x100,2)
281  D_ALL_PARAM_NAMES_X(0x200,3)
282
283  /* add a multiple of this constant to the basic parameter numbers to get
284   * the parameters for the second, third etc axes.
285   */
286  dParamGroup=0x100
287};
288
289
290/* angular motor mode numbers */
291
292enum{
293  dAMotorUser = 0,
294  dAMotorEuler = 1
295};
296
297
298/* joint force feedback information */
299
300typedef struct dJointFeedback {
301  dVector3 f1;          /* force applied to body 1 */
302  dVector3 t1;          /* torque applied to body 1 */
303  dVector3 f2;          /* force applied to body 2 */
304  dVector3 t2;          /* torque applied to body 2 */
305} dJointFeedback;
306
307
308/* private functions that must be implemented by the collision library:
309 * (1) indicate that a geom has moved, (2) get the next geom in a body list.
310 * these functions are called whenever the position of geoms connected to a
311 * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or
312 * when the ODE step function updates the body state.
313 */
314
315void dGeomMoved (dGeomID);
316dGeomID dGeomGetBodyNext (dGeomID);
317
318
319#ifdef __cplusplus
320}
321#endif
322
323#endif
Note: See TracBrowser for help on using the repository browser.