2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // world.c -- world query functions
23 #include "clvm_cmds.h"
24 #include "cl_collision.h"
28 entities never clip against themselves, or their owner
30 line of sight checks trace->inopen and trace->inwater, but bullets don't
34 static void World_Physics_Init(void);
41 static void World_Physics_Shutdown(void);
42 void World_Shutdown(void)
44 World_Physics_Shutdown();
47 static void World_Physics_Start(world_t *world);
48 void World_Start(world_t *world)
50 World_Physics_Start(world);
53 static void World_Physics_End(world_t *world);
54 void World_End(world_t *world)
56 World_Physics_End(world);
59 //============================================================================
61 /// World_ClearLink is used for new headnodes
62 void World_ClearLink (link_t *l)
65 l->prev = l->next = l;
68 void World_RemoveLink (link_t *l)
70 l->next->prev = l->prev;
71 l->prev->next = l->next;
74 void World_InsertLinkBefore (link_t *l, link_t *before, int entitynumber)
76 l->entitynumber = entitynumber;
78 l->prev = before->prev;
84 ===============================================================================
88 ===============================================================================
91 void World_PrintAreaStats(world_t *world, const char *worldname)
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;
105 void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs, prvm_prog_t *prog)
109 strlcpy(world->filename, filename, sizeof(world->filename));
110 VectorCopy(mins, world->mins);
111 VectorCopy(maxs, world->maxs);
114 // the areagrid_marknumber is not allowed to be 0
115 if (world->areagrid_marknumber < 1)
116 world->areagrid_marknumber = 1;
117 // choose either the world box size, or a larger box to ensure the grid isn't too fine
118 world->areagrid_size[0] = max(world->maxs[0] - world->mins[0], AREA_GRID * sv_areagrid_mingridsize.value);
119 world->areagrid_size[1] = max(world->maxs[1] - world->mins[1], AREA_GRID * sv_areagrid_mingridsize.value);
120 world->areagrid_size[2] = max(world->maxs[2] - world->mins[2], AREA_GRID * sv_areagrid_mingridsize.value);
121 // figure out the corners of such a box, centered at the center of the world box
122 world->areagrid_mins[0] = (world->mins[0] + world->maxs[0] - world->areagrid_size[0]) * 0.5f;
123 world->areagrid_mins[1] = (world->mins[1] + world->maxs[1] - world->areagrid_size[1]) * 0.5f;
124 world->areagrid_mins[2] = (world->mins[2] + world->maxs[2] - world->areagrid_size[2]) * 0.5f;
125 world->areagrid_maxs[0] = (world->mins[0] + world->maxs[0] + world->areagrid_size[0]) * 0.5f;
126 world->areagrid_maxs[1] = (world->mins[1] + world->maxs[1] + world->areagrid_size[1]) * 0.5f;
127 world->areagrid_maxs[2] = (world->mins[2] + world->maxs[2] + world->areagrid_size[2]) * 0.5f;
128 // now calculate the actual useful info from that
129 VectorNegate(world->areagrid_mins, world->areagrid_bias);
130 world->areagrid_scale[0] = AREA_GRID / world->areagrid_size[0];
131 world->areagrid_scale[1] = AREA_GRID / world->areagrid_size[1];
132 world->areagrid_scale[2] = AREA_GRID / world->areagrid_size[2];
133 World_ClearLink(&world->areagrid_outside);
134 for (i = 0;i < AREA_GRIDNODES;i++)
135 World_ClearLink(&world->areagrid[i]);
136 if (developer_extra.integer)
137 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);
146 void World_UnlinkAll(world_t *world)
148 prvm_prog_t *prog = world->prog;
151 // unlink all entities one by one
152 grid = &world->areagrid_outside;
153 while (grid->next != grid)
154 World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
155 for (i = 0, grid = world->areagrid;i < AREA_GRIDNODES;i++, grid++)
156 while (grid->next != grid)
157 World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
165 void World_UnlinkEdict(prvm_edict_t *ent)
168 for (i = 0;i < ENTITYGRIDAREAS;i++)
170 if (ent->priv.server->areagrid[i].prev)
172 World_RemoveLink (&ent->priv.server->areagrid[i]);
173 ent->priv.server->areagrid[i].prev = ent->priv.server->areagrid[i].next = NULL;
178 int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t requestmaxs, int maxlist, prvm_edict_t **list)
180 prvm_prog_t *prog = world->prog;
185 vec3_t paddedmins, paddedmaxs;
186 int igrid[3], igridmins[3], igridmaxs[3];
188 // avoid crash in showtex code on level change
189 if (prog == NULL || prog->num_edicts < 1)
192 // LadyHavoc: discovered this actually causes its own bugs (dm6 teleporters being too close to info_teleport_destination)
193 //VectorSet(paddedmins, requestmins[0] - 1.0f, requestmins[1] - 1.0f, requestmins[2] - 1.0f);
194 //VectorSet(paddedmaxs, requestmaxs[0] + 1.0f, requestmaxs[1] + 1.0f, requestmaxs[2] + 1.0f);
195 VectorCopy(requestmins, paddedmins);
196 VectorCopy(requestmaxs, paddedmaxs);
198 // FIXME: if areagrid_marknumber wraps, all entities need their
199 // ent->priv.server->areagridmarknumber reset
200 world->areagrid_stats_calls++;
201 world->areagrid_marknumber++;
202 igridmins[0] = (int) floor((paddedmins[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]);
203 igridmins[1] = (int) floor((paddedmins[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]);
204 //igridmins[2] = (int) ((paddedmins[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]);
205 igridmaxs[0] = (int) floor((paddedmaxs[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]) + 1;
206 igridmaxs[1] = (int) floor((paddedmaxs[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]) + 1;
207 //igridmaxs[2] = (int) ((paddedmaxs[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]) + 1;
208 igridmins[0] = max(0, igridmins[0]);
209 igridmins[1] = max(0, igridmins[1]);
210 //igridmins[2] = max(0, igridmins[2]);
211 igridmaxs[0] = min(AREA_GRID, igridmaxs[0]);
212 igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
213 //igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
215 // paranoid debugging
216 //VectorSet(igridmins, 0, 0, 0);VectorSet(igridmaxs, AREA_GRID, AREA_GRID, AREA_GRID);
219 // add entities not linked into areagrid because they are too big or
220 // outside the grid bounds
221 if (world->areagrid_outside.next)
223 grid = &world->areagrid_outside;
224 for (l = grid->next;l != grid;l = l->next)
226 ent = PRVM_EDICT_NUM(l->entitynumber);
227 if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
229 ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
230 if (!ent->priv.server->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
232 if (numlist < maxlist)
236 world->areagrid_stats_entitychecks++;
240 // add grid linked entities
241 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
243 grid = world->areagrid + igrid[1] * AREA_GRID + igridmins[0];
244 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
248 for (l = grid->next;l != grid;l = l->next)
250 ent = PRVM_EDICT_NUM(l->entitynumber);
251 if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
253 ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
254 if (!ent->priv.server->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
256 if (numlist < maxlist)
260 //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]);
262 world->areagrid_stats_entitychecks++;
270 static void World_LinkEdict_AreaGrid(world_t *world, prvm_edict_t *ent)
272 prvm_prog_t *prog = world->prog;
274 int igrid[3], igridmins[3], igridmaxs[3], gridnum, entitynumber = PRVM_NUM_FOR_EDICT(ent);
276 if (entitynumber <= 0 || entitynumber >= prog->max_edicts || PRVM_EDICT_NUM(entitynumber) != ent)
278 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);
282 igridmins[0] = (int) floor((ent->priv.server->areamins[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]);
283 igridmins[1] = (int) floor((ent->priv.server->areamins[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]);
284 //igridmins[2] = (int) floor((ent->priv.server->areamins[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]);
285 igridmaxs[0] = (int) floor((ent->priv.server->areamaxs[0] + world->areagrid_bias[0]) * world->areagrid_scale[0]) + 1;
286 igridmaxs[1] = (int) floor((ent->priv.server->areamaxs[1] + world->areagrid_bias[1]) * world->areagrid_scale[1]) + 1;
287 //igridmaxs[2] = (int) floor((ent->priv.server->areamaxs[2] + world->areagrid_bias[2]) * world->areagrid_scale[2]) + 1;
288 if (igridmins[0] < 0 || igridmaxs[0] > AREA_GRID || igridmins[1] < 0 || igridmaxs[1] > AREA_GRID || ((igridmaxs[0] - igridmins[0]) * (igridmaxs[1] - igridmins[1])) > ENTITYGRIDAREAS)
290 // wow, something outside the grid, store it as such
291 World_InsertLinkBefore (&ent->priv.server->areagrid[0], &world->areagrid_outside, entitynumber);
296 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
298 grid = world->areagrid + igrid[1] * AREA_GRID + igridmins[0];
299 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++, gridnum++)
300 World_InsertLinkBefore (&ent->priv.server->areagrid[gridnum], grid, entitynumber);
310 void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const vec3_t maxs)
312 prvm_prog_t *prog = world->prog;
313 // unlink from old position first
314 if (ent->priv.server->areagrid[0].prev)
315 World_UnlinkEdict(ent);
317 // don't add the world
318 if (ent == prog->edicts)
321 // don't add free entities
322 if (ent->priv.server->free)
325 VectorCopy(mins, ent->priv.server->areamins);
326 VectorCopy(maxs, ent->priv.server->areamaxs);
327 World_LinkEdict_AreaGrid(world, ent);
333 //============================================================================
334 // physics engine support
335 //============================================================================
338 cvar_t physics_ode_quadtree_depth = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_quadtree_depth","5", "desired subdivision level of quadtree culling space"};
339 cvar_t physics_ode_allowconvex = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_allowconvex", "0", "allow usage of Convex Hull primitive type on trimeshes that have custom 'collisionconvex' mesh. If disabled, trimesh primitive type are used."};
340 cvar_t physics_ode_contactsurfacelayer = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_contactsurfacelayer","1", "allows objects to overlap this many units to reduce jitter"};
341 cvar_t physics_ode_worldstep_iterations = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_worldstep_iterations", "20", "parameter to dWorldQuickStep"};
342 cvar_t physics_ode_contact_mu = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_contact_mu", "1", "contact solver mu parameter - friction pyramid approximation 1 (see ODE User Guide)"};
343 cvar_t physics_ode_contact_erp = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_contact_erp", "0.96", "contact solver erp parameter - Error Restitution Percent (see ODE User Guide)"};
344 cvar_t physics_ode_contact_cfm = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_contact_cfm", "0", "contact solver cfm parameter - Constraint Force Mixing (see ODE User Guide)"};
345 cvar_t physics_ode_contact_maxpoints = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_contact_maxpoints", "16", "maximal number of contact points between 2 objects, higher = stable (and slower), can be up to 32"};
346 cvar_t physics_ode_world_erp = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_erp", "-1", "world solver erp parameter - Error Restitution Percent (see ODE User Guide); use defaults when set to -1"};
347 cvar_t physics_ode_world_cfm = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_cfm", "-1", "world solver cfm parameter - Constraint Force Mixing (see ODE User Guide); not touched when -1"};
348 cvar_t physics_ode_world_damping = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_damping", "1", "enabled damping scale (see ODE User Guide), this scales all damping values, be aware that behavior depends of step type"};
349 cvar_t physics_ode_world_damping_linear = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_damping_linear", "0.01", "world linear damping scale (see ODE User Guide); use defaults when set to -1"};
350 cvar_t physics_ode_world_damping_linear_threshold = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_damping_linear_threshold", "0.1", "world linear damping threshold (see ODE User Guide); use defaults when set to -1"};
351 cvar_t physics_ode_world_damping_angular = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_damping_angular", "0.05", "world angular damping scale (see ODE User Guide); use defaults when set to -1"};
352 cvar_t physics_ode_world_damping_angular_threshold = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_damping_angular_threshold", "0.1", "world angular damping threshold (see ODE User Guide); use defaults when set to -1"};
353 cvar_t physics_ode_world_gravitymod = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_world_gravitymod", "1", "multiplies gravity got from sv_gravity, this may be needed to tweak if strong damping is used"};
354 cvar_t physics_ode_iterationsperframe = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_iterationsperframe", "1", "divisor for time step, runs multiple physics steps per frame"};
355 cvar_t physics_ode_constantstep = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_constantstep", "0", "use constant step instead of variable step which tends to increase stability, if set to 1 uses sys_ticrate, instead uses it's own value"};
356 cvar_t physics_ode_autodisable = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable", "1", "automatic disabling of objects which dont move for long period of time, makes object stacking a lot faster"};
357 cvar_t physics_ode_autodisable_steps = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable_steps", "10", "how many steps object should be dormant to be autodisabled"};
358 cvar_t physics_ode_autodisable_time = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable_time", "0", "how many seconds object should be dormant to be autodisabled"};
359 cvar_t physics_ode_autodisable_threshold_linear = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable_threshold_linear", "0.6", "body will be disabled if it's linear move below this value"};
360 cvar_t physics_ode_autodisable_threshold_angular = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable_threshold_angular", "6", "body will be disabled if it's angular move below this value"};
361 cvar_t physics_ode_autodisable_threshold_samples = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_autodisable_threshold_samples", "5", "average threshold with this number of samples"};
362 cvar_t physics_ode_movelimit = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_movelimit", "0.5", "clamp velocity if a single move would exceed this percentage of object thickness, to prevent flying through walls, be aware that behavior depends of step type"};
363 cvar_t physics_ode_spinlimit = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_spinlimit", "10000", "reset spin velocity if it gets too large"};
364 cvar_t physics_ode_trick_fixnan = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_trick_fixnan", "1", "engine trick that checks and fixes NaN velocity/origin/angles on objects, a value of 2 makes console prints on each fix"};
365 cvar_t physics_ode_printstats = {CVAR_CLIENT | CVAR_SERVER, "physics_ode_printstats", "0", "print ODE stats each frame"};
367 cvar_t physics_ode = {CVAR_CLIENT | CVAR_SERVER, "physics_ode", "0", "run ODE physics (VERY experimental and potentially buggy)"};
369 // LadyHavoc: this large chunk of definitions comes from the ODE library
372 #ifdef LINK_TO_LIBODE
376 // ODE does not use WINAPI
382 // note: dynamic builds of ODE tend to be double precision, this is not used
384 typedef double dReal;
386 typedef dReal dVector3[4];
387 typedef dReal dVector4[4];
388 typedef dReal dMatrix3[4*3];
389 typedef dReal dMatrix4[4*4];
390 typedef dReal dMatrix6[8*6];
391 typedef dReal dQuaternion[4];
393 struct dxWorld; /* dynamics world */
394 struct dxSpace; /* collision space */
395 struct dxBody; /* rigid body (dynamics object) */
396 struct dxGeom; /* geometry (collision object) */
400 struct dxTriMeshData;
402 #define dInfinity 3.402823466e+38f
404 typedef struct dxWorld *dWorldID;
405 typedef struct dxSpace *dSpaceID;
406 typedef struct dxBody *dBodyID;
407 typedef struct dxGeom *dGeomID;
408 typedef struct dxJoint *dJointID;
409 typedef struct dxJointGroup *dJointGroupID;
410 typedef struct dxTriMeshData *dTriMeshDataID;
412 typedef struct dJointFeedback
414 dVector3 f1; /* force applied to body 1 */
415 dVector3 t1; /* torque applied to body 1 */
416 dVector3 f2; /* force applied to body 2 */
417 dVector3 t2; /* torque applied to body 2 */
421 typedef enum dJointType
441 #define D_ALL_PARAM_NAMES(start) \
442 /* parameters for limits and motors */ \
443 dParamLoStop = start, \
452 /* parameters for suspension */ \
453 dParamSuspensionERP, \
454 dParamSuspensionCFM, \
457 #define D_ALL_PARAM_NAMES_X(start,x) \
458 /* parameters for limits and motors */ \
459 dParamLoStop ## x = start, \
463 dParamFudgeFactor ## x, \
466 dParamStopERP ## x, \
467 dParamStopCFM ## x, \
468 /* parameters for suspension */ \
469 dParamSuspensionERP ## x, \
470 dParamSuspensionCFM ## x, \
475 D_ALL_PARAM_NAMES_X(0x100,2)
476 D_ALL_PARAM_NAMES_X(0x200,3)
478 /* add a multiple of this constant to the basic parameter numbers to get
479 * the parameters for the second, third etc axes.
495 dContactFDir1 = 0x002,
496 dContactBounce = 0x004,
497 dContactSoftERP = 0x008,
498 dContactSoftCFM = 0x010,
499 dContactMotion1 = 0x020,
500 dContactMotion2 = 0x040,
501 dContactMotionN = 0x080,
502 dContactSlip1 = 0x100,
503 dContactSlip2 = 0x200,
505 dContactApprox0 = 0x0000,
506 dContactApprox1_1 = 0x1000,
507 dContactApprox1_2 = 0x2000,
508 dContactApprox1 = 0x3000
511 typedef struct dSurfaceParameters
513 /* must always be defined */
517 /* only defined if the corresponding flag is set in mode */
523 dReal motion1,motion2,motionN;
525 } dSurfaceParameters;
527 typedef struct dContactGeom
529 dVector3 pos; ///< contact position
530 dVector3 normal; ///< normal vector
531 dReal depth; ///< penetration depth
532 dGeomID g1,g2; ///< the colliding geoms
533 int side1,side2; ///< (to be documented)
537 typedef struct dContact
539 dSurfaceParameters surface;
545 typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
548 // Order XZY or ZXY usually works best, if your Y is up.
549 #define dSAP_AXES_XYZ ((0)|(1<<2)|(2<<4))
550 #define dSAP_AXES_XZY ((0)|(2<<2)|(1<<4))
551 #define dSAP_AXES_YXZ ((1)|(0<<2)|(2<<4))
552 #define dSAP_AXES_YZX ((1)|(2<<2)|(0<<4))
553 #define dSAP_AXES_ZXY ((2)|(0<<2)|(1<<4))
554 #define dSAP_AXES_ZYX ((2)|(1<<2)|(0<<4))
556 const char* (ODE_API *dGetConfiguration)(void);
557 int (ODE_API *dCheckConfiguration)( const char* token );
558 int (ODE_API *dInitODE)(void);
559 //int (ODE_API *dInitODE2)(unsigned int uiInitFlags);
560 //int (ODE_API *dAllocateODEDataForThread)(unsigned int uiAllocateFlags);
561 //void (ODE_API *dCleanupODEAllDataForThread)(void);
562 void (ODE_API *dCloseODE)(void);
564 //int (ODE_API *dMassCheck)(const dMass *m);
565 //void (ODE_API *dMassSetZero)(dMass *);
566 //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);
567 //void (ODE_API *dMassSetSphere)(dMass *, dReal density, dReal radius);
568 void (ODE_API *dMassSetSphereTotal)(dMass *, dReal total_mass, dReal radius);
569 //void (ODE_API *dMassSetCapsule)(dMass *, dReal density, int direction, dReal radius, dReal length);
570 void (ODE_API *dMassSetCapsuleTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
571 //void (ODE_API *dMassSetCylinder)(dMass *, dReal density, int direction, dReal radius, dReal length);
572 void (ODE_API *dMassSetCylinderTotal)(dMass *, dReal total_mass, int direction, dReal radius, dReal length);
573 //void (ODE_API *dMassSetBox)(dMass *, dReal density, dReal lx, dReal ly, dReal lz);
574 void (ODE_API *dMassSetBoxTotal)(dMass *, dReal total_mass, dReal lx, dReal ly, dReal lz);
575 //void (ODE_API *dMassSetTrimesh)(dMass *, dReal density, dGeomID g);
576 //void (ODE_API *dMassSetTrimeshTotal)(dMass *m, dReal total_mass, dGeomID g);
577 //void (ODE_API *dMassAdjust)(dMass *, dReal newmass);
578 //void (ODE_API *dMassTranslate)(dMass *, dReal x, dReal y, dReal z);
579 //void (ODE_API *dMassRotate)(dMass *, const dMatrix3 R);
580 //void (ODE_API *dMassAdd)(dMass *a, const dMass *b);
582 dWorldID (ODE_API *dWorldCreate)(void);
583 void (ODE_API *dWorldDestroy)(dWorldID world);
584 void (ODE_API *dWorldSetGravity)(dWorldID, dReal x, dReal y, dReal z);
585 void (ODE_API *dWorldGetGravity)(dWorldID, dVector3 gravity);
586 void (ODE_API *dWorldSetERP)(dWorldID, dReal erp);
587 //dReal (ODE_API *dWorldGetERP)(dWorldID);
588 void (ODE_API *dWorldSetCFM)(dWorldID, dReal cfm);
589 //dReal (ODE_API *dWorldGetCFM)(dWorldID);
590 //void (ODE_API *dWorldStep)(dWorldID, dReal stepsize);
591 //void (ODE_API *dWorldImpulseToForce)(dWorldID, dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force);
592 void (ODE_API *dWorldQuickStep)(dWorldID w, dReal stepsize);
593 void (ODE_API *dWorldSetQuickStepNumIterations)(dWorldID, int num);
594 //int (ODE_API *dWorldGetQuickStepNumIterations)(dWorldID);
595 //void (ODE_API *dWorldSetQuickStepW)(dWorldID, dReal over_relaxation);
596 //dReal (ODE_API *dWorldGetQuickStepW)(dWorldID);
597 //void (ODE_API *dWorldSetContactMaxCorrectingVel)(dWorldID, dReal vel);
598 //dReal (ODE_API *dWorldGetContactMaxCorrectingVel)(dWorldID);
599 void (ODE_API *dWorldSetContactSurfaceLayer)(dWorldID, dReal depth);
600 //dReal (ODE_API *dWorldGetContactSurfaceLayer)(dWorldID);
601 //void (ODE_API *dWorldStepFast1)(dWorldID, dReal stepsize, int maxiterations);
602 //void (ODE_API *dWorldSetAutoEnableDepthSF1)(dWorldID, int autoEnableDepth);
603 //int (ODE_API *dWorldGetAutoEnableDepthSF1)(dWorldID);
604 //dReal (ODE_API *dWorldGetAutoDisableLinearThreshold)(dWorldID);
605 void (ODE_API *dWorldSetAutoDisableLinearThreshold)(dWorldID, dReal linear_threshold);
606 //dReal (ODE_API *dWorldGetAutoDisableAngularThreshold)(dWorldID);
607 void (ODE_API *dWorldSetAutoDisableAngularThreshold)(dWorldID, dReal angular_threshold);
608 //dReal (ODE_API *dWorldGetAutoDisableLinearAverageThreshold)(dWorldID);
609 //void (ODE_API *dWorldSetAutoDisableLinearAverageThreshold)(dWorldID, dReal linear_average_threshold);
610 //dReal (ODE_API *dWorldGetAutoDisableAngularAverageThreshold)(dWorldID);
611 //void (ODE_API *dWorldSetAutoDisableAngularAverageThreshold)(dWorldID, dReal angular_average_threshold);
612 //int (ODE_API *dWorldGetAutoDisableAverageSamplesCount)(dWorldID);
613 void (ODE_API *dWorldSetAutoDisableAverageSamplesCount)(dWorldID, unsigned int average_samples_count );
614 //int (ODE_API *dWorldGetAutoDisableSteps)(dWorldID);
615 void (ODE_API *dWorldSetAutoDisableSteps)(dWorldID, int steps);
616 //dReal (ODE_API *dWorldGetAutoDisableTime)(dWorldID);
617 void (ODE_API *dWorldSetAutoDisableTime)(dWorldID, dReal time);
618 //int (ODE_API *dWorldGetAutoDisableFlag)(dWorldID);
619 void (ODE_API *dWorldSetAutoDisableFlag)(dWorldID, int do_auto_disable);
620 //dReal (ODE_API *dWorldGetLinearDampingThreshold)(dWorldID w);
621 void (ODE_API *dWorldSetLinearDampingThreshold)(dWorldID w, dReal threshold);
622 //dReal (ODE_API *dWorldGetAngularDampingThreshold)(dWorldID w);
623 void (ODE_API *dWorldSetAngularDampingThreshold)(dWorldID w, dReal threshold);
624 //dReal (ODE_API *dWorldGetLinearDamping)(dWorldID w);
625 void (ODE_API *dWorldSetLinearDamping)(dWorldID w, dReal scale);
626 //dReal (ODE_API *dWorldGetAngularDamping)(dWorldID w);
627 void (ODE_API *dWorldSetAngularDamping)(dWorldID w, dReal scale);
628 //void (ODE_API *dWorldSetDamping)(dWorldID w, dReal linear_scale, dReal angular_scale);
629 //dReal (ODE_API *dWorldGetMaxAngularSpeed)(dWorldID w);
630 //void (ODE_API *dWorldSetMaxAngularSpeed)(dWorldID w, dReal max_speed);
631 //dReal (ODE_API *dBodyGetAutoDisableLinearThreshold)(dBodyID);
632 //void (ODE_API *dBodySetAutoDisableLinearThreshold)(dBodyID, dReal linear_average_threshold);
633 //dReal (ODE_API *dBodyGetAutoDisableAngularThreshold)(dBodyID);
634 //void (ODE_API *dBodySetAutoDisableAngularThreshold)(dBodyID, dReal angular_average_threshold);
635 //int (ODE_API *dBodyGetAutoDisableAverageSamplesCount)(dBodyID);
636 //void (ODE_API *dBodySetAutoDisableAverageSamplesCount)(dBodyID, unsigned int average_samples_count);
637 //int (ODE_API *dBodyGetAutoDisableSteps)(dBodyID);
638 //void (ODE_API *dBodySetAutoDisableSteps)(dBodyID, int steps);
639 //dReal (ODE_API *dBodyGetAutoDisableTime)(dBodyID);
640 //void (ODE_API *dBodySetAutoDisableTime)(dBodyID, dReal time);
641 //int (ODE_API *dBodyGetAutoDisableFlag)(dBodyID);
642 //void (ODE_API *dBodySetAutoDisableFlag)(dBodyID, int do_auto_disable);
643 //void (ODE_API *dBodySetAutoDisableDefaults)(dBodyID);
644 //dWorldID (ODE_API *dBodyGetWorld)(dBodyID);
645 dBodyID (ODE_API *dBodyCreate)(dWorldID);
646 void (ODE_API *dBodyDestroy)(dBodyID);
647 void (ODE_API *dBodySetData)(dBodyID, void *data);
648 void * (ODE_API *dBodyGetData)(dBodyID);
649 void (ODE_API *dBodySetPosition)(dBodyID, dReal x, dReal y, dReal z);
650 void (ODE_API *dBodySetRotation)(dBodyID, const dMatrix3 R);
651 //void (ODE_API *dBodySetQuaternion)(dBodyID, const dQuaternion q);
652 void (ODE_API *dBodySetLinearVel)(dBodyID, dReal x, dReal y, dReal z);
653 void (ODE_API *dBodySetAngularVel)(dBodyID, dReal x, dReal y, dReal z);
654 const dReal * (ODE_API *dBodyGetPosition)(dBodyID);
655 //void (ODE_API *dBodyCopyPosition)(dBodyID body, dVector3 pos);
656 const dReal * (ODE_API *dBodyGetRotation)(dBodyID);
657 //void (ODE_API *dBodyCopyRotation)(dBodyID, dMatrix3 R);
658 //const dReal * (ODE_API *dBodyGetQuaternion)(dBodyID);
659 //void (ODE_API *dBodyCopyQuaternion)(dBodyID body, dQuaternion quat);
660 const dReal * (ODE_API *dBodyGetLinearVel)(dBodyID);
661 const dReal * (ODE_API *dBodyGetAngularVel)(dBodyID);
662 void (ODE_API *dBodySetMass)(dBodyID, const dMass *mass);
663 //void (ODE_API *dBodyGetMass)(dBodyID, dMass *mass);
664 void (ODE_API *dBodyAddForce)(dBodyID, dReal fx, dReal fy, dReal fz);
665 void (ODE_API *dBodyAddTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
666 //void (ODE_API *dBodyAddRelForce)(dBodyID, dReal fx, dReal fy, dReal fz);
667 //void (ODE_API *dBodyAddRelTorque)(dBodyID, dReal fx, dReal fy, dReal fz);
668 void (ODE_API *dBodyAddForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
669 //void (ODE_API *dBodyAddForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
670 //void (ODE_API *dBodyAddRelForceAtPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
671 //void (ODE_API *dBodyAddRelForceAtRelPos)(dBodyID, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
672 //const dReal * (ODE_API *dBodyGetForce)(dBodyID);
673 //const dReal * (ODE_API *dBodyGetTorque)(dBodyID);
674 //void (ODE_API *dBodySetForce)(dBodyID b, dReal x, dReal y, dReal z);
675 //void (ODE_API *dBodySetTorque)(dBodyID b, dReal x, dReal y, dReal z);
676 //void (ODE_API *dBodyGetRelPointPos)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
677 //void (ODE_API *dBodyGetRelPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
678 //void (ODE_API *dBodyGetPointVel)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
679 //void (ODE_API *dBodyGetPosRelPoint)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
680 //void (ODE_API *dBodyVectorToWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
681 //void (ODE_API *dBodyVectorFromWorld)(dBodyID, dReal px, dReal py, dReal pz, dVector3 result);
682 //void (ODE_API *dBodySetFiniteRotationMode)(dBodyID, int mode);
683 //void (ODE_API *dBodySetFiniteRotationAxis)(dBodyID, dReal x, dReal y, dReal z);
684 //int (ODE_API *dBodyGetFiniteRotationMode)(dBodyID);
685 //void (ODE_API *dBodyGetFiniteRotationAxis)(dBodyID, dVector3 result);
686 int (ODE_API *dBodyGetNumJoints)(dBodyID b);
687 dJointID (ODE_API *dBodyGetJoint)(dBodyID, int index);
688 //void (ODE_API *dBodySetDynamic)(dBodyID);
689 //void (ODE_API *dBodySetKinematic)(dBodyID);
690 //int (ODE_API *dBodyIsKinematic)(dBodyID);
691 void (ODE_API *dBodyEnable)(dBodyID);
692 void (ODE_API *dBodyDisable)(dBodyID);
693 int (ODE_API *dBodyIsEnabled)(dBodyID);
694 void (ODE_API *dBodySetGravityMode)(dBodyID b, int mode);
695 int (ODE_API *dBodyGetGravityMode)(dBodyID b);
696 //void (*dBodySetMovedCallback)(dBodyID b, void(ODE_API *callback)(dBodyID));
697 //dGeomID (ODE_API *dBodyGetFirstGeom)(dBodyID b);
698 //dGeomID (ODE_API *dBodyGetNextGeom)(dGeomID g);
699 //void (ODE_API *dBodySetDampingDefaults)(dBodyID b);
700 //dReal (ODE_API *dBodyGetLinearDamping)(dBodyID b);
701 //void (ODE_API *dBodySetLinearDamping)(dBodyID b, dReal scale);
702 //dReal (ODE_API *dBodyGetAngularDamping)(dBodyID b);
703 //void (ODE_API *dBodySetAngularDamping)(dBodyID b, dReal scale);
704 //void (ODE_API *dBodySetDamping)(dBodyID b, dReal linear_scale, dReal angular_scale);
705 //dReal (ODE_API *dBodyGetLinearDampingThreshold)(dBodyID b);
706 //void (ODE_API *dBodySetLinearDampingThreshold)(dBodyID b, dReal threshold);
707 //dReal (ODE_API *dBodyGetAngularDampingThreshold)(dBodyID b);
708 //void (ODE_API *dBodySetAngularDampingThreshold)(dBodyID b, dReal threshold);
709 //dReal (ODE_API *dBodyGetMaxAngularSpeed)(dBodyID b);
710 //void (ODE_API *dBodySetMaxAngularSpeed)(dBodyID b, dReal max_speed);
711 //int (ODE_API *dBodyGetGyroscopicMode)(dBodyID b);
712 //void (ODE_API *dBodySetGyroscopicMode)(dBodyID b, int enabled);
713 dJointID (ODE_API *dJointCreateBall)(dWorldID, dJointGroupID);
714 dJointID (ODE_API *dJointCreateHinge)(dWorldID, dJointGroupID);
715 dJointID (ODE_API *dJointCreateSlider)(dWorldID, dJointGroupID);
716 dJointID (ODE_API *dJointCreateContact)(dWorldID, dJointGroupID, const dContact *);
717 dJointID (ODE_API *dJointCreateHinge2)(dWorldID, dJointGroupID);
718 dJointID (ODE_API *dJointCreateUniversal)(dWorldID, dJointGroupID);
719 //dJointID (ODE_API *dJointCreatePR)(dWorldID, dJointGroupID);
720 //dJointID (ODE_API *dJointCreatePU)(dWorldID, dJointGroupID);
721 //dJointID (ODE_API *dJointCreatePiston)(dWorldID, dJointGroupID);
722 dJointID (ODE_API *dJointCreateFixed)(dWorldID, dJointGroupID);
723 //dJointID (ODE_API *dJointCreateNull)(dWorldID, dJointGroupID);
724 //dJointID (ODE_API *dJointCreateAMotor)(dWorldID, dJointGroupID);
725 //dJointID (ODE_API *dJointCreateLMotor)(dWorldID, dJointGroupID);
726 //dJointID (ODE_API *dJointCreatePlane2D)(dWorldID, dJointGroupID);
727 void (ODE_API *dJointDestroy)(dJointID);
728 dJointGroupID (ODE_API *dJointGroupCreate)(int max_size);
729 void (ODE_API *dJointGroupDestroy)(dJointGroupID);
730 void (ODE_API *dJointGroupEmpty)(dJointGroupID);
731 //int (ODE_API *dJointGetNumBodies)(dJointID);
732 void (ODE_API *dJointAttach)(dJointID, dBodyID body1, dBodyID body2);
733 //void (ODE_API *dJointEnable)(dJointID);
734 //void (ODE_API *dJointDisable)(dJointID);
735 //int (ODE_API *dJointIsEnabled)(dJointID);
736 void (ODE_API *dJointSetData)(dJointID, void *data);
737 void * (ODE_API *dJointGetData)(dJointID);
738 //dJointType (ODE_API *dJointGetType)(dJointID);
739 dBodyID (ODE_API *dJointGetBody)(dJointID, int index);
740 //void (ODE_API *dJointSetFeedback)(dJointID, dJointFeedback *);
741 //dJointFeedback *(ODE_API *dJointGetFeedback)(dJointID);
742 void (ODE_API *dJointSetBallAnchor)(dJointID, dReal x, dReal y, dReal z);
743 //void (ODE_API *dJointSetBallAnchor2)(dJointID, dReal x, dReal y, dReal z);
744 void (ODE_API *dJointSetBallParam)(dJointID, int parameter, dReal value);
745 void (ODE_API *dJointSetHingeAnchor)(dJointID, dReal x, dReal y, dReal z);
746 //void (ODE_API *dJointSetHingeAnchorDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
747 void (ODE_API *dJointSetHingeAxis)(dJointID, dReal x, dReal y, dReal z);
748 //void (ODE_API *dJointSetHingeAxisOffset)(dJointID j, dReal x, dReal y, dReal z, dReal angle);
749 void (ODE_API *dJointSetHingeParam)(dJointID, int parameter, dReal value);
750 //void (ODE_API *dJointAddHingeTorque)(dJointID joint, dReal torque);
751 void (ODE_API *dJointSetSliderAxis)(dJointID, dReal x, dReal y, dReal z);
752 //void (ODE_API *dJointSetSliderAxisDelta)(dJointID, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
753 void (ODE_API *dJointSetSliderParam)(dJointID, int parameter, dReal value);
754 //void (ODE_API *dJointAddSliderForce)(dJointID joint, dReal force);
755 void (ODE_API *dJointSetHinge2Anchor)(dJointID, dReal x, dReal y, dReal z);
756 void (ODE_API *dJointSetHinge2Axis1)(dJointID, dReal x, dReal y, dReal z);
757 void (ODE_API *dJointSetHinge2Axis2)(dJointID, dReal x, dReal y, dReal z);
758 void (ODE_API *dJointSetHinge2Param)(dJointID, int parameter, dReal value);
759 //void (ODE_API *dJointAddHinge2Torques)(dJointID joint, dReal torque1, dReal torque2);
760 void (ODE_API *dJointSetUniversalAnchor)(dJointID, dReal x, dReal y, dReal z);
761 void (ODE_API *dJointSetUniversalAxis1)(dJointID, dReal x, dReal y, dReal z);
762 //void (ODE_API *dJointSetUniversalAxis1Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
763 void (ODE_API *dJointSetUniversalAxis2)(dJointID, dReal x, dReal y, dReal z);
764 //void (ODE_API *dJointSetUniversalAxis2Offset)(dJointID, dReal x, dReal y, dReal z, dReal offset1, dReal offset2);
765 void (ODE_API *dJointSetUniversalParam)(dJointID, int parameter, dReal value);
766 //void (ODE_API *dJointAddUniversalTorques)(dJointID joint, dReal torque1, dReal torque2);
767 //void (ODE_API *dJointSetPRAnchor)(dJointID, dReal x, dReal y, dReal z);
768 //void (ODE_API *dJointSetPRAxis1)(dJointID, dReal x, dReal y, dReal z);
769 //void (ODE_API *dJointSetPRAxis2)(dJointID, dReal x, dReal y, dReal z);
770 //void (ODE_API *dJointSetPRParam)(dJointID, int parameter, dReal value);
771 //void (ODE_API *dJointAddPRTorque)(dJointID j, dReal torque);
772 //void (ODE_API *dJointSetPUAnchor)(dJointID, dReal x, dReal y, dReal z);
773 //void (ODE_API *dJointSetPUAnchorOffset)(dJointID, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
774 //void (ODE_API *dJointSetPUAxis1)(dJointID, dReal x, dReal y, dReal z);
775 //void (ODE_API *dJointSetPUAxis2)(dJointID, dReal x, dReal y, dReal z);
776 //void (ODE_API *dJointSetPUAxis3)(dJointID, dReal x, dReal y, dReal z);
777 //void (ODE_API *dJointSetPUAxisP)(dJointID id, dReal x, dReal y, dReal z);
778 //void (ODE_API *dJointSetPUParam)(dJointID, int parameter, dReal value);
779 //void (ODE_API *dJointAddPUTorque)(dJointID j, dReal torque);
780 //void (ODE_API *dJointSetPistonAnchor)(dJointID, dReal x, dReal y, dReal z);
781 //void (ODE_API *dJointSetPistonAnchorOffset)(dJointID j, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz);
782 //void (ODE_API *dJointSetPistonParam)(dJointID, int parameter, dReal value);
783 //void (ODE_API *dJointAddPistonForce)(dJointID joint, dReal force);
784 //void (ODE_API *dJointSetFixed)(dJointID);
785 //void (ODE_API *dJointSetFixedParam)(dJointID, int parameter, dReal value);
786 //void (ODE_API *dJointSetAMotorNumAxes)(dJointID, int num);
787 //void (ODE_API *dJointSetAMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
788 //void (ODE_API *dJointSetAMotorAngle)(dJointID, int anum, dReal angle);
789 //void (ODE_API *dJointSetAMotorParam)(dJointID, int parameter, dReal value);
790 //void (ODE_API *dJointSetAMotorMode)(dJointID, int mode);
791 //void (ODE_API *dJointAddAMotorTorques)(dJointID, dReal torque1, dReal torque2, dReal torque3);
792 //void (ODE_API *dJointSetLMotorNumAxes)(dJointID, int num);
793 //void (ODE_API *dJointSetLMotorAxis)(dJointID, int anum, int rel, dReal x, dReal y, dReal z);
794 //void (ODE_API *dJointSetLMotorParam)(dJointID, int parameter, dReal value);
795 //void (ODE_API *dJointSetPlane2DXParam)(dJointID, int parameter, dReal value);
796 //void (ODE_API *dJointSetPlane2DYParam)(dJointID, int parameter, dReal value);
797 //void (ODE_API *dJointSetPlane2DAngleParam)(dJointID, int parameter, dReal value);
798 //void (ODE_API *dJointGetBallAnchor)(dJointID, dVector3 result);
799 //void (ODE_API *dJointGetBallAnchor2)(dJointID, dVector3 result);
800 //dReal (ODE_API *dJointGetBallParam)(dJointID, int parameter);
801 //void (ODE_API *dJointGetHingeAnchor)(dJointID, dVector3 result);
802 //void (ODE_API *dJointGetHingeAnchor2)(dJointID, dVector3 result);
803 //void (ODE_API *dJointGetHingeAxis)(dJointID, dVector3 result);
804 //dReal (ODE_API *dJointGetHingeParam)(dJointID, int parameter);
805 //dReal (ODE_API *dJointGetHingeAngle)(dJointID);
806 //dReal (ODE_API *dJointGetHingeAngleRate)(dJointID);
807 //dReal (ODE_API *dJointGetSliderPosition)(dJointID);
808 //dReal (ODE_API *dJointGetSliderPositionRate)(dJointID);
809 //void (ODE_API *dJointGetSliderAxis)(dJointID, dVector3 result);
810 //dReal (ODE_API *dJointGetSliderParam)(dJointID, int parameter);
811 //void (ODE_API *dJointGetHinge2Anchor)(dJointID, dVector3 result);
812 //void (ODE_API *dJointGetHinge2Anchor2)(dJointID, dVector3 result);
813 //void (ODE_API *dJointGetHinge2Axis1)(dJointID, dVector3 result);
814 //void (ODE_API *dJointGetHinge2Axis2)(dJointID, dVector3 result);
815 //dReal (ODE_API *dJointGetHinge2Param)(dJointID, int parameter);
816 //dReal (ODE_API *dJointGetHinge2Angle1)(dJointID);
817 //dReal (ODE_API *dJointGetHinge2Angle1Rate)(dJointID);
818 //dReal (ODE_API *dJointGetHinge2Angle2Rate)(dJointID);
819 //void (ODE_API *dJointGetUniversalAnchor)(dJointID, dVector3 result);
820 //void (ODE_API *dJointGetUniversalAnchor2)(dJointID, dVector3 result);
821 //void (ODE_API *dJointGetUniversalAxis1)(dJointID, dVector3 result);
822 //void (ODE_API *dJointGetUniversalAxis2)(dJointID, dVector3 result);
823 //dReal (ODE_API *dJointGetUniversalParam)(dJointID, int parameter);
824 //void (ODE_API *dJointGetUniversalAngles)(dJointID, dReal *angle1, dReal *angle2);
825 //dReal (ODE_API *dJointGetUniversalAngle1)(dJointID);
826 //dReal (ODE_API *dJointGetUniversalAngle2)(dJointID);
827 //dReal (ODE_API *dJointGetUniversalAngle1Rate)(dJointID);
828 //dReal (ODE_API *dJointGetUniversalAngle2Rate)(dJointID);
829 //void (ODE_API *dJointGetPRAnchor)(dJointID, dVector3 result);
830 //dReal (ODE_API *dJointGetPRPosition)(dJointID);
831 //dReal (ODE_API *dJointGetPRPositionRate)(dJointID);
832 //dReal (ODE_API *dJointGetPRAngle)(dJointID);
833 //dReal (ODE_API *dJointGetPRAngleRate)(dJointID);
834 //void (ODE_API *dJointGetPRAxis1)(dJointID, dVector3 result);
835 //void (ODE_API *dJointGetPRAxis2)(dJointID, dVector3 result);
836 //dReal (ODE_API *dJointGetPRParam)(dJointID, int parameter);
837 //void (ODE_API *dJointGetPUAnchor)(dJointID, dVector3 result);
838 //dReal (ODE_API *dJointGetPUPosition)(dJointID);
839 //dReal (ODE_API *dJointGetPUPositionRate)(dJointID);
840 //void (ODE_API *dJointGetPUAxis1)(dJointID, dVector3 result);
841 //void (ODE_API *dJointGetPUAxis2)(dJointID, dVector3 result);
842 //void (ODE_API *dJointGetPUAxis3)(dJointID, dVector3 result);
843 //void (ODE_API *dJointGetPUAxisP)(dJointID id, dVector3 result);
844 //void (ODE_API *dJointGetPUAngles)(dJointID, dReal *angle1, dReal *angle2);
845 //dReal (ODE_API *dJointGetPUAngle1)(dJointID);
846 //dReal (ODE_API *dJointGetPUAngle1Rate)(dJointID);
847 //dReal (ODE_API *dJointGetPUAngle2)(dJointID);
848 //dReal (ODE_API *dJointGetPUAngle2Rate)(dJointID);
849 //dReal (ODE_API *dJointGetPUParam)(dJointID, int parameter);
850 //dReal (ODE_API *dJointGetPistonPosition)(dJointID);
851 //dReal (ODE_API *dJointGetPistonPositionRate)(dJointID);
852 //dReal (ODE_API *dJointGetPistonAngle)(dJointID);
853 //dReal (ODE_API *dJointGetPistonAngleRate)(dJointID);
854 //void (ODE_API *dJointGetPistonAnchor)(dJointID, dVector3 result);
855 //void (ODE_API *dJointGetPistonAnchor2)(dJointID, dVector3 result);
856 //void (ODE_API *dJointGetPistonAxis)(dJointID, dVector3 result);
857 //dReal (ODE_API *dJointGetPistonParam)(dJointID, int parameter);
858 //int (ODE_API *dJointGetAMotorNumAxes)(dJointID);
859 //void (ODE_API *dJointGetAMotorAxis)(dJointID, int anum, dVector3 result);
860 //int (ODE_API *dJointGetAMotorAxisRel)(dJointID, int anum);
861 //dReal (ODE_API *dJointGetAMotorAngle)(dJointID, int anum);
862 //dReal (ODE_API *dJointGetAMotorAngleRate)(dJointID, int anum);
863 //dReal (ODE_API *dJointGetAMotorParam)(dJointID, int parameter);
864 //int (ODE_API *dJointGetAMotorMode)(dJointID);
865 //int (ODE_API *dJointGetLMotorNumAxes)(dJointID);
866 //void (ODE_API *dJointGetLMotorAxis)(dJointID, int anum, dVector3 result);
867 //dReal (ODE_API *dJointGetLMotorParam)(dJointID, int parameter);
868 //dReal (ODE_API *dJointGetFixedParam)(dJointID, int parameter);
869 //dJointID (ODE_API *dConnectingJoint)(dBodyID, dBodyID);
870 //int (ODE_API *dConnectingJointList)(dBodyID, dBodyID, dJointID*);
871 int (ODE_API *dAreConnected)(dBodyID, dBodyID);
872 int (ODE_API *dAreConnectedExcluding)(dBodyID body1, dBodyID body2, int joint_type);
874 dSpaceID (ODE_API *dSimpleSpaceCreate)(dSpaceID space);
875 dSpaceID (ODE_API *dHashSpaceCreate)(dSpaceID space);
876 dSpaceID (ODE_API *dQuadTreeSpaceCreate)(dSpaceID space, const dVector3 Center, const dVector3 Extents, int Depth);
877 //dSpaceID (ODE_API *dSweepAndPruneSpaceCreate)( dSpaceID space, int axisorder );
878 void (ODE_API *dSpaceDestroy)(dSpaceID);
879 //void (ODE_API *dHashSpaceSetLevels)(dSpaceID space, int minlevel, int maxlevel);
880 //void (ODE_API *dHashSpaceGetLevels)(dSpaceID space, int *minlevel, int *maxlevel);
881 //void (ODE_API *dSpaceSetCleanup)(dSpaceID space, int mode);
882 //int (ODE_API *dSpaceGetCleanup)(dSpaceID space);
883 //void (ODE_API *dSpaceSetSublevel)(dSpaceID space, int sublevel);
884 //int (ODE_API *dSpaceGetSublevel)(dSpaceID space);
885 //void (ODE_API *dSpaceSetManualCleanup)(dSpaceID space, int mode);
886 //int (ODE_API *dSpaceGetManualCleanup)(dSpaceID space);
887 //void (ODE_API *dSpaceAdd)(dSpaceID, dGeomID);
888 //void (ODE_API *dSpaceRemove)(dSpaceID, dGeomID);
889 //int (ODE_API *dSpaceQuery)(dSpaceID, dGeomID);
890 //void (ODE_API *dSpaceClean)(dSpaceID);
891 //int (ODE_API *dSpaceGetNumGeoms)(dSpaceID);
892 //dGeomID (ODE_API *dSpaceGetGeom)(dSpaceID, int i);
893 //int (ODE_API *dSpaceGetClass)(dSpaceID space);
895 void (ODE_API *dGeomDestroy)(dGeomID geom);
896 void (ODE_API *dGeomSetData)(dGeomID geom, void* data);
897 void * (ODE_API *dGeomGetData)(dGeomID geom);
898 void (ODE_API *dGeomSetBody)(dGeomID geom, dBodyID body);
899 dBodyID (ODE_API *dGeomGetBody)(dGeomID geom);
900 void (ODE_API *dGeomSetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
901 void (ODE_API *dGeomSetRotation)(dGeomID geom, const dMatrix3 R);
902 //void (ODE_API *dGeomSetQuaternion)(dGeomID geom, const dQuaternion Q);
903 //const dReal * (ODE_API *dGeomGetPosition)(dGeomID geom);
904 //void (ODE_API *dGeomCopyPosition)(dGeomID geom, dVector3 pos);
905 //const dReal * (ODE_API *dGeomGetRotation)(dGeomID geom);
906 //void (ODE_API *dGeomCopyRotation)(dGeomID geom, dMatrix3 R);
907 //void (ODE_API *dGeomGetQuaternion)(dGeomID geom, dQuaternion result);
908 //void (ODE_API *dGeomGetAABB)(dGeomID geom, dReal aabb[6]);
909 int (ODE_API *dGeomIsSpace)(dGeomID geom);
910 //dSpaceID (ODE_API *dGeomGetSpace)(dGeomID);
911 //int (ODE_API *dGeomGetClass)(dGeomID geom);
912 //void (ODE_API *dGeomSetCategoryBits)(dGeomID geom, unsigned long bits);
913 //void (ODE_API *dGeomSetCollideBits)(dGeomID geom, unsigned long bits);
914 //unsigned long (ODE_API *dGeomGetCategoryBits)(dGeomID);
915 //unsigned long (ODE_API *dGeomGetCollideBits)(dGeomID);
916 //void (ODE_API *dGeomEnable)(dGeomID geom);
917 //void (ODE_API *dGeomDisable)(dGeomID geom);
918 //int (ODE_API *dGeomIsEnabled)(dGeomID geom);
919 //void (ODE_API *dGeomSetOffsetPosition)(dGeomID geom, dReal x, dReal y, dReal z);
920 //void (ODE_API *dGeomSetOffsetRotation)(dGeomID geom, const dMatrix3 R);
921 //void (ODE_API *dGeomSetOffsetQuaternion)(dGeomID geom, const dQuaternion Q);
922 //void (ODE_API *dGeomSetOffsetWorldPosition)(dGeomID geom, dReal x, dReal y, dReal z);
923 //void (ODE_API *dGeomSetOffsetWorldRotation)(dGeomID geom, const dMatrix3 R);
924 //void (ODE_API *dGeomSetOffsetWorldQuaternion)(dGeomID geom, const dQuaternion);
925 //void (ODE_API *dGeomClearOffset)(dGeomID geom);
926 //int (ODE_API *dGeomIsOffset)(dGeomID geom);
927 //const dReal * (ODE_API *dGeomGetOffsetPosition)(dGeomID geom);
928 //void (ODE_API *dGeomCopyOffsetPosition)(dGeomID geom, dVector3 pos);
929 //const dReal * (ODE_API *dGeomGetOffsetRotation)(dGeomID geom);
930 //void (ODE_API *dGeomCopyOffsetRotation)(dGeomID geom, dMatrix3 R);
931 //void (ODE_API *dGeomGetOffsetQuaternion)(dGeomID geom, dQuaternion result);
932 int (ODE_API *dCollide)(dGeomID o1, dGeomID o2, int flags, dContactGeom *contact, int skip);
934 void (ODE_API *dSpaceCollide)(dSpaceID space, void *data, dNearCallback *callback);
935 void (ODE_API *dSpaceCollide2)(dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
937 dGeomID (ODE_API *dCreateSphere)(dSpaceID space, dReal radius);
938 //void (ODE_API *dGeomSphereSetRadius)(dGeomID sphere, dReal radius);
939 //dReal (ODE_API *dGeomSphereGetRadius)(dGeomID sphere);
940 //dReal (ODE_API *dGeomSpherePointDepth)(dGeomID sphere, dReal x, dReal y, dReal z);
942 dGeomID (ODE_API *dCreateConvex)(dSpaceID space, dReal *_planes, unsigned int _planecount, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
943 //void (ODE_API *dGeomSetConvex)(dGeomID g, dReal *_planes, unsigned int _count, dReal *_points, unsigned int _pointcount,unsigned int *_polygons);
945 dGeomID (ODE_API *dCreateBox)(dSpaceID space, dReal lx, dReal ly, dReal lz);
946 //void (ODE_API *dGeomBoxSetLengths)(dGeomID box, dReal lx, dReal ly, dReal lz);
947 //void (ODE_API *dGeomBoxGetLengths)(dGeomID box, dVector3 result);
948 //dReal (ODE_API *dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
949 //dReal (ODE_API *dGeomBoxPointDepth)(dGeomID box, dReal x, dReal y, dReal z);
951 //dGeomID (ODE_API *dCreatePlane)(dSpaceID space, dReal a, dReal b, dReal c, dReal d);
952 //void (ODE_API *dGeomPlaneSetParams)(dGeomID plane, dReal a, dReal b, dReal c, dReal d);
953 //void (ODE_API *dGeomPlaneGetParams)(dGeomID plane, dVector4 result);
954 //dReal (ODE_API *dGeomPlanePointDepth)(dGeomID plane, dReal x, dReal y, dReal z);
956 dGeomID (ODE_API *dCreateCapsule)(dSpaceID space, dReal radius, dReal length);
957 //void (ODE_API *dGeomCapsuleSetParams)(dGeomID ccylinder, dReal radius, dReal length);
958 //void (ODE_API *dGeomCapsuleGetParams)(dGeomID ccylinder, dReal *radius, dReal *length);
959 //dReal (ODE_API *dGeomCapsulePointDepth)(dGeomID ccylinder, dReal x, dReal y, dReal z);
961 dGeomID (ODE_API *dCreateCylinder)(dSpaceID space, dReal radius, dReal length);
962 //void (ODE_API *dGeomCylinderSetParams)(dGeomID cylinder, dReal radius, dReal length);
963 //void (ODE_API *dGeomCylinderGetParams)(dGeomID cylinder, dReal *radius, dReal *length);
965 //dGeomID (ODE_API *dCreateRay)(dSpaceID space, dReal length);
966 //void (ODE_API *dGeomRaySetLength)(dGeomID ray, dReal length);
967 //dReal (ODE_API *dGeomRayGetLength)(dGeomID ray);
968 //void (ODE_API *dGeomRaySet)(dGeomID ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
969 //void (ODE_API *dGeomRayGet)(dGeomID ray, dVector3 start, dVector3 dir);
971 dGeomID (ODE_API *dCreateGeomTransform)(dSpaceID space);
972 void (ODE_API *dGeomTransformSetGeom)(dGeomID g, dGeomID obj);
973 //dGeomID (ODE_API *dGeomTransformGetGeom)(dGeomID g);
974 void (ODE_API *dGeomTransformSetCleanup)(dGeomID g, int mode);
975 //int (ODE_API *dGeomTransformGetCleanup)(dGeomID g);
976 //void (ODE_API *dGeomTransformSetInfo)(dGeomID g, int mode);
977 //int (ODE_API *dGeomTransformGetInfo)(dGeomID g);
979 enum { TRIMESH_FACE_NORMALS };
980 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
981 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
982 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
983 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex);
985 dTriMeshDataID (ODE_API *dGeomTriMeshDataCreate)(void);
986 void (ODE_API *dGeomTriMeshDataDestroy)(dTriMeshDataID g);
987 //void (ODE_API *dGeomTriMeshDataSet)(dTriMeshDataID g, int data_id, void* in_data);
988 //void* (ODE_API *dGeomTriMeshDataGet)(dTriMeshDataID g, int data_id);
989 //void (*dGeomTriMeshSetLastTransform)( (ODE_API *dGeomID g, dMatrix4 last_trans );
990 //dReal* (*dGeomTriMeshGetLastTransform)( (ODE_API *dGeomID g );
991 void (ODE_API *dGeomTriMeshDataBuildSingle)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount, const void* Indices, int IndexCount, int TriStride);
992 //void (ODE_API *dGeomTriMeshDataBuildSingle1)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount, const void* Indices, int IndexCount, int TriStride, const void* Normals);
993 //void (ODE_API *dGeomTriMeshDataBuildDouble)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount, const void* Indices, int IndexCount, int TriStride);
994 //void (ODE_API *dGeomTriMeshDataBuildDouble1)(dTriMeshDataID g, const void* Vertices, int VertexStride, int VertexCount, const void* Indices, int IndexCount, int TriStride, const void* Normals);
995 //void (ODE_API *dGeomTriMeshDataBuildSimple)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount);
996 //void (ODE_API *dGeomTriMeshDataBuildSimple1)(dTriMeshDataID g, const dReal* Vertices, int VertexCount, const dTriIndex* Indices, int IndexCount, const int* Normals);
997 //void (ODE_API *dGeomTriMeshDataPreprocess)(dTriMeshDataID g);
998 //void (ODE_API *dGeomTriMeshDataGetBuffer)(dTriMeshDataID g, unsigned char** buf, int* bufLen);
999 //void (ODE_API *dGeomTriMeshDataSetBuffer)(dTriMeshDataID g, unsigned char* buf);
1000 //void (ODE_API *dGeomTriMeshSetCallback)(dGeomID g, dTriCallback* Callback);
1001 //dTriCallback* (ODE_API *dGeomTriMeshGetCallback)(dGeomID g);
1002 //void (ODE_API *dGeomTriMeshSetArrayCallback)(dGeomID g, dTriArrayCallback* ArrayCallback);
1003 //dTriArrayCallback* (ODE_API *dGeomTriMeshGetArrayCallback)(dGeomID g);
1004 //void (ODE_API *dGeomTriMeshSetRayCallback)(dGeomID g, dTriRayCallback* Callback);
1005 //dTriRayCallback* (ODE_API *dGeomTriMeshGetRayCallback)(dGeomID g);
1006 //void (ODE_API *dGeomTriMeshSetTriMergeCallback)(dGeomID g, dTriTriMergeCallback* Callback);
1007 //dTriTriMergeCallback* (ODE_API *dGeomTriMeshGetTriMergeCallback)(dGeomID g);
1008 dGeomID (ODE_API *dCreateTriMesh)(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
1009 //void (ODE_API *dGeomTriMeshSetData)(dGeomID g, dTriMeshDataID Data);
1010 //dTriMeshDataID (ODE_API *dGeomTriMeshGetData)(dGeomID g);
1011 //void (ODE_API *dGeomTriMeshEnableTC)(dGeomID g, int geomClass, int enable);
1012 //int (ODE_API *dGeomTriMeshIsTCEnabled)(dGeomID g, int geomClass);
1013 //void (ODE_API *dGeomTriMeshClearTCCache)(dGeomID g);
1014 //dTriMeshDataID (ODE_API *dGeomTriMeshGetTriMeshDataID)(dGeomID g);
1015 //void (ODE_API *dGeomTriMeshGetTriangle)(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
1016 //void (ODE_API *dGeomTriMeshGetPoint)(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
1017 //int (ODE_API *dGeomTriMeshGetTriangleCount )(dGeomID g);
1018 //void (ODE_API *dGeomTriMeshDataUpdate)(dTriMeshDataID g);
1020 static dllfunction_t odefuncs[] =
1022 {"dGetConfiguration", (void **) &dGetConfiguration},
1023 {"dCheckConfiguration", (void **) &dCheckConfiguration},
1024 {"dInitODE", (void **) &dInitODE},
1025 // {"dInitODE2", (void **) &dInitODE2},
1026 // {"dAllocateODEDataForThread", (void **) &dAllocateODEDataForThread},
1027 // {"dCleanupODEAllDataForThread", (void **) &dCleanupODEAllDataForThread},
1028 {"dCloseODE", (void **) &dCloseODE},
1029 // {"dMassCheck", (void **) &dMassCheck},
1030 // {"dMassSetZero", (void **) &dMassSetZero},
1031 // {"dMassSetParameters", (void **) &dMassSetParameters},
1032 // {"dMassSetSphere", (void **) &dMassSetSphere},
1033 {"dMassSetSphereTotal", (void **) &dMassSetSphereTotal},
1034 // {"dMassSetCapsule", (void **) &dMassSetCapsule},
1035 {"dMassSetCapsuleTotal", (void **) &dMassSetCapsuleTotal},
1036 // {"dMassSetCylinder", (void **) &dMassSetCylinder},
1037 {"dMassSetCylinderTotal", (void **) &dMassSetCylinderTotal},
1038 // {"dMassSetBox", (void **) &dMassSetBox},
1039 {"dMassSetBoxTotal", (void **) &dMassSetBoxTotal},
1040 // {"dMassSetTrimesh", (void **) &dMassSetTrimesh},
1041 // {"dMassSetTrimeshTotal", (void **) &dMassSetTrimeshTotal},
1042 // {"dMassAdjust", (void **) &dMassAdjust},
1043 // {"dMassTranslate", (void **) &dMassTranslate},
1044 // {"dMassRotate", (void **) &dMassRotate},
1045 // {"dMassAdd", (void **) &dMassAdd},
1047 {"dWorldCreate", (void **) &dWorldCreate},
1048 {"dWorldDestroy", (void **) &dWorldDestroy},
1049 {"dWorldSetGravity", (void **) &dWorldSetGravity},
1050 {"dWorldGetGravity", (void **) &dWorldGetGravity},
1051 {"dWorldSetERP", (void **) &dWorldSetERP},
1052 // {"dWorldGetERP", (void **) &dWorldGetERP},
1053 {"dWorldSetCFM", (void **) &dWorldSetCFM},
1054 // {"dWorldGetCFM", (void **) &dWorldGetCFM},
1055 // {"dWorldStep", (void **) &dWorldStep},
1056 // {"dWorldImpulseToForce", (void **) &dWorldImpulseToForce},
1057 {"dWorldQuickStep", (void **) &dWorldQuickStep},
1058 {"dWorldSetQuickStepNumIterations", (void **) &dWorldSetQuickStepNumIterations},
1059 // {"dWorldGetQuickStepNumIterations", (void **) &dWorldGetQuickStepNumIterations},
1060 // {"dWorldSetQuickStepW", (void **) &dWorldSetQuickStepW},
1061 // {"dWorldGetQuickStepW", (void **) &dWorldGetQuickStepW},
1062 // {"dWorldSetContactMaxCorrectingVel", (void **) &dWorldSetContactMaxCorrectingVel},
1063 // {"dWorldGetContactMaxCorrectingVel", (void **) &dWorldGetContactMaxCorrectingVel},
1064 {"dWorldSetContactSurfaceLayer", (void **) &dWorldSetContactSurfaceLayer},
1065 // {"dWorldGetContactSurfaceLayer", (void **) &dWorldGetContactSurfaceLayer},
1066 // {"dWorldStepFast1", (void **) &dWorldStepFast1},
1067 // {"dWorldSetAutoEnableDepthSF1", (void **) &dWorldSetAutoEnableDepthSF1},
1068 // {"dWorldGetAutoEnableDepthSF1", (void **) &dWorldGetAutoEnableDepthSF1},
1069 // {"dWorldGetAutoDisableLinearThreshold", (void **) &dWorldGetAutoDisableLinearThreshold},
1070 {"dWorldSetAutoDisableLinearThreshold", (void **) &dWorldSetAutoDisableLinearThreshold},
1071 // {"dWorldGetAutoDisableAngularThreshold", (void **) &dWorldGetAutoDisableAngularThreshold},
1072 {"dWorldSetAutoDisableAngularThreshold", (void **) &dWorldSetAutoDisableAngularThreshold},
1073 // {"dWorldGetAutoDisableLinearAverageThreshold", (void **) &dWorldGetAutoDisableLinearAverageThreshold},
1074 // {"dWorldSetAutoDisableLinearAverageThreshold", (void **) &dWorldSetAutoDisableLinearAverageThreshold},
1075 // {"dWorldGetAutoDisableAngularAverageThreshold", (void **) &dWorldGetAutoDisableAngularAverageThreshold},
1076 // {"dWorldSetAutoDisableAngularAverageThreshold", (void **) &dWorldSetAutoDisableAngularAverageThreshold},
1077 // {"dWorldGetAutoDisableAverageSamplesCount", (void **) &dWorldGetAutoDisableAverageSamplesCount},
1078 {"dWorldSetAutoDisableAverageSamplesCount", (void **) &dWorldSetAutoDisableAverageSamplesCount},
1079 // {"dWorldGetAutoDisableSteps", (void **) &dWorldGetAutoDisableSteps},
1080 {"dWorldSetAutoDisableSteps", (void **) &dWorldSetAutoDisableSteps},
1081 // {"dWorldGetAutoDisableTime", (void **) &dWorldGetAutoDisableTime},
1082 {"dWorldSetAutoDisableTime", (void **) &dWorldSetAutoDisableTime},
1083 // {"dWorldGetAutoDisableFlag", (void **) &dWorldGetAutoDisableFlag},
1084 {"dWorldSetAutoDisableFlag", (void **) &dWorldSetAutoDisableFlag},
1085 // {"dWorldGetLinearDampingThreshold", (void **) &dWorldGetLinearDampingThreshold},
1086 {"dWorldSetLinearDampingThreshold", (void **) &dWorldSetLinearDampingThreshold},
1087 // {"dWorldGetAngularDampingThreshold", (void **) &dWorldGetAngularDampingThreshold},
1088 {"dWorldSetAngularDampingThreshold", (void **) &dWorldSetAngularDampingThreshold},
1089 // {"dWorldGetLinearDamping", (void **) &dWorldGetLinearDamping},
1090 {"dWorldSetLinearDamping", (void **) &dWorldSetLinearDamping},
1091 // {"dWorldGetAngularDamping", (void **) &dWorldGetAngularDamping},
1092 {"dWorldSetAngularDamping", (void **) &dWorldSetAngularDamping},
1093 // {"dWorldSetDamping", (void **) &dWorldSetDamping},
1094 // {"dWorldGetMaxAngularSpeed", (void **) &dWorldGetMaxAngularSpeed},
1095 // {"dWorldSetMaxAngularSpeed", (void **) &dWorldSetMaxAngularSpeed},
1096 // {"dBodyGetAutoDisableLinearThreshold", (void **) &dBodyGetAutoDisableLinearThreshold},
1097 // {"dBodySetAutoDisableLinearThreshold", (void **) &dBodySetAutoDisableLinearThreshold},
1098 // {"dBodyGetAutoDisableAngularThreshold", (void **) &dBodyGetAutoDisableAngularThreshold},
1099 // {"dBodySetAutoDisableAngularThreshold", (void **) &dBodySetAutoDisableAngularThreshold},
1100 // {"dBodyGetAutoDisableAverageSamplesCount", (void **) &dBodyGetAutoDisableAverageSamplesCount},
1101 // {"dBodySetAutoDisableAverageSamplesCount", (void **) &dBodySetAutoDisableAverageSamplesCount},
1102 // {"dBodyGetAutoDisableSteps", (void **) &dBodyGetAutoDisableSteps},
1103 // {"dBodySetAutoDisableSteps", (void **) &dBodySetAutoDisableSteps},
1104 // {"dBodyGetAutoDisableTime", (void **) &dBodyGetAutoDisableTime},
1105 // {"dBodySetAutoDisableTime", (void **) &dBodySetAutoDisableTime},
1106 // {"dBodyGetAutoDisableFlag", (void **) &dBodyGetAutoDisableFlag},
1107 // {"dBodySetAutoDisableFlag", (void **) &dBodySetAutoDisableFlag},
1108 // {"dBodySetAutoDisableDefaults", (void **) &dBodySetAutoDisableDefaults},
1109 // {"dBodyGetWorld", (void **) &dBodyGetWorld},
1110 {"dBodyCreate", (void **) &dBodyCreate},
1111 {"dBodyDestroy", (void **) &dBodyDestroy},
1112 {"dBodySetData", (void **) &dBodySetData},
1113 {"dBodyGetData", (void **) &dBodyGetData},
1114 {"dBodySetPosition", (void **) &dBodySetPosition},
1115 {"dBodySetRotation", (void **) &dBodySetRotation},
1116 // {"dBodySetQuaternion", (void **) &dBodySetQuaternion},
1117 {"dBodySetLinearVel", (void **) &dBodySetLinearVel},
1118 {"dBodySetAngularVel", (void **) &dBodySetAngularVel},
1119 {"dBodyGetPosition", (void **) &dBodyGetPosition},
1120 // {"dBodyCopyPosition", (void **) &dBodyCopyPosition},
1121 {"dBodyGetRotation", (void **) &dBodyGetRotation},
1122 // {"dBodyCopyRotation", (void **) &dBodyCopyRotation},
1123 // {"dBodyGetQuaternion", (void **) &dBodyGetQuaternion},
1124 // {"dBodyCopyQuaternion", (void **) &dBodyCopyQuaternion},
1125 {"dBodyGetLinearVel", (void **) &dBodyGetLinearVel},
1126 {"dBodyGetAngularVel", (void **) &dBodyGetAngularVel},
1127 {"dBodySetMass", (void **) &dBodySetMass},
1128 // {"dBodyGetMass", (void **) &dBodyGetMass},
1129 {"dBodyAddForce", (void **) &dBodyAddForce},
1130 {"dBodyAddTorque", (void **) &dBodyAddTorque},
1131 // {"dBodyAddRelForce", (void **) &dBodyAddRelForce},
1132 // {"dBodyAddRelTorque", (void **) &dBodyAddRelTorque},
1133 {"dBodyAddForceAtPos", (void **) &dBodyAddForceAtPos},
1134 // {"dBodyAddForceAtRelPos", (void **) &dBodyAddForceAtRelPos},
1135 // {"dBodyAddRelForceAtPos", (void **) &dBodyAddRelForceAtPos},
1136 // {"dBodyAddRelForceAtRelPos", (void **) &dBodyAddRelForceAtRelPos},
1137 // {"dBodyGetForce", (void **) &dBodyGetForce},
1138 // {"dBodyGetTorque", (void **) &dBodyGetTorque},
1139 // {"dBodySetForce", (void **) &dBodySetForce},
1140 // {"dBodySetTorque", (void **) &dBodySetTorque},
1141 // {"dBodyGetRelPointPos", (void **) &dBodyGetRelPointPos},
1142 // {"dBodyGetRelPointVel", (void **) &dBodyGetRelPointVel},
1143 // {"dBodyGetPointVel", (void **) &dBodyGetPointVel},
1144 // {"dBodyGetPosRelPoint", (void **) &dBodyGetPosRelPoint},
1145 // {"dBodyVectorToWorld", (void **) &dBodyVectorToWorld},
1146 // {"dBodyVectorFromWorld", (void **) &dBodyVectorFromWorld},
1147 // {"dBodySetFiniteRotationMode", (void **) &dBodySetFiniteRotationMode},
1148 // {"dBodySetFiniteRotationAxis", (void **) &dBodySetFiniteRotationAxis},
1149 // {"dBodyGetFiniteRotationMode", (void **) &dBodyGetFiniteRotationMode},
1150 // {"dBodyGetFiniteRotationAxis", (void **) &dBodyGetFiniteRotationAxis},
1151 {"dBodyGetNumJoints", (void **) &dBodyGetNumJoints},
1152 {"dBodyGetJoint", (void **) &dBodyGetJoint},
1153 // {"dBodySetDynamic", (void **) &dBodySetDynamic},
1154 // {"dBodySetKinematic", (void **) &dBodySetKinematic},
1155 // {"dBodyIsKinematic", (void **) &dBodyIsKinematic},
1156 {"dBodyEnable", (void **) &dBodyEnable},
1157 {"dBodyDisable", (void **) &dBodyDisable},
1158 {"dBodyIsEnabled", (void **) &dBodyIsEnabled},
1159 {"dBodySetGravityMode", (void **) &dBodySetGravityMode},
1160 {"dBodyGetGravityMode", (void **) &dBodyGetGravityMode},
1161 // {"dBodySetMovedCallback", (void **) &dBodySetMovedCallback},
1162 // {"dBodyGetFirstGeom", (void **) &dBodyGetFirstGeom},
1163 // {"dBodyGetNextGeom", (void **) &dBodyGetNextGeom},
1164 // {"dBodySetDampingDefaults", (void **) &dBodySetDampingDefaults},
1165 // {"dBodyGetLinearDamping", (void **) &dBodyGetLinearDamping},
1166 // {"dBodySetLinearDamping", (void **) &dBodySetLinearDamping},
1167 // {"dBodyGetAngularDamping", (void **) &dBodyGetAngularDamping},
1168 // {"dBodySetAngularDamping", (void **) &dBodySetAngularDamping},
1169 // {"dBodySetDamping", (void **) &dBodySetDamping},
1170 // {"dBodyGetLinearDampingThreshold", (void **) &dBodyGetLinearDampingThreshold},
1171 // {"dBodySetLinearDampingThreshold", (void **) &dBodySetLinearDampingThreshold},
1172 // {"dBodyGetAngularDampingThreshold", (void **) &dBodyGetAngularDampingThreshold},
1173 // {"dBodySetAngularDampingThreshold", (void **) &dBodySetAngularDampingThreshold},
1174 // {"dBodyGetMaxAngularSpeed", (void **) &dBodyGetMaxAngularSpeed},
1175 // {"dBodySetMaxAngularSpeed", (void **) &dBodySetMaxAngularSpeed},
1176 // {"dBodyGetGyroscopicMode", (void **) &dBodyGetGyroscopicMode},
1177 // {"dBodySetGyroscopicMode", (void **) &dBodySetGyroscopicMode},
1178 {"dJointCreateBall", (void **) &dJointCreateBall},
1179 {"dJointCreateHinge", (void **) &dJointCreateHinge},
1180 {"dJointCreateSlider", (void **) &dJointCreateSlider},
1181 {"dJointCreateContact", (void **) &dJointCreateContact},
1182 {"dJointCreateHinge2", (void **) &dJointCreateHinge2},
1183 {"dJointCreateUniversal", (void **) &dJointCreateUniversal},
1184 // {"dJointCreatePR", (void **) &dJointCreatePR},
1185 // {"dJointCreatePU", (void **) &dJointCreatePU},
1186 // {"dJointCreatePiston", (void **) &dJointCreatePiston},
1187 {"dJointCreateFixed", (void **) &dJointCreateFixed},
1188 // {"dJointCreateNull", (void **) &dJointCreateNull},
1189 // {"dJointCreateAMotor", (void **) &dJointCreateAMotor},
1190 // {"dJointCreateLMotor", (void **) &dJointCreateLMotor},
1191 // {"dJointCreatePlane2D", (void **) &dJointCreatePlane2D},
1192 {"dJointDestroy", (void **) &dJointDestroy},
1193 {"dJointGroupCreate", (void **) &dJointGroupCreate},
1194 {"dJointGroupDestroy", (void **) &dJointGroupDestroy},
1195 {"dJointGroupEmpty", (void **) &dJointGroupEmpty},
1196 // {"dJointGetNumBodies", (void **) &dJointGetNumBodies},
1197 {"dJointAttach", (void **) &dJointAttach},
1198 // {"dJointEnable", (void **) &dJointEnable},
1199 // {"dJointDisable", (void **) &dJointDisable},
1200 // {"dJointIsEnabled", (void **) &dJointIsEnabled},
1201 {"dJointSetData", (void **) &dJointSetData},
1202 {"dJointGetData", (void **) &dJointGetData},
1203 // {"dJointGetType", (void **) &dJointGetType},
1204 {"dJointGetBody", (void **) &dJointGetBody},
1205 // {"dJointSetFeedback", (void **) &dJointSetFeedback},
1206 // {"dJointGetFeedback", (void **) &dJointGetFeedback},
1207 {"dJointSetBallAnchor", (void **) &dJointSetBallAnchor},
1208 // {"dJointSetBallAnchor2", (void **) &dJointSetBallAnchor2},
1209 {"dJointSetBallParam", (void **) &dJointSetBallParam},
1210 {"dJointSetHingeAnchor", (void **) &dJointSetHingeAnchor},
1211 // {"dJointSetHingeAnchorDelta", (void **) &dJointSetHingeAnchorDelta},
1212 {"dJointSetHingeAxis", (void **) &dJointSetHingeAxis},
1213 // {"dJointSetHingeAxisOffset", (void **) &dJointSetHingeAxisOffset},
1214 {"dJointSetHingeParam", (void **) &dJointSetHingeParam},
1215 // {"dJointAddHingeTorque", (void **) &dJointAddHingeTorque},
1216 {"dJointSetSliderAxis", (void **) &dJointSetSliderAxis},
1217 // {"dJointSetSliderAxisDelta", (void **) &dJointSetSliderAxisDelta},
1218 {"dJointSetSliderParam", (void **) &dJointSetSliderParam},
1219 // {"dJointAddSliderForce", (void **) &dJointAddSliderForce},
1220 {"dJointSetHinge2Anchor", (void **) &dJointSetHinge2Anchor},
1221 {"dJointSetHinge2Axis1", (void **) &dJointSetHinge2Axis1},
1222 {"dJointSetHinge2Axis2", (void **) &dJointSetHinge2Axis2},
1223 {"dJointSetHinge2Param", (void **) &dJointSetHinge2Param},
1224 // {"dJointAddHinge2Torques", (void **) &dJointAddHinge2Torques},
1225 {"dJointSetUniversalAnchor", (void **) &dJointSetUniversalAnchor},
1226 {"dJointSetUniversalAxis1", (void **) &dJointSetUniversalAxis1},
1227 // {"dJointSetUniversalAxis1Offset", (void **) &dJointSetUniversalAxis1Offset},
1228 {"dJointSetUniversalAxis2", (void **) &dJointSetUniversalAxis2},
1229 // {"dJointSetUniversalAxis2Offset", (void **) &dJointSetUniversalAxis2Offset},
1230 {"dJointSetUniversalParam", (void **) &dJointSetUniversalParam},
1231 // {"dJointAddUniversalTorques", (void **) &dJointAddUniversalTorques},
1232 // {"dJointSetPRAnchor", (void **) &dJointSetPRAnchor},
1233 // {"dJointSetPRAxis1", (void **) &dJointSetPRAxis1},
1234 // {"dJointSetPRAxis2", (void **) &dJointSetPRAxis2},
1235 // {"dJointSetPRParam", (void **) &dJointSetPRParam},
1236 // {"dJointAddPRTorque", (void **) &dJointAddPRTorque},
1237 // {"dJointSetPUAnchor", (void **) &dJointSetPUAnchor},
1238 // {"dJointSetPUAnchorOffset", (void **) &dJointSetPUAnchorOffset},
1239 // {"dJointSetPUAxis1", (void **) &dJointSetPUAxis1},
1240 // {"dJointSetPUAxis2", (void **) &dJointSetPUAxis2},
1241 // {"dJointSetPUAxis3", (void **) &dJointSetPUAxis3},
1242 // {"dJointSetPUAxisP", (void **) &dJointSetPUAxisP},
1243 // {"dJointSetPUParam", (void **) &dJointSetPUParam},
1244 // {"dJointAddPUTorque", (void **) &dJointAddPUTorque},
1245 // {"dJointSetPistonAnchor", (void **) &dJointSetPistonAnchor},
1246 // {"dJointSetPistonAnchorOffset", (void **) &dJointSetPistonAnchorOffset},
1247 // {"dJointSetPistonParam", (void **) &dJointSetPistonParam},
1248 // {"dJointAddPistonForce", (void **) &dJointAddPistonForce},
1249 // {"dJointSetFixed", (void **) &dJointSetFixed},
1250 // {"dJointSetFixedParam", (void **) &dJointSetFixedParam},
1251 // {"dJointSetAMotorNumAxes", (void **) &dJointSetAMotorNumAxes},
1252 // {"dJointSetAMotorAxis", (void **) &dJointSetAMotorAxis},
1253 // {"dJointSetAMotorAngle", (void **) &dJointSetAMotorAngle},
1254 // {"dJointSetAMotorParam", (void **) &dJointSetAMotorParam},
1255 // {"dJointSetAMotorMode", (void **) &dJointSetAMotorMode},
1256 // {"dJointAddAMotorTorques", (void **) &dJointAddAMotorTorques},
1257 // {"dJointSetLMotorNumAxes", (void **) &dJointSetLMotorNumAxes},
1258 // {"dJointSetLMotorAxis", (void **) &dJointSetLMotorAxis},
1259 // {"dJointSetLMotorParam", (void **) &dJointSetLMotorParam},
1260 // {"dJointSetPlane2DXParam", (void **) &dJointSetPlane2DXParam},
1261 // {"dJointSetPlane2DYParam", (void **) &dJointSetPlane2DYParam},
1262 // {"dJointSetPlane2DAngleParam", (void **) &dJointSetPlane2DAngleParam},
1263 // {"dJointGetBallAnchor", (void **) &dJointGetBallAnchor},
1264 // {"dJointGetBallAnchor2", (void **) &dJointGetBallAnchor2},
1265 // {"dJointGetBallParam", (void **) &dJointGetBallParam},
1266 // {"dJointGetHingeAnchor", (void **) &dJointGetHingeAnchor},
1267 // {"dJointGetHingeAnchor2", (void **) &dJointGetHingeAnchor2},
1268 // {"dJointGetHingeAxis", (void **) &dJointGetHingeAxis},
1269 // {"dJointGetHingeParam", (void **) &dJointGetHingeParam},
1270 // {"dJointGetHingeAngle", (void **) &dJointGetHingeAngle},
1271 // {"dJointGetHingeAngleRate", (void **) &dJointGetHingeAngleRate},
1272 // {"dJointGetSliderPosition", (void **) &dJointGetSliderPosition},
1273 // {"dJointGetSliderPositionRate", (void **) &dJointGetSliderPositionRate},
1274 // {"dJointGetSliderAxis", (void **) &dJointGetSliderAxis},
1275 // {"dJointGetSliderParam", (void **) &dJointGetSliderParam},
1276 // {"dJointGetHinge2Anchor", (void **) &dJointGetHinge2Anchor},
1277 // {"dJointGetHinge2Anchor2", (void **) &dJointGetHinge2Anchor2},
1278 // {"dJointGetHinge2Axis1", (void **) &dJointGetHinge2Axis1},
1279 // {"dJointGetHinge2Axis2", (void **) &dJointGetHinge2Axis2},
1280 // {"dJointGetHinge2Param", (void **) &dJointGetHinge2Param},
1281 // {"dJointGetHinge2Angle1", (void **) &dJointGetHinge2Angle1},
1282 // {"dJointGetHinge2Angle1Rate", (void **) &dJointGetHinge2Angle1Rate},
1283 // {"dJointGetHinge2Angle2Rate", (void **) &dJointGetHinge2Angle2Rate},
1284 // {"dJointGetUniversalAnchor", (void **) &dJointGetUniversalAnchor},
1285 // {"dJointGetUniversalAnchor2", (void **) &dJointGetUniversalAnchor2},
1286 // {"dJointGetUniversalAxis1", (void **) &dJointGetUniversalAxis1},
1287 // {"dJointGetUniversalAxis2", (void **) &dJointGetUniversalAxis2},
1288 // {"dJointGetUniversalParam", (void **) &dJointGetUniversalParam},
1289 // {"dJointGetUniversalAngles", (void **) &dJointGetUniversalAngles},
1290 // {"dJointGetUniversalAngle1", (void **) &dJointGetUniversalAngle1},
1291 // {"dJointGetUniversalAngle2", (void **) &dJointGetUniversalAngle2},
1292 // {"dJointGetUniversalAngle1Rate", (void **) &dJointGetUniversalAngle1Rate},
1293 // {"dJointGetUniversalAngle2Rate", (void **) &dJointGetUniversalAngle2Rate},
1294 // {"dJointGetPRAnchor", (void **) &dJointGetPRAnchor},
1295 // {"dJointGetPRPosition", (void **) &dJointGetPRPosition},
1296 // {"dJointGetPRPositionRate", (void **) &dJointGetPRPositionRate},
1297 // {"dJointGetPRAngle", (void **) &dJointGetPRAngle},
1298 // {"dJointGetPRAngleRate", (void **) &dJointGetPRAngleRate},
1299 // {"dJointGetPRAxis1", (void **) &dJointGetPRAxis1},
1300 // {"dJointGetPRAxis2", (void **) &dJointGetPRAxis2},
1301 // {"dJointGetPRParam", (void **) &dJointGetPRParam},
1302 // {"dJointGetPUAnchor", (void **) &dJointGetPUAnchor},
1303 // {"dJointGetPUPosition", (void **) &dJointGetPUPosition},
1304 // {"dJointGetPUPositionRate", (void **) &dJointGetPUPositionRate},
1305 // {"dJointGetPUAxis1", (void **) &dJointGetPUAxis1},
1306 // {"dJointGetPUAxis2", (void **) &dJointGetPUAxis2},
1307 // {"dJointGetPUAxis3", (void **) &dJointGetPUAxis3},
1308 // {"dJointGetPUAxisP", (void **) &dJointGetPUAxisP},
1309 // {"dJointGetPUAngles", (void **) &dJointGetPUAngles},
1310 // {"dJointGetPUAngle1", (void **) &dJointGetPUAngle1},
1311 // {"dJointGetPUAngle1Rate", (void **) &dJointGetPUAngle1Rate},
1312 // {"dJointGetPUAngle2", (void **) &dJointGetPUAngle2},
1313 // {"dJointGetPUAngle2Rate", (void **) &dJointGetPUAngle2Rate},
1314 // {"dJointGetPUParam", (void **) &dJointGetPUParam},
1315 // {"dJointGetPistonPosition", (void **) &dJointGetPistonPosition},
1316 // {"dJointGetPistonPositionRate", (void **) &dJointGetPistonPositionRate},
1317 // {"dJointGetPistonAngle", (void **) &dJointGetPistonAngle},
1318 // {"dJointGetPistonAngleRate", (void **) &dJointGetPistonAngleRate},
1319 // {"dJointGetPistonAnchor", (void **) &dJointGetPistonAnchor},
1320 // {"dJointGetPistonAnchor2", (void **) &dJointGetPistonAnchor2},
1321 // {"dJointGetPistonAxis", (void **) &dJointGetPistonAxis},
1322 // {"dJointGetPistonParam", (void **) &dJointGetPistonParam},
1323 // {"dJointGetAMotorNumAxes", (void **) &dJointGetAMotorNumAxes},
1324 // {"dJointGetAMotorAxis", (void **) &dJointGetAMotorAxis},
1325 // {"dJointGetAMotorAxisRel", (void **) &dJointGetAMotorAxisRel},
1326 // {"dJointGetAMotorAngle", (void **) &dJointGetAMotorAngle},
1327 // {"dJointGetAMotorAngleRate", (void **) &dJointGetAMotorAngleRate},
1328 // {"dJointGetAMotorParam", (void **) &dJointGetAMotorParam},
1329 // {"dJointGetAMotorMode", (void **) &dJointGetAMotorMode},
1330 // {"dJointGetLMotorNumAxes", (void **) &dJointGetLMotorNumAxes},
1331 // {"dJointGetLMotorAxis", (void **) &dJointGetLMotorAxis},
1332 // {"dJointGetLMotorParam", (void **) &dJointGetLMotorParam},
1333 // {"dJointGetFixedParam", (void **) &dJointGetFixedParam},
1334 // {"dConnectingJoint", (void **) &dConnectingJoint},
1335 // {"dConnectingJointList", (void **) &dConnectingJointList},
1336 {"dAreConnected", (void **) &dAreConnected},
1337 {"dAreConnectedExcluding", (void **) &dAreConnectedExcluding},
1338 {"dSimpleSpaceCreate", (void **) &dSimpleSpaceCreate},
1339 {"dHashSpaceCreate", (void **) &dHashSpaceCreate},
1340 {"dQuadTreeSpaceCreate", (void **) &dQuadTreeSpaceCreate},
1341 // {"dSweepAndPruneSpaceCreate", (void **) &dSweepAndPruneSpaceCreate},
1342 {"dSpaceDestroy", (void **) &dSpaceDestroy},
1343 // {"dHashSpaceSetLevels", (void **) &dHashSpaceSetLevels},
1344 // {"dHashSpaceGetLevels", (void **) &dHashSpaceGetLevels},
1345 // {"dSpaceSetCleanup", (void **) &dSpaceSetCleanup},
1346 // {"dSpaceGetCleanup", (void **) &dSpaceGetCleanup},
1347 // {"dSpaceSetSublevel", (void **) &dSpaceSetSublevel},
1348 // {"dSpaceGetSublevel", (void **) &dSpaceGetSublevel},
1349 // {"dSpaceSetManualCleanup", (void **) &dSpaceSetManualCleanup},
1350 // {"dSpaceGetManualCleanup", (void **) &dSpaceGetManualCleanup},
1351 // {"dSpaceAdd", (void **) &dSpaceAdd},
1352 // {"dSpaceRemove", (void **) &dSpaceRemove},
1353 // {"dSpaceQuery", (void **) &dSpaceQuery},
1354 // {"dSpaceClean", (void **) &dSpaceClean},
1355 // {"dSpaceGetNumGeoms", (void **) &dSpaceGetNumGeoms},
1356 // {"dSpaceGetGeom", (void **) &dSpaceGetGeom},
1357 // {"dSpaceGetClass", (void **) &dSpaceGetClass},
1358 {"dGeomDestroy", (void **) &dGeomDestroy},
1359 {"dGeomSetData", (void **) &dGeomSetData},
1360 {"dGeomGetData", (void **) &dGeomGetData},
1361 {"dGeomSetBody", (void **) &dGeomSetBody},
1362 {"dGeomGetBody", (void **) &dGeomGetBody},
1363 {"dGeomSetPosition", (void **) &dGeomSetPosition},
1364 {"dGeomSetRotation", (void **) &dGeomSetRotation},
1365 // {"dGeomSetQuaternion", (void **) &dGeomSetQuaternion},
1366 // {"dGeomGetPosition", (void **) &dGeomGetPosition},
1367 // {"dGeomCopyPosition", (void **) &dGeomCopyPosition},
1368 // {"dGeomGetRotation", (void **) &dGeomGetRotation},
1369 // {"dGeomCopyRotation", (void **) &dGeomCopyRotation},
1370 // {"dGeomGetQuaternion", (void **) &dGeomGetQuaternion},
1371 // {"dGeomGetAABB", (void **) &dGeomGetAABB},
1372 {"dGeomIsSpace", (void **) &dGeomIsSpace},
1373 // {"dGeomGetSpace", (void **) &dGeomGetSpace},
1374 // {"dGeomGetClass", (void **) &dGeomGetClass},
1375 // {"dGeomSetCategoryBits", (void **) &dGeomSetCategoryBits},
1376 // {"dGeomSetCollideBits", (void **) &dGeomSetCollideBits},
1377 // {"dGeomGetCategoryBits", (void **) &dGeomGetCategoryBits},
1378 // {"dGeomGetCollideBits", (void **) &dGeomGetCollideBits},
1379 // {"dGeomEnable", (void **) &dGeomEnable},
1380 // {"dGeomDisable", (void **) &dGeomDisable},
1381 // {"dGeomIsEnabled", (void **) &dGeomIsEnabled},
1382 // {"dGeomSetOffsetPosition", (void **) &dGeomSetOffsetPosition},
1383 // {"dGeomSetOffsetRotation", (void **) &dGeomSetOffsetRotation},
1384 // {"dGeomSetOffsetQuaternion", (void **) &dGeomSetOffsetQuaternion},
1385 // {"dGeomSetOffsetWorldPosition", (void **) &dGeomSetOffsetWorldPosition},
1386 // {"dGeomSetOffsetWorldRotation", (void **) &dGeomSetOffsetWorldRotation},
1387 // {"dGeomSetOffsetWorldQuaternion", (void **) &dGeomSetOffsetWorldQuaternion},
1388 // {"dGeomClearOffset", (void **) &dGeomClearOffset},
1389 // {"dGeomIsOffset", (void **) &dGeomIsOffset},
1390 // {"dGeomGetOffsetPosition", (void **) &dGeomGetOffsetPosition},
1391 // {"dGeomCopyOffsetPosition", (void **) &dGeomCopyOffsetPosition},
1392 // {"dGeomGetOffsetRotation", (void **) &dGeomGetOffsetRotation},
1393 // {"dGeomCopyOffsetRotation", (void **) &dGeomCopyOffsetRotation},
1394 // {"dGeomGetOffsetQuaternion", (void **) &dGeomGetOffsetQuaternion},
1395 {"dCollide", (void **) &dCollide},
1396 {"dSpaceCollide", (void **) &dSpaceCollide},
1397 {"dSpaceCollide2", (void **) &dSpaceCollide2},
1398 {"dCreateSphere", (void **) &dCreateSphere},
1399 // {"dGeomSphereSetRadius", (void **) &dGeomSphereSetRadius},
1400 // {"dGeomSphereGetRadius", (void **) &dGeomSphereGetRadius},
1401 // {"dGeomSpherePointDepth", (void **) &dGeomSpherePointDepth},
1402 {"dCreateConvex", (void **) &dCreateConvex},
1403 // {"dGeomSetConvex", (void **) &dGeomSetConvex},
1404 {"dCreateBox", (void **) &dCreateBox},
1405 // {"dGeomBoxSetLengths", (void **) &dGeomBoxSetLengths},
1406 // {"dGeomBoxGetLengths", (void **) &dGeomBoxGetLengths},
1407 // {"dGeomBoxPointDepth", (void **) &dGeomBoxPointDepth},
1408 // {"dGeomBoxPointDepth", (void **) &dGeomBoxPointDepth},
1409 // {"dCreatePlane", (void **) &dCreatePlane},
1410 // {"dGeomPlaneSetParams", (void **) &dGeomPlaneSetParams},
1411 // {"dGeomPlaneGetParams", (void **) &dGeomPlaneGetParams},
1412 // {"dGeomPlanePointDepth", (void **) &dGeomPlanePointDepth},
1413 {"dCreateCapsule", (void **) &dCreateCapsule},
1414 // {"dGeomCapsuleSetParams", (void **) &dGeomCapsuleSetParams},
1415 // {"dGeomCapsuleGetParams", (void **) &dGeomCapsuleGetParams},
1416 // {"dGeomCapsulePointDepth", (void **) &dGeomCapsulePointDepth},
1417 {"dCreateCylinder", (void **) &dCreateCylinder},
1418 // {"dGeomCylinderSetParams", (void **) &dGeomCylinderSetParams},
1419 // {"dGeomCylinderGetParams", (void **) &dGeomCylinderGetParams},
1420 // {"dCreateRay", (void **) &dCreateRay},
1421 // {"dGeomRaySetLength", (void **) &dGeomRaySetLength},
1422 // {"dGeomRayGetLength", (void **) &dGeomRayGetLength},
1423 // {"dGeomRaySet", (void **) &dGeomRaySet},
1424 // {"dGeomRayGet", (void **) &dGeomRayGet},
1425 {"dCreateGeomTransform", (void **) &dCreateGeomTransform},
1426 {"dGeomTransformSetGeom", (void **) &dGeomTransformSetGeom},
1427 // {"dGeomTransformGetGeom", (void **) &dGeomTransformGetGeom},
1428 {"dGeomTransformSetCleanup", (void **) &dGeomTransformSetCleanup},
1429 // {"dGeomTransformGetCleanup", (void **) &dGeomTransformGetCleanup},
1430 // {"dGeomTransformSetInfo", (void **) &dGeomTransformSetInfo},
1431 // {"dGeomTransformGetInfo", (void **) &dGeomTransformGetInfo},
1432 {"dGeomTriMeshDataCreate", (void **) &dGeomTriMeshDataCreate},
1433 {"dGeomTriMeshDataDestroy", (void **) &dGeomTriMeshDataDestroy},
1434 // {"dGeomTriMeshDataSet", (void **) &dGeomTriMeshDataSet},
1435 // {"dGeomTriMeshDataGet", (void **) &dGeomTriMeshDataGet},
1436 // {"dGeomTriMeshSetLastTransform", (void **) &dGeomTriMeshSetLastTransform},
1437 // {"dGeomTriMeshGetLastTransform", (void **) &dGeomTriMeshGetLastTransform},
1438 {"dGeomTriMeshDataBuildSingle", (void **) &dGeomTriMeshDataBuildSingle},
1439 // {"dGeomTriMeshDataBuildSingle1", (void **) &dGeomTriMeshDataBuildSingle1},
1440 // {"dGeomTriMeshDataBuildDouble", (void **) &dGeomTriMeshDataBuildDouble},
1441 // {"dGeomTriMeshDataBuildDouble1", (void **) &dGeomTriMeshDataBuildDouble1},
1442 // {"dGeomTriMeshDataBuildSimple", (void **) &dGeomTriMeshDataBuildSimple},
1443 // {"dGeomTriMeshDataBuildSimple1", (void **) &dGeomTriMeshDataBuildSimple1},
1444 // {"dGeomTriMeshDataPreprocess", (void **) &dGeomTriMeshDataPreprocess},
1445 // {"dGeomTriMeshDataGetBuffer", (void **) &dGeomTriMeshDataGetBuffer},
1446 // {"dGeomTriMeshDataSetBuffer", (void **) &dGeomTriMeshDataSetBuffer},
1447 // {"dGeomTriMeshSetCallback", (void **) &dGeomTriMeshSetCallback},
1448 // {"dGeomTriMeshGetCallback", (void **) &dGeomTriMeshGetCallback},
1449 // {"dGeomTriMeshSetArrayCallback", (void **) &dGeomTriMeshSetArrayCallback},
1450 // {"dGeomTriMeshGetArrayCallback", (void **) &dGeomTriMeshGetArrayCallback},
1451 // {"dGeomTriMeshSetRayCallback", (void **) &dGeomTriMeshSetRayCallback},
1452 // {"dGeomTriMeshGetRayCallback", (void **) &dGeomTriMeshGetRayCallback},
1453 // {"dGeomTriMeshSetTriMergeCallback", (void **) &dGeomTriMeshSetTriMergeCallback},
1454 // {"dGeomTriMeshGetTriMergeCallback", (void **) &dGeomTriMeshGetTriMergeCallback},
1455 {"dCreateTriMesh", (void **) &dCreateTriMesh},
1456 // {"dGeomTriMeshSetData", (void **) &dGeomTriMeshSetData},
1457 // {"dGeomTriMeshGetData", (void **) &dGeomTriMeshGetData},
1458 // {"dGeomTriMeshEnableTC", (void **) &dGeomTriMeshEnableTC},
1459 // {"dGeomTriMeshIsTCEnabled", (void **) &dGeomTriMeshIsTCEnabled},
1460 // {"dGeomTriMeshClearTCCache", (void **) &dGeomTriMeshClearTCCache},
1461 // {"dGeomTriMeshGetTriMeshDataID", (void **) &dGeomTriMeshGetTriMeshDataID},
1462 // {"dGeomTriMeshGetTriangle", (void **) &dGeomTriMeshGetTriangle},
1463 // {"dGeomTriMeshGetPoint", (void **) &dGeomTriMeshGetPoint},
1464 // {"dGeomTriMeshGetTriangleCount", (void **) &dGeomTriMeshGetTriangleCount},
1465 // {"dGeomTriMeshDataUpdate", (void **) &dGeomTriMeshDataUpdate},
1469 // Handle for ODE DLL
1470 dllhandle_t ode_dll = NULL;
1474 static void World_Physics_Init(void)
1477 #ifndef LINK_TO_LIBODE
1478 const char* dllnames [] =
1484 # elif defined(MACOSX)
1497 Cvar_RegisterVariable(&physics_ode_quadtree_depth);
1498 Cvar_RegisterVariable(&physics_ode_contactsurfacelayer);
1499 Cvar_RegisterVariable(&physics_ode_worldstep_iterations);
1500 Cvar_RegisterVariable(&physics_ode_contact_mu);
1501 Cvar_RegisterVariable(&physics_ode_contact_erp);
1502 Cvar_RegisterVariable(&physics_ode_contact_cfm);
1503 Cvar_RegisterVariable(&physics_ode_contact_maxpoints);
1504 Cvar_RegisterVariable(&physics_ode_world_erp);
1505 Cvar_RegisterVariable(&physics_ode_world_cfm);
1506 Cvar_RegisterVariable(&physics_ode_world_damping);
1507 Cvar_RegisterVariable(&physics_ode_world_damping_linear);
1508 Cvar_RegisterVariable(&physics_ode_world_damping_linear_threshold);
1509 Cvar_RegisterVariable(&physics_ode_world_damping_angular);
1510 Cvar_RegisterVariable(&physics_ode_world_damping_angular_threshold);
1511 Cvar_RegisterVariable(&physics_ode_world_gravitymod);
1512 Cvar_RegisterVariable(&physics_ode_iterationsperframe);
1513 Cvar_RegisterVariable(&physics_ode_constantstep);
1514 Cvar_RegisterVariable(&physics_ode_movelimit);
1515 Cvar_RegisterVariable(&physics_ode_spinlimit);
1516 Cvar_RegisterVariable(&physics_ode_trick_fixnan);
1517 Cvar_RegisterVariable(&physics_ode_autodisable);
1518 Cvar_RegisterVariable(&physics_ode_autodisable_steps);
1519 Cvar_RegisterVariable(&physics_ode_autodisable_time);
1520 Cvar_RegisterVariable(&physics_ode_autodisable_threshold_linear);
1521 Cvar_RegisterVariable(&physics_ode_autodisable_threshold_angular);
1522 Cvar_RegisterVariable(&physics_ode_autodisable_threshold_samples);
1523 Cvar_RegisterVariable(&physics_ode_printstats);
1524 Cvar_RegisterVariable(&physics_ode_allowconvex);
1525 Cvar_RegisterVariable(&physics_ode);
1527 #ifndef LINK_TO_LIBODE
1529 if (Sys_LoadLibrary (dllnames, &ode_dll, odefuncs))
1534 #ifndef LINK_TO_LIBODE
1536 if (!dCheckConfiguration("ODE_single_precision"))
1538 if (!dCheckConfiguration("ODE_double_precision"))
1542 Con_Printf("ODE library not compiled for single precision - incompatible! Not using ODE physics.\n");
1544 Con_Printf("ODE library not compiled for double precision - incompatible! Not using ODE physics.\n");
1546 Sys_UnloadLibrary(&ode_dll);
1552 Con_Printf("ODE library loaded with single precision.\n");
1554 Con_Printf("ODE library loaded with double precision.\n");
1556 Con_Printf("ODE configuration list: %s\n", dGetConfiguration());
1563 static void World_Physics_Shutdown(void)
1566 #ifndef LINK_TO_LIBODE
1571 #ifndef LINK_TO_LIBODE
1572 Sys_UnloadLibrary(&ode_dll);
1580 static void World_Physics_UpdateODE(world_t *world)
1584 odeworld = (dWorldID)world->physics.ode_world;
1587 if (physics_ode_world_erp.value >= 0)
1588 dWorldSetERP(odeworld, physics_ode_world_erp.value);
1589 if (physics_ode_world_cfm.value >= 0)
1590 dWorldSetCFM(odeworld, physics_ode_world_cfm.value);
1592 if (physics_ode_world_damping.integer)
1594 dWorldSetLinearDamping(odeworld, (physics_ode_world_damping_linear.value >= 0) ? (physics_ode_world_damping_linear.value * physics_ode_world_damping.value) : 0);
1595 dWorldSetLinearDampingThreshold(odeworld, (physics_ode_world_damping_linear_threshold.value >= 0) ? (physics_ode_world_damping_linear_threshold.value * physics_ode_world_damping.value) : 0);
1596 dWorldSetAngularDamping(odeworld, (physics_ode_world_damping_angular.value >= 0) ? (physics_ode_world_damping_angular.value * physics_ode_world_damping.value) : 0);
1597 dWorldSetAngularDampingThreshold(odeworld, (physics_ode_world_damping_angular_threshold.value >= 0) ? (physics_ode_world_damping_angular_threshold.value * physics_ode_world_damping.value) : 0);
1601 dWorldSetLinearDamping(odeworld, 0);
1602 dWorldSetLinearDampingThreshold(odeworld, 0);
1603 dWorldSetAngularDamping(odeworld, 0);
1604 dWorldSetAngularDampingThreshold(odeworld, 0);
1607 dWorldSetAutoDisableFlag(odeworld, (physics_ode_autodisable.integer) ? 1 : 0);
1608 if (physics_ode_autodisable.integer)
1610 dWorldSetAutoDisableSteps(odeworld, bound(1, physics_ode_autodisable_steps.integer, 100));
1611 dWorldSetAutoDisableTime(odeworld, physics_ode_autodisable_time.value);
1612 dWorldSetAutoDisableAverageSamplesCount(odeworld, bound(1, physics_ode_autodisable_threshold_samples.integer, 100));
1613 dWorldSetAutoDisableLinearThreshold(odeworld, physics_ode_autodisable_threshold_linear.value);
1614 dWorldSetAutoDisableAngularThreshold(odeworld, physics_ode_autodisable_threshold_angular.value);
1618 static void World_Physics_EnableODE(world_t *world)
1620 dVector3 center, extents;
1621 if (world->physics.ode)
1623 #ifndef LINK_TO_LIBODE
1627 world->physics.ode = true;
1628 VectorMAM(0.5f, world->mins, 0.5f, world->maxs, center);
1629 VectorSubtract(world->maxs, center, extents);
1630 world->physics.ode_world = dWorldCreate();
1631 world->physics.ode_space = dQuadTreeSpaceCreate(NULL, center, extents, bound(1, physics_ode_quadtree_depth.integer, 10));
1632 world->physics.ode_contactgroup = dJointGroupCreate(0);
1634 World_Physics_UpdateODE(world);
1638 static void World_Physics_Start(world_t *world)
1641 if (world->physics.ode)
1643 World_Physics_EnableODE(world);
1647 static void World_Physics_End(world_t *world)
1650 if (world->physics.ode)
1652 dWorldDestroy((dWorldID)world->physics.ode_world);
1653 dSpaceDestroy((dSpaceID)world->physics.ode_space);
1654 dJointGroupDestroy((dJointGroupID)world->physics.ode_contactgroup);
1655 world->physics.ode = false;
1660 void World_Physics_RemoveJointFromEntity(world_t *world, prvm_edict_t *ed)
1662 ed->priv.server->ode_joint_type = 0;
1664 if(ed->priv.server->ode_joint)
1665 dJointDestroy((dJointID)ed->priv.server->ode_joint);
1666 ed->priv.server->ode_joint = NULL;
1670 void World_Physics_RemoveFromEntity(world_t *world, prvm_edict_t *ed)
1672 edict_odefunc_t *f, *nf;
1674 // entity is not physics controlled, free any physics data
1675 ed->priv.server->ode_physics = false;
1677 if (ed->priv.server->ode_geom)
1678 dGeomDestroy((dGeomID)ed->priv.server->ode_geom);
1679 ed->priv.server->ode_geom = NULL;
1680 if (ed->priv.server->ode_body)
1685 while(dBodyGetNumJoints((dBodyID)ed->priv.server->ode_body))
1687 j = dBodyGetJoint((dBodyID)ed->priv.server->ode_body, 0);
1688 ed2 = (prvm_edict_t *) dJointGetData(j);
1689 b1 = dJointGetBody(j, 0);
1690 b2 = dJointGetBody(j, 1);
1691 if(b1 == (dBodyID)ed->priv.server->ode_body)
1694 ed2->priv.server->ode_joint_enemy = 0;
1696 if(b2 == (dBodyID)ed->priv.server->ode_body)
1699 ed2->priv.server->ode_joint_aiment = 0;
1701 dJointAttach(j, b1, b2);
1703 dBodyDestroy((dBodyID)ed->priv.server->ode_body);
1705 ed->priv.server->ode_body = NULL;
1707 if (ed->priv.server->ode_vertex3f)
1708 Mem_Free(ed->priv.server->ode_vertex3f);
1709 ed->priv.server->ode_vertex3f = NULL;
1710 ed->priv.server->ode_numvertices = 0;
1711 if (ed->priv.server->ode_element3i)
1712 Mem_Free(ed->priv.server->ode_element3i);
1713 ed->priv.server->ode_element3i = NULL;
1714 ed->priv.server->ode_numtriangles = 0;
1715 if(ed->priv.server->ode_massbuf)
1716 Mem_Free(ed->priv.server->ode_massbuf);
1717 ed->priv.server->ode_massbuf = NULL;
1718 // clear functions stack
1719 for(f = ed->priv.server->ode_func; f; f = nf)
1724 ed->priv.server->ode_func = NULL;
1727 void World_Physics_ApplyCmd(prvm_edict_t *ed, edict_odefunc_t *f)
1730 dBodyID body = (dBodyID)ed->priv.server->ode_body;
1734 case ODEFUNC_ENABLE:
1737 case ODEFUNC_DISABLE:
1742 dBodyAddForceAtPos(body, f->v1[0], f->v1[1], f->v1[2], f->v2[0], f->v2[1], f->v2[2]);
1744 case ODEFUNC_TORQUE:
1746 dBodyAddTorque(body, f->v1[0], f->v1[1], f->v1[2]);
1755 static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
1757 prvm_prog_t *prog = world->prog;
1760 const dReal *r; // for some reason dBodyGetRotation returns a [3][4] matrix
1762 dBodyID body = (dBodyID)ed->priv.server->ode_body;
1764 matrix4x4_t bodymatrix;
1765 matrix4x4_t entitymatrix;
1768 vec3_t forward, left, up;
1770 vec3_t spinvelocity;
1775 movetype = (int)PRVM_gameedictfloat(ed, movetype);
1776 if (movetype != MOVETYPE_PHYSICS)
1778 jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
1781 // TODO feed back data from physics
1782 case JOINTTYPE_POINT:
1784 case JOINTTYPE_HINGE:
1786 case JOINTTYPE_SLIDER:
1788 case JOINTTYPE_UNIVERSAL:
1790 case JOINTTYPE_HINGE2:
1792 case JOINTTYPE_FIXED:
1797 // store the physics engine data into the entity
1798 o = dBodyGetPosition(body);
1799 r = dBodyGetRotation(body);
1800 vel = dBodyGetLinearVel(body);
1801 avel = dBodyGetAngularVel(body);
1802 VectorCopy(o, origin);
1812 VectorCopy(vel, velocity);
1813 VectorCopy(avel, spinvelocity);
1814 Matrix4x4_FromVectors(&bodymatrix, forward, left, up, origin);
1815 Matrix4x4_Concat(&entitymatrix, &bodymatrix, &ed->priv.server->ode_offsetimatrix);
1816 Matrix4x4_ToVectors(&entitymatrix, forward, left, up, origin);
1818 AnglesFromVectors(angles, forward, up, false);
1819 VectorSet(avelocity, RAD2DEG(spinvelocity[PITCH]), RAD2DEG(spinvelocity[ROLL]), RAD2DEG(spinvelocity[YAW]));
1822 float pitchsign = 1;
1823 if(prog == SVVM_prog) // FIXME some better way?
1825 pitchsign = SV_GetPitchSign(prog, ed);
1827 else if(prog == CLVM_prog)
1829 pitchsign = CL_GetPitchSign(prog, ed);
1831 angles[PITCH] *= pitchsign;
1832 avelocity[PITCH] *= pitchsign;
1835 VectorCopy(origin, PRVM_gameedictvector(ed, origin));
1836 VectorCopy(velocity, PRVM_gameedictvector(ed, velocity));
1837 //VectorCopy(forward, PRVM_gameedictvector(ed, axis_forward));
1838 //VectorCopy(left, PRVM_gameedictvector(ed, axis_left));
1839 //VectorCopy(up, PRVM_gameedictvector(ed, axis_up));
1840 //VectorCopy(spinvelocity, PRVM_gameedictvector(ed, spinvelocity));
1841 VectorCopy(angles, PRVM_gameedictvector(ed, angles));
1842 VectorCopy(avelocity, PRVM_gameedictvector(ed, avelocity));
1844 // values for BodyFromEntity to check if the qc modified anything later
1845 VectorCopy(origin, ed->priv.server->ode_origin);
1846 VectorCopy(velocity, ed->priv.server->ode_velocity);
1847 VectorCopy(angles, ed->priv.server->ode_angles);
1848 VectorCopy(avelocity, ed->priv.server->ode_avelocity);
1849 ed->priv.server->ode_gravity = dBodyGetGravityMode(body) != 0;
1851 if(prog == SVVM_prog) // FIXME some better way?
1854 SV_LinkEdict_TouchAreaGrid(ed);
1858 static void World_Physics_Frame_ForceFromEntity(world_t *world, prvm_edict_t *ed)
1860 prvm_prog_t *prog = world->prog;
1861 int forcetype = 0, movetype = 0, enemy = 0;
1862 vec3_t movedir, origin;
1864 movetype = (int)PRVM_gameedictfloat(ed, movetype);
1865 forcetype = (int)PRVM_gameedictfloat(ed, forcetype);
1866 if (movetype == MOVETYPE_PHYSICS)
1867 forcetype = FORCETYPE_NONE; // can't have both
1870 enemy = PRVM_gameedictedict(ed, enemy);
1871 if (enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
1873 VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
1874 VectorCopy(PRVM_gameedictvector(ed, origin), origin);
1875 dBodyEnable((dBodyID)prog->edicts[enemy].priv.server->ode_body);
1878 case FORCETYPE_FORCE:
1879 if (movedir[0] || movedir[1] || movedir[2])
1880 dBodyAddForce((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2]);
1882 case FORCETYPE_FORCEATPOS:
1883 if (movedir[0] || movedir[1] || movedir[2])
1884 dBodyAddForceAtPos((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2], origin[0], origin[1], origin[2]);
1886 case FORCETYPE_TORQUE:
1887 if (movedir[0] || movedir[1] || movedir[2])
1888 dBodyAddTorque((dBodyID)prog->edicts[enemy].priv.server->ode_body, movedir[0], movedir[1], movedir[2]);
1890 case FORCETYPE_NONE:
1897 static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed)
1899 prvm_prog_t *prog = world->prog;
1905 int enemy = 0, aiment = 0;
1906 vec3_t origin, velocity, angles, forward, left, up, movedir;
1907 vec_t CFM, ERP, FMax, Stop, Vel;
1909 movetype = (int)PRVM_gameedictfloat(ed, movetype);
1910 jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
1911 VectorClear(origin);
1912 VectorClear(velocity);
1913 VectorClear(angles);
1914 VectorClear(movedir);
1915 enemy = PRVM_gameedictedict(ed, enemy);
1916 aiment = PRVM_gameedictedict(ed, aiment);
1917 VectorCopy(PRVM_gameedictvector(ed, origin), origin);
1918 VectorCopy(PRVM_gameedictvector(ed, velocity), velocity);
1919 VectorCopy(PRVM_gameedictvector(ed, angles), angles);
1920 VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
1921 if(movetype == MOVETYPE_PHYSICS)
1922 jointtype = JOINTTYPE_NONE; // can't have both
1923 if(enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
1925 if(aiment <= 0 || aiment >= prog->num_edicts || prog->edicts[aiment].priv.required->free || prog->edicts[aiment].priv.server->ode_body == 0)
1927 // see http://www.ode.org/old_list_archives/2006-January/017614.html
1928 // we want to set ERP? make it fps independent and work like a spring constant
1929 // note: if movedir[2] is 0, it becomes ERP = 1, CFM = 1.0 / (H * K)
1930 if(movedir[0] > 0 && movedir[1] > 0)
1932 float K = movedir[0];
1933 float D = movedir[1];
1934 float R = 2.0 * D * sqrt(K); // we assume D is premultiplied by sqrt(sprungMass)
1935 CFM = 1.0 / (world->physics.ode_step * K + R); // always > 0
1936 ERP = world->physics.ode_step * K * CFM;
1941 else if(movedir[1] < 0)
1946 FMax = -movedir[1]; // TODO do we need to multiply with world.physics.ode_step?
1947 Stop = movedir[2] > 0 ? movedir[2] : dInfinity;
1949 else // movedir[0] > 0, movedir[1] == 0 or movedir[0] < 0, movedir[1] >= 0
1957 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))
1958 return; // nothing to do
1959 AngleVectorsFLU(angles, forward, left, up);
1962 case JOINTTYPE_POINT:
1963 j = dJointCreateBall((dWorldID)world->physics.ode_world, 0);
1965 case JOINTTYPE_HINGE:
1966 j = dJointCreateHinge((dWorldID)world->physics.ode_world, 0);
1968 case JOINTTYPE_SLIDER:
1969 j = dJointCreateSlider((dWorldID)world->physics.ode_world, 0);
1971 case JOINTTYPE_UNIVERSAL:
1972 j = dJointCreateUniversal((dWorldID)world->physics.ode_world, 0);
1974 case JOINTTYPE_HINGE2:
1975 j = dJointCreateHinge2((dWorldID)world->physics.ode_world, 0);
1977 case JOINTTYPE_FIXED:
1978 j = dJointCreateFixed((dWorldID)world->physics.ode_world, 0);
1980 case JOINTTYPE_NONE:
1986 if(ed->priv.server->ode_joint)
1988 //Con_Printf("deleted old joint %i\n", (int) (ed - prog->edicts));
1989 dJointAttach((dJointID)ed->priv.server->ode_joint, 0, 0);
1990 dJointDestroy((dJointID)ed->priv.server->ode_joint);
1992 ed->priv.server->ode_joint = (void *) j;
1993 ed->priv.server->ode_joint_type = jointtype;
1994 ed->priv.server->ode_joint_enemy = enemy;
1995 ed->priv.server->ode_joint_aiment = aiment;
1996 VectorCopy(origin, ed->priv.server->ode_joint_origin);
1997 VectorCopy(velocity, ed->priv.server->ode_joint_velocity);
1998 VectorCopy(angles, ed->priv.server->ode_joint_angles);
1999 VectorCopy(movedir, ed->priv.server->ode_joint_movedir);
2002 //Con_Printf("made new joint %i\n", (int) (ed - prog->edicts));
2003 dJointSetData(j, (void *) ed);
2005 b1 = (dBodyID)prog->edicts[enemy].priv.server->ode_body;
2007 b2 = (dBodyID)prog->edicts[aiment].priv.server->ode_body;
2008 dJointAttach(j, b1, b2);
2012 case JOINTTYPE_POINT:
2013 dJointSetBallAnchor(j, origin[0], origin[1], origin[2]);
2015 case JOINTTYPE_HINGE:
2016 dJointSetHingeAnchor(j, origin[0], origin[1], origin[2]);
2017 dJointSetHingeAxis(j, forward[0], forward[1], forward[2]);
2018 dJointSetHingeParam(j, dParamFMax, FMax);
2019 dJointSetHingeParam(j, dParamHiStop, Stop);
2020 dJointSetHingeParam(j, dParamLoStop, -Stop);
2021 dJointSetHingeParam(j, dParamStopCFM, CFM);
2022 dJointSetHingeParam(j, dParamStopERP, ERP);
2023 dJointSetHingeParam(j, dParamVel, Vel);
2025 case JOINTTYPE_SLIDER:
2026 dJointSetSliderAxis(j, forward[0], forward[1], forward[2]);
2027 dJointSetSliderParam(j, dParamFMax, FMax);
2028 dJointSetSliderParam(j, dParamHiStop, Stop);
2029 dJointSetSliderParam(j, dParamLoStop, -Stop);
2030 dJointSetSliderParam(j, dParamStopCFM, CFM);
2031 dJointSetSliderParam(j, dParamStopERP, ERP);
2032 dJointSetSliderParam(j, dParamVel, Vel);
2034 case JOINTTYPE_UNIVERSAL:
2035 dJointSetUniversalAnchor(j, origin[0], origin[1], origin[2]);
2036 dJointSetUniversalAxis1(j, forward[0], forward[1], forward[2]);
2037 dJointSetUniversalAxis2(j, up[0], up[1], up[2]);
2038 dJointSetUniversalParam(j, dParamFMax, FMax);
2039 dJointSetUniversalParam(j, dParamHiStop, Stop);
2040 dJointSetUniversalParam(j, dParamLoStop, -Stop);
2041 dJointSetUniversalParam(j, dParamStopCFM, CFM);
2042 dJointSetUniversalParam(j, dParamStopERP, ERP);
2043 dJointSetUniversalParam(j, dParamVel, Vel);
2044 dJointSetUniversalParam(j, dParamFMax2, FMax);
2045 dJointSetUniversalParam(j, dParamHiStop2, Stop);
2046 dJointSetUniversalParam(j, dParamLoStop2, -Stop);
2047 dJointSetUniversalParam(j, dParamStopCFM2, CFM);
2048 dJointSetUniversalParam(j, dParamStopERP2, ERP);
2049 dJointSetUniversalParam(j, dParamVel2, Vel);
2051 case JOINTTYPE_HINGE2:
2052 dJointSetHinge2Anchor(j, origin[0], origin[1], origin[2]);
2053 dJointSetHinge2Axis1(j, forward[0], forward[1], forward[2]);
2054 dJointSetHinge2Axis2(j, velocity[0], velocity[1], velocity[2]);
2055 dJointSetHinge2Param(j, dParamFMax, FMax);
2056 dJointSetHinge2Param(j, dParamHiStop, Stop);
2057 dJointSetHinge2Param(j, dParamLoStop, -Stop);
2058 dJointSetHinge2Param(j, dParamStopCFM, CFM);
2059 dJointSetHinge2Param(j, dParamStopERP, ERP);
2060 dJointSetHinge2Param(j, dParamVel, Vel);
2061 dJointSetHinge2Param(j, dParamFMax2, FMax);
2062 dJointSetHinge2Param(j, dParamHiStop2, Stop);
2063 dJointSetHinge2Param(j, dParamLoStop2, -Stop);
2064 dJointSetHinge2Param(j, dParamStopCFM2, CFM);
2065 dJointSetHinge2Param(j, dParamStopERP2, ERP);
2066 dJointSetHinge2Param(j, dParamVel2, Vel);
2068 case JOINTTYPE_FIXED:
2072 Sys_Error("what? but above the joint was valid...\n");
2080 // test convex geometry data
2081 // planes for a cube, these should coincide with the
2082 dReal test_convex_planes[] =
2084 1.0f ,0.0f ,0.0f ,2.25f,
2085 0.0f ,1.0f ,0.0f ,2.25f,
2086 0.0f ,0.0f ,1.0f ,2.25f,
2087 -1.0f,0.0f ,0.0f ,2.25f,
2088 0.0f ,-1.0f,0.0f ,2.25f,
2089 0.0f ,0.0f ,-1.0f,2.25f
2091 const unsigned int test_convex_planecount = 6;
2092 // points for a cube
2093 dReal test_convex_points[] =
2095 2.25f,2.25f,2.25f, // point 0
2096 -2.25f,2.25f,2.25f, // point 1
2097 2.25f,-2.25f,2.25f, // point 2
2098 -2.25f,-2.25f,2.25f, // point 3
2099 2.25f,2.25f,-2.25f, // point 4
2100 -2.25f,2.25f,-2.25f, // point 5
2101 2.25f,-2.25f,-2.25f, // point 6
2102 -2.25f,-2.25f,-2.25f, // point 7
2104 const unsigned int test_convex_pointcount = 8;
2105 // polygons for a cube (6 squares), index
2106 unsigned int test_convex_polygons[] =
2108 4,0,2,6,4, // positive X
2109 4,1,0,4,5, // positive Y
2110 4,0,1,3,2, // positive Z
2111 4,3,1,5,7, // negative X
2112 4,2,3,7,6, // negative Y
2113 4,5,4,6,7, // negative Z
2116 static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
2118 prvm_prog_t *prog = world->prog;
2123 const dReal *ovelocity, *ospinvelocity;
2130 int movetype = MOVETYPE_NONE;
2133 int solid = SOLID_NOT, geomtype = 0;
2137 qboolean modified = false;
2147 vec3_t spinvelocity;
2152 vec_t massval = 1.0f;
2159 qboolean geom_modified = false;
2160 edict_odefunc_t *func, *nextf;
2162 dReal *planes, *planesData, *pointsData;
2163 unsigned int *polygons, *polygonsData, polyvert;
2164 qboolean *mapped, *used, convex_compatible;
2165 int numplanes = 0, numpoints = 0, i;
2167 #ifndef LINK_TO_LIBODE
2171 VectorClear(entmins);
2172 VectorClear(entmaxs);
2174 solid = (int)PRVM_gameedictfloat(ed, solid);
2175 geomtype = (int)PRVM_gameedictfloat(ed, geomtype);
2176 movetype = (int)PRVM_gameedictfloat(ed, movetype);
2177 // support scale and q3map/radiant's modelscale_vec
2178 if (PRVM_gameedictvector(ed, modelscale_vec)[0] != 0.0 || PRVM_gameedictvector(ed, modelscale_vec)[1] != 0.0 || PRVM_gameedictvector(ed, modelscale_vec)[2] != 0.0)
2179 VectorCopy(PRVM_gameedictvector(ed, modelscale_vec), scale);
2180 else if (PRVM_gameedictfloat(ed, scale))
2181 VectorSet(scale, PRVM_gameedictfloat(ed, scale), PRVM_gameedictfloat(ed, scale), PRVM_gameedictfloat(ed, scale));
2183 VectorSet(scale, 1.0f, 1.0f, 1.0f);
2185 if (PRVM_gameedictfloat(ed, mass))
2186 massval = PRVM_gameedictfloat(ed, mass);
2187 if (movetype != MOVETYPE_PHYSICS)
2189 mempool = prog->progs_mempool;
2193 // VorteX: keep support for deprecated solid fields to not break mods
2194 if (solid == SOLID_PHYSICS_TRIMESH || solid == SOLID_BSP)
2195 geomtype = GEOMTYPE_TRIMESH;
2196 else if (solid == SOLID_NOT || solid == SOLID_TRIGGER)
2197 geomtype = GEOMTYPE_NONE;
2198 else if (solid == SOLID_PHYSICS_SPHERE)
2199 geomtype = GEOMTYPE_SPHERE;
2200 else if (solid == SOLID_PHYSICS_CAPSULE)
2201 geomtype = GEOMTYPE_CAPSULE;
2202 else if (solid == SOLID_PHYSICS_CYLINDER)
2203 geomtype = GEOMTYPE_CYLINDER;
2204 else if (solid == SOLID_PHYSICS_BOX)
2205 geomtype = GEOMTYPE_BOX;
2207 geomtype = GEOMTYPE_BOX;
2209 if (geomtype == GEOMTYPE_TRIMESH)
2211 modelindex = (int)PRVM_gameedictfloat(ed, modelindex);
2212 if (world == &sv.world)
2213 model = SV_GetModelByIndex(modelindex);
2214 else if (world == &cl.world)
2215 model = CL_GetModelByIndex(modelindex);
2220 entmins[0] = model->normalmins[0] * scale[0];
2221 entmins[1] = model->normalmins[1] * scale[1];
2222 entmins[2] = model->normalmins[2] * scale[2];
2223 entmaxs[0] = model->normalmaxs[0] * scale[0];
2224 entmaxs[1] = model->normalmaxs[1] * scale[1];
2225 entmaxs[2] = model->normalmaxs[2] * scale[2];
2226 geom_modified = !VectorCompare(ed->priv.server->ode_scale, scale) || ed->priv.server->ode_modelindex != modelindex;
2230 Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
2231 geomtype = GEOMTYPE_BOX;
2232 VectorCopy(PRVM_gameedictvector(ed, mins), entmins);
2233 VectorCopy(PRVM_gameedictvector(ed, maxs), entmaxs);
2235 geom_modified = !VectorCompare(ed->priv.server->ode_mins, entmins) || !VectorCompare(ed->priv.server->ode_maxs, entmaxs);
2238 else if (geomtype && geomtype != GEOMTYPE_NONE)
2240 VectorCopy(PRVM_gameedictvector(ed, mins), entmins);
2241 VectorCopy(PRVM_gameedictvector(ed, maxs), entmaxs);
2242 geom_modified = !VectorCompare(ed->priv.server->ode_mins, entmins) || !VectorCompare(ed->priv.server->ode_maxs, entmaxs);
2246 // geometry type not set, falling back
2247 if (ed->priv.server->ode_physics)
2248 World_Physics_RemoveFromEntity(world, ed);
2252 VectorSubtract(entmaxs, entmins, geomsize);
2253 if (VectorLength2(geomsize) == 0)
2255 // we don't allow point-size physics objects...
2256 if (ed->priv.server->ode_physics)
2257 World_Physics_RemoveFromEntity(world, ed);
2262 ed->priv.server->ode_friction = PRVM_gameedictfloat(ed, friction) ? PRVM_gameedictfloat(ed, friction) : 1.0f;
2264 // check if we need to create or replace the geom
2265 if (!ed->priv.server->ode_physics || ed->priv.server->ode_mass != massval || geom_modified)
2268 World_Physics_RemoveFromEntity(world, ed);
2269 ed->priv.server->ode_physics = true;
2270 VectorMAM(0.5f, entmins, 0.5f, entmaxs, geomcenter);
2271 if (PRVM_gameedictvector(ed, massofs))
2272 VectorCopy(geomcenter, PRVM_gameedictvector(ed, massofs));
2275 if (geomsize[0] * geomsize[1] * geomsize[2] == 0)
2277 if (movetype == MOVETYPE_PHYSICS)
2278 Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
2279 VectorSet(geomsize, 1.0f, 1.0f, 1.0f);
2285 case GEOMTYPE_TRIMESH:
2286 // add an optimized mesh to the model containing only the SUPERCONTENTS_SOLID surfaces
2287 if (!model->brush.collisionmesh)
2288 Mod_CreateCollisionMesh(model);
2289 if (!model->brush.collisionmesh)
2291 Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)));
2295 // check if trimesh can be defined with convex
2296 convex_compatible = false;
2297 for (i = 0;i < model->nummodelsurfaces;i++)
2299 if (!strcmp(((msurface_t *)(model->data_surfaces + model->firstmodelsurface + i))->texture->name, "collisionconvex"))
2301 convex_compatible = true;
2306 // ODE requires persistent mesh storage, so we need to copy out
2307 // the data from the model because renderer restarts could free it
2308 // during the game, additionally we need to flip the triangles...
2309 // note: ODE does preprocessing of the mesh for culling, removing
2310 // concave edges, etc., so this is not a lightweight operation
2311 ed->priv.server->ode_numvertices = numvertices = model->brush.collisionmesh->numverts;
2312 ed->priv.server->ode_vertex3f = (float *)Mem_Alloc(mempool, numvertices * sizeof(float[3]));
2314 // VorteX: rebuild geomsize based on entity's collision mesh, honor scale
2315 VectorSet(entmins, 0, 0, 0);
2316 VectorSet(entmaxs, 0, 0, 0);
2317 for (vertexindex = 0, ov = ed->priv.server->ode_vertex3f, iv = model->brush.collisionmesh->vertex3f;vertexindex < numvertices;vertexindex++, ov += 3, iv += 3)
2319 ov[0] = iv[0] * scale[0];
2320 ov[1] = iv[1] * scale[1];
2321 ov[2] = iv[2] * scale[2];
2322 entmins[0] = min(entmins[0], ov[0]);
2323 entmins[1] = min(entmins[1], ov[1]);
2324 entmins[2] = min(entmins[2], ov[2]);
2325 entmaxs[0] = max(entmaxs[0], ov[0]);
2326 entmaxs[1] = max(entmaxs[1], ov[1]);
2327 entmaxs[2] = max(entmaxs[2], ov[2]);
2329 if (!PRVM_gameedictvector(ed, massofs))
2330 VectorMAM(0.5f, entmins, 0.5f, entmaxs, geomcenter);
2331 for (vertexindex = 0, ov = ed->priv.server->ode_vertex3f, iv = model->brush.collisionmesh->vertex3f;vertexindex < numvertices;vertexindex++, ov += 3, iv += 3)
2333 ov[0] = ov[0] - geomcenter[0];
2334 ov[1] = ov[1] - geomcenter[1];
2335 ov[2] = ov[2] - geomcenter[2];
2337 VectorSubtract(entmaxs, entmins, geomsize);
2338 if (VectorLength2(geomsize) == 0)
2340 if (movetype == MOVETYPE_PHYSICS)
2341 Con_Printf("entity %i collision mesh has null geomsize\n", PRVM_NUM_FOR_EDICT(ed));
2342 VectorSet(geomsize, 1.0f, 1.0f, 1.0f);
2344 ed->priv.server->ode_numtriangles = numtriangles = model->brush.collisionmesh->numtriangles;
2345 ed->priv.server->ode_element3i = (int *)Mem_Alloc(mempool, numtriangles * sizeof(int[3]));
2346 //memcpy(ed->priv.server->ode_element3i, model->brush.collisionmesh->element3i, ed->priv.server->ode_numtriangles * sizeof(int[3]));
2347 for (triangleindex = 0, oe = ed->priv.server->ode_element3i, ie = model->brush.collisionmesh->element3i;triangleindex < numtriangles;triangleindex++, oe += 3, ie += 3)
2354 Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
2355 if (!convex_compatible || !physics_ode_allowconvex.integer)
2358 dataID = dGeomTriMeshDataCreate();
2359 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]));
2360 ed->priv.server->ode_geom = (void *)dCreateTriMesh((dSpaceID)world->physics.ode_space, (dTriMeshDataID)dataID, NULL, NULL, NULL);
2361 dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
2365 // VorteX: this code is unfinished in two ways
2366 // - no duplicate vertex merging are done
2367 // - triangles that shares same edge and havee sam plane are not merget into poly
2368 // so, currently it only works for geosphere meshes with no UV
2370 Con_Printf("Build convex hull for model %s...\n", model->name);
2371 // build convex geometry from trimesh data
2372 // this ensures that trimesh's triangles can form correct convex geometry
2373 // not many of error checking is performed
2374 // ODE's conve hull data consist of:
2375 // planes : an array of planes in the form: normal X, normal Y, normal Z, distance
2376 // points : an array of points X,Y,Z
2377 // polygons: an array of indices to the points of each polygon,it should be the number of vertices
2378 // followed by that amount of indices to "points" in counter clockwise order
2379 polygonsData = polygons = (unsigned int *)Mem_Alloc(mempool, numtriangles*sizeof(int)*4);
2380 planesData = planes = (dReal *)Mem_Alloc(mempool, numtriangles*sizeof(dReal)*4);
2381 mapped = (qboolean *)Mem_Alloc(mempool, numvertices*sizeof(qboolean));
2382 used = (qboolean *)Mem_Alloc(mempool, numtriangles*sizeof(qboolean));
2383 memset(mapped, 0, numvertices*sizeof(qboolean));
2384 memset(used, 0, numtriangles*sizeof(qboolean));
2385 numplanes = numpoints = polyvert = 0;
2386 // build convex hull
2387 // todo: merge duplicated verts here
2388 Con_Printf("Building...\n");
2389 iv = ed->priv.server->ode_vertex3f;
2390 for (triangleindex = 0; triangleindex < numtriangles; triangleindex++)
2392 // already formed a polygon?
2393 if (used[triangleindex])
2396 // switch clockwise->counterclockwise
2397 ie = &model->brush.collisionmesh->element3i[triangleindex*3];
2398 used[triangleindex] = true;
2399 TriangleNormal(&iv[ie[0]*3], &iv[ie[1]*3], &iv[ie[2]*3], planes);
2400 VectorNormalize(planes);
2402 polygons[3] = (unsigned int)ie[0]; mapped[polygons[3]] = true;
2403 polygons[2] = (unsigned int)ie[1]; mapped[polygons[2]] = true;
2404 polygons[1] = (unsigned int)ie[2]; mapped[polygons[1]] = true;
2406 // now find and include concave triangles
2407 for (i = triangleindex; i < numtriangles; i++)
2411 // should share at least 2 vertexes
2412 for (polyvert = 1; polyvert <= polygons[0]; polyvert++)
2414 // todo: merge in triangles that shares an edge and have same plane here
2418 // add polygon to overall stats
2419 planes[3] = DotProduct(&iv[polygons[1]*3], planes);
2420 polygons += (polygons[0]+1);
2426 for (vertexindex = 0, numpoints = 0; vertexindex < numvertices; vertexindex++)
2427 if (mapped[vertexindex])
2429 pointsData = (dReal *)Mem_Alloc(mempool, numpoints*sizeof(dReal)*3 + numplanes*sizeof(dReal)*4); // planes is appended
2430 for (vertexindex = 0, numpoints = 0; vertexindex < numvertices; vertexindex++)
2432 if (mapped[vertexindex])
2434 VectorCopy(&iv[vertexindex*3], &pointsData[numpoints*3]);
2439 Con_Printf("Points: \n");
2440 for (i = 0; i < (int)numpoints; i++)
2441 Con_Printf("%3i: %3.1f %3.1f %3.1f\n", i, pointsData[i*3], pointsData[i*3+1], pointsData[i*3+2]);
2443 planes = planesData;
2444 planesData = pointsData + numpoints*3;
2445 memcpy(planesData, planes, numplanes*sizeof(dReal)*4);
2447 Con_Printf("planes...\n");
2448 for (i = 0; i < numplanes; i++)
2449 Con_Printf("%3i: %1.1f %1.1f %1.1f %1.1f\n", i, planesData[i*4], planesData[i*4 + 1], planesData[i*4 + 2], planesData[i*4 + 3]);
2451 polyvert = polygons - polygonsData;
2452 polygons = polygonsData;
2453 polygonsData = (unsigned int *)Mem_Alloc(mempool, polyvert*sizeof(int));
2454 memcpy(polygonsData, polygons, polyvert*sizeof(int));
2456 Con_Printf("Polygons: \n");
2457 polygons = polygonsData;
2458 for (i = 0; i < numplanes; i++)
2460 Con_Printf("%3i : %i ", i, polygons[0]);
2461 for (triangleindex = 1; triangleindex <= (int)polygons[0]; triangleindex++)
2462 Con_Printf("%3i ", polygons[triangleindex]);
2463 polygons += (polygons[0]+1);
2466 Mem_Free(ed->priv.server->ode_element3i);
2467 ed->priv.server->ode_element3i = (int *)polygonsData;
2468 Mem_Free(ed->priv.server->ode_vertex3f);
2469 ed->priv.server->ode_vertex3f = (float *)pointsData;
2470 // check for properly build polygons by calculating the determinant of the 3x3 matrix composed of the first 3 points in the polygon
2471 // this code is picked from ODE Source
2472 Con_Printf("Check...\n");
2473 polygons = polygonsData;
2474 for (i = 0; i < numplanes; i++)
2476 if((pointsData[(polygons[1]*3)+0]*pointsData[(polygons[2]*3)+1]*pointsData[(polygons[3]*3)+2] +
2477 pointsData[(polygons[1]*3)+1]*pointsData[(polygons[2]*3)+2]*pointsData[(polygons[3]*3)+0] +
2478 pointsData[(polygons[1]*3)+2]*pointsData[(polygons[2]*3)+0]*pointsData[(polygons[3]*3)+1] -
2479 pointsData[(polygons[1]*3)+2]*pointsData[(polygons[2]*3)+1]*pointsData[(polygons[3]*3)+0] -
2480 pointsData[(polygons[1]*3)+1]*pointsData[(polygons[2]*3)+0]*pointsData[(polygons[3]*3)+2] -
2481 pointsData[(polygons[1]*3)+0]*pointsData[(polygons[2]*3)+2]*pointsData[(polygons[3]*3)+1]) < 0)
2482 Con_Printf(CON_WARN "WARNING: Polygon %d is not defined counterclockwise\n", i);
2483 if (planesData[(i*4)+3] < 0)
2484 Con_Printf(CON_WARN "WARNING: Plane %d does not contain the origin\n", i);
2485 polygons += (*polygons + 1);
2488 Con_Printf("Create geom...\n");
2489 ed->priv.server->ode_geom = (void *)dCreateConvex((dSpaceID)world->physics.ode_space, planesData, numplanes, pointsData, numpoints, polygonsData);
2490 dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
2491 Con_Printf("Done!\n");
2496 Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
2497 ed->priv.server->ode_geom = (void *)dCreateBox((dSpaceID)world->physics.ode_space, geomsize[0], geomsize[1], geomsize[2]);
2498 dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
2500 case GEOMTYPE_SPHERE:
2501 Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
2502 ed->priv.server->ode_geom = (void *)dCreateSphere((dSpaceID)world->physics.ode_space, geomsize[0] * 0.5f);
2503 dMassSetSphereTotal(&mass, massval, geomsize[0] * 0.5f);
2505 case GEOMTYPE_CAPSULE:
2507 if (geomsize[axisindex] < geomsize[1])
2509 if (geomsize[axisindex] < geomsize[2])
2511 // the qc gives us 3 axis radius, the longest axis is the capsule
2512 // axis, since ODE doesn't like this idea we have to create a
2513 // capsule which uses the standard orientation, and apply a
2517 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
2518 radius = min(geomsize[1], geomsize[2]) * 0.5f;
2520 else if (axisindex == 1)
2522 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
2523 radius = min(geomsize[0], geomsize[2]) * 0.5f;
2527 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
2528 radius = min(geomsize[0], geomsize[1]) * 0.5f;
2530 length = geomsize[axisindex] - radius*2;
2531 // because we want to support more than one axisindex, we have to
2532 // create a transform, and turn on its cleanup setting (which will
2533 // cause the child to be destroyed when it is destroyed)
2534 ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
2535 dMassSetCapsuleTotal(&mass, massval, axisindex+1, radius, length);
2537 case GEOMTYPE_CAPSULE_X:
2538 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
2539 radius = min(geomsize[1], geomsize[2]) * 0.5f;
2540 length = geomsize[0] - radius*2;
2541 // check if length is not enough, reduce radius then
2544 radius -= (1 - length)*0.5;
2547 ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
2548 dMassSetCapsuleTotal(&mass, massval, 1, radius, length);
2550 case GEOMTYPE_CAPSULE_Y:
2551 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
2552 radius = min(geomsize[0], geomsize[2]) * 0.5f;
2553 length = geomsize[1] - radius*2;
2554 // check if length is not enough, reduce radius then
2557 radius -= (1 - length)*0.5;
2560 ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
2561 dMassSetCapsuleTotal(&mass, massval, 2, radius, length);
2563 case GEOMTYPE_CAPSULE_Z:
2564 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
2565 radius = min(geomsize[1], geomsize[0]) * 0.5f;
2566 length = geomsize[2] - radius*2;
2567 // check if length is not enough, reduce radius then
2570 radius -= (1 - length)*0.5;
2573 ed->priv.server->ode_geom = (void *)dCreateCapsule((dSpaceID)world->physics.ode_space, radius, length);
2574 dMassSetCapsuleTotal(&mass, massval, 3, radius, length);
2576 case GEOMTYPE_CYLINDER:
2578 if (geomsize[axisindex] < geomsize[1])
2580 if (geomsize[axisindex] < geomsize[2])
2582 // the qc gives us 3 axis radius, the longest axis is the capsule
2583 // axis, since ODE doesn't like this idea we have to create a
2584 // capsule which uses the standard orientation, and apply a
2588 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
2589 radius = min(geomsize[1], geomsize[2]) * 0.5f;
2591 else if (axisindex == 1)
2593 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
2594 radius = min(geomsize[0], geomsize[2]) * 0.5f;
2598 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
2599 radius = min(geomsize[0], geomsize[1]) * 0.5f;
2601 length = geomsize[axisindex];
2602 // check if length is not enough, reduce radius then
2605 radius -= (1 - length)*0.5;
2608 ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
2609 dMassSetCylinderTotal(&mass, massval, axisindex+1, radius, length);
2611 case GEOMTYPE_CYLINDER_X:
2612 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 90, 1);
2613 radius = min(geomsize[1], geomsize[2]) * 0.5f;
2614 length = geomsize[0];
2615 ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
2616 dMassSetCylinderTotal(&mass, massval, 1, radius, length);
2618 case GEOMTYPE_CYLINDER_Y:
2619 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 90, 0, 0, 1);
2620 radius = min(geomsize[0], geomsize[2]) * 0.5f;
2621 length = geomsize[1];
2622 ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
2623 dMassSetCylinderTotal(&mass, massval, 2, radius, length);
2625 case GEOMTYPE_CYLINDER_Z:
2626 Matrix4x4_CreateFromQuakeEntity(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2], 0, 0, 0, 1);
2627 radius = min(geomsize[0], geomsize[1]) * 0.5f;
2628 length = geomsize[2];
2629 ed->priv.server->ode_geom = (void *)dCreateCylinder((dSpaceID)world->physics.ode_space, radius, length);
2630 dMassSetCylinderTotal(&mass, massval, 3, radius, length);
2633 Sys_Error("World_Physics_BodyFromEntity: unrecognized geomtype value %i was accepted by filter\n", solid);
2634 // this goto only exists to prevent warnings from the compiler
2635 // about uninitialized variables (mass), while allowing it to
2636 // catch legitimate uninitialized variable warnings
2639 ed->priv.server->ode_mass = massval;
2640 ed->priv.server->ode_modelindex = modelindex;
2641 VectorCopy(entmins, ed->priv.server->ode_mins);
2642 VectorCopy(entmaxs, ed->priv.server->ode_maxs);
2643 VectorCopy(scale, ed->priv.server->ode_scale);
2644 ed->priv.server->ode_movelimit = min(geomsize[0], min(geomsize[1], geomsize[2]));
2645 Matrix4x4_Invert_Simple(&ed->priv.server->ode_offsetimatrix, &ed->priv.server->ode_offsetmatrix);
2646 ed->priv.server->ode_massbuf = Mem_Alloc(mempool, sizeof(mass));
2647 memcpy(ed->priv.server->ode_massbuf, &mass, sizeof(dMass));
2650 if (ed->priv.server->ode_geom)
2651 dGeomSetData((dGeomID)ed->priv.server->ode_geom, (void*)ed);
2652 if (movetype == MOVETYPE_PHYSICS && ed->priv.server->ode_geom)
2654 // entity is dynamic
2655 if (ed->priv.server->ode_body == NULL)
2657 ed->priv.server->ode_body = (void *)(body = dBodyCreate((dWorldID)world->physics.ode_world));
2658 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, body);
2659 dBodySetData(body, (void*)ed);
2660 dBodySetMass(body, (dMass *) ed->priv.server->ode_massbuf);
2666 // entity is deactivated
2667 if (ed->priv.server->ode_body != NULL)
2669 if(ed->priv.server->ode_geom)
2670 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, 0);
2671 dBodyDestroy((dBodyID) ed->priv.server->ode_body);
2672 ed->priv.server->ode_body = NULL;
2677 // get current data from entity
2678 VectorClear(origin);
2679 VectorClear(velocity);
2680 //VectorClear(forward);
2681 //VectorClear(left);
2683 //VectorClear(spinvelocity);
2684 VectorClear(angles);
2685 VectorClear(avelocity);
2687 VectorCopy(PRVM_gameedictvector(ed, origin), origin);
2688 VectorCopy(PRVM_gameedictvector(ed, velocity), velocity);
2689 //VectorCopy(PRVM_gameedictvector(ed, axis_forward), forward);
2690 //VectorCopy(PRVM_gameedictvector(ed, axis_left), left);
2691 //VectorCopy(PRVM_gameedictvector(ed, axis_up), up);
2692 //VectorCopy(PRVM_gameedictvector(ed, spinvelocity), spinvelocity);
2693 VectorCopy(PRVM_gameedictvector(ed, angles), angles);
2694 VectorCopy(PRVM_gameedictvector(ed, avelocity), avelocity);
2695 if (PRVM_gameedictfloat(ed, gravity) != 0.0f && PRVM_gameedictfloat(ed, gravity) < 0.5f) gravity = false;
2696 if (ed == prog->edicts)
2699 // compatibility for legacy entities
2700 //if (!VectorLength2(forward) || solid == SOLID_BSP)
2702 float pitchsign = 1;
2703 vec3_t qangles, qavelocity;
2704 VectorCopy(angles, qangles);
2705 VectorCopy(avelocity, qavelocity);
2707 if(prog == SVVM_prog) // FIXME some better way?
2709 pitchsign = SV_GetPitchSign(prog, ed);
2711 else if(prog == CLVM_prog)
2713 pitchsign = CL_GetPitchSign(prog, ed);
2715 qangles[PITCH] *= pitchsign;
2716 qavelocity[PITCH] *= pitchsign;
2718 AngleVectorsFLU(qangles, forward, left, up);
2719 // convert single-axis rotations in avelocity to spinvelocity
2720 // FIXME: untested math - check signs
2721 VectorSet(spinvelocity, DEG2RAD(qavelocity[PITCH]), DEG2RAD(qavelocity[ROLL]), DEG2RAD(qavelocity[YAW]));
2724 // compatibility for legacy entities
2728 case SOLID_SLIDEBOX:
2730 VectorSet(forward, 1, 0, 0);
2731 VectorSet(left, 0, 1, 0);
2732 VectorSet(up, 0, 0, 1);
2733 VectorSet(spinvelocity, 0, 0, 0);
2738 // we must prevent NANs...
2739 if (physics_ode_trick_fixnan.integer)
2741 test = VectorLength2(origin) + VectorLength2(forward) + VectorLength2(left) + VectorLength2(up) + VectorLength2(velocity) + VectorLength2(spinvelocity);
2742 if (VEC_IS_NAN(test))
2745 //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_gameedictstring(ed, classname)), 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]);
2746 if (physics_ode_trick_fixnan.integer >= 2)
2747 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(prog, PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
2748 test = VectorLength2(origin);
2749 if (VEC_IS_NAN(test))
2750 VectorClear(origin);
2751 test = VectorLength2(forward) * VectorLength2(left) * VectorLength2(up);
2752 if (VEC_IS_NAN(test))
2754 VectorSet(angles, 0, 0, 0);
2755 VectorSet(forward, 1, 0, 0);
2756 VectorSet(left, 0, 1, 0);
2757 VectorSet(up, 0, 0, 1);
2759 test = VectorLength2(velocity);
2760 if (VEC_IS_NAN(test))
2761 VectorClear(velocity);
2762 test = VectorLength2(spinvelocity);
2763 if (VEC_IS_NAN(test))
2765 VectorClear(avelocity);
2766 VectorClear(spinvelocity);
2771 // check if the qc edited any position data
2772 if (!VectorCompare(origin, ed->priv.server->ode_origin)
2773 || !VectorCompare(velocity, ed->priv.server->ode_velocity)
2774 || !VectorCompare(angles, ed->priv.server->ode_angles)
2775 || !VectorCompare(avelocity, ed->priv.server->ode_avelocity)
2776 || gravity != ed->priv.server->ode_gravity)
2779 // store the qc values into the physics engine
2780 body = (dBodyID)ed->priv.server->ode_body;
2781 if (modified && ed->priv.server->ode_geom)
2784 matrix4x4_t entitymatrix;
2785 matrix4x4_t bodymatrix;
2788 Con_Printf("entity %i got changed by QC\n", (int) (ed - prog->edicts));
2789 if(!VectorCompare(origin, ed->priv.server->ode_origin))
2790 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]);
2791 if(!VectorCompare(velocity, ed->priv.server->ode_velocity))
2792 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]);
2793 if(!VectorCompare(angles, ed->priv.server->ode_angles))
2794 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]);
2795 if(!VectorCompare(avelocity, ed->priv.server->ode_avelocity))
2796 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]);
2797 if(gravity != ed->priv.server->ode_gravity)
2798 Con_Printf(" gravity: %i -> %i\n", ed->priv.server->ode_gravity, gravity);
2800 // values for BodyFromEntity to check if the qc modified anything later
2801 VectorCopy(origin, ed->priv.server->ode_origin);
2802 VectorCopy(velocity, ed->priv.server->ode_velocity);
2803 VectorCopy(angles, ed->priv.server->ode_angles);
2804 VectorCopy(avelocity, ed->priv.server->ode_avelocity);
2805 ed->priv.server->ode_gravity = gravity;
2807 Matrix4x4_FromVectors(&entitymatrix, forward, left, up, origin);
2808 Matrix4x4_Concat(&bodymatrix, &entitymatrix, &ed->priv.server->ode_offsetmatrix);
2809 Matrix4x4_ToVectors(&bodymatrix, forward, left, up, origin);
2810 r[0][0] = forward[0];
2811 r[1][0] = forward[1];
2812 r[2][0] = forward[2];
2821 if (movetype == MOVETYPE_PHYSICS)
2823 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, body);
2824 dBodySetPosition(body, origin[0], origin[1], origin[2]);
2825 dBodySetRotation(body, r[0]);
2826 dBodySetLinearVel(body, velocity[0], velocity[1], velocity[2]);
2827 dBodySetAngularVel(body, spinvelocity[0], spinvelocity[1], spinvelocity[2]);
2828 dBodySetGravityMode(body, gravity);
2832 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, body);
2833 dBodySetPosition(body, origin[0], origin[1], origin[2]);
2834 dBodySetRotation(body, r[0]);
2835 dBodySetLinearVel(body, velocity[0], velocity[1], velocity[2]);
2836 dBodySetAngularVel(body, spinvelocity[0], spinvelocity[1], spinvelocity[2]);
2837 dBodySetGravityMode(body, gravity);
2838 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, 0);
2843 // no body... then let's adjust the parameters of the geom directly
2844 dGeomSetBody((dGeomID)ed->priv.server->ode_geom, 0); // just in case we previously HAD a body (which should never happen)
2845 dGeomSetPosition((dGeomID)ed->priv.server->ode_geom, origin[0], origin[1], origin[2]);
2846 dGeomSetRotation((dGeomID)ed->priv.server->ode_geom, r[0]);
2853 // limit movement speed to prevent missed collisions at high speed
2854 ovelocity = dBodyGetLinearVel(body);
2855 ospinvelocity = dBodyGetAngularVel(body);
2856 movelimit = ed->priv.server->ode_movelimit * world->physics.ode_movelimit;
2857 test = VectorLength2(ovelocity);
2858 if (test > movelimit*movelimit)
2860 // scale down linear velocity to the movelimit
2861 // scale down angular velocity the same amount for consistency
2862 f = movelimit / sqrt(test);
2863 VectorScale(ovelocity, f, velocity);
2864 VectorScale(ospinvelocity, f, spinvelocity);
2865 dBodySetLinearVel(body, velocity[0], velocity[1], velocity[2]);
2866 dBodySetAngularVel(body, spinvelocity[0], spinvelocity[1], spinvelocity[2]);
2869 // make sure the angular velocity is not exploding
2870 spinlimit = physics_ode_spinlimit.value;
2871 test = VectorLength2(ospinvelocity);
2872 if (test > spinlimit)
2874 dBodySetAngularVel(body, 0, 0, 0);
2877 // apply functions and clear stack
2878 for(func = ed->priv.server->ode_func; func; func = nextf)
2881 World_Physics_ApplyCmd(ed, func);
2884 ed->priv.server->ode_func = NULL;
2888 #define MAX_CONTACTS 32
2889 static void nearCallback (void *data, dGeomID o1, dGeomID o2)
2891 world_t *world = (world_t *)data;
2892 prvm_prog_t *prog = world->prog;
2893 dContact contact[MAX_CONTACTS]; // max contacts per collision pair
2894 int b1enabled = 0, b2enabled = 0;
2899 float bouncefactor1 = 0.0f;
2900 float bouncestop1 = 60.0f / 800.0f;
2901 float bouncefactor2 = 0.0f;
2902 float bouncestop2 = 60.0f / 800.0f;
2905 prvm_edict_t *ed1, *ed2;
2907 if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
2909 // colliding a space with something
2910 dSpaceCollide2(o1, o2, data, &nearCallback);
2911 // Note we do not want to test intersections within a space,
2912 // only between spaces.
2913 //if (dGeomIsSpace(o1)) dSpaceCollide(o1, data, &nearCallback);
2914 //if (dGeomIsSpace(o2)) dSpaceCollide(o2, data, &nearCallback);
2918 b1 = dGeomGetBody(o1);
2920 b1enabled = dBodyIsEnabled(b1);
2921 b2 = dGeomGetBody(o2);
2923 b2enabled = dBodyIsEnabled(b2);
2925 // at least one object has to be using MOVETYPE_PHYSICS and should be enabled or we just don't care
2926 if (!b1enabled && !b2enabled)
2929 // exit without doing anything if the two bodies are connected by a joint
2930 if (b1 && b2 && dAreConnectedExcluding(b1, b2, dJointTypeContact))
2933 ed1 = (prvm_edict_t *) dGeomGetData(o1);
2934 if(ed1 && ed1->priv.server->free)
2938 bouncefactor1 = PRVM_gameedictfloat(ed1, bouncefactor);
2939 bouncestop1 = PRVM_gameedictfloat(ed1, bouncestop);
2941 bouncestop1 = 60.0f / 800.0f;
2944 ed2 = (prvm_edict_t *) dGeomGetData(o2);
2945 if(ed2 && ed2->priv.server->free)
2949 bouncefactor2 = PRVM_gameedictfloat(ed2, bouncefactor);
2950 bouncestop2 = PRVM_gameedictfloat(ed2, bouncestop);
2952 bouncestop2 = 60.0f / 800.0f;
2955 if(prog == SVVM_prog)
2957 if(ed1 && PRVM_serveredictfunction(ed1, touch))
2959 SV_LinkEdict_TouchAreaGrid_Call(ed1, ed2 ? ed2 : prog->edicts);
2961 if(ed2 && PRVM_serveredictfunction(ed2, touch))
2963 SV_LinkEdict_TouchAreaGrid_Call(ed2, ed1 ? ed1 : prog->edicts);
2967 // merge bounce factors and bounce stop
2968 if(bouncefactor2 > 0)
2970 if(bouncefactor1 > 0)
2972 // TODO possibly better logic to merge bounce factor data?
2973 if(bouncestop2 < bouncestop1)
2974 bouncestop1 = bouncestop2;
2975 if(bouncefactor2 > bouncefactor1)
2976 bouncefactor1 = bouncefactor2;
2980 bouncestop1 = bouncestop2;
2981 bouncefactor1 = bouncefactor2;
2984 dWorldGetGravity((dWorldID)world->physics.ode_world, grav);
2985 bouncestop1 *= fabs(grav[2]);
2988 // select object that moves faster ang get it's erp
2989 erp = (VectorLength2(PRVM_gameedictvector(ed1, velocity)) > VectorLength2(PRVM_gameedictvector(ed2, velocity))) ? PRVM_gameedictfloat(ed1, erp) : PRVM_gameedictfloat(ed2, erp);
2991 // get max contact points for this collision
2992 numcontacts = (int)PRVM_gameedictfloat(ed1, maxcontacts);
2994 numcontacts = physics_ode_contact_maxpoints.integer;
2995 if (PRVM_gameedictfloat(ed2, maxcontacts))
2996 numcontacts = max(numcontacts, (int)PRVM_gameedictfloat(ed2, maxcontacts));
2998 numcontacts = max(numcontacts, physics_ode_contact_maxpoints.integer);
3000 // generate contact points between the two non-space geoms
3001 numcontacts = dCollide(o1, o2, min(MAX_CONTACTS, numcontacts), &(contact[0].geom), sizeof(contact[0]));
3002 // add these contact points to the simulation
3003 for (i = 0;i < numcontacts;i++)
3005 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);
3006 contact[i].surface.mu = physics_ode_contact_mu.value * ed1->priv.server->ode_friction * ed2->priv.server->ode_friction;
3007 contact[i].surface.soft_erp = physics_ode_contact_erp.value + erp;
3008 contact[i].surface.soft_cfm = physics_ode_contact_cfm.value;
3009 contact[i].surface.bounce = bouncefactor1;
3010 contact[i].surface.bounce_vel = bouncestop1;
3011 c = dJointCreateContact((dWorldID)world->physics.ode_world, (dJointGroupID)world->physics.ode_contactgroup, contact + i);
3012 dJointAttach(c, b1, b2);
3017 void World_Physics_Frame(world_t *world, double frametime, double gravity)
3020 prvm_prog_t *prog = world->prog;
3021 double tdelta, tdelta2, tdelta3, simulationtime, collisiontime;
3023 tdelta = Sys_DirtyTime();
3024 if (world->physics.ode && physics_ode.integer)
3029 if (!physics_ode_constantstep.value)
3031 world->physics.ode_iterations = bound(1, physics_ode_iterationsperframe.integer, 1000);
3032 world->physics.ode_step = frametime / world->physics.ode_iterations;
3036 world->physics.ode_time += frametime;
3038 if (physics_ode_constantstep.value > 0 && physics_ode_constantstep.value < 1)
3039 world->physics.ode_step = physics_ode_constantstep.value;
3041 world->physics.ode_step = sys_ticrate.value;
3042 if (world->physics.ode_time > 0.2f)
3043 world->physics.ode_time = world->physics.ode_step;
3044 // set number of iterations to process
3045 world->physics.ode_iterations = 0;
3046 while(world->physics.ode_time >= world->physics.ode_step)
3048 world->physics.ode_iterations++;
3049 world->physics.ode_time -= world->physics.ode_step;
3052 world->physics.ode_movelimit = physics_ode_movelimit.value / world->physics.ode_step;
3053 World_Physics_UpdateODE(world);
3055 // copy physics properties from entities to physics engine
3058 for (i = 0, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
3059 if (!prog->edicts[i].priv.required->free)
3060 World_Physics_Frame_BodyFromEntity(world, ed);
3061 // oh, and it must be called after all bodies were created
3062 for (i = 0, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
3063 if (!prog->edicts[i].priv.required->free)
3064 World_Physics_Frame_JointFromEntity(world, ed);
3067 tdelta2 = Sys_DirtyTime();
3069 for (i = 0;i < world->physics.ode_iterations;i++)
3072 dWorldSetGravity((dWorldID)world->physics.ode_world, 0, 0, -gravity * physics_ode_world_gravitymod.value);
3073 // set the tolerance for closeness of objects
3074 dWorldSetContactSurfaceLayer((dWorldID)world->physics.ode_world, max(0, physics_ode_contactsurfacelayer.value));
3075 // run collisions for the current world state, creating JointGroup
3076 tdelta3 = Sys_DirtyTime();
3077 dSpaceCollide((dSpaceID)world->physics.ode_space, (void *)world, nearCallback);
3078 collisiontime += (Sys_DirtyTime() - tdelta3)*10000;
3083 for (j = 0, ed = prog->edicts + j;j < prog->num_edicts;j++, ed++)
3084 if (!prog->edicts[j].priv.required->free)
3085 World_Physics_Frame_ForceFromEntity(world, ed);
3087 // run physics (move objects, calculate new velocities)
3088 // be sure not to pass 0 as step time because that causes an ODE error
3089 dWorldSetQuickStepNumIterations((dWorldID)world->physics.ode_world, bound(1, physics_ode_worldstep_iterations.integer, 200));
3090 if (world->physics.ode_step > 0)
3091 dWorldQuickStep((dWorldID)world->physics.ode_world, world->physics.ode_step);
3092 // clear the JointGroup now that we're done with it
3093 dJointGroupEmpty((dJointGroupID)world->physics.ode_contactgroup);
3095 simulationtime = (Sys_DirtyTime() - tdelta2)*10000;
3097 // copy physics properties from physics engine to entities and do some stats
3100 for (i = 1, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
3101 if (!prog->edicts[i].priv.required->free)
3102 World_Physics_Frame_BodyToEntity(world, ed);
3105 if (physics_ode_printstats.integer)
3109 world->physics.ode_numobjects = 0;
3110 world->physics.ode_activeovjects = 0;
3111 for (i = 1, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
3113 if (prog->edicts[i].priv.required->free)
3115 body = (dBodyID)prog->edicts[i].priv.server->ode_body;
3118 world->physics.ode_numobjects++;
3119 if (dBodyIsEnabled(body))
3120 world->physics.ode_activeovjects++;
3122 Con_Printf("ODE Stats(%s): %i iterations, %3.01f (%3.01f collision) %3.01f total : %i objects %i active %i disabled\n", prog->name, world->physics.ode_iterations, simulationtime, collisiontime, (Sys_DirtyTime() - tdelta)*10000, world->physics.ode_numobjects, world->physics.ode_activeovjects, (world->physics.ode_numobjects - world->physics.ode_activeovjects));