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