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