]> git.xonotic.org Git - xonotic/darkplaces.git/blob - world.c
ODE physics engine support, needs more work, disabled by default
[xonotic/darkplaces.git] / world.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // world.c -- world query functions
21
22 #include "quakedef.h"
23
24 /*
25
26 entities never clip against themselves, or their owner
27
28 line of sight checks trace->inopen and trace->inwater, but bullets don't
29
30 */
31
32 static void World_Physics_Init(void);
33 void World_Init(void)
34 {
35         Collision_Init();
36         World_Physics_Init();
37 }
38
39 static void World_Physics_Shutdown(void);
40 void World_Shutdown(void)
41 {
42         World_Physics_Shutdown();
43 }
44
45 static void World_Physics_Start(world_t *world);
46 void World_Start(world_t *world)
47 {
48         World_Physics_Start(world);
49 }
50
51 static void World_Physics_End(world_t *world);
52 void World_End(world_t *world)
53 {
54         World_Physics_End(world);
55 }
56
57 //============================================================================
58
59 /// World_ClearLink is used for new headnodes
60 void World_ClearLink (link_t *l)
61 {
62         l->entitynumber = 0;
63         l->prev = l->next = l;
64 }
65
66 void World_RemoveLink (link_t *l)
67 {
68         l->next->prev = l->prev;
69         l->prev->next = l->next;
70 }
71
72 void World_InsertLinkBefore (link_t *l, link_t *before, int entitynumber)
73 {
74         l->entitynumber = entitynumber;
75         l->next = before;
76         l->prev = before->prev;
77         l->prev->next = l;
78         l->next->prev = l;
79 }
80
81 /*
82 ===============================================================================
83
84 ENTITY AREA CHECKING
85
86 ===============================================================================
87 */
88
89 void World_PrintAreaStats(world_t *world, const char *worldname)
90 {
91         Con_Printf("%s areagrid check stats: %d calls %d nodes (%f per call) %d entities (%f per call)\n", worldname, world->areagrid_stats_calls, world->areagrid_stats_nodechecks, (double) world->areagrid_stats_nodechecks / (double) world->areagrid_stats_calls, world->areagrid_stats_entitychecks, (double) world->areagrid_stats_entitychecks / (double) world->areagrid_stats_calls);
92         world->areagrid_stats_calls = 0;
93         world->areagrid_stats_nodechecks = 0;
94         world->areagrid_stats_entitychecks = 0;
95 }
96
97 /*
98 ===============
99 World_SetSize
100
101 ===============
102 */
103 void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs)
104 {
105         int i;
106
107         strlcpy(world->filename, filename, sizeof(world->filename));
108         VectorCopy(mins, world->mins);
109         VectorCopy(maxs, world->maxs);
110
111         // the areagrid_marknumber is not allowed to be 0
112         if (world->areagrid_marknumber < 1)
113                 world->areagrid_marknumber = 1;
114         // choose either the world box size, or a larger box to ensure the grid isn't too fine
115         world->areagrid_size[0] = max(world->areagrid_maxs[0] - world->areagrid_mins[0], AREA_GRID * sv_areagrid_mingridsize.value);
116         world->areagrid_size[1] = max(world->areagrid_maxs[1] - world->areagrid_mins[1], AREA_GRID * sv_areagrid_mingridsize.value);
117         world->areagrid_size[2] = max(world->areagrid_maxs[2] - world->areagrid_mins[2], AREA_GRID * sv_areagrid_mingridsize.value);
118         // figure out the corners of such a box, centered at the center of the world box
119         world->areagrid_mins[0] = (world->areagrid_mins[0] + world->areagrid_maxs[0] - world->areagrid_size[0]) * 0.5f;
120         world->areagrid_mins[1] = (world->areagrid_mins[1] + world->areagrid_maxs[1] - world->areagrid_size[1]) * 0.5f;
121         world->areagrid_mins[2] = (world->areagrid_mins[2] + world->areagrid_maxs[2] - world->areagrid_size[2]) * 0.5f;
122         world->areagrid_maxs[0] = (world->areagrid_mins[0] + world->areagrid_maxs[0] + world->areagrid_size[0]) * 0.5f;
123         world->areagrid_maxs[1] = (world->areagrid_mins[1] + world->areagrid_maxs[1] + world->areagrid_size[1]) * 0.5f;
124         world->areagrid_maxs[2] = (world->areagrid_mins[2] + world->areagrid_maxs[2] + world->areagrid_size[2]) * 0.5f;
125         // now calculate the actual useful info from that
126         VectorNegate(world->areagrid_mins, world->areagrid_bias);
127         world->areagrid_scale[0] = AREA_GRID / world->areagrid_size[0];
128         world->areagrid_scale[1] = AREA_GRID / world->areagrid_size[1];
129         world->areagrid_scale[2] = AREA_GRID / world->areagrid_size[2];
130         World_ClearLink(&world->areagrid_outside);
131         for (i = 0;i < AREA_GRIDNODES;i++)
132                 World_ClearLink(&world->areagrid[i]);
133         if (developer.integer >= 10)
134                 Con_Printf("areagrid settings: divisions %ix%ix1 : box %f %f %f : %f %f %f size %f %f %f grid %f %f %f (mingrid %f)\n", AREA_GRID, AREA_GRID, world->areagrid_mins[0], world->areagrid_mins[1], world->areagrid_mins[2], world->areagrid_maxs[0], world->areagrid_maxs[1], world->areagrid_maxs[2], world->areagrid_size[0], world->areagrid_size[1], world->areagrid_size[2], 1.0f / world->areagrid_scale[0], 1.0f / world->areagrid_scale[1], 1.0f / world->areagrid_scale[2], sv_areagrid_mingridsize.value);
135 }
136
137 /*
138 ===============
139 World_UnlinkAll
140
141 ===============
142 */
143 void World_UnlinkAll(world_t *world)
144 {
145         int i;
146         link_t *grid;
147         // unlink all entities one by one
148         grid = &world->areagrid_outside;
149         while (grid->next != grid)
150                 World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
151         for (i = 0, grid = world->areagrid;i < AREA_GRIDNODES;i++, grid++)
152                 while (grid->next != grid)
153                         World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
154 }
155
156 /*
157 ===============
158
159 ===============
160 */
161 void World_UnlinkEdict(prvm_edict_t *ent)
162 {
163         int i;
164         for (i = 0;i < ENTITYGRIDAREAS;i++)
165         {
166                 if (ent->priv.server->areagrid[i].prev)
167                 {
168                         World_RemoveLink (&ent->priv.server->areagrid[i]);
169                         ent->priv.server->areagrid[i].prev = ent->priv.server->areagrid[i].next = NULL;
170                 }
171         }
172 }
173
174 int World_EntitiesInBox(world_t *world, const vec3_t mins, const vec3_t maxs, int maxlist, prvm_edict_t **list)
175 {
176         int numlist;
177         link_t *grid;
178         link_t *l;
179         prvm_edict_t *ent;
180         int igrid[3], igridmins[3], igridmaxs[3];
181
182         // FIXME: if areagrid_marknumber wraps, all entities need their
183         // ent->priv.server->areagridmarknumber reset
184         world->areagrid_stats_calls++;
185         world->areagrid_marknumber++;
186         igridmins[0] = (int) floor((mins[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]);
187         igridmins[1] = (int) floor((mins[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]);
188         //igridmins[2] = (int) ((mins[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]);
189         igridmaxs[0] = (int) floor((maxs[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]) + 1;
190         igridmaxs[1] = (int) floor((maxs[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]) + 1;
191         //igridmaxs[2] = (int) ((maxs[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]) + 1;
192         igridmins[0] = max(0, igridmins[0]);
193         igridmins[1] = max(0, igridmins[1]);
194         //igridmins[2] = max(0, igridmins[2]);
195         igridmaxs[0] = min(AREA_GRID, igridmaxs[0]);
196         igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
197         //igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
198
199         numlist = 0;
200         // add entities not linked into areagrid because they are too big or
201         // outside the grid bounds
202         if (world->areagrid_outside.next != &world->areagrid_outside)
203         {
204                 grid = &world->areagrid_outside;
205                 for (l = grid->next;l != grid;l = l->next)
206                 {
207                         ent = PRVM_EDICT_NUM(l->entitynumber);
208                         if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
209                         {
210                                 ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
211                                 if (!ent->priv.server->free && BoxesOverlap(mins, maxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
212                                 {
213                                         if (numlist < maxlist)
214                                                 list[numlist] = ent;
215                                         numlist++;
216                                 }
217                                 world->areagrid_stats_entitychecks++;
218                         }
219                 }
220         }
221         // add grid linked entities
222         for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
223         {
224                 grid = world->areagrid + igrid[1] * AREA_GRID + igridmins[0];
225                 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
226                 {
227                         if (grid->next != grid)
228                         {
229                                 for (l = grid->next;l != grid;l = l->next)
230                                 {
231                                         ent = PRVM_EDICT_NUM(l->entitynumber);
232                                         if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
233                                         {
234                                                 ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
235                                                 if (!ent->priv.server->free && BoxesOverlap(mins, maxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
236                                                 {
237                                                         if (numlist < maxlist)
238                                                                 list[numlist] = ent;
239                                                         numlist++;
240                                                 }
241                                                 //Con_Printf("%d %f %f %f %f %f %f : %d : %f %f %f %f %f %f\n", BoxesOverlap(mins, maxs, ent->priv.server->areamins, ent->priv.server->areamaxs), ent->priv.server->areamins[0], ent->priv.server->areamins[1], ent->priv.server->areamins[2], ent->priv.server->areamaxs[0], ent->priv.server->areamaxs[1], ent->priv.server->areamaxs[2], PRVM_NUM_FOR_EDICT(ent), mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
242                                         }
243                                         world->areagrid_stats_entitychecks++;
244                                 }
245                         }
246                 }
247         }
248         return numlist;
249 }
250
251 void World_LinkEdict_AreaGrid(world_t *world, prvm_edict_t *ent)
252 {
253         link_t *grid;
254         int igrid[3], igridmins[3], igridmaxs[3], gridnum, entitynumber = PRVM_NUM_FOR_EDICT(ent);
255
256         if (entitynumber <= 0 || entitynumber >= prog->max_edicts || PRVM_EDICT_NUM(entitynumber) != ent)
257         {
258                 Con_Printf ("World_LinkEdict_AreaGrid: invalid edict %p (edicts is %p, edict compared to prog->edicts is %i)\n", (void *)ent, (void *)prog->edicts, entitynumber);
259                 return;
260         }
261
262         igridmins[0] = (int) floor((ent->priv.server->areamins[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]);
263         igridmins[1] = (int) floor((ent->priv.server->areamins[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]);
264         //igridmins[2] = (int) floor((ent->priv.server->areamins[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]);
265         igridmaxs[0] = (int) floor((ent->priv.server->areamaxs[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]) + 1;
266         igridmaxs[1] = (int) floor((ent->priv.server->areamaxs[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]) + 1;
267         //igridmaxs[2] = (int) floor((ent->priv.server->areamaxs[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]) + 1;
268         if (igridmins[0] < 0 || igridmaxs[0] > AREA_GRID || igridmins[1] < 0 || igridmaxs[1] > AREA_GRID || ((igridmaxs[0] - igridmins[0]) * (igridmaxs[1] - igridmins[1])) > ENTITYGRIDAREAS)
269         {
270                 // wow, something outside the grid, store it as such
271                 World_InsertLinkBefore (&ent->priv.server->areagrid[0], &world->areagrid_outside, entitynumber);
272                 return;
273         }
274
275         gridnum = 0;
276         for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
277         {
278                 grid = world->areagrid + igrid[1] * AREA_GRID + igridmins[0];
279                 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++, gridnum++)
280                         World_InsertLinkBefore (&ent->priv.server->areagrid[gridnum], grid, entitynumber);
281         }
282 }
283
284 /*
285 ===============
286 World_LinkEdict
287
288 ===============
289 */
290 void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const vec3_t maxs)
291 {
292         // unlink from old position first
293         if (ent->priv.server->areagrid[0].prev)
294                 World_UnlinkEdict(ent);
295
296         // don't add the world
297         if (ent == prog->edicts)
298                 return;
299
300         // don't add free entities
301         if (ent->priv.server->free)
302                 return;
303
304         VectorCopy(mins, ent->priv.server->areamins);
305         VectorCopy(maxs, ent->priv.server->areamaxs);
306         World_LinkEdict_AreaGrid(world, ent);
307 }
308
309
310
311
312 //============================================================================
313 // physics engine support
314 //============================================================================
315
316 cvar_t physics_ode_quadtree_depth = {0, "physics_ode_quadtree_depth","5", "desired subdivision level of quadtree culling space"};
317 cvar_t physics_ode_contactsurfacelayer = {0, "physics_ode_contactsurfacelayer","0", "allows objects to overlap this many units to reduce jitter"};
318 cvar_t physics_ode_worldquickstep = {0, "physics_ode_worldquickstep","1", "use dWorldQuickStep rather than dWorldStepFast1 or dWorldStep"};
319 cvar_t physics_ode_worldquickstep_iterations = {0, "physics_ode_worldquickstep_iterations","20", "parameter to dWorldQuickStep"};
320 cvar_t physics_ode_worldstepfast = {0, "physics_ode_worldstepfast","0", "use dWorldStepFast1 rather than dWorldStep"};
321 cvar_t physics_ode_worldstepfast_iterations = {0, "physics_ode_worldstepfast_iterations","20", "parameter to dWorldStepFast1"};
322 cvar_t physics_ode_contact_mu = {0, "physics_ode_contact_mu", "1", "contact solver mu parameter - friction pyramid approximation 1 (see ODE User Guide)"};
323 cvar_t physics_ode_contact_erp = {0, "physics_ode_contact_erp", "0.96", "contact solver erp parameter - Error Restitution Percent (see ODE User Guide)"};
324 cvar_t physics_ode_contact_cfm = {0, "physics_ode_contact_cfm", "0", "contact solver cfm parameter - Constraint Force Mixing (see ODE User Guide)"};
325 cvar_t physics_ode_iterationsperframe = {0, "physics_ode_iterationsperframe", "4", "divisor for time step, runs multiple physics steps per frame"};
326 cvar_t physics_ode_movelimit = {0, "physics_ode_movelimit", "0.5", "clamp velocity if a single move would exceed this percentage of object thickness, to prevent flying through walls"};
327 cvar_t physics_ode_spinlimit = {0, "physics_ode_spinlimit", "10000", "reset spin velocity if it gets too large"};
328
329 // LordHavoc: this large chunk of definitions comes from the ODE library
330 // include files.
331
332 //#ifndef ODE_STATIC
333 //#define ODE_DYNAMIC 1
334 //#endif
335
336 #if defined(ODE_STATIC) || defined(ODE_DYNAMIC)
337 #define USEODE 1
338 #endif
339
340 #ifdef USEODE
341 #ifdef ODE_STATIC
342 #include "ode/ode.h"
343 #else
344 #ifdef WINAPI
345 #define ODE_API WINAPI
346 #else
347 #define ODE_API
348 #endif
349
350 // note: dynamic builds of ODE tend to be double precision, this is not used
351 // for static builds
352 typedef double dReal;
353
354 typedef dReal dVector3[4];
355 typedef dReal dVector4[4];
356 typedef dReal dMatrix3[4*3];
357 typedef dReal dMatrix4[4*4];
358 typedef dReal dMatrix6[8*6];
359 typedef dReal dQuaternion[4];
360
361 struct dxWorld;         /* dynamics world */
362 struct dxSpace;         /* collision space */
363 struct dxBody;          /* rigid body (dynamics object) */
364 struct dxGeom;          /* geometry (collision object) */
365 struct dxJoint;
366 struct dxJointNode;
367 struct dxJointGroup;
368 struct dxTriMeshData;
369
370 typedef struct dxWorld *dWorldID;
371 typedef struct dxSpace *dSpaceID;
372 typedef struct dxBody *dBodyID;
373 typedef struct dxGeom *dGeomID;
374 typedef struct dxJoint *dJointID;
375 typedef struct dxJointGroup *dJointGroupID;
376 typedef struct dxTriMeshData *dTriMeshDataID;
377
378 typedef struct dJointFeedback
379 {
380         dVector3 f1;            /* force applied to body 1 */
381         dVector3 t1;            /* torque applied to body 1 */
382         dVector3 f2;            /* force applied to body 2 */
383         dVector3 t2;            /* torque applied to body 2 */
384 }
385 dJointFeedback;
386
387 typedef enum dJointType
388 {
389         dJointTypeNone = 0,
390         dJointTypeBall,
391         dJointTypeHinge,
392         dJointTypeSlider,
393         dJointTypeContact,
394         dJointTypeUniversal,
395         dJointTypeHinge2,
396         dJointTypeFixed,
397         dJointTypeNull,
398         dJointTypeAMotor,
399         dJointTypeLMotor,
400         dJointTypePlane2D,
401         dJointTypePR,
402         dJointTypePU,
403         dJointTypePiston
404 }
405 dJointType;
406
407 typedef struct dMass
408 {
409         dReal mass;
410         dVector3 c;
411         dMatrix3 I;
412 }
413 dMass;
414
415 enum
416 {
417         dContactMu2                     = 0x001,
418         dContactFDir1           = 0x002,
419         dContactBounce          = 0x004,
420         dContactSoftERP         = 0x008,
421         dContactSoftCFM         = 0x010,
422         dContactMotion1         = 0x020,
423         dContactMotion2         = 0x040,
424         dContactMotionN         = 0x080,
425         dContactSlip1           = 0x100,
426         dContactSlip2           = 0x200,
427         
428         dContactApprox0         = 0x0000,
429         dContactApprox1_1       = 0x1000,
430         dContactApprox1_2       = 0x2000,
431         dContactApprox1         = 0x3000
432 };
433
434 typedef struct dSurfaceParameters
435 {
436         /* must always be defined */
437         int mode;
438         dReal mu;
439
440         /* only defined if the corresponding flag is set in mode */
441         dReal mu2;
442         dReal bounce;
443         dReal bounce_vel;
444         dReal soft_erp;
445         dReal soft_cfm;
446         dReal motion1,motion2,motionN;
447         dReal slip1,slip2;
448 } dSurfaceParameters;
449
450 typedef struct dContactGeom
451 {
452         dVector3 pos;          ///< contact position
453         dVector3 normal;       ///< normal vector
454         dReal depth;           ///< penetration depth
455         dGeomID g1,g2;         ///< the colliding geoms
456         int side1,side2;       ///< (to be documented)
457 }
458 dContactGeom;
459
460 typedef struct dContact
461 {
462         dSurfaceParameters surface;
463         dContactGeom geom;
464         dVector3 fdir1;
465 }
466 dContact;
467
468 typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
469
470 // SAP
471 // Order XZY or ZXY usually works best, if your Y is up.
472 #define dSAP_AXES_XYZ  ((0)|(1<<2)|(2<<4))
473 #define dSAP_AXES_XZY  ((0)|(2<<2)|(1<<4))
474 #define dSAP_AXES_YXZ  ((1)|(0<<2)|(2<<4))
475 #define dSAP_AXES_YZX  ((1)|(2<<2)|(0<<4))
476 #define dSAP_AXES_ZXY  ((2)|(0<<2)|(1<<4))
477 #define dSAP_AXES_ZYX  ((2)|(1<<2)|(0<<4))
478
479 ODE_API const char*     (*dGetConfiguration)(void);
480 ODE_API int             (*dCheckConfiguration)( const char* token );
481 ODE_API int             (*dInitODE2)(unsigned int uiInitFlags);
482 ODE_API int             (*dAllocateODEDataForThread)(unsigned int uiAllocateFlags);
483 ODE_API void            (*dCleanupODEAllDataForThread)(void);
484 ODE_API void            (*dCloseODE)(void);
485
486 //ODE_API int             (*dMassCheck)(const dMass *m);
487 //ODE_API void            (*dMassSetZero)(dMass *);
488 //ODE_API void            (*dMassSetParameters)(dMass *, dReal themass, dReal cgx, dReal cgy, dReal cgz, dReal I11, dReal I22, dReal I33, dReal I12, dReal I13, dReal I23);
489 //ODE_API void            (*dMassSetSphere)(dMass *, dReal density, dReal radius);
490 ODE_API void            (*dMassSetSphereTotal)(dMass *, dReal total_mass, dReal radius);
491 //ODE_API void            (*dMassSetCapsule)(dMass *, dReal density, int direction, dReal radius, dReal length);
492 ODE_API void            (*dMassSetCapsuleTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
493 //ODE_API void            (*dMassSetCylinder)(dMass *, dReal density, int direction, dReal radius, dReal length);
494 //ODE_API void            (*dMassSetCylinderTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
495 //ODE_API void            (*dMassSetBox)(dMass *, dReal density, dReal lx, dReal ly, dReal lz);
496 ODE_API void            (*dMassSetBoxTotal)(dMass *, dReal total_mass, dReal lx, dReal ly, dReal lz);
497 //ODE_API void            (*dMassSetTrimesh)(dMass *, dReal density, dGeomID g);
498 //ODE_API void            (*dMassSetTrimeshTotal)(dMass *m, dReal total_mass, dGeomID g);
499 //ODE_API void            (*dMassAdjust)(dMass *, dReal newmass);
500 //ODE_API void            (*dMassTranslate)(dMass *, dReal x, dReal y, dReal z);
501 //ODE_API void            (*dMassRotate)(dMass *, const dMatrix3 R);
502 //ODE_API void            (*dMassAdd)(dMass *a, const dMass *b);
503 //
504 ODE_API dWorldID        (*dWorldCreate)(void);
505 ODE_API void            (*dWorldDestroy)(dWorldID world);
506 ODE_API void            (*dWorldSetGravity)(dWorldID, dReal x, dReal y, dReal z);
507 //ODE_API void            (*dWorldGetGravity)(dWorldID, dVector3 gravity);
508 //ODE_API void            (*dWorldSetERP)(dWorldID, dReal erp);
509 //ODE_API dReal           (*dWorldGetERP)(dWorldID);
510 //ODE_API void            (*dWorldSetCFM)(dWorldID, dReal cfm);
511 //ODE_API dReal           (*dWorldGetCFM)(dWorldID);
512 ODE_API void            (*dWorldStep)(dWorldID, dReal stepsize);
513 //ODE_API void            (*dWorldImpulseToForce)(dWorldID, dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force);
514 ODE_API void            (*dWorldQuickStep)(dWorldID w, dReal stepsize);
515 ODE_API void            (*dWorldSetQuickStepNumIterations)(dWorldID, int num);
516 //ODE_API int             (*dWorldGetQuickStepNumIterations)(dWorldID);
517 //ODE_API void            (*dWorldSetQuickStepW)(dWorldID, dReal over_relaxation);
518 //ODE_API dReal           (*dWorldGetQuickStepW)(dWorldID);
519 //ODE_API void            (*dWorldSetContactMaxCorrectingVel)(dWorldID, dReal vel);
520 //ODE_API dReal           (*dWorldGetContactMaxCorrectingVel)(dWorldID);
521 ODE_API void            (*dWorldSetContactSurfaceLayer)(dWorldID, dReal depth);
522 //ODE_API dReal           (*dWorldGetContactSurfaceLayer)(dWorldID);
523 ODE_API void            (*dWorldStepFast1)(dWorldID, dReal stepsize, int maxiterations);
524 //ODE_API void            (*dWorldSetAutoEnableDepthSF1)(dWorldID, int autoEnableDepth);
525 //ODE_API int             (*dWorldGetAutoEnableDepthSF1)(dWorldID);
526 //ODE_API dReal           (*dWorldGetAutoDisableLinearThreshold)(dWorldID);
527 //ODE_API void            (*dWorldSetAutoDisableLinearThreshold)(dWorldID, dReal linear_threshold);
528 //ODE_API dReal           (*dWorldGetAutoDisableAngularThreshold)(dWorldID);
529 //ODE_API void            (*dWorldSetAutoDisableAngularThreshold)(dWorldID, dReal angular_threshold);
530 //ODE_API dReal           (*dWorldGetAutoDisableLinearAverageThreshold)(dWorldID);
531 //ODE_API void            (*dWorldSetAutoDisableLinearAverageThreshold)(dWorldID, dReal linear_average_threshold);
532 //ODE_API dReal           (*dWorldGetAutoDisableAngularAverageThreshold)(dWorldID);
533 //ODE_API void            (*dWorldSetAutoDisableAngularAverageThreshold)(dWorldID, dReal angular_average_threshold);
534 //ODE_API int             (*dWorldGetAutoDisableAverageSamplesCount)(dWorldID);
535 //ODE_API void            (*dWorldSetAutoDisableAverageSamplesCount)(dWorldID, unsigned int average_samples_count );
536 //ODE_API int             (*dWorldGetAutoDisableSteps)(dWorldID);
537 //ODE_API void            (*dWorldSetAutoDisableSteps)(dWorldID, int steps);
538 //ODE_API dReal           (*dWorldGetAutoDisableTime)(dWorldID);
539 //ODE_API void            (*dWorldSetAutoDisableTime)(dWorldID, dReal time);
540 //ODE_API int             (*dWorldGetAutoDisableFlag)(dWorldID);
541 //ODE_API void            (*dWorldSetAutoDisableFlag)(dWorldID, int do_auto_disable);
542 //ODE_API dReal           (*dWorldGetLinearDampingThreshold)(dWorldID w);
543 //ODE_API void            (*dWorldSetLinearDampingThreshold)(dWorldID w, dReal threshold);
544 //ODE_API dReal           (*dWorldGetAngularDampingThreshold)(dWorldID w);
545 //ODE_API void            (*dWorldSetAngularDampingThreshold)(dWorldID w, dReal threshold);
546 //ODE_API dReal           (*dWorldGetLinearDamping)(dWorldID w);
547 //ODE_API void            (*dWorldSetLinearDamping)(dWorldID w, dReal scale);
548 //ODE_API dReal           (*dWorldGetAngularDamping)(dWorldID w);
549 //ODE_API void            (*dWorldSetAngularDamping)(dWorldID w, dReal scale);
550 //ODE_API void            (*dWorldSetDamping)(dWorldID w, dReal linear_scale, dReal angular_scale);
551 //ODE_API dReal           (*dWorldGetMaxAngularSpeed)(dWorldID w);
552 //ODE_API void            (*dWorldSetMaxAngularSpeed)(dWorldID w, dReal max_speed);
553 //ODE_API dReal           (*dBodyGetAutoDisableLinearThreshold)(dBodyID);
554 //ODE_API void            (*dBodySetAutoDisableLinearThreshold)(dBodyID, dReal linear_average_threshold);
555 //ODE_API dReal           (*dBodyGetAutoDisableAngularThreshold)(dBodyID);
556 //ODE_API void            (*dBodySetAutoDisableAngularThreshold)(dBodyID, dReal angular_average_threshold);
557 //ODE_API int             (*dBodyGetAutoDisableAverageSamplesCount)(dBodyID);
558 //ODE_API void            (*dBodySetAutoDisableAverageSamplesCount)(dBodyID, unsigned int average_samples_count);
559 //ODE_API int             (*dBodyGetAutoDisableSteps)(dBodyID);
560 //ODE_API void            (*dBodySetAutoDisableSteps)(dBodyID, int steps);
561 //ODE_API dReal           (*dBodyGetAutoDisableTime)(dBodyID);
562 //ODE_API void            (*dBodySetAutoDisableTime)(dBodyID, dReal time);
563 //ODE_API int             (*dBodyGetAutoDisableFlag)(dBodyID);
564 //ODE_API void            (*dBodySetAutoDisableFlag)(dBodyID, int do_auto_disable);
565 //ODE_API void            (*dBodySetAutoDisableDefaults)(dBodyID);
566 //ODE_API dWorldID        (*dBodyGetWorld)(dBodyID);
567 ODE_API dBodyID         (*dBodyCreate)(dWorldID);
568 ODE_API void            (*dBodyDestroy)(dBodyID);
569 ODE_API void            (*dBodySetData)(dBodyID, void *data);
570 //ODE_API void *          (*dBodyGetData)(dBodyID);
571 ODE_API void            (*dBodySetPosition)(dBodyID, dReal x, dReal y, dReal z);
572 ODE_API void            (*dBodySetRotation)(dBodyID, const dMatrix3 R);
573 //ODE_API void            (*dBodySetQuaternion)(dBodyID, const dQuaternion q);
574 ODE_API void            (*dBodySetLinearVel)(dBodyID, dReal x, dReal y, dReal z);
575 ODE_API void            (*dBodySetAngularVel)(dBodyID, dReal x, dReal y, dReal z);
576 ODE_API const dReal *   (*dBodyGetPosition)(dBodyID);
577 //ODE_API void            (*dBodyCopyPosition)(dBodyID body, dVector3 pos);
578 ODE_API const dReal *   (*dBodyGetRotation)(dBodyID);
579 //ODE_API void            (*dBodyCopyRotation)(dBodyID, dMatrix3 R);
580 //ODE_API const dReal *   (*dBodyGetQuaternion)(dBodyID);
581 //ODE_API void            (*dBodyCopyQuaternion)(dBodyID body, dQuaternion quat);
582 ODE_API const dReal *   (*dBodyGetLinearVel)(dBodyID);
583 ODE_API const dReal *   (*dBodyGetAngularVel)(dBodyID);
584 ODE_API void            (*dBodySetMass)(dBodyID, const dMass *mass);
585 //ODE_API void            (*dBodyGetMass)(dBodyID, dMass *mass);
586 //ODE_API void            (*dBodyAddForce)(dBodyID, dReal fx, dReal fy, dReal fz);
587 //ODE_API void            (*dBodyAddTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
588 //ODE_API void            (*dBodyAddRelForce)(dBodyID, dReal fx, dReal fy, dReal fz);
589 //ODE_API void            (*dBodyAddRelTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
590 //ODE_API void            (*dBodyAddForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
591 //ODE_API void            (*dBodyAddForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
592 //ODE_API void            (*dBodyAddRelForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
593 //ODE_API void            (*dBodyAddRelForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
594 //ODE_API const dReal *   (*dBodyGetForce)(dBodyID);
595 //ODE_API const dReal *   (*dBodyGetTorque)(dBodyID);
596 //ODE_API void            (*dBodySetForce)(dBodyID b, dReal x, dReal y, dReal z);
597 //ODE_API void            (*dBodySetTorque)(dBodyID b, dReal x, dReal y, dReal z);
598 //ODE_API void            (*dBodyGetRelPointPos)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
599 //ODE_API void            (*dBodyGetRelPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
600 //ODE_API void            (*dBodyGetPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
601 //ODE_API void            (*dBodyGetPosRelPoint)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
602 //ODE_API void            (*dBodyVectorToWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
603 //ODE_API void            (*dBodyVectorFromWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
604 //ODE_API void            (*dBodySetFiniteRotationMode)(dBodyID, int mode);
605 //ODE_API void            (*dBodySetFiniteRotationAxis)(dBodyID, dReal x, dReal y, dReal z);
606 //ODE_API int             (*dBodyGetFiniteRotationMode)(dBodyID);
607 //ODE_API void            (*dBodyGetFiniteRotationAxis)(dBodyID, dVector3 result);
608 //ODE_API int             (*dBodyGetNumJoints)(dBodyID b);
609 //ODE_API dJointID        (*dBodyGetJoint)(dBodyID, int index);
610 //ODE_API void            (*dBodySetDynamic)(dBodyID);
611 //ODE_API void            (*dBodySetKinematic)(dBodyID);
612 //ODE_API int             (*dBodyIsKinematic)(dBodyID);
613 //ODE_API void            (*dBodyEnable)(dBodyID);
614 //ODE_API void            (*dBodyDisable)(dBodyID);
615 //ODE_API int             (*dBodyIsEnabled)(dBodyID);
616 //ODE_API void            (*dBodySetGravityMode)(dBodyID b, int mode);
617 //ODE_API int             (*dBodyGetGravityMode)(dBodyID b);
618 //ODE_API void            (*dBodySetMovedCallback)(dBodyID b, void(*callback)(dBodyID));
619 //ODE_API dGeomID         (*dBodyGetFirstGeom)(dBodyID b);
620 //ODE_API dGeomID         (*dBodyGetNextGeom)(dGeomID g);
621 //ODE_API void            (*dBodySetDampingDefaults)(dBodyID b);
622 //ODE_API dReal           (*dBodyGetLinearDamping)(dBodyID b);
623 //ODE_API void            (*dBodySetLinearDamping)(dBodyID b, dReal scale);
624 //ODE_API dReal           (*dBodyGetAngularDamping)(dBodyID b);
625 //ODE_API void            (*dBodySetAngularDamping)(dBodyID b, dReal scale);
626 //ODE_API void            (*dBodySetDamping)(dBodyID b, dReal linear_scale, dReal angular_scale);
627 //ODE_API dReal           (*dBodyGetLinearDampingThreshold)(dBodyID b);
628 //ODE_API void            (*dBodySetLinearDampingThreshold)(dBodyID b, dReal threshold);
629 //ODE_API dReal           (*dBodyGetAngularDampingThreshold)(dBodyID b);
630 //ODE_API void            (*dBodySetAngularDampingThreshold)(dBodyID b, dReal threshold);
631 //ODE_API dReal           (*dBodyGetMaxAngularSpeed)(dBodyID b);
632 //ODE_API void            (*dBodySetMaxAngularSpeed)(dBodyID b, dReal max_speed);
633 //ODE_API int             (*dBodyGetGyroscopicMode)(dBodyID b);
634 //ODE_API void            (*dBodySetGyroscopicMode)(dBodyID b, int enabled);
635 //ODE_API dJointID        (*dJointCreateBall)(dWorldID, dJointGroupID);
636 //ODE_API dJointID        (*dJointCreateHinge)(dWorldID, dJointGroupID);
637 //ODE_API dJointID        (*dJointCreateSlider)(dWorldID, dJointGroupID);
638 ODE_API dJointID        (*dJointCreateContact)(dWorldID, dJointGroupID, const dContact *);
639 //ODE_API dJointID        (*dJointCreateHinge2)(dWorldID, dJointGroupID);
640 //ODE_API dJointID        (*dJointCreateUniversal)(dWorldID, dJointGroupID);
641 //ODE_API dJointID        (*dJointCreatePR)(dWorldID, dJointGroupID);
642 //ODE_API dJointID        (*dJointCreatePU)(dWorldID, dJointGroupID);
643 //ODE_API dJointID        (*dJointCreatePiston)(dWorldID, dJointGroupID);
644 //ODE_API dJointID        (*dJointCreateFixed)(dWorldID, dJointGroupID);
645 //ODE_API dJointID        (*dJointCreateNull)(dWorldID, dJointGroupID);
646 //ODE_API dJointID        (*dJointCreateAMotor)(dWorldID, dJointGroupID);
647 //ODE_API dJointID        (*dJointCreateLMotor)(dWorldID, dJointGroupID);
648 //ODE_API dJointID        (*dJointCreatePlane2D)(dWorldID, dJointGroupID);
649 //ODE_API void            (*dJointDestroy)(dJointID);
650 ODE_API dJointGroupID   (*dJointGroupCreate)(int max_size);
651 ODE_API void            (*dJointGroupDestroy)(dJointGroupID);
652 ODE_API void            (*dJointGroupEmpty)(dJointGroupID);
653 //ODE_API int             (*dJointGetNumBodies)(dJointID);
654 ODE_API void            (*dJointAttach)(dJointID, dBodyID body1, dBodyID body2);
655 //ODE_API void            (*dJointEnable)(dJointID);
656 //ODE_API void            (*dJointDisable)(dJointID);
657 //ODE_API int             (*dJointIsEnabled)(dJointID);
658 //ODE_API void            (*dJointSetData)(dJointID, void *data);
659 //ODE_API void *          (*dJointGetData)(dJointID);
660 //ODE_API dJointType      (*dJointGetType)(dJointID);
661 //ODE_API dBodyID         (*dJointGetBody)(dJointID, int index);
662 //ODE_API void            (*dJointSetFeedback)(dJointID, dJointFeedback *);
663 //ODE_API dJointFeedback *(*dJointGetFeedback)(dJointID);
664 //ODE_API void            (*dJointSetBallAnchor)(dJointID, dReal x, dReal y, dReal z);
665 //ODE_API void            (*dJointSetBallAnchor2)(dJointID, dReal x, dReal y, dReal z);
666 //ODE_API void            (*dJointSetBallParam)(dJointID, int parameter, dReal value);
667 //ODE_API void            (*dJointSetHingeAnchor)(dJointID, dReal x, dReal y, dReal z);
668 //ODE_API void            (*dJointSetHingeAnchorDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
669 //ODE_API void            (*dJointSetHingeAxis)(dJointID, dReal x, dReal y, dReal z);
670 //ODE_API void            (*dJointSetHingeAxisOffset)(dJointID j, dReal x, dReal y, dReal z, dReal angle);
671 //ODE_API void            (*dJointSetHingeParam)(dJointID, int parameter, dReal value);
672 //ODE_API void            (*dJointAddHingeTorque)(dJointID joint, dReal torque);
673 //ODE_API void            (*dJointSetSliderAxis)(dJointID, dReal x, dReal y, dReal z);
674 //ODE_API void            (*dJointSetSliderAxisDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
675 //ODE_API void            (*dJointSetSliderParam)(dJointID, int parameter, dReal value);
676 //ODE_API void            (*dJointAddSliderForce)(dJointID joint, dReal force);
677 //ODE_API void            (*dJointSetHinge2Anchor)(dJointID, dReal x, dReal y, dReal z);
678 //ODE_API void            (*dJointSetHinge2Axis1)(dJointID, dReal x, dReal y, dReal z);
679 //ODE_API void            (*dJointSetHinge2Axis2)(dJointID, dReal x, dReal y, dReal z);
680 //ODE_API void            (*dJointSetHinge2Param)(dJointID, int parameter, dReal value);
681 //ODE_API void            (*dJointAddHinge2Torques)(dJointID joint, dReal torque1, dReal torque2);
682 //ODE_API void            (*dJointSetUniversalAnchor)(dJointID, dReal x, dReal y, dReal z);
683 //ODE_API void            (*dJointSetUniversalAxis1)(dJointID, dReal x, dReal y, dReal z);
684 //ODE_API void            (*dJointSetUniversalAxis1Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
685 //ODE_API void            (*dJointSetUniversalAxis2)(dJointID, dReal x, dReal y, dReal z);
686 //ODE_API void            (*dJointSetUniversalAxis2Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
687 //ODE_API void            (*dJointSetUniversalParam)(dJointID, int parameter, dReal value);
688 //ODE_API void            (*dJointAddUniversalTorques)(dJointID joint, dReal torque1, dReal torque2);
689 //ODE_API void            (*dJointSetPRAnchor)(dJointID, dReal x, dReal y, dReal z);
690 //ODE_API void            (*dJointSetPRAxis1)(dJointID, dReal x, dReal y, dReal z);
691 //ODE_API void            (*dJointSetPRAxis2)(dJointID, dReal x, dReal y, dReal z);
692 //ODE_API void            (*dJointSetPRParam)(dJointID, int parameter, dReal value);
693 //ODE_API void            (*dJointAddPRTorque)(dJointID j, dReal torque);
694 //ODE_API void            (*dJointSetPUAnchor)(dJointID, dReal x, dReal y, dReal z);
695 //ODE_API void            (*dJointSetPUAnchorOffset)(dJointID, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
696 //ODE_API void            (*dJointSetPUAxis1)(dJointID, dReal x, dReal y, dReal z);
697 //ODE_API void            (*dJointSetPUAxis2)(dJointID, dReal x, dReal y, dReal z);
698 //ODE_API void            (*dJointSetPUAxis3)(dJointID, dReal x, dReal y, dReal z);
699 //ODE_API void            (*dJointSetPUAxisP)(dJointID id, dReal x, dReal y, dReal z);
700 //ODE_API void            (*dJointSetPUParam)(dJointID, int parameter, dReal value);
701 //ODE_API void            (*dJointAddPUTorque)(dJointID j, dReal torque);
702 //ODE_API void            (*dJointSetPistonAnchor)(dJointID, dReal x, dReal y, dReal z);
703 //ODE_API void            (*dJointSetPistonAnchorOffset)(dJointID j, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
704 //ODE_API void            (*dJointSetPistonParam)(dJointID, int parameter, dReal value);
705 //ODE_API void            (*dJointAddPistonForce)(dJointID joint, dReal force);
706 //ODE_API void            (*dJointSetFixed)(dJointID);
707 //ODE_API void            (*dJointSetFixedParam)(dJointID, int parameter, dReal value);
708 //ODE_API void            (*dJointSetAMotorNumAxes)(dJointID, int num);
709 //ODE_API void            (*dJointSetAMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
710 //ODE_API void            (*dJointSetAMotorAngle)(dJointID, int anum, dReal angle);
711 //ODE_API void            (*dJointSetAMotorParam)(dJointID, int parameter, dReal value);
712 //ODE_API void            (*dJointSetAMotorMode)(dJointID, int mode);
713 //ODE_API void            (*dJointAddAMotorTorques)(dJointID, dReal torque1, dReal torque2, dReal torque3);
714 //ODE_API void            (*dJointSetLMotorNumAxes)(dJointID, int num);
715 //ODE_API void            (*dJointSetLMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
716 //ODE_API void            (*dJointSetLMotorParam)(dJointID, int parameter, dReal value);
717 //ODE_API void            (*dJointSetPlane2DXParam)(dJointID, int parameter, dReal value);
718 //ODE_API void            (*dJointSetPlane2DYParam)(dJointID, int parameter, dReal value);
719 //ODE_API void            (*dJointSetPlane2DAngleParam)(dJointID, int parameter, dReal value);
720 //ODE_API void            (*dJointGetBallAnchor)(dJointID, dVector3 result);
721 //ODE_API void            (*dJointGetBallAnchor2)(dJointID, dVector3 result);
722 //ODE_API dReal           (*dJointGetBallParam)(dJointID, int parameter);
723 //ODE_API void            (*dJointGetHingeAnchor)(dJointID, dVector3 result);
724 //ODE_API void            (*dJointGetHingeAnchor2)(dJointID, dVector3 result);
725 //ODE_API void            (*dJointGetHingeAxis)(dJointID, dVector3 result);
726 //ODE_API dReal           (*dJointGetHingeParam)(dJointID, int parameter);
727 //ODE_API dReal           (*dJointGetHingeAngle)(dJointID);
728 //ODE_API dReal           (*dJointGetHingeAngleRate)(dJointID);
729 //ODE_API dReal           (*dJointGetSliderPosition)(dJointID);
730 //ODE_API dReal           (*dJointGetSliderPositionRate)(dJointID);
731 //ODE_API void            (*dJointGetSliderAxis)(dJointID, dVector3 result);
732 //ODE_API dReal           (*dJointGetSliderParam)(dJointID, int parameter);
733 //ODE_API void            (*dJointGetHinge2Anchor)(dJointID, dVector3 result);
734 //ODE_API void            (*dJointGetHinge2Anchor2)(dJointID, dVector3 result);
735 //ODE_API void            (*dJointGetHinge2Axis1)(dJointID, dVector3 result);
736 //ODE_API void            (*dJointGetHinge2Axis2)(dJointID, dVector3 result);
737 //ODE_API dReal           (*dJointGetHinge2Param)(dJointID, int parameter);
738 //ODE_API dReal           (*dJointGetHinge2Angle1)(dJointID);
739 //ODE_API dReal           (*dJointGetHinge2Angle1Rate)(dJointID);
740 //ODE_API dReal           (*dJointGetHinge2Angle2Rate)(dJointID);
741 //ODE_API void            (*dJointGetUniversalAnchor)(dJointID, dVector3 result);
742 //ODE_API void            (*dJointGetUniversalAnchor2)(dJointID, dVector3 result);
743 //ODE_API void            (*dJointGetUniversalAxis1)(dJointID, dVector3 result);
744 //ODE_API void            (*dJointGetUniversalAxis2)(dJointID, dVector3 result);
745 //ODE_API dReal           (*dJointGetUniversalParam)(dJointID, int parameter);
746 //ODE_API void            (*dJointGetUniversalAngles)(dJointID, dReal *angle1, dReal *angle2);
747 //ODE_API dReal           (*dJointGetUniversalAngle1)(dJointID);
748 //ODE_API dReal           (*dJointGetUniversalAngle2)(dJointID);
749 //ODE_API dReal           (*dJointGetUniversalAngle1Rate)(dJointID);
750 //ODE_API dReal           (*dJointGetUniversalAngle2Rate)(dJointID);
751 //ODE_API void            (*dJointGetPRAnchor)(dJointID, dVector3 result);
752 //ODE_API dReal           (*dJointGetPRPosition)(dJointID);
753 //ODE_API dReal           (*dJointGetPRPositionRate)(dJointID);
754 //ODE_API dReal           (*dJointGetPRAngle)(dJointID);
755 //ODE_API dReal           (*dJointGetPRAngleRate)(dJointID);
756 //ODE_API void            (*dJointGetPRAxis1)(dJointID, dVector3 result);
757 //ODE_API void            (*dJointGetPRAxis2)(dJointID, dVector3 result);
758 //ODE_API dReal           (*dJointGetPRParam)(dJointID, int parameter);
759 //ODE_API void            (*dJointGetPUAnchor)(dJointID, dVector3 result);
760 //ODE_API dReal           (*dJointGetPUPosition)(dJointID);
761 //ODE_API dReal           (*dJointGetPUPositionRate)(dJointID);
762 //ODE_API void            (*dJointGetPUAxis1)(dJointID, dVector3 result);
763 //ODE_API void            (*dJointGetPUAxis2)(dJointID, dVector3 result);
764 //ODE_API void            (*dJointGetPUAxis3)(dJointID, dVector3 result);
765 //ODE_API void            (*dJointGetPUAxisP)(dJointID id, dVector3 result);
766 //ODE_API void            (*dJointGetPUAngles)(dJointID, dReal *angle1, dReal *angle2);
767 //ODE_API dReal           (*dJointGetPUAngle1)(dJointID);
768 //ODE_API dReal           (*dJointGetPUAngle1Rate)(dJointID);
769 //ODE_API dReal           (*dJointGetPUAngle2)(dJointID);
770 //ODE_API dReal           (*dJointGetPUAngle2Rate)(dJointID);
771 //ODE_API dReal           (*dJointGetPUParam)(dJointID, int parameter);
772 //ODE_API dReal           (*dJointGetPistonPosition)(dJointID);
773 //ODE_API dReal           (*dJointGetPistonPositionRate)(dJointID);
774 //ODE_API dReal           (*dJointGetPistonAngle)(dJointID);
775 //ODE_API dReal           (*dJointGetPistonAngleRate)(dJointID);
776 //ODE_API void            (*dJointGetPistonAnchor)(dJointID, dVector3 result);
777 //ODE_API void            (*dJointGetPistonAnchor2)(dJointID, dVector3 result);
778 //ODE_API void            (*dJointGetPistonAxis)(dJointID, dVector3 result);
779 //ODE_API dReal           (*dJointGetPistonParam)(dJointID, int parameter);
780 //ODE_API int             (*dJointGetAMotorNumAxes)(dJointID);
781 //ODE_API void            (*dJointGetAMotorAxis)(dJointID, int anum, dVector3 result);
782 //ODE_API int             (*dJointGetAMotorAxisRel)(dJointID, int anum);
783 //ODE_API dReal           (*dJointGetAMotorAngle)(dJointID, int anum);
784 //ODE_API dReal           (*dJointGetAMotorAngleRate)(dJointID, int anum);
785 //ODE_API dReal           (*dJointGetAMotorParam)(dJointID, int parameter);
786 //ODE_API int             (*dJointGetAMotorMode)(dJointID);
787 //ODE_API int             (*dJointGetLMotorNumAxes)(dJointID);
788 //ODE_API void            (*dJointGetLMotorAxis)(dJointID, int anum, dVector3 result);
789 //ODE_API dReal           (*dJointGetLMotorParam)(dJointID, int parameter);
790 //ODE_API dReal           (*dJointGetFixedParam)(dJointID, int parameter);
791 //ODE_API dJointID        (*dConnectingJoint)(dBodyID, dBodyID);
792 //ODE_API int             (*dConnectingJointList)(dBodyID, dBodyID, dJointID*);
793 ODE_API int             (*dAreConnected)(dBodyID, dBodyID);
794 ODE_API int             (*dAreConnectedExcluding)(dBodyID body1, dBodyID body2, int joint_type);
795 //
796 ODE_API dSpaceID        (*dSimpleSpaceCreate)(dSpaceID space);
797 ODE_API dSpaceID        (*dHashSpaceCreate)(dSpaceID space);
798 ODE_API dSpaceID        (*dQuadTreeSpaceCreate)(dSpaceID space, const dVector3 Center, const dVector3 Extents, int Depth);
799 ODE_API dSpaceID        (*dSweepAndPruneSpaceCreate)( dSpaceID space, int axisorder );
800 ODE_API void            (*dSpaceDestroy)(dSpaceID);
801 //ODE_API void            (*dHashSpaceSetLevels)(dSpaceID space, int minlevel, int maxlevel);
802 //ODE_API void            (*dHashSpaceGetLevels)(dSpaceID space, int *minlevel, int *maxlevel);
803 //ODE_API void            (*dSpaceSetCleanup)(dSpaceID space, int mode);
804 //ODE_API int             (*dSpaceGetCleanup)(dSpaceID space);
805 //ODE_API void            (*dSpaceSetSublevel)(dSpaceID space, int sublevel);
806 //ODE_API int             (*dSpaceGetSublevel)(dSpaceID space);
807 //ODE_API void            (*dSpaceSetManualCleanup)(dSpaceID space, int mode);
808 //ODE_API int             (*dSpaceGetManualCleanup)(dSpaceID space);
809 //ODE_API void            (*dSpaceAdd)(dSpaceID, dGeomID);
810 //ODE_API void            (*dSpaceRemove)(dSpaceID, dGeomID);
811 //ODE_API int             (*dSpaceQuery)(dSpaceID, dGeomID);
812 //ODE_API void            (*dSpaceClean)(dSpaceID);
813 //ODE_API int             (*dSpaceGetNumGeoms)(dSpaceID);
814 //ODE_API dGeomID         (*dSpaceGetGeom)(dSpaceID, int i);
815 //ODE_API int             (*dSpaceGetClass)(dSpaceID space);
816 //
817 ODE_API void            (*dGeomDestroy)(dGeomID geom);
818 //ODE_API void            (*dGeomSetData)(dGeomID geom, void* data);
819 //ODE_API void *          (*dGeomGetData)(dGeomID geom);
820 ODE_API void            (*dGeomSetBody)(dGeomID geom, dBodyID body);
821 ODE_API dBodyID         (*dGeomGetBody)(dGeomID geom);
822 //ODE_API void            (*dGeomSetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
823 ODE_API void            (*dGeomSetRotation)(dGeomID geom, const dMatrix3 R);
824 //ODE_API void            (*dGeomSetQuaternion)(dGeomID geom, const dQuaternion Q);
825 //ODE_API const dReal *   (*dGeomGetPosition)(dGeomID geom);
826 //ODE_API void            (*dGeomCopyPosition)(dGeomID geom, dVector3 pos);
827 //ODE_API const dReal *   (*dGeomGetRotation)(dGeomID geom);
828 //ODE_API void            (*dGeomCopyRotation)(dGeomID geom, dMatrix3 R);
829 //ODE_API void            (*dGeomGetQuaternion)(dGeomID geom, dQuaternion result);
830 //ODE_API void            (*dGeomGetAABB)(dGeomID geom, dReal aabb[6]);
831 ODE_API int             (*dGeomIsSpace)(dGeomID geom);
832 //ODE_API dSpaceID        (*dGeomGetSpace)(dGeomID);
833 //ODE_API int             (*dGeomGetClass)(dGeomID geom);
834 //ODE_API void            (*dGeomSetCategoryBits)(dGeomID geom, unsigned long bits);
835 //ODE_API void            (*dGeomSetCollideBits)(dGeomID geom, unsigned long bits);
836 //ODE_API unsigned long   (*dGeomGetCategoryBits)(dGeomID);
837 //ODE_API unsigned long   (*dGeomGetCollideBits)(dGeomID);
838 //ODE_API void            (*dGeomEnable)(dGeomID geom);
839 //ODE_API void            (*dGeomDisable)(dGeomID geom);
840 //ODE_API int             (*dGeomIsEnabled)(dGeomID geom);
841 //ODE_API void            (*dGeomSetOffsetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
842 //ODE_API void            (*dGeomSetOffsetRotation)(dGeomID geom, const dMatrix3 R);
843 //ODE_API void            (*dGeomSetOffsetQuaternion)(dGeomID geom, const dQuaternion Q);
844 //ODE_API void            (*dGeomSetOffsetWorldPosition)(dGeomID geom, dReal x, dReal y, dReal z);
845 //ODE_API void            (*dGeomSetOffsetWorldRotation)(dGeomID geom, const dMatrix3 R);
846 //ODE_API void            (*dGeomSetOffsetWorldQuaternion)(dGeomID geom, const dQuaternion);
847 //ODE_API void            (*dGeomClearOffset)(dGeomID geom);
848 //ODE_API int             (*dGeomIsOffset)(dGeomID geom);
849 //ODE_API const dReal *   (*dGeomGetOffsetPosition)(dGeomID geom);
850 //ODE_API void            (*dGeomCopyOffsetPosition)(dGeomID geom, dVector3 pos);
851 //ODE_API const dReal *   (*dGeomGetOffsetRotation)(dGeomID geom);
852 //ODE_API void            (*dGeomCopyOffsetRotation)(dGeomID geom, dMatrix3 R);
853 //ODE_API void            (*dGeomGetOffsetQuaternion)(dGeomID geom, dQuaternion result);
854 ODE_API int             (*dCollide)(dGeomID o1, dGeomID o2, int flags, dContactGeom *contact, int skip);
855 //
856 ODE_API void            (*dSpaceCollide)(dSpaceID space, void *data, dNearCallback *callback);
857 ODE_API void            (*dSpaceCollide2)(dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
858 //
859 ODE_API dGeomID         (*dCreateSphere)(dSpaceID space, dReal radius);
860 //ODE_API void            (*dGeomSphereSetRadius)(dGeomID sphere, dReal radius);
861 //ODE_API dReal           (*dGeomSphereGetRadius)(dGeomID sphere);
862 //ODE_API dReal           (*dGeomSpherePointDepth)(dGeomID sphere, dReal x, dReal y, dReal z);
863 //
864 //ODE_API dGeomID         (*dCreateConvex)(dSpaceID space, dReal *_planes, unsigned int _planecount, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
865 //ODE_API void            (*dGeomSetConvex)(dGeomID g, dReal *_planes, unsigned int _count, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
866 //
867 ODE_API dGeomID         (*dCreateBox)(dSpaceID space, dReal lx, dReal ly, dReal lz);
868 //ODE_API void            (*dGeomBoxSetLengths)(dGeomID box, dReal lx, dReal ly, dReal lz);
869 //ODE_API void            (*dGeomBoxGetLengths)(dGeomID box, dVector3 result);
870 //ODE_API dReal           (*dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
871 //ODE_API dReal           (*dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
872 //
873 //ODE_API dGeomID         (*dCreatePlane)(dSpaceID space, dReal a, dReal b, dReal c, dReal d);
874 //ODE_API void            (*dGeomPlaneSetParams)(dGeomID plane, dReal a, dReal b, dReal c, dReal d);
875 //ODE_API void            (*dGeomPlaneGetParams)(dGeomID plane, dVector4 result);
876 //ODE_API dReal           (*dGeomPlanePointDepth)(dGeomID plane, dReal x, dReal y, dReal z);
877 //
878 ODE_API dGeomID         (*dCreateCapsule)(dSpaceID space, dReal radius, dReal length);
879 //ODE_API void            (*dGeomCapsuleSetParams)(dGeomID ccylinder, dReal radius, dReal length);
880 //ODE_API void            (*dGeomCapsuleGetParams)(dGeomID ccylinder, dReal *radius, dReal *length);
881 //ODE_API dReal           (*dGeomCapsulePointDepth)(dGeomID ccylinder, dReal x, dReal y, dReal z);
882 //
883 //ODE_API dGeomID         (*dCreateCylinder)(dSpaceID space, dReal radius, dReal length);
884 //ODE_API void            (*dGeomCylinderSetParams)(dGeomID cylinder, dReal radius, dReal length);
885 //ODE_API void            (*dGeomCylinderGetParams)(dGeomID cylinder, dReal *radius, dReal *length);
886 //
887 //ODE_API dGeomID         (*dCreateRay)(dSpaceID space, dReal length);
888 //ODE_API void            (*dGeomRaySetLength)(dGeomID ray, dReal length);
889 //ODE_API dReal           (*dGeomRayGetLength)(dGeomID ray);
890 //ODE_API void            (*dGeomRaySet)(dGeomID ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
891 //ODE_API void            (*dGeomRayGet)(dGeomID ray, dVector3 start, dVector3 dir);
892 //
893 ODE_API dGeomID         (*dCreateGeomTransform)(dSpaceID space);
894 ODE_API void            (*dGeomTransformSetGeom)(dGeomID g, dGeomID obj);
895 //ODE_API dGeomID         (*dGeomTransformGetGeom)(dGeomID g);
896 ODE_API void            (*dGeomTransformSetCleanup)(dGeomID g, int mode);
897 //ODE_API int             (*dGeomTransformGetCleanup)(dGeomID g);
898 //ODE_API void            (*dGeomTransformSetInfo)(dGeomID g, int mode);
899 //ODE_API int             (*dGeomTransformGetInfo)(dGeomID g);
900
901 enum { TRIMESH_FACE_NORMALS };
902 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
903 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
904 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
905 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex);
906
907 ODE_API dTriMeshDataID  (*dGeomTriMeshDataCreate)(void);
908 ODE_API void            (*dGeomTriMeshDataDestroy)(dTriMeshDataID g);
909 //ODE_API void            (*dGeomTriMeshDataSet)(dTriMeshDataID g, int data_id, void* in_data);
910 //ODE_API void*           (*dGeomTriMeshDataGet)(dTriMeshDataID g, int data_id);
911 //ODE_API void            (*dGeomTriMeshSetLastTransform)( (*dGeomID g, dMatrix4 last_trans );
912 //ODE_API dReal*          (*dGeomTriMeshGetLastTransform)( (*dGeomID g );
913 ODE_API void            (*dGeomTriMeshDataBuildSingle)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride);
914 //ODE_API void            (*dGeomTriMeshDataBuildSingle1)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride, const void* Normals);
915 //ODE_API void            (*dGeomTriMeshDataBuildDouble)(dTriMeshDataID g,  const void* Vertices,  int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride);
916 //ODE_API void            (*dGeomTriMeshDataBuildDouble1)(dTriMeshDataID g,  const void* Vertices,  int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride, const void* Normals);
917 //ODE_API void            (*dGeomTriMeshDataBuildSimple)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount);
918 //ODE_API void            (*dGeomTriMeshDataBuildSimple1)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount, const int* Normals);
919 //ODE_API void            (*dGeomTriMeshDataPreprocess)(dTriMeshDataID g);
920 //ODE_API void            (*dGeomTriMeshDataGetBuffer)(dTriMeshDataID g, unsigned char** buf, int* bufLen);
921 //ODE_API void            (*dGeomTriMeshDataSetBuffer)(dTriMeshDataID g, unsigned char* buf);
922 //ODE_API void            (*dGeomTriMeshSetCallback)(dGeomID g, dTriCallback* Callback);
923 //ODE_API dTriCallback*   (*dGeomTriMeshGetCallback)(dGeomID g);
924 //ODE_API void            (*dGeomTriMeshSetArrayCallback)(dGeomID g, dTriArrayCallback* ArrayCallback);
925 //ODE_API dTriArrayCallback* (*dGeomTriMeshGetArrayCallback)(dGeomID g);
926 //ODE_API void            (*dGeomTriMeshSetRayCallback)(dGeomID g, dTriRayCallback* Callback);
927 //ODE_API dTriRayCallback* (*dGeomTriMeshGetRayCallback)(dGeomID g);
928 //ODE_API void            (*dGeomTriMeshSetTriMergeCallback)(dGeomID g, dTriTriMergeCallback* Callback);
929 //ODE_API dTriTriMergeCallback* (*dGeomTriMeshGetTriMergeCallback)(dGeomID g);
930 ODE_API dGeomID         (*dCreateTriMesh)(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
931 //ODE_API void            (*dGeomTriMeshSetData)(dGeomID g, dTriMeshDataID Data);
932 //ODE_API dTriMeshDataID  (*dGeomTriMeshGetData)(dGeomID g);
933 //ODE_API void            (*dGeomTriMeshEnableTC)(dGeomID g, int geomClass, int enable);
934 //ODE_API int             (*dGeomTriMeshIsTCEnabled)(dGeomID g, int geomClass);
935 //ODE_API void            (*dGeomTriMeshClearTCCache)(dGeomID g);
936 //ODE_API dTriMeshDataID  (*dGeomTriMeshGetTriMeshDataID)(dGeomID g);
937 //ODE_API void            (*dGeomTriMeshGetTriangle)(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
938 //ODE_API void            (*dGeomTriMeshGetPoint)(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
939 //ODE_API int             (*dGeomTriMeshGetTriangleCount )(dGeomID g);
940 //ODE_API void            (*dGeomTriMeshDataUpdate)(dTriMeshDataID g);
941
942 static dllfunction_t odefuncs[] =
943 {
944         {"dGetConfiguration",                                                   (void **) &dGetConfiguration},
945         {"dCheckConfiguration",                                                 (void **) &dCheckConfiguration},
946         {"dInitODE2",                                                                   (void **) &dInitODE2},
947         {"dAllocateODEDataForThread",                                   (void **) &dAllocateODEDataForThread},
948         {"dCleanupODEAllDataForThread",                                 (void **) &dCleanupODEAllDataForThread},
949         {"dCloseODE",                                                                   (void **) &dCloseODE},
950 //      {"dMassCheck",                                                                  (void **) &dMassCheck},
951 //      {"dMassSetZero",                                                                (void **) &dMassSetZero},
952 //      {"dMassSetParameters",                                                  (void **) &dMassSetParameters},
953 //      {"dMassSetSphere",                                                              (void **) &dMassSetSphere},
954         {"dMassSetSphereTotal",                                                 (void **) &dMassSetSphereTotal},
955 //      {"dMassSetCapsule",                                                             (void **) &dMassSetCapsule},
956         {"dMassSetCapsuleTotal",                                                (void **) &dMassSetCapsuleTotal},
957 //      {"dMassSetCylinder",                                                    (void **) &dMassSetCylinder},
958 //      {"dMassSetCylinderTotal",                                               (void **) &dMassSetCylinderTotal},
959 //      {"dMassSetBox",                                                                 (void **) &dMassSetBox},
960         {"dMassSetBoxTotal",                                                    (void **) &dMassSetBoxTotal},
961 //      {"dMassSetTrimesh",                                                             (void **) &dMassSetTrimesh},
962 //      {"dMassSetTrimeshTotal",                                                (void **) &dMassSetTrimeshTotal},
963 //      {"dMassAdjust",                                                                 (void **) &dMassAdjust},
964 //      {"dMassTranslate",                                                              (void **) &dMassTranslate},
965 //      {"dMassRotate",                                                                 (void **) &dMassRotate},
966 //      {"dMassAdd",                                                                    (void **) &dMassAdd},
967
968         {"dWorldCreate",                                                                (void **) &dWorldCreate},
969         {"dWorldDestroy",                                                               (void **) &dWorldDestroy},
970         {"dWorldSetGravity",                                                    (void **) &dWorldSetGravity},
971 //      {"dWorldGetGravity",                                                    (void **) &dWorldGetGravity},
972 //      {"dWorldSetERP",                                                                (void **) &dWorldSetERP},
973 //      {"dWorldGetERP",                                                                (void **) &dWorldGetERP},
974 //      {"dWorldSetCFM",                                                                (void **) &dWorldSetCFM},
975 //      {"dWorldGetCFM",                                                                (void **) &dWorldGetCFM},
976         {"dWorldStep",                                                                  (void **) &dWorldStep},
977 //      {"dWorldImpulseToForce",                                                (void **) &dWorldImpulseToForce},
978         {"dWorldQuickStep",                                                             (void **) &dWorldQuickStep},
979         {"dWorldSetQuickStepNumIterations",                             (void **) &dWorldSetQuickStepNumIterations},
980 //      {"dWorldGetQuickStepNumIterations",                             (void **) &dWorldGetQuickStepNumIterations},
981 //      {"dWorldSetQuickStepW",                                                 (void **) &dWorldSetQuickStepW},
982 //      {"dWorldGetQuickStepW",                                                 (void **) &dWorldGetQuickStepW},
983 //      {"dWorldSetContactMaxCorrectingVel",                    (void **) &dWorldSetContactMaxCorrectingVel},
984 //      {"dWorldGetContactMaxCorrectingVel",                    (void **) &dWorldGetContactMaxCorrectingVel},
985         {"dWorldSetContactSurfaceLayer",                                (void **) &dWorldSetContactSurfaceLayer},
986 //      {"dWorldGetContactSurfaceLayer",                                (void **) &dWorldGetContactSurfaceLayer},
987         {"dWorldStepFast1",                                                             (void **) &dWorldStepFast1},
988 //      {"dWorldSetAutoEnableDepthSF1",                                 (void **) &dWorldSetAutoEnableDepthSF1},
989 //      {"dWorldGetAutoEnableDepthSF1",                                 (void **) &dWorldGetAutoEnableDepthSF1},
990 //      {"dWorldGetAutoDisableLinearThreshold",                 (void **) &dWorldGetAutoDisableLinearThreshold},
991 //      {"dWorldSetAutoDisableLinearThreshold",                 (void **) &dWorldSetAutoDisableLinearThreshold},
992 //      {"dWorldGetAutoDisableAngularThreshold",                (void **) &dWorldGetAutoDisableAngularThreshold},
993 //      {"dWorldSetAutoDisableAngularThreshold",                (void **) &dWorldSetAutoDisableAngularThreshold},
994 //      {"dWorldGetAutoDisableLinearAverageThreshold",  (void **) &dWorldGetAutoDisableLinearAverageThreshold},
995 //      {"dWorldSetAutoDisableLinearAverageThreshold",  (void **) &dWorldSetAutoDisableLinearAverageThreshold},
996 //      {"dWorldGetAutoDisableAngularAverageThreshold", (void **) &dWorldGetAutoDisableAngularAverageThreshold},
997 //      {"dWorldSetAutoDisableAngularAverageThreshold", (void **) &dWorldSetAutoDisableAngularAverageThreshold},
998 //      {"dWorldGetAutoDisableAverageSamplesCount",             (void **) &dWorldGetAutoDisableAverageSamplesCount},
999 //      {"dWorldSetAutoDisableAverageSamplesCount",             (void **) &dWorldSetAutoDisableAverageSamplesCount},
1000 //      {"dWorldGetAutoDisableSteps",                                   (void **) &dWorldGetAutoDisableSteps},
1001 //      {"dWorldSetAutoDisableSteps",                                   (void **) &dWorldSetAutoDisableSteps},
1002 //      {"dWorldGetAutoDisableTime",                                    (void **) &dWorldGetAutoDisableTime},
1003 //      {"dWorldSetAutoDisableTime",                                    (void **) &dWorldSetAutoDisableTime},
1004 //      {"dWorldGetAutoDisableFlag",                                    (void **) &dWorldGetAutoDisableFlag},
1005 //      {"dWorldSetAutoDisableFlag",                                    (void **) &dWorldSetAutoDisableFlag},
1006 //      {"dWorldGetLinearDampingThreshold",                             (void **) &dWorldGetLinearDampingThreshold},
1007 //      {"dWorldSetLinearDampingThreshold",                             (void **) &dWorldSetLinearDampingThreshold},
1008 //      {"dWorldGetAngularDampingThreshold",                    (void **) &dWorldGetAngularDampingThreshold},
1009 //      {"dWorldSetAngularDampingThreshold",                    (void **) &dWorldSetAngularDampingThreshold},
1010 //      {"dWorldGetLinearDamping",                                              (void **) &dWorldGetLinearDamping},
1011 //      {"dWorldSetLinearDamping",                                              (void **) &dWorldSetLinearDamping},
1012 //      {"dWorldGetAngularDamping",                                             (void **) &dWorldGetAngularDamping},
1013 //      {"dWorldSetAngularDamping",                                             (void **) &dWorldSetAngularDamping},
1014 //      {"dWorldSetDamping",                                                    (void **) &dWorldSetDamping},
1015 //      {"dWorldGetMaxAngularSpeed",                                    (void **) &dWorldGetMaxAngularSpeed},
1016 //      {"dWorldSetMaxAngularSpeed",                                    (void **) &dWorldSetMaxAngularSpeed},
1017 //      {"dBodyGetAutoDisableLinearThreshold",                  (void **) &dBodyGetAutoDisableLinearThreshold},
1018 //      {"dBodySetAutoDisableLinearThreshold",                  (void **) &dBodySetAutoDisableLinearThreshold},
1019 //      {"dBodyGetAutoDisableAngularThreshold",                 (void **) &dBodyGetAutoDisableAngularThreshold},
1020 //      {"dBodySetAutoDisableAngularThreshold",                 (void **) &dBodySetAutoDisableAngularThreshold},
1021 //      {"dBodyGetAutoDisableAverageSamplesCount",              (void **) &dBodyGetAutoDisableAverageSamplesCount},
1022 //      {"dBodySetAutoDisableAverageSamplesCount",              (void **) &dBodySetAutoDisableAverageSamplesCount},
1023 //      {"dBodyGetAutoDisableSteps",                                    (void **) &dBodyGetAutoDisableSteps},
1024 //      {"dBodySetAutoDisableSteps",                                    (void **) &dBodySetAutoDisableSteps},
1025 //      {"dBodyGetAutoDisableTime",                                             (void **) &dBodyGetAutoDisableTime},
1026 //      {"dBodySetAutoDisableTime",                                             (void **) &dBodySetAutoDisableTime},
1027 //      {"dBodyGetAutoDisableFlag",                                             (void **) &dBodyGetAutoDisableFlag},
1028 //      {"dBodySetAutoDisableFlag",                                             (void **) &dBodySetAutoDisableFlag},
1029 //      {"dBodySetAutoDisableDefaults",                                 (void **) &dBodySetAutoDisableDefaults},
1030 //      {"dBodyGetWorld",                                                               (void **) &dBodyGetWorld},
1031         {"dBodyCreate",                                                                 (void **) &dBodyCreate},
1032         {"dBodyDestroy",                                                                (void **) &dBodyDestroy},
1033         {"dBodySetData",                                                                (void **) &dBodySetData},
1034 //      {"dBodyGetData",                                                                (void **) &dBodyGetData},
1035         {"dBodySetPosition",                                                    (void **) &dBodySetPosition},
1036         {"dBodySetRotation",                                                    (void **) &dBodySetRotation},
1037 //      {"dBodySetQuaternion",                                                  (void **) &dBodySetQuaternion},
1038         {"dBodySetLinearVel",                                                   (void **) &dBodySetLinearVel},
1039         {"dBodySetAngularVel",                                                  (void **) &dBodySetAngularVel},
1040         {"dBodyGetPosition",                                                    (void **) &dBodyGetPosition},
1041 //      {"dBodyCopyPosition",                                                   (void **) &dBodyCopyPosition},
1042         {"dBodyGetRotation",                                                    (void **) &dBodyGetRotation},
1043 //      {"dBodyCopyRotation",                                                   (void **) &dBodyCopyRotation},
1044 //      {"dBodyGetQuaternion",                                                  (void **) &dBodyGetQuaternion},
1045 //      {"dBodyCopyQuaternion",                                                 (void **) &dBodyCopyQuaternion},
1046         {"dBodyGetLinearVel",                                                   (void **) &dBodyGetLinearVel},
1047         {"dBodyGetAngularVel",                                                  (void **) &dBodyGetAngularVel},
1048         {"dBodySetMass",                                                                (void **) &dBodySetMass},
1049 //      {"dBodyGetMass",                                                                (void **) &dBodyGetMass},
1050 //      {"dBodyAddForce",                                                               (void **) &dBodyAddForce},
1051 //      {"dBodyAddTorque",                                                              (void **) &dBodyAddTorque},
1052 //      {"dBodyAddRelForce",                                                    (void **) &dBodyAddRelForce},
1053 //      {"dBodyAddRelTorque",                                                   (void **) &dBodyAddRelTorque},
1054 //      {"dBodyAddForceAtPos",                                                  (void **) &dBodyAddForceAtPos},
1055 //      {"dBodyAddForceAtRelPos",                                               (void **) &dBodyAddForceAtRelPos},
1056 //      {"dBodyAddRelForceAtPos",                                               (void **) &dBodyAddRelForceAtPos},
1057 //      {"dBodyAddRelForceAtRelPos",                                    (void **) &dBodyAddRelForceAtRelPos},
1058 //      {"dBodyGetForce",                                                               (void **) &dBodyGetForce},
1059 //      {"dBodyGetTorque",                                                              (void **) &dBodyGetTorque},
1060 //      {"dBodySetForce",                                                               (void **) &dBodySetForce},
1061 //      {"dBodySetTorque",                                                              (void **) &dBodySetTorque},
1062 //      {"dBodyGetRelPointPos",                                                 (void **) &dBodyGetRelPointPos},
1063 //      {"dBodyGetRelPointVel",                                                 (void **) &dBodyGetRelPointVel},
1064 //      {"dBodyGetPointVel",                                                    (void **) &dBodyGetPointVel},
1065 //      {"dBodyGetPosRelPoint",                                                 (void **) &dBodyGetPosRelPoint},
1066 //      {"dBodyVectorToWorld",                                                  (void **) &dBodyVectorToWorld},
1067 //      {"dBodyVectorFromWorld",                                                (void **) &dBodyVectorFromWorld},
1068 //      {"dBodySetFiniteRotationMode",                                  (void **) &dBodySetFiniteRotationMode},
1069 //      {"dBodySetFiniteRotationAxis",                                  (void **) &dBodySetFiniteRotationAxis},
1070 //      {"dBodyGetFiniteRotationMode",                                  (void **) &dBodyGetFiniteRotationMode},
1071 //      {"dBodyGetFiniteRotationAxis",                                  (void **) &dBodyGetFiniteRotationAxis},
1072 //      {"dBodyGetNumJoints",                                                   (void **) &dBodyGetNumJoints},
1073 //      {"dBodyGetJoint",                                                               (void **) &dBodyGetJoint},
1074 //      {"dBodySetDynamic",                                                             (void **) &dBodySetDynamic},
1075 //      {"dBodySetKinematic",                                                   (void **) &dBodySetKinematic},
1076 //      {"dBodyIsKinematic",                                                    (void **) &dBodyIsKinematic},
1077 //      {"dBodyEnable",                                                                 (void **) &dBodyEnable},
1078 //      {"dBodyDisable",                                                                (void **) &dBodyDisable},
1079 //      {"dBodyIsEnabled",                                                              (void **) &dBodyIsEnabled},
1080 //      {"dBodySetGravityMode",                                                 (void **) &dBodySetGravityMode},
1081 //      {"dBodyGetGravityMode",                                                 (void **) &dBodyGetGravityMode},
1082 //      {"dBodySetMovedCallback",                                               (void **) &dBodySetMovedCallback},
1083 //      {"dBodyGetFirstGeom",                                                   (void **) &dBodyGetFirstGeom},
1084 //      {"dBodyGetNextGeom",                                                    (void **) &dBodyGetNextGeom},
1085 //      {"dBodySetDampingDefaults",                                             (void **) &dBodySetDampingDefaults},
1086 //      {"dBodyGetLinearDamping",                                               (void **) &dBodyGetLinearDamping},
1087 //      {"dBodySetLinearDamping",                                               (void **) &dBodySetLinearDamping},
1088 //      {"dBodyGetAngularDamping",                                              (void **) &dBodyGetAngularDamping},
1089 //      {"dBodySetAngularDamping",                                              (void **) &dBodySetAngularDamping},
1090 //      {"dBodySetDamping",                                                             (void **) &dBodySetDamping},
1091 //      {"dBodyGetLinearDampingThreshold",                              (void **) &dBodyGetLinearDampingThreshold},
1092 //      {"dBodySetLinearDampingThreshold",                              (void **) &dBodySetLinearDampingThreshold},
1093 //      {"dBodyGetAngularDampingThreshold",                             (void **) &dBodyGetAngularDampingThreshold},
1094 //      {"dBodySetAngularDampingThreshold",                             (void **) &dBodySetAngularDampingThreshold},
1095 //      {"dBodyGetMaxAngularSpeed",                                             (void **) &dBodyGetMaxAngularSpeed},
1096 //      {"dBodySetMaxAngularSpeed",                                             (void **) &dBodySetMaxAngularSpeed},
1097 //      {"dBodyGetGyroscopicMode",                                              (void **) &dBodyGetGyroscopicMode},
1098 //      {"dBodySetGyroscopicMode",                                              (void **) &dBodySetGyroscopicMode},
1099 //      {"dJointCreateBall",                                                    (void **) &dJointCreateBall},
1100 //      {"dJointCreateHinge",                                                   (void **) &dJointCreateHinge},
1101 //      {"dJointCreateSlider",                                                  (void **) &dJointCreateSlider},
1102         {"dJointCreateContact",                                                 (void **) &dJointCreateContact},
1103 //      {"dJointCreateHinge2",                                                  (void **) &dJointCreateHinge2},
1104 //      {"dJointCreateUniversal",                                               (void **) &dJointCreateUniversal},
1105 //      {"dJointCreatePR",                                                              (void **) &dJointCreatePR},
1106 //      {"dJointCreatePU",                                                              (void **) &dJointCreatePU},
1107 //      {"dJointCreatePiston",                                                  (void **) &dJointCreatePiston},
1108 //      {"dJointCreateFixed",                                                   (void **) &dJointCreateFixed},
1109 //      {"dJointCreateNull",                                                    (void **) &dJointCreateNull},
1110 //      {"dJointCreateAMotor",                                                  (void **) &dJointCreateAMotor},
1111 //      {"dJointCreateLMotor",                                                  (void **) &dJointCreateLMotor},
1112 //      {"dJointCreatePlane2D",                                                 (void **) &dJointCreatePlane2D},
1113 //      {"dJointDestroy",                                                               (void **) &dJointDestroy},
1114         {"dJointGroupCreate",                                                   (void **) &dJointGroupCreate},
1115         {"dJointGroupDestroy",                                                  (void **) &dJointGroupDestroy},
1116         {"dJointGroupEmpty",                                                    (void **) &dJointGroupEmpty},
1117 //      {"dJointGetNumBodies",                                                  (void **) &dJointGetNumBodies},
1118         {"dJointAttach",                                                                (void **) &dJointAttach},
1119 //      {"dJointEnable",                                                                (void **) &dJointEnable},
1120 //      {"dJointDisable",                                                               (void **) &dJointDisable},
1121 //      {"dJointIsEnabled",                                                             (void **) &dJointIsEnabled},
1122 //      {"dJointSetData",                                                               (void **) &dJointSetData},
1123 //      {"dJointGetData",                                                               (void **) &dJointGetData},
1124 //      {"dJointGetType",                                                               (void **) &dJointGetType},
1125 //      {"dJointGetBody",                                                               (void **) &dJointGetBody},
1126 //      {"dJointSetFeedback",                                                   (void **) &dJointSetFeedback},
1127 //      {"dJointGetFeedback",                                                   (void **) &dJointGetFeedback},
1128 //      {"dJointSetBallAnchor",                                                 (void **) &dJointSetBallAnchor},
1129 //      {"dJointSetBallAnchor2",                                                (void **) &dJointSetBallAnchor2},
1130 //      {"dJointSetBallParam",                                                  (void **) &dJointSetBallParam},
1131 //      {"dJointSetHingeAnchor",                                                (void **) &dJointSetHingeAnchor},
1132 //      {"dJointSetHingeAnchorDelta",                                   (void **) &dJointSetHingeAnchorDelta},
1133 //      {"dJointSetHingeAxis",                                                  (void **) &dJointSetHingeAxis},
1134 //      {"dJointSetHingeAxisOffset",                                    (void **) &dJointSetHingeAxisOffset},
1135 //      {"dJointSetHingeParam",                                                 (void **) &dJointSetHingeParam},
1136 //      {"dJointAddHingeTorque",                                                (void **) &dJointAddHingeTorque},
1137 //      {"dJointSetSliderAxis",                                                 (void **) &dJointSetSliderAxis},
1138 //      {"dJointSetSliderAxisDelta",                                    (void **) &dJointSetSliderAxisDelta},
1139 //      {"dJointSetSliderParam",                                                (void **) &dJointSetSliderParam},
1140 //      {"dJointAddSliderForce",                                                (void **) &dJointAddSliderForce},
1141 //      {"dJointSetHinge2Anchor",                                               (void **) &dJointSetHinge2Anchor},
1142 //      {"dJointSetHinge2Axis1",                                                (void **) &dJointSetHinge2Axis1},
1143 //      {"dJointSetHinge2Axis2",                                                (void **) &dJointSetHinge2Axis2},
1144 //      {"dJointSetHinge2Param",                                                (void **) &dJointSetHinge2Param},
1145 //      {"dJointAddHinge2Torques",                                              (void **) &dJointAddHinge2Torques},
1146 //      {"dJointSetUniversalAnchor",                                    (void **) &dJointSetUniversalAnchor},
1147 //      {"dJointSetUniversalAxis1",                                             (void **) &dJointSetUniversalAxis1},
1148 //      {"dJointSetUniversalAxis1Offset",                               (void **) &dJointSetUniversalAxis1Offset},
1149 //      {"dJointSetUniversalAxis2",                                             (void **) &dJointSetUniversalAxis2},
1150 //      {"dJointSetUniversalAxis2Offset",                               (void **) &dJointSetUniversalAxis2Offset},
1151 //      {"dJointSetUniversalParam",                                             (void **) &dJointSetUniversalParam},
1152 //      {"dJointAddUniversalTorques",                                   (void **) &dJointAddUniversalTorques},
1153 //      {"dJointSetPRAnchor",                                                   (void **) &dJointSetPRAnchor},
1154 //      {"dJointSetPRAxis1",                                                    (void **) &dJointSetPRAxis1},
1155 //      {"dJointSetPRAxis2",                                                    (void **) &dJointSetPRAxis2},
1156 //      {"dJointSetPRParam",                                                    (void **) &dJointSetPRParam},
1157 //      {"dJointAddPRTorque",                                                   (void **) &dJointAddPRTorque},
1158 //      {"dJointSetPUAnchor",                                                   (void **) &dJointSetPUAnchor},
1159 //      {"dJointSetPUAnchorOffset",                                             (void **) &dJointSetPUAnchorOffset},
1160 //      {"dJointSetPUAxis1",                                                    (void **) &dJointSetPUAxis1},
1161 //      {"dJointSetPUAxis2",                                                    (void **) &dJointSetPUAxis2},
1162 //      {"dJointSetPUAxis3",                                                    (void **) &dJointSetPUAxis3},
1163 //      {"dJointSetPUAxisP",                                                    (void **) &dJointSetPUAxisP},
1164 //      {"dJointSetPUParam",                                                    (void **) &dJointSetPUParam},
1165 //      {"dJointAddPUTorque",                                                   (void **) &dJointAddPUTorque},
1166 //      {"dJointSetPistonAnchor",                                               (void **) &dJointSetPistonAnchor},
1167 //      {"dJointSetPistonAnchorOffset",                                 (void **) &dJointSetPistonAnchorOffset},
1168 //      {"dJointSetPistonParam",                                                (void **) &dJointSetPistonParam},
1169 //      {"dJointAddPistonForce",                                                (void **) &dJointAddPistonForce},
1170 //      {"dJointSetFixed",                                                              (void **) &dJointSetFixed},
1171 //      {"dJointSetFixedParam",                                                 (void **) &dJointSetFixedParam},
1172 //      {"dJointSetAMotorNumAxes",                                              (void **) &dJointSetAMotorNumAxes},
1173 //      {"dJointSetAMotorAxis",                                                 (void **) &dJointSetAMotorAxis},
1174 //      {"dJointSetAMotorAngle",                                                (void **) &dJointSetAMotorAngle},
1175 //      {"dJointSetAMotorParam",                                                (void **) &dJointSetAMotorParam},
1176 //      {"dJointSetAMotorMode",                                                 (void **) &dJointSetAMotorMode},
1177 //      {"dJointAddAMotorTorques",                                              (void **) &dJointAddAMotorTorques},
1178 //      {"dJointSetLMotorNumAxes",                                              (void **) &dJointSetLMotorNumAxes},
1179 //      {"dJointSetLMotorAxis",                                                 (void **) &dJointSetLMotorAxis},
1180 //      {"dJointSetLMotorParam",                                                (void **) &dJointSetLMotorParam},
1181 //      {"dJointSetPlane2DXParam",                                              (void **) &dJointSetPlane2DXParam},
1182 //      {"dJointSetPlane2DYParam",                                              (void **) &dJointSetPlane2DYParam},
1183 //      {"dJointSetPlane2DAngleParam",                                  (void **) &dJointSetPlane2DAngleParam},
1184 //      {"dJointGetBallAnchor",                                                 (void **) &dJointGetBallAnchor},
1185 //      {"dJointGetBallAnchor2",                                                (void **) &dJointGetBallAnchor2},
1186 //      {"dJointGetBallParam",                                                  (void **) &dJointGetBallParam},
1187 //      {"dJointGetHingeAnchor",                                                (void **) &dJointGetHingeAnchor},
1188 //      {"dJointGetHingeAnchor2",                                               (void **) &dJointGetHingeAnchor2},
1189 //      {"dJointGetHingeAxis",                                                  (void **) &dJointGetHingeAxis},
1190 //      {"dJointGetHingeParam",                                                 (void **) &dJointGetHingeParam},
1191 //      {"dJointGetHingeAngle",                                                 (void **) &dJointGetHingeAngle},
1192 //      {"dJointGetHingeAngleRate",                                             (void **) &dJointGetHingeAngleRate},
1193 //      {"dJointGetSliderPosition",                                             (void **) &dJointGetSliderPosition},
1194 //      {"dJointGetSliderPositionRate",                                 (void **) &dJointGetSliderPositionRate},
1195 //      {"dJointGetSliderAxis",                                                 (void **) &dJointGetSliderAxis},
1196 //      {"dJointGetSliderParam",                                                (void **) &dJointGetSliderParam},
1197 //      {"dJointGetHinge2Anchor",                                               (void **) &dJointGetHinge2Anchor},
1198 //      {"dJointGetHinge2Anchor2",                                              (void **) &dJointGetHinge2Anchor2},
1199 //      {"dJointGetHinge2Axis1",                                                (void **) &dJointGetHinge2Axis1},
1200 //      {"dJointGetHinge2Axis2",                                                (void **) &dJointGetHinge2Axis2},
1201 //      {"dJointGetHinge2Param",                                                (void **) &dJointGetHinge2Param},
1202 //      {"dJointGetHinge2Angle1",                                               (void **) &dJointGetHinge2Angle1},
1203 //      {"dJointGetHinge2Angle1Rate",                                   (void **) &dJointGetHinge2Angle1Rate},
1204 //      {"dJointGetHinge2Angle2Rate",                                   (void **) &dJointGetHinge2Angle2Rate},
1205 //      {"dJointGetUniversalAnchor",                                    (void **) &dJointGetUniversalAnchor},
1206 //      {"dJointGetUniversalAnchor2",                                   (void **) &dJointGetUniversalAnchor2},
1207 //      {"dJointGetUniversalAxis1",                                             (void **) &dJointGetUniversalAxis1},
1208 //      {"dJointGetUniversalAxis2",                                             (void **) &dJointGetUniversalAxis2},
1209 //      {"dJointGetUniversalParam",                                             (void **) &dJointGetUniversalParam},
1210 //      {"dJointGetUniversalAngles",                                    (void **) &dJointGetUniversalAngles},
1211 //      {"dJointGetUniversalAngle1",                                    (void **) &dJointGetUniversalAngle1},
1212 //      {"dJointGetUniversalAngle2",                                    (void **) &dJointGetUniversalAngle2},
1213 //      {"dJointGetUniversalAngle1Rate",                                (void **) &dJointGetUniversalAngle1Rate},
1214 //      {"dJointGetUniversalAngle2Rate",                                (void **) &dJointGetUniversalAngle2Rate},
1215 //      {"dJointGetPRAnchor",                                                   (void **) &dJointGetPRAnchor},
1216 //      {"dJointGetPRPosition",                                                 (void **) &dJointGetPRPosition},
1217 //      {"dJointGetPRPositionRate",                                             (void **) &dJointGetPRPositionRate},
1218 //      {"dJointGetPRAngle",                                                    (void **) &dJointGetPRAngle},
1219 //      {"dJointGetPRAngleRate",                                                (void **) &dJointGetPRAngleRate},
1220 //      {"dJointGetPRAxis1",                                                    (void **) &dJointGetPRAxis1},
1221 //      {"dJointGetPRAxis2",                                                    (void **) &dJointGetPRAxis2},
1222 //      {"dJointGetPRParam",                                                    (void **) &dJointGetPRParam},
1223 //      {"dJointGetPUAnchor",                                                   (void **) &dJointGetPUAnchor},
1224 //      {"dJointGetPUPosition",                                                 (void **) &dJointGetPUPosition},
1225 //      {"dJointGetPUPositionRate",                                             (void **) &dJointGetPUPositionRate},
1226 //      {"dJointGetPUAxis1",                                                    (void **) &dJointGetPUAxis1},
1227 //      {"dJointGetPUAxis2",                                                    (void **) &dJointGetPUAxis2},
1228 //      {"dJointGetPUAxis3",                                                    (void **) &dJointGetPUAxis3},
1229 //      {"dJointGetPUAxisP",                                                    (void **) &dJointGetPUAxisP},
1230 //      {"dJointGetPUAngles",                                                   (void **) &dJointGetPUAngles},
1231 //      {"dJointGetPUAngle1",                                                   (void **) &dJointGetPUAngle1},
1232 //      {"dJointGetPUAngle1Rate",                                               (void **) &dJointGetPUAngle1Rate},
1233 //      {"dJointGetPUAngle2",                                                   (void **) &dJointGetPUAngle2},
1234 //      {"dJointGetPUAngle2Rate",                                               (void **) &dJointGetPUAngle2Rate},
1235 //      {"dJointGetPUParam",                                                    (void **) &dJointGetPUParam},
1236 //      {"dJointGetPistonPosition",                                             (void **) &dJointGetPistonPosition},
1237 //      {"dJointGetPistonPositionRate",                                 (void **) &dJointGetPistonPositionRate},
1238 //      {"dJointGetPistonAngle",                                                (void **) &dJointGetPistonAngle},
1239 //      {"dJointGetPistonAngleRate",                                    (void **) &dJointGetPistonAngleRate},
1240 //      {"dJointGetPistonAnchor",                                               (void **) &dJointGetPistonAnchor},
1241 //      {"dJointGetPistonAnchor2",                                              (void **) &dJointGetPistonAnchor2},
1242 //      {"dJointGetPistonAxis",                                                 (void **) &dJointGetPistonAxis},
1243 //      {"dJointGetPistonParam",                                                (void **) &dJointGetPistonParam},
1244 //      {"dJointGetAMotorNumAxes",                                              (void **) &dJointGetAMotorNumAxes},
1245 //      {"dJointGetAMotorAxis",                                                 (void **) &dJointGetAMotorAxis},
1246 //      {"dJointGetAMotorAxisRel",                                              (void **) &dJointGetAMotorAxisRel},
1247 //      {"dJointGetAMotorAngle",                                                (void **) &dJointGetAMotorAngle},
1248 //      {"dJointGetAMotorAngleRate",                                    (void **) &dJointGetAMotorAngleRate},
1249 //      {"dJointGetAMotorParam",                                                (void **) &dJointGetAMotorParam},
1250 //      {"dJointGetAMotorMode",                                                 (void **) &dJointGetAMotorMode},
1251 //      {"dJointGetLMotorNumAxes",                                              (void **) &dJointGetLMotorNumAxes},
1252 //      {"dJointGetLMotorAxis",                                                 (void **) &dJointGetLMotorAxis},
1253 //      {"dJointGetLMotorParam",                                                (void **) &dJointGetLMotorParam},
1254 //      {"dJointGetFixedParam",                                                 (void **) &dJointGetFixedParam},
1255 //      {"dConnectingJoint",                                                    (void **) &dConnectingJoint},
1256 //      {"dConnectingJointList",                                                (void **) &dConnectingJointList},
1257         {"dAreConnected",                                                               (void **) &dAreConnected},
1258         {"dAreConnectedExcluding",                                              (void **) &dAreConnectedExcluding},
1259         {"dSimpleSpaceCreate",                                                  (void **) &dSimpleSpaceCreate},
1260         {"dHashSpaceCreate",                                                    (void **) &dHashSpaceCreate},
1261         {"dQuadTreeSpaceCreate",                                                (void **) &dQuadTreeSpaceCreate},
1262         {"dSweepAndPruneSpaceCreate",                                   (void **) &dSweepAndPruneSpaceCreate},
1263         {"dSpaceDestroy",                                                               (void **) &dSpaceDestroy},
1264 //      {"dHashSpaceSetLevels",                                                 (void **) &dHashSpaceSetLevels},
1265 //      {"dHashSpaceGetLevels",                                                 (void **) &dHashSpaceGetLevels},
1266 //      {"dSpaceSetCleanup",                                                    (void **) &dSpaceSetCleanup},
1267 //      {"dSpaceGetCleanup",                                                    (void **) &dSpaceGetCleanup},
1268 //      {"dSpaceSetSublevel",                                                   (void **) &dSpaceSetSublevel},
1269 //      {"dSpaceGetSublevel",                                                   (void **) &dSpaceGetSublevel},
1270 //      {"dSpaceSetManualCleanup",                                              (void **) &dSpaceSetManualCleanup},
1271 //      {"dSpaceGetManualCleanup",                                              (void **) &dSpaceGetManualCleanup},
1272 //      {"dSpaceAdd",                                                                   (void **) &dSpaceAdd},
1273 //      {"dSpaceRemove",                                                                (void **) &dSpaceRemove},
1274 //      {"dSpaceQuery",                                                                 (void **) &dSpaceQuery},
1275 //      {"dSpaceClean",                                                                 (void **) &dSpaceClean},
1276 //      {"dSpaceGetNumGeoms",                                                   (void **) &dSpaceGetNumGeoms},
1277 //      {"dSpaceGetGeom",                                                               (void **) &dSpaceGetGeom},
1278 //      {"dSpaceGetClass",                                                              (void **) &dSpaceGetClass},
1279         {"dGeomDestroy",                                                                (void **) &dGeomDestroy},
1280 //      {"dGeomSetData",                                                                (void **) &dGeomSetData},
1281 //      {"dGeomGetData",                                                                (void **) &dGeomGetData},
1282         {"dGeomSetBody",                                                                (void **) &dGeomSetBody},
1283         {"dGeomGetBody",                                                                (void **) &dGeomGetBody},
1284 //      {"dGeomSetPosition",                                                    (void **) &dGeomSetPosition},
1285         {"dGeomSetRotation",                                                    (void **) &dGeomSetRotation},
1286 //      {"dGeomSetQuaternion",                                                  (void **) &dGeomSetQuaternion},
1287 //      {"dGeomGetPosition",                                                    (void **) &dGeomGetPosition},
1288 //      {"dGeomCopyPosition",                                                   (void **) &dGeomCopyPosition},
1289 //      {"dGeomGetRotation",                                                    (void **) &dGeomGetRotation},
1290 //      {"dGeomCopyRotation",                                                   (void **) &dGeomCopyRotation},
1291 //      {"dGeomGetQuaternion",                                                  (void **) &dGeomGetQuaternion},
1292 //      {"dGeomGetAABB",                                                                (void **) &dGeomGetAABB},
1293         {"dGeomIsSpace",                                                                (void **) &dGeomIsSpace},
1294 //      {"dGeomGetSpace",                                                               (void **) &dGeomGetSpace},
1295 //      {"dGeomGetClass",                                                               (void **) &dGeomGetClass},
1296 //      {"dGeomSetCategoryBits",                                                (void **) &dGeomSetCategoryBits},
1297 //      {"dGeomSetCollideBits",                                                 (void **) &dGeomSetCollideBits},
1298 //      {"dGeomGetCategoryBits",                                                (void **) &dGeomGetCategoryBits},
1299 //      {"dGeomGetCollideBits",                                                 (void **) &dGeomGetCollideBits},
1300 //      {"dGeomEnable",                                                                 (void **) &dGeomEnable},
1301 //      {"dGeomDisable",                                                                (void **) &dGeomDisable},
1302 //      {"dGeomIsEnabled",                                                              (void **) &dGeomIsEnabled},
1303 //      {"dGeomSetOffsetPosition",                                              (void **) &dGeomSetOffsetPosition},
1304 //      {"dGeomSetOffsetRotation",                                              (void **) &dGeomSetOffsetRotation},
1305 //      {"dGeomSetOffsetQuaternion",                                    (void **) &dGeomSetOffsetQuaternion},
1306 //      {"dGeomSetOffsetWorldPosition",                                 (void **) &dGeomSetOffsetWorldPosition},
1307 //      {"dGeomSetOffsetWorldRotation",                                 (void **) &dGeomSetOffsetWorldRotation},
1308 //      {"dGeomSetOffsetWorldQuaternion",                               (void **) &dGeomSetOffsetWorldQuaternion},
1309 //      {"dGeomClearOffset",                                                    (void **) &dGeomClearOffset},
1310 //      {"dGeomIsOffset",                                                               (void **) &dGeomIsOffset},
1311 //      {"dGeomGetOffsetPosition",                                              (void **) &dGeomGetOffsetPosition},
1312 //      {"dGeomCopyOffsetPosition",                                             (void **) &dGeomCopyOffsetPosition},
1313 //      {"dGeomGetOffsetRotation",                                              (void **) &dGeomGetOffsetRotation},
1314 //      {"dGeomCopyOffsetRotation",                                             (void **) &dGeomCopyOffsetRotation},
1315 //      {"dGeomGetOffsetQuaternion",                                    (void **) &dGeomGetOffsetQuaternion},
1316         {"dCollide",                                                                    (void **) &dCollide},
1317         {"dSpaceCollide",                                                               (void **) &dSpaceCollide},
1318         {"dSpaceCollide2",                                                              (void **) &dSpaceCollide2},
1319         {"dCreateSphere",                                                               (void **) &dCreateSphere},
1320 //      {"dGeomSphereSetRadius",                                                (void **) &dGeomSphereSetRadius},
1321 //      {"dGeomSphereGetRadius",                                                (void **) &dGeomSphereGetRadius},
1322 //      {"dGeomSpherePointDepth",                                               (void **) &dGeomSpherePointDepth},
1323 //      {"dCreateConvex",                                                               (void **) &dCreateConvex},
1324 //      {"dGeomSetConvex",                                                              (void **) &dGeomSetConvex},
1325         {"dCreateBox",                                                                  (void **) &dCreateBox},
1326 //      {"dGeomBoxSetLengths",                                                  (void **) &dGeomBoxSetLengths},
1327 //      {"dGeomBoxGetLengths",                                                  (void **) &dGeomBoxGetLengths},
1328 //      {"dGeomBoxPointDepth",                                                  (void **) &dGeomBoxPointDepth},
1329 //      {"dGeomBoxPointDepth",                                                  (void **) &dGeomBoxPointDepth},
1330 //      {"dCreatePlane",                                                                (void **) &dCreatePlane},
1331 //      {"dGeomPlaneSetParams",                                                 (void **) &dGeomPlaneSetParams},
1332 //      {"dGeomPlaneGetParams",                                                 (void **) &dGeomPlaneGetParams},
1333 //      {"dGeomPlanePointDepth",                                                (void **) &dGeomPlanePointDepth},
1334         {"dCreateCapsule",                                                              (void **) &dCreateCapsule},
1335 //      {"dGeomCapsuleSetParams",                                               (void **) &dGeomCapsuleSetParams},
1336 //      {"dGeomCapsuleGetParams",                                               (void **) &dGeomCapsuleGetParams},
1337 //      {"dGeomCapsulePointDepth",                                              (void **) &dGeomCapsulePointDepth},
1338 //      {"dCreateCylinder",                                                             (void **) &dCreateCylinder},
1339 //      {"dGeomCylinderSetParams",                                              (void **) &dGeomCylinderSetParams},
1340 //      {"dGeomCylinderGetParams",                                              (void **) &dGeomCylinderGetParams},
1341 //      {"dCreateRay",                                                                  (void **) &dCreateRay},
1342 //      {"dGeomRaySetLength",                                                   (void **) &dGeomRaySetLength},
1343 //      {"dGeomRayGetLength",                                                   (void **) &dGeomRayGetLength},
1344 //      {"dGeomRaySet",                                                                 (void **) &dGeomRaySet},
1345 //      {"dGeomRayGet",                                                                 (void **) &dGeomRayGet},
1346         {"dCreateGeomTransform",                                                (void **) &dCreateGeomTransform},
1347         {"dGeomTransformSetGeom",                                               (void **) &dGeomTransformSetGeom},
1348 //      {"dGeomTransformGetGeom",                                               (void **) &dGeomTransformGetGeom},
1349         {"dGeomTransformSetCleanup",                                    (void **) &dGeomTransformSetCleanup},
1350 //      {"dGeomTransformGetCleanup",                                    (void **) &dGeomTransformGetCleanup},
1351 //      {"dGeomTransformSetInfo",                                               (void **) &dGeomTransformSetInfo},
1352 //      {"dGeomTransformGetInfo",                                               (void **) &dGeomTransformGetInfo},
1353         {"dGeomTriMeshDataCreate",                      (void **) &dGeomTriMeshDataCreate},
1354         {"dGeomTriMeshDataDestroy",                     (void **) &dGeomTriMeshDataDestroy},
1355 //      {"dGeomTriMeshDataSet",                         (void **) &dGeomTriMeshDataSet},
1356 //      {"dGeomTriMeshDataGet",                         (void **) &dGeomTriMeshDataGet},
1357 //      {"dGeomTriMeshSetLastTransform",                (void **) &dGeomTriMeshSetLastTransform},
1358 //      {"dGeomTriMeshGetLastTransform",                (void **) &dGeomTriMeshGetLastTransform},
1359         {"dGeomTriMeshDataBuildSingle",                 (void **) &dGeomTriMeshDataBuildSingle},
1360 //      {"dGeomTriMeshDataBuildSingle1",                (void **) &dGeomTriMeshDataBuildSingle1},
1361 //      {"dGeomTriMeshDataBuildDouble",                 (void **) &dGeomTriMeshDataBuildDouble},
1362 //      {"dGeomTriMeshDataBuildDouble1",                (void **) &dGeomTriMeshDataBuildDouble1},
1363 //      {"dGeomTriMeshDataBuildSimple",                 (void **) &dGeomTriMeshDataBuildSimple},
1364 //      {"dGeomTriMeshDataBuildSimple1",                (void **) &dGeomTriMeshDataBuildSimple1},
1365 //      {"dGeomTriMeshDataPreprocess",                  (void **) &dGeomTriMeshDataPreprocess},
1366 //      {"dGeomTriMeshDataGetBuffer",                   (void **) &dGeomTriMeshDataGetBuffer},
1367 //      {"dGeomTriMeshDataSetBuffer",                   (void **) &dGeomTriMeshDataSetBuffer},
1368 //      {"dGeomTriMeshSetCallback",                     (void **) &dGeomTriMeshSetCallback},
1369 //      {"dGeomTriMeshGetCallback",                     (void **) &dGeomTriMeshGetCallback},
1370 //      {"dGeomTriMeshSetArrayCallback",                (void **) &dGeomTriMeshSetArrayCallback},
1371 //      {"dGeomTriMeshGetArrayCallback",                (void **) &dGeomTriMeshGetArrayCallback},
1372 //      {"dGeomTriMeshSetRayCallback",                  (void **) &dGeomTriMeshSetRayCallback},
1373 //      {"dGeomTriMeshGetRayCallback",                  (void **) &dGeomTriMeshGetRayCallback},
1374 //      {"dGeomTriMeshSetTriMergeCallback",             (void **) &dGeomTriMeshSetTriMergeCallback},
1375 //      {"dGeomTriMeshGetTriMergeCallback",             (void **) &dGeomTriMeshGetTriMergeCallback},
1376         {"dCreateTriMesh",                              (void **) &dCreateTriMesh},
1377 //      {"dGeomTriMeshSetData",                         (void **) &dGeomTriMeshSetData},
1378 //      {"dGeomTriMeshGetData",                         (void **) &dGeomTriMeshGetData},
1379 //      {"dGeomTriMeshEnableTC",                        (void **) &dGeomTriMeshEnableTC},
1380 //      {"dGeomTriMeshIsTCEnabled",                     (void **) &dGeomTriMeshIsTCEnabled},
1381 //      {"dGeomTriMeshClearTCCache",                    (void **) &dGeomTriMeshClearTCCache},
1382 //      {"dGeomTriMeshGetTriMeshDataID",                (void **) &dGeomTriMeshGetTriMeshDataID},
1383 //      {"dGeomTriMeshGetTriangle",                     (void **) &dGeomTriMeshGetTriangle},
1384 //      {"dGeomTriMeshGetPoint",                        (void **) &dGeomTriMeshGetPoint},
1385 //      {"dGeomTriMeshGetTriangleCount",                (void **) &dGeomTriMeshGetTriangleCount},
1386 //      {"dGeomTriMeshDataUpdate",                      (void **) &dGeomTriMeshDataUpdate},
1387         {NULL, NULL}
1388 };
1389
1390 // Handle for ODE DLL
1391 dllhandle_t ode_dll = NULL;
1392 #endif
1393 #endif
1394
1395 static void World_Physics_Init(void)
1396 {
1397 #ifdef USEODE
1398 #ifndef ODE_STATIC
1399         const char* dllnames [] =
1400         {
1401 # if defined(WIN64)
1402                 "libode1_64.dll",
1403 # elif defined(WIN32)
1404                 "libode1.dll",
1405 # elif defined(MACOSX)
1406                 "libode.1.dylib",
1407 # else
1408                 "libode.so.1",
1409 # endif
1410                 NULL
1411         };
1412 #endif
1413
1414         Cvar_RegisterVariable(&physics_ode_quadtree_depth);
1415         Cvar_RegisterVariable(&physics_ode_contactsurfacelayer);
1416         Cvar_RegisterVariable(&physics_ode_worldquickstep);
1417         Cvar_RegisterVariable(&physics_ode_worldquickstep_iterations);
1418         Cvar_RegisterVariable(&physics_ode_worldstepfast);
1419         Cvar_RegisterVariable(&physics_ode_worldstepfast_iterations);
1420         Cvar_RegisterVariable(&physics_ode_contact_mu);
1421         Cvar_RegisterVariable(&physics_ode_contact_erp);
1422         Cvar_RegisterVariable(&physics_ode_contact_cfm);
1423         Cvar_RegisterVariable(&physics_ode_iterationsperframe);
1424         Cvar_RegisterVariable(&physics_ode_movelimit);
1425         Cvar_RegisterVariable(&physics_ode_spinlimit);
1426
1427 #ifndef ODE_STATIC
1428         // Load the DLL
1429         if (Sys_LoadLibrary (dllnames, &ode_dll, odefuncs))
1430 #endif
1431         {
1432                 dInitODE2(0);
1433 #ifndef ODE_STATIC
1434 # ifdef dSINGLE
1435                 if (!dCheckConfiguration("ODE_single_precision"))
1436 # else
1437                 if (!dCheckConfiguration("ODE_double_precision"))
1438 # endif
1439                 {
1440 # ifdef dSINGLE
1441                         Con_Printf("ode library not compiled for single precision - incompatible!  Not using ODE physics.\n");
1442 # else
1443                         Con_Printf("ode library not compiled for double precision - incompatible!  Not using ODE physics.\n");
1444 # endif
1445                         Sys_UnloadLibrary(ode_dll);
1446                         ode_dll = NULL;
1447                 }
1448 #endif
1449         }
1450 #endif
1451 }
1452
1453 static void World_Physics_Shutdown(void)
1454 {
1455 #ifdef USEODE
1456 #ifndef ODE_STATIC
1457         if (ode_dll)
1458 #endif
1459         {
1460                 dCloseODE();
1461 #ifndef ODE_STATIC
1462                 Sys_UnloadLibrary(ode_dll);
1463                 ode_dll = NULL;
1464 #endif
1465         }
1466 #endif
1467 }
1468
1469 #ifdef USEODE
1470 static void World_Physics_EnableODE(world_t *world)
1471 {
1472         dVector3 center, extents;
1473         if (world->physics.ode)
1474                 return;
1475 #ifndef ODE_STATIC
1476         if (!ode_dll)
1477                 return;
1478 #endif
1479         world->physics.ode = true;
1480         VectorMAM(0.5f, world->mins, 0.5f, world->maxs, center);
1481         VectorSubtract(world->maxs, center, extents);
1482         world->physics.ode_world = dWorldCreate();
1483         world->physics.ode_space = dQuadTreeSpaceCreate(NULL, center, extents, bound(1, physics_ode_quadtree_depth.integer, 10));
1484         world->physics.ode_contactgroup = dJointGroupCreate(0);
1485         // we don't currently set dWorldSetCFM or dWorldSetERP because the defaults seem fine
1486 }
1487 #endif
1488
1489 static void World_Physics_Start(world_t *world)
1490 {
1491 #ifdef USEODE
1492         if (world->physics.ode)
1493                 return;
1494         World_Physics_EnableODE(world);
1495 #endif
1496 }
1497
1498 static void World_Physics_End(world_t *world)
1499 {
1500 #ifdef USEODE
1501         if (world->physics.ode)
1502         {
1503                 dWorldDestroy(world->physics.ode_world);
1504                 dSpaceDestroy(world->physics.ode_space);
1505                 dJointGroupDestroy(world->physics.ode_contactgroup);
1506                 world->physics.ode = false;
1507         }
1508 #endif
1509 }
1510
1511 void World_Physics_RemoveFromEntity(world_t *world, prvm_edict_t *ed)
1512 {
1513 #ifdef USEODE
1514         // entity is not physics controlled, free any physics data
1515         ed->priv.server->ode_physics = false;
1516         if (ed->priv.server->ode_geom)
1517                 dGeomDestroy((dGeomID)ed->priv.server->ode_geom);
1518         ed->priv.server->ode_geom = NULL;
1519         if (ed->priv.server->ode_body)
1520                 dBodyDestroy((dBodyID)ed->priv.server->ode_body);
1521         ed->priv.server->ode_body = NULL;
1522         if (ed->priv.server->ode_vertex3f)
1523                 Mem_Free(ed->priv.server->ode_vertex3f);
1524         ed->priv.server->ode_vertex3f = NULL;
1525         ed->priv.server->ode_numvertices = 0;
1526         if (ed->priv.server->ode_element3i)
1527                 Mem_Free(ed->priv.server->ode_element3i);
1528         ed->priv.server->ode_element3i = NULL;
1529         ed->priv.server->ode_numtriangles = 0;
1530 #endif
1531 }
1532
1533 #ifdef USEODE
1534 static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
1535 {
1536         const dReal *avel;
1537         const dReal *o;
1538         const dReal *r; // for some reason dBodyGetRotation returns a [3][4] matrix
1539         const dReal *vel;
1540         dBodyID body = (dBodyID)ed->priv.server->ode_body;
1541         int movetype;
1542         matrix4x4_t bodymatrix;
1543         matrix4x4_t entitymatrix;
1544         prvm_eval_t *val;
1545         vec3_t forward, left, up;
1546         vec3_t origin;
1547         vec3_t spinvelocity;
1548         vec3_t velocity;
1549         if (!body)
1550                 return;
1551         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);
1552         movetype = (int)val->_float;
1553         if (movetype != MOVETYPE_PHYSICS)
1554                 return;
1555         // store the physics engine data into the entity
1556         o = dBodyGetPosition(body);
1557         r = dBodyGetRotation(body);
1558         vel = dBodyGetLinearVel(body);
1559         avel = dBodyGetAngularVel(body);
1560         VectorCopy(o, origin);
1561         forward[0] = r[0];
1562         forward[1] = r[4];
1563         forward[2] = r[8];
1564         left[0] = r[1];
1565         left[1] = r[5];
1566         left[2] = r[9];
1567         up[0] = r[2];
1568         up[1] = r[6];
1569         up[2] = r[10];
1570         VectorCopy(vel, velocity);
1571         VectorCopy(avel, spinvelocity);
1572         Matrix4x4_FromVectors(&bodymatrix, forward, left, up, origin);
1573         Matrix4x4_Concat(&entitymatrix, &bodymatrix, &ed->priv.server->ode_offsetimatrix);
1574         Matrix4x4_ToVectors(&entitymatrix, forward, left, up, origin);
1575         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(origin, val->vector);
1576         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(forward, val->vector);
1577         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(left, val->vector);
1578         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(up, val->vector);
1579         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(velocity, val->vector);
1580         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(spinvelocity, val->vector);
1581         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) AnglesFromVectors(val->vector, forward, up, true);
1582 }
1583
1584 static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
1585 {
1586         const float *iv;
1587         const int *ie;
1588         dBodyID body = (dBodyID)ed->priv.server->ode_body;
1589         dMass mass;
1590         dReal test;
1591         void *dataID;
1592         dVector3 capsulerot[3];
1593         dp_model_t *model;
1594         float *ov;
1595         int *oe;
1596         int axisindex;
1597         int modelindex = 0;
1598         int movetype;
1599         int numtriangles;
1600         int numvertices;
1601         int solid;
1602         int triangleindex;
1603         int vertexindex;
1604         mempool_t *mempool;
1605         prvm_eval_t *val;
1606         vec3_t angles;
1607         vec3_t avelocity;
1608         vec3_t entmaxs;
1609         vec3_t entmins;
1610         vec3_t forward;
1611         vec3_t geomcenter;
1612         vec3_t geomsize;
1613         vec3_t left;
1614         vec3_t origin;
1615         vec3_t spinvelocity;
1616         vec3_t up;
1617         vec3_t velocity;
1618         vec_t f;
1619         vec_t length;
1620         vec_t massval = 1.0f;
1621         vec_t movelimit;
1622         vec_t radius;
1623         vec_t spinlimit;
1624 #ifndef ODE_STATIC
1625         if (!ode_dll)
1626                 return;
1627 #endif
1628         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.solid);
1629         solid = (int)val->_float;
1630         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);
1631         movetype = (int)val->_float;
1632         switch(solid)
1633         {
1634         case SOLID_BSP:
1635                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.modelindex);
1636                 modelindex = (int)val->_float;
1637                 if (world == &sv.world && modelindex >= 1 && modelindex < MAX_MODELS)
1638                 {
1639                         model = sv.models[modelindex];
1640                         mempool = sv_mempool;
1641                 }
1642                 else if (world == &cl.world && modelindex >= 1 && modelindex < MAX_MODELS)
1643                 {
1644                         model = cl.model_precache[modelindex];
1645                         mempool = cls.levelmempool;
1646                 }
1647                 else
1648                 {
1649                         model = NULL;
1650                         mempool = NULL;
1651                         modelindex = 0;
1652                 }
1653                 if (model)
1654                 {
1655                         VectorCopy(model->normalmins, entmins);
1656                         VectorCopy(model->normalmaxs, entmaxs);
1657                         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mass);if (val) massval = val->_float;
1658                 }
1659                 else
1660                 {
1661                         modelindex = 0;
1662                         massval = 1.0f;
1663                 }
1664                 break;
1665         case SOLID_BBOX:
1666         //case SOLID_SLIDEBOX:
1667         case SOLID_CORPSE:
1668         case SOLID_PHYSICS_BOX:
1669         case SOLID_PHYSICS_SPHERE:
1670         case SOLID_PHYSICS_CAPSULE:
1671                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mins);if (val) VectorCopy(val->vector, entmins);
1672                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.maxs);if (val) VectorCopy(val->vector, entmaxs);
1673                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mass);if (val) massval = val->_float;
1674                 break;
1675         default:
1676                 if (ed->priv.server->ode_physics)
1677                         World_Physics_RemoveFromEntity(world, ed);
1678                 return;
1679         }
1680
1681         VectorSubtract(entmaxs, entmins, geomsize);
1682         if (VectorLength2(geomsize) == 0)
1683         {
1684                 // we don't allow point-size physics objects...
1685                 if (ed->priv.server->ode_physics)
1686                         World_Physics_RemoveFromEntity(world, ed);
1687                 return;
1688         }
1689
1690         if (movetype != MOVETYPE_PHYSICS)
1691                 massval = 1.0f;
1692
1693         // check if we need to create or replace the geom
1694         if (!ed->priv.server->ode_physics
1695          || !VectorCompare(ed->priv.server->ode_mins, entmins)
1696          || !VectorCompare(ed->priv.server->ode_maxs, entmaxs)
1697          || ed->priv.server->ode_mass != massval
1698          || ed->priv.server->ode_modelindex != modelindex)
1699         {
1700                 World_Physics_RemoveFromEntity(world, ed);
1701                 ed->priv.server->ode_physics = true;
1702                 VectorCopy(entmins, ed->priv.server->ode_mins);
1703                 VectorCopy(entmaxs, ed->priv.server->ode_maxs);
1704                 ed->priv.server->ode_mass = massval;
1705                 ed->priv.server->ode_modelindex = modelindex;
1706                 VectorMAM(0.5f, entmins, 0.5f, entmaxs, geomcenter);
1707                 ed->priv.server->ode_movelimit = min(geomsize[0], min(geomsize[1], geomsize[2]));
1708
1709                 if (massval * geomsize[0] * geomsize[1] * geomsize[2] == 0)
1710                 {
1711                         if (movetype == MOVETYPE_PHYSICS)
1712                                 Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
1713                         massval = 1.0f;
1714                         VectorSet(geomsize, 1.0f, 1.0f, 1.0f);
1715                 }
1716
1717                 switch(solid)
1718                 {
1719                 case SOLID_BSP:
1720                         ed->priv.server->ode_offsetmatrix = identitymatrix;
1721                         if (!model)
1722                         {
1723                                 Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
1724                                 break;
1725                         }
1726                         // add an optimized mesh to the model containing only the SUPERCONTENTS_SOLID surfaces
1727                         if (!model->brush.collisionmesh)
1728                                 Mod_CreateCollisionMesh(model);
1729                         if (!model->brush.collisionmesh || !model->brush.collisionmesh->numtriangles)
1730                         {
1731                                 Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
1732                                 break;
1733                         }
1734                         // ODE requires persistent mesh storage, so we need to copy out
1735                         // the data from the model because renderer restarts could free it
1736                         // during the game, additionally we need to flip the triangles...
1737                         // note: ODE does preprocessing of the mesh for culling, removing
1738                         // concave edges, etc., so this is not a lightweight operation
1739                         ed->priv.server->ode_numvertices = numvertices = model->brush.collisionmesh->numverts;
1740                         ed->priv.server->ode_vertex3f = (float *)Mem_Alloc(mempool, numvertices * sizeof(float[3]));
1741                         for (vertexindex = 0, ov = ed->priv.server->ode_vertex3f, iv = model->brush.collisionmesh->vertex3f;vertexindex < numvertices;vertexindex++, ov += 3, iv += 3)
1742                         {
1743                                 ov[0] = iv[0] - geomcenter[0];
1744                                 ov[1] = iv[1] - geomcenter[1];
1745                                 ov[2] = iv[2] - geomcenter[2];
1746                         }
1747                         ed->priv.server->ode_numtriangles = numtriangles = model->brush.collisionmesh->numtriangles;
1748                         ed->priv.server->ode_element3i = (int *)Mem_Alloc(mempool, numtriangles * sizeof(int[3]));
1749                         //memcpy(ed->priv.server->ode_element3i, model->brush.collisionmesh->element3i, ed->priv.server->ode_numtriangles * sizeof(int[3]));
1750                         for (triangleindex = 0, oe = ed->priv.server->ode_element3i, ie = model->brush.collisionmesh->element3i;triangleindex < numtriangles;triangleindex++, oe += 3, ie += 3)
1751                         {
1752                                 oe[0] = ie[2];
1753                                 oe[1] = ie[1];
1754                                 oe[2] = ie[0];
1755                         }
1756                         Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
1757                         // now create the geom
1758                         dataID = dGeomTriMeshDataCreate();
1759                         dGeomTriMeshDataBuildSingle(dataID, (void*)ed->priv.server->ode_vertex3f, sizeof(float[3]), ed->priv.server->ode_numvertices, ed->priv.server->ode_element3i, ed->priv.server->ode_numtriangles*3, sizeof(int[3]));
1760                         ed->priv.server->ode_body = (void *)(body = dBodyCreate(world->physics.ode_world));
1761                         ed->priv.server->ode_geom = (void *)dCreateTriMesh(world->physics.ode_space, dataID, NULL, NULL, NULL);
1762                         dGeomSetBody(ed->priv.server->ode_geom, body);
1763                         dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
1764                         dBodySetMass(body, &mass);
1765                         dBodySetData(body, (void*)ed);
1766                         break;
1767                 case SOLID_BBOX:
1768                 case SOLID_SLIDEBOX:
1769                 case SOLID_CORPSE:
1770                 case SOLID_PHYSICS_BOX:
1771                         Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
1772                         ed->priv.server->ode_body = (void *)(body = dBodyCreate(world->physics.ode_world));
1773                         ed->priv.server->ode_geom = (void *)dCreateBox(world->physics.ode_space, geomsize[0], geomsize[1], geomsize[2]);
1774                         dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
1775                         dGeomSetBody(ed->priv.server->ode_geom, body);
1776                         dBodySetMass(body, &mass);
1777                         dBodySetData(body, (void*)ed);
1778                         break;
1779                 case SOLID_PHYSICS_SPHERE:
1780                         Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
1781                         ed->priv.server->ode_body = (void *)(body = dBodyCreate(world->physics.ode_world));
1782                         ed->priv.server->ode_geom = (void *)dCreateSphere(world->physics.ode_space, geomsize[0] * 0.5f);
1783                         dMassSetSphereTotal(&mass, massval, geomsize[0] * 0.5f);
1784                         dGeomSetBody(ed->priv.server->ode_geom, body);
1785                         dBodySetMass(body, &mass);
1786                         dBodySetData(body, (void*)ed);
1787                         break;
1788                 case SOLID_PHYSICS_CAPSULE:
1789                         axisindex = 0;
1790                         if (geomsize[axisindex] < geomsize[1])
1791                                 axisindex = 1;
1792                         if (geomsize[axisindex] < geomsize[2])
1793                                 axisindex = 2;
1794                         // the qc gives us 3 axis radius, the longest axis is the capsule
1795                         // axis, since ODE doesn't like this idea we have to create a
1796                         // capsule which uses the standard orientation, and apply a
1797                         // transform to it
1798                         memset(capsulerot, 0, sizeof(capsulerot));
1799                         if (axisindex == 0)
1800                                 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
1801                         else if (axisindex == 1)
1802                                 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
1803                         else
1804                                 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
1805                         radius = geomsize[!axisindex] * 0.5f; // any other axis is the radius
1806                         length = geomsize[axisindex] - radius*2;
1807                         // because we want to support more than one axisindex, we have to
1808                         // create a transform, and turn on its cleanup setting (which will
1809                         // cause the child to be destroyed when it is destroyed)
1810                         ed->priv.server->ode_body = (void *)(body = dBodyCreate(world->physics.ode_world));
1811                         ed->priv.server->ode_geom = (void *)dCreateCapsule(world->physics.ode_space, radius, length);
1812                         dMassSetCapsuleTotal(&mass, massval, axisindex+1, radius, length);
1813                         dGeomSetBody(ed->priv.server->ode_geom, body);
1814                         dBodySetMass(body, &mass);
1815                         dBodySetData(body, (void*)ed);
1816                         break;
1817                 default:
1818                         Sys_Error("World_Physics_BodyFromEntity: unrecognized solid value %i was accepted by filter\n", solid);
1819                 }
1820                 Matrix4x4_Invert_Simple(&ed->priv.server->ode_offsetimatrix, &ed->priv.server->ode_offsetmatrix);
1821         }
1822
1823         // get current data from entity
1824         VectorClear(origin);
1825         VectorClear(forward);
1826         VectorClear(left);
1827         VectorClear(up);
1828         VectorClear(velocity);
1829         VectorClear(spinvelocity);
1830         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(val->vector, origin);
1831         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(val->vector, forward);
1832         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(val->vector, left);
1833         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(val->vector, up);
1834         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, velocity);
1835         val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(val->vector, spinvelocity);
1836
1837         // compatibility for legacy entities
1838         switch (solid)
1839         {
1840         case SOLID_BSP:
1841                 //VectorClear(velocity);
1842                 VectorClear(angles);
1843                 VectorClear(avelocity);
1844                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(val->vector, angles);
1845                 val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, avelocity);
1846                 AngleVectorsFLU(angles, forward, left, up);
1847                 // convert single-axis rotations in avelocity to spinvelocity
1848                 // FIXME: untested math - check signs
1849                 VectorSet(spinvelocity, avelocity[PITCH] * ((float)M_PI / 180.0f), avelocity[ROLL] * ((float)M_PI / 180.0f), avelocity[YAW] * ((float)M_PI / 180.0f));
1850                 break;
1851         case SOLID_BBOX:
1852         case SOLID_SLIDEBOX:
1853         case SOLID_CORPSE:
1854                 //VectorClear(velocity);
1855                 VectorSet(forward, 1, 0, 0);
1856                 VectorSet(left, 0, 1, 0);
1857                 VectorSet(up, 0, 0, 1);
1858                 VectorSet(spinvelocity, 0, 0, 0);
1859                 break;
1860         }
1861
1862         // we must prevent NANs...
1863         test = VectorLength2(origin) + VectorLength2(forward) + VectorLength2(left) + VectorLength2(up) + VectorLength2(velocity) + VectorLength2(spinvelocity);
1864         if (IS_NAN(test))
1865         {
1866                 Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = '%f %f %f' .velocity = '%f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], velocity[0], velocity[1], velocity[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
1867                 test = VectorLength2(origin);
1868                 if (IS_NAN(test))
1869                         VectorClear(origin);
1870                 test = VectorLength2(forward) * VectorLength2(left) * VectorLength2(up);
1871                 if (IS_NAN(test))
1872                 {
1873                         VectorSet(forward, 1, 0, 0);
1874                         VectorSet(left, 0, 1, 0);
1875                         VectorSet(up, 0, 0, 1);
1876                 }
1877                 test = VectorLength2(velocity);
1878                 if (IS_NAN(test))
1879                         VectorClear(velocity);
1880                 test = VectorLength2(spinvelocity);
1881                 if (IS_NAN(test))
1882                 {
1883                         VectorClear(spinvelocity);
1884                 }
1885         }
1886
1887         // limit movement speed to prevent missed collisions at high speed
1888         movelimit = ed->priv.server->ode_movelimit * world->physics.ode_movelimit;
1889         test = VectorLength2(velocity);
1890         if (test > movelimit*movelimit)
1891         {
1892                 // scale down linear velocity to the movelimit
1893                 // scale down angular velocity the same amount for consistency
1894                 f = movelimit / sqrt(test);
1895                 VectorScale(velocity, f, velocity);
1896                 VectorScale(spinvelocity, f, spinvelocity);
1897         }
1898
1899         // make sure the angular velocity is not exploding
1900         spinlimit = physics_ode_spinlimit.value;
1901         test = VectorLength2(spinvelocity);
1902         if (test > spinlimit)
1903                 VectorClear(spinvelocity);
1904
1905         // store the values into the physics engine
1906         body = ed->priv.server->ode_body;
1907         if (body)
1908         {
1909                 dVector3 r[3];
1910                 matrix4x4_t entitymatrix;
1911                 matrix4x4_t bodymatrix;
1912                 Matrix4x4_FromVectors(&entitymatrix, forward, left, up, origin);
1913                 Matrix4x4_Concat(&bodymatrix, &entitymatrix, &ed->priv.server->ode_offsetmatrix);
1914                 Matrix4x4_ToVectors(&bodymatrix, forward, left, up, origin);
1915                 r[0][0] = forward[0];
1916                 r[1][0] = forward[1];
1917                 r[2][0] = forward[2];
1918                 r[0][1] = left[0];
1919                 r[1][1] = left[1];
1920                 r[2][1] = left[2];
1921                 r[0][2] = up[0];
1922                 r[1][2] = up[1];
1923                 r[2][2] = up[2];
1924                 dGeomSetBody(ed->priv.server->ode_geom, ed->priv.server->ode_body);
1925                 dBodySetPosition(body, origin[0], origin[1], origin[2]);
1926                 dBodySetRotation(body, r[0]);
1927                 dBodySetLinearVel(body, velocity[0], velocity[1], velocity[2]);
1928                 dBodySetAngularVel(body, spinvelocity[0], spinvelocity[1], spinvelocity[2]);
1929                 // setting body to NULL makes an immovable object
1930                 if (movetype != MOVETYPE_PHYSICS)
1931                         dGeomSetBody(ed->priv.server->ode_geom, 0);
1932         }
1933 }
1934
1935 #define MAX_CONTACTS 16
1936 static void nearCallback (void *data, dGeomID o1, dGeomID o2)
1937 {
1938         world_t *world = (world_t *)data;
1939         dContact contact[MAX_CONTACTS]; // max contacts per collision pair
1940         dBodyID b1;
1941         dBodyID b2;
1942         dJointID c;
1943         int i;
1944         int numcontacts;
1945
1946         if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
1947         {
1948                 // colliding a space with something
1949                 dSpaceCollide2(o1, o2, data, &nearCallback);
1950                 // Note we do not want to test intersections within a space,
1951                 // only between spaces.
1952                 //if (dGeomIsSpace(o1)) dSpaceCollide(o1, data, &nearCallback);
1953                 //if (dGeomIsSpace(o2)) dSpaceCollide(o2, data, &nearCallback);
1954                 return;
1955         }
1956
1957         b1 = dGeomGetBody(o1);
1958         b2 = dGeomGetBody(o2);
1959
1960         // at least one object has to be using MOVETYPE_PHYSICS or we just don't care
1961         if (!b1 && !b2)
1962                 return;
1963
1964         // exit without doing anything if the two bodies are connected by a joint
1965         if (b1 && b2 && dAreConnectedExcluding(b1, b2, dJointTypeContact))
1966                 return;
1967
1968         // generate contact points between the two non-space geoms
1969         numcontacts = dCollide(o1, o2, MAX_CONTACTS, &(contact[0].geom), sizeof(contact[0]));
1970         // add these contact points to the simulation
1971         for (i = 0;i < numcontacts;i++)
1972         {
1973                 contact[i].surface.mode = (physics_ode_contact_mu.value != -1 ? dContactApprox1 : 0) | (physics_ode_contact_erp.value != -1 ? dContactSoftERP : 0) | (physics_ode_contact_cfm.value != -1 ? dContactSoftCFM : 0);
1974                 contact[i].surface.mu = physics_ode_contact_mu.value;
1975                 contact[i].surface.soft_erp = physics_ode_contact_erp.value;
1976                 contact[i].surface.soft_cfm = physics_ode_contact_cfm.value;
1977                 c = dJointCreateContact(world->physics.ode_world, world->physics.ode_contactgroup, contact + i);
1978                 dJointAttach(c, b1, b2);
1979         }
1980 }
1981 #endif
1982
1983 void World_Physics_Frame(world_t *world, double frametime, double gravity)
1984 {
1985 #ifdef USEODE
1986         if (world->physics.ode)
1987         {
1988                 int i;
1989                 prvm_edict_t *ed;
1990
1991                 // copy physics properties from entities to physics engine
1992                 if (prog)
1993                         for (i = 0, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
1994                                 if (!prog->edicts[i].priv.required->free)
1995                                         World_Physics_Frame_BodyFromEntity(world, ed);
1996
1997                 world->physics.ode_iterations = bound(1, physics_ode_iterationsperframe.integer, 1000);
1998                 world->physics.ode_step = frametime / world->physics.ode_iterations;
1999                 world->physics.ode_movelimit = physics_ode_movelimit.value / world->physics.ode_step;
2000                 for (i = 0;i < world->physics.ode_iterations;i++)
2001                 {
2002                         // set the gravity
2003                         dWorldSetGravity(world->physics.ode_world, 0, 0, -gravity);
2004                         // set the tolerance for closeness of objects
2005                         dWorldSetContactSurfaceLayer(world->physics.ode_world, max(0, physics_ode_contactsurfacelayer.value));
2006
2007                         // run collisions for the current world state, creating JointGroup
2008                         dSpaceCollide(world->physics.ode_space, (void *)world, nearCallback);
2009
2010                         // run physics (move objects, calculate new velocities)
2011                         if (physics_ode_worldquickstep.integer)
2012                         {
2013                                 dWorldSetQuickStepNumIterations(world->physics.ode_world, bound(1, physics_ode_worldquickstep_iterations.integer, 200));
2014                                 dWorldQuickStep(world->physics.ode_world, world->physics.ode_step);
2015                         }
2016                         else if (physics_ode_worldstepfast.integer)
2017                                 dWorldStepFast1(world->physics.ode_world, world->physics.ode_step, bound(1, physics_ode_worldstepfast_iterations.integer, 200));
2018                         else
2019                                 dWorldStep(world->physics.ode_world, world->physics.ode_step);
2020
2021                         // clear the JointGroup now that we're done with it
2022                         dJointGroupEmpty(world->physics.ode_contactgroup);
2023                 }
2024
2025                 // copy physics properties from physics engine to entities
2026                 if (prog)
2027                         for (i = 1, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
2028                                 if (!prog->edicts[i].priv.required->free && PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype)->_float == MOVETYPE_PHYSICS)
2029                                         World_Physics_Frame_BodyToEntity(world, ed);
2030         }
2031 #endif
2032 }