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