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