move the ODE_API modifiers where they should be
[divverent/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 const char*     (ODE_API *dGetConfiguration)(void);
480 int             (ODE_API *dCheckConfiguration)( const char* token );
481 int             (ODE_API *dInitODE2)(unsigned int uiInitFlags);
482 int             (ODE_API *dAllocateODEDataForThread)(unsigned int uiAllocateFlags);
483 void            (ODE_API *dCleanupODEAllDataForThread)(void);
484 void            (ODE_API *dCloseODE)(void);
485
486 //int             (ODE_API *dMassCheck)(const dMass *m);
487 //void            (ODE_API *dMassSetZero)(dMass *);
488 //void            (ODE_API *dMassSetParameters)(dMass *, dReal themass, dReal cgx, dReal cgy, dReal cgz, dReal I11, dReal I22, dReal I33, dReal I12, dReal I13, dReal I23);
489 //void            (ODE_API *dMassSetSphere)(dMass *, dReal density, dReal radius);
490 void            (ODE_API *dMassSetSphereTotal)(dMass *, dReal total_mass, dReal radius);
491 //void            (ODE_API *dMassSetCapsule)(dMass *, dReal density, int direction, dReal radius, dReal length);
492 void            (ODE_API *dMassSetCapsuleTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
493 //void            (ODE_API *dMassSetCylinder)(dMass *, dReal density, int direction, dReal radius, dReal length);
494 //void            (ODE_API *dMassSetCylinderTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
495 //void            (ODE_API *dMassSetBox)(dMass *, dReal density, dReal lx, dReal ly, dReal lz);
496 void            (ODE_API *dMassSetBoxTotal)(dMass *, dReal total_mass, dReal lx, dReal ly, dReal lz);
497 //void            (ODE_API *dMassSetTrimesh)(dMass *, dReal density, dGeomID g);
498 //void            (ODE_API *dMassSetTrimeshTotal)(dMass *m, dReal total_mass, dGeomID g);
499 //void            (ODE_API *dMassAdjust)(dMass *, dReal newmass);
500 //void            (ODE_API *dMassTranslate)(dMass *, dReal x, dReal y, dReal z);
501 //void            (ODE_API *dMassRotate)(dMass *, const dMatrix3 R);
502 //void            (ODE_API *dMassAdd)(dMass *a, const dMass *b);
503 //
504 dWorldID        (ODE_API *dWorldCreate)(void);
505 void            (ODE_API *dWorldDestroy)(dWorldID world);
506 void            (ODE_API *dWorldSetGravity)(dWorldID, dReal x, dReal y, dReal z);
507 //void            (ODE_API *dWorldGetGravity)(dWorldID, dVector3 gravity);
508 //void            (ODE_API *dWorldSetERP)(dWorldID, dReal erp);
509 //dReal           (ODE_API *dWorldGetERP)(dWorldID);
510 //void            (ODE_API *dWorldSetCFM)(dWorldID, dReal cfm);
511 //dReal           (ODE_API *dWorldGetCFM)(dWorldID);
512 void            (ODE_API *dWorldStep)(dWorldID, dReal stepsize);
513 //void            (ODE_API *dWorldImpulseToForce)(dWorldID, dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force);
514 void            (ODE_API *dWorldQuickStep)(dWorldID w, dReal stepsize);
515 void            (ODE_API *dWorldSetQuickStepNumIterations)(dWorldID, int num);
516 //int             (ODE_API *dWorldGetQuickStepNumIterations)(dWorldID);
517 //void            (ODE_API *dWorldSetQuickStepW)(dWorldID, dReal over_relaxation);
518 //dReal           (ODE_API *dWorldGetQuickStepW)(dWorldID);
519 //void            (ODE_API *dWorldSetContactMaxCorrectingVel)(dWorldID, dReal vel);
520 //dReal           (ODE_API *dWorldGetContactMaxCorrectingVel)(dWorldID);
521 void            (ODE_API *dWorldSetContactSurfaceLayer)(dWorldID, dReal depth);
522 //dReal           (ODE_API *dWorldGetContactSurfaceLayer)(dWorldID);
523 void            (ODE_API *dWorldStepFast1)(dWorldID, dReal stepsize, int maxiterations);
524 //void            (ODE_API *dWorldSetAutoEnableDepthSF1)(dWorldID, int autoEnableDepth);
525 //int             (ODE_API *dWorldGetAutoEnableDepthSF1)(dWorldID);
526 //dReal           (ODE_API *dWorldGetAutoDisableLinearThreshold)(dWorldID);
527 //void            (ODE_API *dWorldSetAutoDisableLinearThreshold)(dWorldID, dReal linear_threshold);
528 //dReal           (ODE_API *dWorldGetAutoDisableAngularThreshold)(dWorldID);
529 //void            (ODE_API *dWorldSetAutoDisableAngularThreshold)(dWorldID, dReal angular_threshold);
530 //dReal           (ODE_API *dWorldGetAutoDisableLinearAverageThreshold)(dWorldID);
531 //void            (ODE_API *dWorldSetAutoDisableLinearAverageThreshold)(dWorldID, dReal linear_average_threshold);
532 //dReal           (ODE_API *dWorldGetAutoDisableAngularAverageThreshold)(dWorldID);
533 //void            (ODE_API *dWorldSetAutoDisableAngularAverageThreshold)(dWorldID, dReal angular_average_threshold);
534 //int             (ODE_API *dWorldGetAutoDisableAverageSamplesCount)(dWorldID);
535 //void            (ODE_API *dWorldSetAutoDisableAverageSamplesCount)(dWorldID, unsigned int average_samples_count );
536 //int             (ODE_API *dWorldGetAutoDisableSteps)(dWorldID);
537 //void            (ODE_API *dWorldSetAutoDisableSteps)(dWorldID, int steps);
538 //dReal           (ODE_API *dWorldGetAutoDisableTime)(dWorldID);
539 //void            (ODE_API *dWorldSetAutoDisableTime)(dWorldID, dReal time);
540 //int             (ODE_API *dWorldGetAutoDisableFlag)(dWorldID);
541 //void            (ODE_API *dWorldSetAutoDisableFlag)(dWorldID, int do_auto_disable);
542 //dReal           (ODE_API *dWorldGetLinearDampingThreshold)(dWorldID w);
543 //void            (ODE_API *dWorldSetLinearDampingThreshold)(dWorldID w, dReal threshold);
544 //dReal           (ODE_API *dWorldGetAngularDampingThreshold)(dWorldID w);
545 //void            (ODE_API *dWorldSetAngularDampingThreshold)(dWorldID w, dReal threshold);
546 //dReal           (ODE_API *dWorldGetLinearDamping)(dWorldID w);
547 //void            (ODE_API *dWorldSetLinearDamping)(dWorldID w, dReal scale);
548 //dReal           (ODE_API *dWorldGetAngularDamping)(dWorldID w);
549 //void            (ODE_API *dWorldSetAngularDamping)(dWorldID w, dReal scale);
550 //void            (ODE_API *dWorldSetDamping)(dWorldID w, dReal linear_scale, dReal angular_scale);
551 //dReal           (ODE_API *dWorldGetMaxAngularSpeed)(dWorldID w);
552 //void            (ODE_API *dWorldSetMaxAngularSpeed)(dWorldID w, dReal max_speed);
553 //dReal           (ODE_API *dBodyGetAutoDisableLinearThreshold)(dBodyID);
554 //void            (ODE_API *dBodySetAutoDisableLinearThreshold)(dBodyID, dReal linear_average_threshold);
555 //dReal           (ODE_API *dBodyGetAutoDisableAngularThreshold)(dBodyID);
556 //void            (ODE_API *dBodySetAutoDisableAngularThreshold)(dBodyID, dReal angular_average_threshold);
557 //int             (ODE_API *dBodyGetAutoDisableAverageSamplesCount)(dBodyID);
558 //void            (ODE_API *dBodySetAutoDisableAverageSamplesCount)(dBodyID, unsigned int average_samples_count);
559 //int             (ODE_API *dBodyGetAutoDisableSteps)(dBodyID);
560 //void            (ODE_API *dBodySetAutoDisableSteps)(dBodyID, int steps);
561 //dReal           (ODE_API *dBodyGetAutoDisableTime)(dBodyID);
562 //void            (ODE_API *dBodySetAutoDisableTime)(dBodyID, dReal time);
563 //int             (ODE_API *dBodyGetAutoDisableFlag)(dBodyID);
564 //void            (ODE_API *dBodySetAutoDisableFlag)(dBodyID, int do_auto_disable);
565 //void            (ODE_API *dBodySetAutoDisableDefaults)(dBodyID);
566 //dWorldID        (ODE_API *dBodyGetWorld)(dBodyID);
567 dBodyID         (ODE_API *dBodyCreate)(dWorldID);
568 void            (ODE_API *dBodyDestroy)(dBodyID);
569 void            (ODE_API *dBodySetData)(dBodyID, void *data);
570 //void *          (ODE_API *dBodyGetData)(dBodyID);
571 void            (ODE_API *dBodySetPosition)(dBodyID, dReal x, dReal y, dReal z);
572 void            (ODE_API *dBodySetRotation)(dBodyID, const dMatrix3 R);
573 //void            (ODE_API *dBodySetQuaternion)(dBodyID, const dQuaternion q);
574 void            (ODE_API *dBodySetLinearVel)(dBodyID, dReal x, dReal y, dReal z);
575 void            (ODE_API *dBodySetAngularVel)(dBodyID, dReal x, dReal y, dReal z);
576 const dReal *   (ODE_API *dBodyGetPosition)(dBodyID);
577 //void            (ODE_API *dBodyCopyPosition)(dBodyID body, dVector3 pos);
578 const dReal *   (ODE_API *dBodyGetRotation)(dBodyID);
579 //void            (ODE_API *dBodyCopyRotation)(dBodyID, dMatrix3 R);
580 //const dReal *   (ODE_API *dBodyGetQuaternion)(dBodyID);
581 //void            (ODE_API *dBodyCopyQuaternion)(dBodyID body, dQuaternion quat);
582 const dReal *   (ODE_API *dBodyGetLinearVel)(dBodyID);
583 const dReal *   (ODE_API *dBodyGetAngularVel)(dBodyID);
584 void            (ODE_API *dBodySetMass)(dBodyID, const dMass *mass);
585 //void            (ODE_API *dBodyGetMass)(dBodyID, dMass *mass);
586 //void            (ODE_API *dBodyAddForce)(dBodyID, dReal fx, dReal fy, dReal fz);
587 //void            (ODE_API *dBodyAddTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
588 //void            (ODE_API *dBodyAddRelForce)(dBodyID, dReal fx, dReal fy, dReal fz);
589 //void            (ODE_API *dBodyAddRelTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
590 //void            (ODE_API *dBodyAddForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
591 //void            (ODE_API *dBodyAddForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
592 //void            (ODE_API *dBodyAddRelForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
593 //void            (ODE_API *dBodyAddRelForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
594 //const dReal *   (ODE_API *dBodyGetForce)(dBodyID);
595 //const dReal *   (ODE_API *dBodyGetTorque)(dBodyID);
596 //void            (ODE_API *dBodySetForce)(dBodyID b, dReal x, dReal y, dReal z);
597 //void            (ODE_API *dBodySetTorque)(dBodyID b, dReal x, dReal y, dReal z);
598 //void            (ODE_API *dBodyGetRelPointPos)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
599 //void            (ODE_API *dBodyGetRelPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
600 //void            (ODE_API *dBodyGetPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
601 //void            (ODE_API *dBodyGetPosRelPoint)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
602 //void            (ODE_API *dBodyVectorToWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
603 //void            (ODE_API *dBodyVectorFromWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
604 //void            (ODE_API *dBodySetFiniteRotationMode)(dBodyID, int mode);
605 //void            (ODE_API *dBodySetFiniteRotationAxis)(dBodyID, dReal x, dReal y, dReal z);
606 //int             (ODE_API *dBodyGetFiniteRotationMode)(dBodyID);
607 //void            (ODE_API *dBodyGetFiniteRotationAxis)(dBodyID, dVector3 result);
608 //int             (ODE_API *dBodyGetNumJoints)(dBodyID b);
609 //dJointID        (ODE_API *dBodyGetJoint)(dBodyID, int index);
610 //void            (ODE_API *dBodySetDynamic)(dBodyID);
611 //void            (ODE_API *dBodySetKinematic)(dBodyID);
612 //int             (ODE_API *dBodyIsKinematic)(dBodyID);
613 //void            (ODE_API *dBodyEnable)(dBodyID);
614 //void            (ODE_API *dBodyDisable)(dBodyID);
615 //int             (ODE_API *dBodyIsEnabled)(dBodyID);
616 //void            (ODE_API *dBodySetGravityMode)(dBodyID b, int mode);
617 //int             (ODE_API *dBodyGetGravityMode)(dBodyID b);
618 //void            (*dBodySetMovedCallback)(dBodyID b, void(ODE_API *callback)(dBodyID));
619 //dGeomID         (ODE_API *dBodyGetFirstGeom)(dBodyID b);
620 //dGeomID         (ODE_API *dBodyGetNextGeom)(dGeomID g);
621 //void            (ODE_API *dBodySetDampingDefaults)(dBodyID b);
622 //dReal           (ODE_API *dBodyGetLinearDamping)(dBodyID b);
623 //void            (ODE_API *dBodySetLinearDamping)(dBodyID b, dReal scale);
624 //dReal           (ODE_API *dBodyGetAngularDamping)(dBodyID b);
625 //void            (ODE_API *dBodySetAngularDamping)(dBodyID b, dReal scale);
626 //void            (ODE_API *dBodySetDamping)(dBodyID b, dReal linear_scale, dReal angular_scale);
627 //dReal           (ODE_API *dBodyGetLinearDampingThreshold)(dBodyID b);
628 //void            (ODE_API *dBodySetLinearDampingThreshold)(dBodyID b, dReal threshold);
629 //dReal           (ODE_API *dBodyGetAngularDampingThreshold)(dBodyID b);
630 //void            (ODE_API *dBodySetAngularDampingThreshold)(dBodyID b, dReal threshold);
631 //dReal           (ODE_API *dBodyGetMaxAngularSpeed)(dBodyID b);
632 //void            (ODE_API *dBodySetMaxAngularSpeed)(dBodyID b, dReal max_speed);
633 //int             (ODE_API *dBodyGetGyroscopicMode)(dBodyID b);
634 //void            (ODE_API *dBodySetGyroscopicMode)(dBodyID b, int enabled);
635 //dJointID        (ODE_API *dJointCreateBall)(dWorldID, dJointGroupID);
636 //dJointID        (ODE_API *dJointCreateHinge)(dWorldID, dJointGroupID);
637 //dJointID        (ODE_API *dJointCreateSlider)(dWorldID, dJointGroupID);
638 dJointID        (ODE_API *dJointCreateContact)(dWorldID, dJointGroupID, const dContact *);
639 //dJointID        (ODE_API *dJointCreateHinge2)(dWorldID, dJointGroupID);
640 //dJointID        (ODE_API *dJointCreateUniversal)(dWorldID, dJointGroupID);
641 //dJointID        (ODE_API *dJointCreatePR)(dWorldID, dJointGroupID);
642 //dJointID        (ODE_API *dJointCreatePU)(dWorldID, dJointGroupID);
643 //dJointID        (ODE_API *dJointCreatePiston)(dWorldID, dJointGroupID);
644 //dJointID        (ODE_API *dJointCreateFixed)(dWorldID, dJointGroupID);
645 //dJointID        (ODE_API *dJointCreateNull)(dWorldID, dJointGroupID);
646 //dJointID        (ODE_API *dJointCreateAMotor)(dWorldID, dJointGroupID);
647 //dJointID        (ODE_API *dJointCreateLMotor)(dWorldID, dJointGroupID);
648 //dJointID        (ODE_API *dJointCreatePlane2D)(dWorldID, dJointGroupID);
649 //void            (ODE_API *dJointDestroy)(dJointID);
650 dJointGroupID   (ODE_API *dJointGroupCreate)(int max_size);
651 void            (ODE_API *dJointGroupDestroy)(dJointGroupID);
652 void            (ODE_API *dJointGroupEmpty)(dJointGroupID);
653 //int             (ODE_API *dJointGetNumBodies)(dJointID);
654 void            (ODE_API *dJointAttach)(dJointID, dBodyID body1, dBodyID body2);
655 //void            (ODE_API *dJointEnable)(dJointID);
656 //void            (ODE_API *dJointDisable)(dJointID);
657 //int             (ODE_API *dJointIsEnabled)(dJointID);
658 //void            (ODE_API *dJointSetData)(dJointID, void *data);
659 //void *          (ODE_API *dJointGetData)(dJointID);
660 //dJointType      (ODE_API *dJointGetType)(dJointID);
661 //dBodyID         (ODE_API *dJointGetBody)(dJointID, int index);
662 //void            (ODE_API *dJointSetFeedback)(dJointID, dJointFeedback *);
663 //dJointFeedback *(ODE_API *dJointGetFeedback)(dJointID);
664 //void            (ODE_API *dJointSetBallAnchor)(dJointID, dReal x, dReal y, dReal z);
665 //void            (ODE_API *dJointSetBallAnchor2)(dJointID, dReal x, dReal y, dReal z);
666 //void            (ODE_API *dJointSetBallParam)(dJointID, int parameter, dReal value);
667 //void            (ODE_API *dJointSetHingeAnchor)(dJointID, dReal x, dReal y, dReal z);
668 //void            (ODE_API *dJointSetHingeAnchorDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
669 //void            (ODE_API *dJointSetHingeAxis)(dJointID, dReal x, dReal y, dReal z);
670 //void            (ODE_API *dJointSetHingeAxisOffset)(dJointID j, dReal x, dReal y, dReal z, dReal angle);
671 //void            (ODE_API *dJointSetHingeParam)(dJointID, int parameter, dReal value);
672 //void            (ODE_API *dJointAddHingeTorque)(dJointID joint, dReal torque);
673 //void            (ODE_API *dJointSetSliderAxis)(dJointID, dReal x, dReal y, dReal z);
674 //void            (ODE_API *dJointSetSliderAxisDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
675 //void            (ODE_API *dJointSetSliderParam)(dJointID, int parameter, dReal value);
676 //void            (ODE_API *dJointAddSliderForce)(dJointID joint, dReal force);
677 //void            (ODE_API *dJointSetHinge2Anchor)(dJointID, dReal x, dReal y, dReal z);
678 //void            (ODE_API *dJointSetHinge2Axis1)(dJointID, dReal x, dReal y, dReal z);
679 //void            (ODE_API *dJointSetHinge2Axis2)(dJointID, dReal x, dReal y, dReal z);
680 //void            (ODE_API *dJointSetHinge2Param)(dJointID, int parameter, dReal value);
681 //void            (ODE_API *dJointAddHinge2Torques)(dJointID joint, dReal torque1, dReal torque2);
682 //void            (ODE_API *dJointSetUniversalAnchor)(dJointID, dReal x, dReal y, dReal z);
683 //void            (ODE_API *dJointSetUniversalAxis1)(dJointID, dReal x, dReal y, dReal z);
684 //void            (ODE_API *dJointSetUniversalAxis1Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
685 //void            (ODE_API *dJointSetUniversalAxis2)(dJointID, dReal x, dReal y, dReal z);
686 //void            (ODE_API *dJointSetUniversalAxis2Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
687 //void            (ODE_API *dJointSetUniversalParam)(dJointID, int parameter, dReal value);
688 //void            (ODE_API *dJointAddUniversalTorques)(dJointID joint, dReal torque1, dReal torque2);
689 //void            (ODE_API *dJointSetPRAnchor)(dJointID, dReal x, dReal y, dReal z);
690 //void            (ODE_API *dJointSetPRAxis1)(dJointID, dReal x, dReal y, dReal z);
691 //void            (ODE_API *dJointSetPRAxis2)(dJointID, dReal x, dReal y, dReal z);
692 //void            (ODE_API *dJointSetPRParam)(dJointID, int parameter, dReal value);
693 //void            (ODE_API *dJointAddPRTorque)(dJointID j, dReal torque);
694 //void            (ODE_API *dJointSetPUAnchor)(dJointID, dReal x, dReal y, dReal z);
695 //void            (ODE_API *dJointSetPUAnchorOffset)(dJointID, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
696 //void            (ODE_API *dJointSetPUAxis1)(dJointID, dReal x, dReal y, dReal z);
697 //void            (ODE_API *dJointSetPUAxis2)(dJointID, dReal x, dReal y, dReal z);
698 //void            (ODE_API *dJointSetPUAxis3)(dJointID, dReal x, dReal y, dReal z);
699 //void            (ODE_API *dJointSetPUAxisP)(dJointID id, dReal x, dReal y, dReal z);
700 //void            (ODE_API *dJointSetPUParam)(dJointID, int parameter, dReal value);
701 //void            (ODE_API *dJointAddPUTorque)(dJointID j, dReal torque);
702 //void            (ODE_API *dJointSetPistonAnchor)(dJointID, dReal x, dReal y, dReal z);
703 //void            (ODE_API *dJointSetPistonAnchorOffset)(dJointID j, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
704 //void            (ODE_API *dJointSetPistonParam)(dJointID, int parameter, dReal value);
705 //void            (ODE_API *dJointAddPistonForce)(dJointID joint, dReal force);
706 //void            (ODE_API *dJointSetFixed)(dJointID);
707 //void            (ODE_API *dJointSetFixedParam)(dJointID, int parameter, dReal value);
708 //void            (ODE_API *dJointSetAMotorNumAxes)(dJointID, int num);
709 //void            (ODE_API *dJointSetAMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
710 //void            (ODE_API *dJointSetAMotorAngle)(dJointID, int anum, dReal angle);
711 //void            (ODE_API *dJointSetAMotorParam)(dJointID, int parameter, dReal value);
712 //void            (ODE_API *dJointSetAMotorMode)(dJointID, int mode);
713 //void            (ODE_API *dJointAddAMotorTorques)(dJointID, dReal torque1, dReal torque2, dReal torque3);
714 //void            (ODE_API *dJointSetLMotorNumAxes)(dJointID, int num);
715 //void            (ODE_API *dJointSetLMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
716 //void            (ODE_API *dJointSetLMotorParam)(dJointID, int parameter, dReal value);
717 //void            (ODE_API *dJointSetPlane2DXParam)(dJointID, int parameter, dReal value);
718 //void            (ODE_API *dJointSetPlane2DYParam)(dJointID, int parameter, dReal value);
719 //void            (ODE_API *dJointSetPlane2DAngleParam)(dJointID, int parameter, dReal value);
720 //void            (ODE_API *dJointGetBallAnchor)(dJointID, dVector3 result);
721 //void            (ODE_API *dJointGetBallAnchor2)(dJointID, dVector3 result);
722 //dReal           (ODE_API *dJointGetBallParam)(dJointID, int parameter);
723 //void            (ODE_API *dJointGetHingeAnchor)(dJointID, dVector3 result);
724 //void            (ODE_API *dJointGetHingeAnchor2)(dJointID, dVector3 result);
725 //void            (ODE_API *dJointGetHingeAxis)(dJointID, dVector3 result);
726 //dReal           (ODE_API *dJointGetHingeParam)(dJointID, int parameter);
727 //dReal           (ODE_API *dJointGetHingeAngle)(dJointID);
728 //dReal           (ODE_API *dJointGetHingeAngleRate)(dJointID);
729 //dReal           (ODE_API *dJointGetSliderPosition)(dJointID);
730 //dReal           (ODE_API *dJointGetSliderPositionRate)(dJointID);
731 //void            (ODE_API *dJointGetSliderAxis)(dJointID, dVector3 result);
732 //dReal           (ODE_API *dJointGetSliderParam)(dJointID, int parameter);
733 //void            (ODE_API *dJointGetHinge2Anchor)(dJointID, dVector3 result);
734 //void            (ODE_API *dJointGetHinge2Anchor2)(dJointID, dVector3 result);
735 //void            (ODE_API *dJointGetHinge2Axis1)(dJointID, dVector3 result);
736 //void            (ODE_API *dJointGetHinge2Axis2)(dJointID, dVector3 result);
737 //dReal           (ODE_API *dJointGetHinge2Param)(dJointID, int parameter);
738 //dReal           (ODE_API *dJointGetHinge2Angle1)(dJointID);
739 //dReal           (ODE_API *dJointGetHinge2Angle1Rate)(dJointID);
740 //dReal           (ODE_API *dJointGetHinge2Angle2Rate)(dJointID);
741 //void            (ODE_API *dJointGetUniversalAnchor)(dJointID, dVector3 result);
742 //void            (ODE_API *dJointGetUniversalAnchor2)(dJointID, dVector3 result);
743 //void            (ODE_API *dJointGetUniversalAxis1)(dJointID, dVector3 result);
744 //void            (ODE_API *dJointGetUniversalAxis2)(dJointID, dVector3 result);
745 //dReal           (ODE_API *dJointGetUniversalParam)(dJointID, int parameter);
746 //void            (ODE_API *dJointGetUniversalAngles)(dJointID, dReal *angle1, dReal *angle2);
747 //dReal           (ODE_API *dJointGetUniversalAngle1)(dJointID);
748 //dReal           (ODE_API *dJointGetUniversalAngle2)(dJointID);
749 //dReal           (ODE_API *dJointGetUniversalAngle1Rate)(dJointID);
750 //dReal           (ODE_API *dJointGetUniversalAngle2Rate)(dJointID);
751 //void            (ODE_API *dJointGetPRAnchor)(dJointID, dVector3 result);
752 //dReal           (ODE_API *dJointGetPRPosition)(dJointID);
753 //dReal           (ODE_API *dJointGetPRPositionRate)(dJointID);
754 //dReal           (ODE_API *dJointGetPRAngle)(dJointID);
755 //dReal           (ODE_API *dJointGetPRAngleRate)(dJointID);
756 //void            (ODE_API *dJointGetPRAxis1)(dJointID, dVector3 result);
757 //void            (ODE_API *dJointGetPRAxis2)(dJointID, dVector3 result);
758 //dReal           (ODE_API *dJointGetPRParam)(dJointID, int parameter);
759 //void            (ODE_API *dJointGetPUAnchor)(dJointID, dVector3 result);
760 //dReal           (ODE_API *dJointGetPUPosition)(dJointID);
761 //dReal           (ODE_API *dJointGetPUPositionRate)(dJointID);
762 //void            (ODE_API *dJointGetPUAxis1)(dJointID, dVector3 result);
763 //void            (ODE_API *dJointGetPUAxis2)(dJointID, dVector3 result);
764 //void            (ODE_API *dJointGetPUAxis3)(dJointID, dVector3 result);
765 //void            (ODE_API *dJointGetPUAxisP)(dJointID id, dVector3 result);
766 //void            (ODE_API *dJointGetPUAngles)(dJointID, dReal *angle1, dReal *angle2);
767 //dReal           (ODE_API *dJointGetPUAngle1)(dJointID);
768 //dReal           (ODE_API *dJointGetPUAngle1Rate)(dJointID);
769 //dReal           (ODE_API *dJointGetPUAngle2)(dJointID);
770 //dReal           (ODE_API *dJointGetPUAngle2Rate)(dJointID);
771 //dReal           (ODE_API *dJointGetPUParam)(dJointID, int parameter);
772 //dReal           (ODE_API *dJointGetPistonPosition)(dJointID);
773 //dReal           (ODE_API *dJointGetPistonPositionRate)(dJointID);
774 //dReal           (ODE_API *dJointGetPistonAngle)(dJointID);
775 //dReal           (ODE_API *dJointGetPistonAngleRate)(dJointID);
776 //void            (ODE_API *dJointGetPistonAnchor)(dJointID, dVector3 result);
777 //void            (ODE_API *dJointGetPistonAnchor2)(dJointID, dVector3 result);
778 //void            (ODE_API *dJointGetPistonAxis)(dJointID, dVector3 result);
779 //dReal           (ODE_API *dJointGetPistonParam)(dJointID, int parameter);
780 //int             (ODE_API *dJointGetAMotorNumAxes)(dJointID);
781 //void            (ODE_API *dJointGetAMotorAxis)(dJointID, int anum, dVector3 result);
782 //int             (ODE_API *dJointGetAMotorAxisRel)(dJointID, int anum);
783 //dReal           (ODE_API *dJointGetAMotorAngle)(dJointID, int anum);
784 //dReal           (ODE_API *dJointGetAMotorAngleRate)(dJointID, int anum);
785 //dReal           (ODE_API *dJointGetAMotorParam)(dJointID, int parameter);
786 //int             (ODE_API *dJointGetAMotorMode)(dJointID);
787 //int             (ODE_API *dJointGetLMotorNumAxes)(dJointID);
788 //void            (ODE_API *dJointGetLMotorAxis)(dJointID, int anum, dVector3 result);
789 //dReal           (ODE_API *dJointGetLMotorParam)(dJointID, int parameter);
790 //dReal           (ODE_API *dJointGetFixedParam)(dJointID, int parameter);
791 //dJointID        (ODE_API *dConnectingJoint)(dBodyID, dBodyID);
792 //int             (ODE_API *dConnectingJointList)(dBodyID, dBodyID, dJointID*);
793 int             (ODE_API *dAreConnected)(dBodyID, dBodyID);
794 int             (ODE_API *dAreConnectedExcluding)(dBodyID body1, dBodyID body2, int joint_type);
795 //
796 dSpaceID        (ODE_API *dSimpleSpaceCreate)(dSpaceID space);
797 dSpaceID        (ODE_API *dHashSpaceCreate)(dSpaceID space);
798 dSpaceID        (ODE_API *dQuadTreeSpaceCreate)(dSpaceID space, const dVector3 Center, const dVector3 Extents, int Depth);
799 dSpaceID        (ODE_API *dSweepAndPruneSpaceCreate)( dSpaceID space, int axisorder );
800 void            (ODE_API *dSpaceDestroy)(dSpaceID);
801 //void            (ODE_API *dHashSpaceSetLevels)(dSpaceID space, int minlevel, int maxlevel);
802 //void            (ODE_API *dHashSpaceGetLevels)(dSpaceID space, int *minlevel, int *maxlevel);
803 //void            (ODE_API *dSpaceSetCleanup)(dSpaceID space, int mode);
804 //int             (ODE_API *dSpaceGetCleanup)(dSpaceID space);
805 //void            (ODE_API *dSpaceSetSublevel)(dSpaceID space, int sublevel);
806 //int             (ODE_API *dSpaceGetSublevel)(dSpaceID space);
807 //void            (ODE_API *dSpaceSetManualCleanup)(dSpaceID space, int mode);
808 //int             (ODE_API *dSpaceGetManualCleanup)(dSpaceID space);
809 //void            (ODE_API *dSpaceAdd)(dSpaceID, dGeomID);
810 //void            (ODE_API *dSpaceRemove)(dSpaceID, dGeomID);
811 //int             (ODE_API *dSpaceQuery)(dSpaceID, dGeomID);
812 //void            (ODE_API *dSpaceClean)(dSpaceID);
813 //int             (ODE_API *dSpaceGetNumGeoms)(dSpaceID);
814 //dGeomID         (ODE_API *dSpaceGetGeom)(dSpaceID, int i);
815 //int             (ODE_API *dSpaceGetClass)(dSpaceID space);
816 //
817 void            (ODE_API *dGeomDestroy)(dGeomID geom);
818 //void            (ODE_API *dGeomSetData)(dGeomID geom, void* data);
819 //void *          (ODE_API *dGeomGetData)(dGeomID geom);
820 void            (ODE_API *dGeomSetBody)(dGeomID geom, dBodyID body);
821 dBodyID         (ODE_API *dGeomGetBody)(dGeomID geom);
822 //void            (ODE_API *dGeomSetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
823 void            (ODE_API *dGeomSetRotation)(dGeomID geom, const dMatrix3 R);
824 //void            (ODE_API *dGeomSetQuaternion)(dGeomID geom, const dQuaternion Q);
825 //const dReal *   (ODE_API *dGeomGetPosition)(dGeomID geom);
826 //void            (ODE_API *dGeomCopyPosition)(dGeomID geom, dVector3 pos);
827 //const dReal *   (ODE_API *dGeomGetRotation)(dGeomID geom);
828 //void            (ODE_API *dGeomCopyRotation)(dGeomID geom, dMatrix3 R);
829 //void            (ODE_API *dGeomGetQuaternion)(dGeomID geom, dQuaternion result);
830 //void            (ODE_API *dGeomGetAABB)(dGeomID geom, dReal aabb[6]);
831 int             (ODE_API *dGeomIsSpace)(dGeomID geom);
832 //dSpaceID        (ODE_API *dGeomGetSpace)(dGeomID);
833 //int             (ODE_API *dGeomGetClass)(dGeomID geom);
834 //void            (ODE_API *dGeomSetCategoryBits)(dGeomID geom, unsigned long bits);
835 //void            (ODE_API *dGeomSetCollideBits)(dGeomID geom, unsigned long bits);
836 //unsigned long   (ODE_API *dGeomGetCategoryBits)(dGeomID);
837 //unsigned long   (ODE_API *dGeomGetCollideBits)(dGeomID);
838 //void            (ODE_API *dGeomEnable)(dGeomID geom);
839 //void            (ODE_API *dGeomDisable)(dGeomID geom);
840 //int             (ODE_API *dGeomIsEnabled)(dGeomID geom);
841 //void            (ODE_API *dGeomSetOffsetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
842 //void            (ODE_API *dGeomSetOffsetRotation)(dGeomID geom, const dMatrix3 R);
843 //void            (ODE_API *dGeomSetOffsetQuaternion)(dGeomID geom, const dQuaternion Q);
844 //void            (ODE_API *dGeomSetOffsetWorldPosition)(dGeomID geom, dReal x, dReal y, dReal z);
845 //void            (ODE_API *dGeomSetOffsetWorldRotation)(dGeomID geom, const dMatrix3 R);
846 //void            (ODE_API *dGeomSetOffsetWorldQuaternion)(dGeomID geom, const dQuaternion);
847 //void            (ODE_API *dGeomClearOffset)(dGeomID geom);
848 //int             (ODE_API *dGeomIsOffset)(dGeomID geom);
849 //const dReal *   (ODE_API *dGeomGetOffsetPosition)(dGeomID geom);
850 //void            (ODE_API *dGeomCopyOffsetPosition)(dGeomID geom, dVector3 pos);
851 //const dReal *   (ODE_API *dGeomGetOffsetRotation)(dGeomID geom);
852 //void            (ODE_API *dGeomCopyOffsetRotation)(dGeomID geom, dMatrix3 R);
853 //void            (ODE_API *dGeomGetOffsetQuaternion)(dGeomID geom, dQuaternion result);
854 int             (ODE_API *dCollide)(dGeomID o1, dGeomID o2, int flags, dContactGeom *contact, int skip);
855 //
856 void            (ODE_API *dSpaceCollide)(dSpaceID space, void *data, dNearCallback *callback);
857 void            (ODE_API *dSpaceCollide2)(dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
858 //
859 dGeomID         (ODE_API *dCreateSphere)(dSpaceID space, dReal radius);
860 //void            (ODE_API *dGeomSphereSetRadius)(dGeomID sphere, dReal radius);
861 //dReal           (ODE_API *dGeomSphereGetRadius)(dGeomID sphere);
862 //dReal           (ODE_API *dGeomSpherePointDepth)(dGeomID sphere, dReal x, dReal y, dReal z);
863 //
864 //dGeomID         (ODE_API *dCreateConvex)(dSpaceID space, dReal *_planes, unsigned int _planecount, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
865 //void            (ODE_API *dGeomSetConvex)(dGeomID g, dReal *_planes, unsigned int _count, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
866 //
867 dGeomID         (ODE_API *dCreateBox)(dSpaceID space, dReal lx, dReal ly, dReal lz);
868 //void            (ODE_API *dGeomBoxSetLengths)(dGeomID box, dReal lx, dReal ly, dReal lz);
869 //void            (ODE_API *dGeomBoxGetLengths)(dGeomID box, dVector3 result);
870 //dReal           (ODE_API *dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
871 //dReal           (ODE_API *dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
872 //
873 //dGeomID         (ODE_API *dCreatePlane)(dSpaceID space, dReal a, dReal b, dReal c, dReal d);
874 //void            (ODE_API *dGeomPlaneSetParams)(dGeomID plane, dReal a, dReal b, dReal c, dReal d);
875 //void            (ODE_API *dGeomPlaneGetParams)(dGeomID plane, dVector4 result);
876 //dReal           (ODE_API *dGeomPlanePointDepth)(dGeomID plane, dReal x, dReal y, dReal z);
877 //
878 dGeomID         (ODE_API *dCreateCapsule)(dSpaceID space, dReal radius, dReal length);
879 //void            (ODE_API *dGeomCapsuleSetParams)(dGeomID ccylinder, dReal radius, dReal length);
880 //void            (ODE_API *dGeomCapsuleGetParams)(dGeomID ccylinder, dReal *radius, dReal *length);
881 //dReal           (ODE_API *dGeomCapsulePointDepth)(dGeomID ccylinder, dReal x, dReal y, dReal z);
882 //
883 //dGeomID         (ODE_API *dCreateCylinder)(dSpaceID space, dReal radius, dReal length);
884 //void            (ODE_API *dGeomCylinderSetParams)(dGeomID cylinder, dReal radius, dReal length);
885 //void            (ODE_API *dGeomCylinderGetParams)(dGeomID cylinder, dReal *radius, dReal *length);
886 //
887 //dGeomID         (ODE_API *dCreateRay)(dSpaceID space, dReal length);
888 //void            (ODE_API *dGeomRaySetLength)(dGeomID ray, dReal length);
889 //dReal           (ODE_API *dGeomRayGetLength)(dGeomID ray);
890 //void            (ODE_API *dGeomRaySet)(dGeomID ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
891 //void            (ODE_API *dGeomRayGet)(dGeomID ray, dVector3 start, dVector3 dir);
892 //
893 dGeomID         (ODE_API *dCreateGeomTransform)(dSpaceID space);
894 void            (ODE_API *dGeomTransformSetGeom)(dGeomID g, dGeomID obj);
895 //dGeomID         (ODE_API *dGeomTransformGetGeom)(dGeomID g);
896 void            (ODE_API *dGeomTransformSetCleanup)(dGeomID g, int mode);
897 //int             (ODE_API *dGeomTransformGetCleanup)(dGeomID g);
898 //void            (ODE_API *dGeomTransformSetInfo)(dGeomID g, int mode);
899 //int             (ODE_API *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 dTriMeshDataID  (ODE_API *dGeomTriMeshDataCreate)(void);
908 void            (ODE_API *dGeomTriMeshDataDestroy)(dTriMeshDataID g);
909 //void            (ODE_API *dGeomTriMeshDataSet)(dTriMeshDataID g, int data_id, void* in_data);
910 //void*           (ODE_API *dGeomTriMeshDataGet)(dTriMeshDataID g, int data_id);
911 //void            (*dGeomTriMeshSetLastTransform)( (ODE_API *dGeomID g, dMatrix4 last_trans );
912 //dReal*          (*dGeomTriMeshGetLastTransform)( (ODE_API *dGeomID g );
913 void            (ODE_API *dGeomTriMeshDataBuildSingle)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride);
914 //void            (ODE_API *dGeomTriMeshDataBuildSingle1)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride, const void* Normals);
915 //void            (ODE_API *dGeomTriMeshDataBuildDouble)(dTriMeshDataID g,  const void* Vertices,  int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride);
916 //void            (ODE_API *dGeomTriMeshDataBuildDouble1)(dTriMeshDataID g,  const void* Vertices,  int VertexStride, int VertexCount,  const void* Indices, int IndexCount, int TriStride, const void* Normals);
917 //void            (ODE_API *dGeomTriMeshDataBuildSimple)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount);
918 //void            (ODE_API *dGeomTriMeshDataBuildSimple1)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount, const int* Normals);
919 //void            (ODE_API *dGeomTriMeshDataPreprocess)(dTriMeshDataID g);
920 //void            (ODE_API *dGeomTriMeshDataGetBuffer)(dTriMeshDataID g, unsigned char** buf, int* bufLen);
921 //void            (ODE_API *dGeomTriMeshDataSetBuffer)(dTriMeshDataID g, unsigned char* buf);
922 //void            (ODE_API *dGeomTriMeshSetCallback)(dGeomID g, dTriCallback* Callback);
923 //dTriCallback*   (ODE_API *dGeomTriMeshGetCallback)(dGeomID g);
924 //void            (ODE_API *dGeomTriMeshSetArrayCallback)(dGeomID g, dTriArrayCallback* ArrayCallback);
925 //dTriArrayCallback* (ODE_API *dGeomTriMeshGetArrayCallback)(dGeomID g);
926 //void            (ODE_API *dGeomTriMeshSetRayCallback)(dGeomID g, dTriRayCallback* Callback);
927 //dTriRayCallback* (ODE_API *dGeomTriMeshGetRayCallback)(dGeomID g);
928 //void            (ODE_API *dGeomTriMeshSetTriMergeCallback)(dGeomID g, dTriTriMergeCallback* Callback);
929 //dTriTriMergeCallback* (ODE_API *dGeomTriMeshGetTriMergeCallback)(dGeomID g);
930 dGeomID         (ODE_API *dCreateTriMesh)(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
931 //void            (ODE_API *dGeomTriMeshSetData)(dGeomID g, dTriMeshDataID Data);
932 //dTriMeshDataID  (ODE_API *dGeomTriMeshGetData)(dGeomID g);
933 //void            (ODE_API *dGeomTriMeshEnableTC)(dGeomID g, int geomClass, int enable);
934 //int             (ODE_API *dGeomTriMeshIsTCEnabled)(dGeomID g, int geomClass);
935 //void            (ODE_API *dGeomTriMeshClearTCCache)(dGeomID g);
936 //dTriMeshDataID  (ODE_API *dGeomTriMeshGetTriMeshDataID)(dGeomID g);
937 //void            (ODE_API *dGeomTriMeshGetTriangle)(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
938 //void            (ODE_API *dGeomTriMeshGetPoint)(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
939 //int             (ODE_API *dGeomTriMeshGetTriangleCount )(dGeomID g);
940 //void            (ODE_API *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 }