// physics engine support
//============================================================================
+#ifndef ODE_STATIC
+#define ODE_DYNAMIC 1
+#endif
+
+#if defined(ODE_STATIC) || defined(ODE_DYNAMIC)
+#define USEODE 1
+#endif
+
+#ifdef USEODE
cvar_t physics_ode_quadtree_depth = {0, "physics_ode_quadtree_depth","5", "desired subdivision level of quadtree culling space"};
cvar_t physics_ode_contactsurfacelayer = {0, "physics_ode_contactsurfacelayer","0", "allows objects to overlap this many units to reduce jitter"};
cvar_t physics_ode_worldquickstep = {0, "physics_ode_worldquickstep","1", "use dWorldQuickStep rather than dWorldStepFast1 or dWorldStep"};
// LordHavoc: this large chunk of definitions comes from the ODE library
// include files.
-#ifndef ODE_STATIC
-#define ODE_DYNAMIC 1
-#endif
-
-#if defined(ODE_STATIC) || defined(ODE_DYNAMIC)
-#define USEODE 1
-#endif
-
-#ifdef USEODE
#ifdef ODE_STATIC
#include "ode/ode.h"
#else
#define dSAP_AXES_ZXY ((2)|(0<<2)|(1<<4))
#define dSAP_AXES_ZYX ((2)|(1<<2)|(0<<4))
-const char* (ODE_API *dGetConfiguration)(void);
-int (ODE_API *dCheckConfiguration)( const char* token );
+//const char* (ODE_API *dGetConfiguration)(void);
+//int (ODE_API *dCheckConfiguration)( const char* token );
int (ODE_API *dInitODE)(void);
//int (ODE_API *dInitODE2)(unsigned int uiInitFlags);
-int (ODE_API *dAllocateODEDataForThread)(unsigned int uiAllocateFlags);
-void (ODE_API *dCleanupODEAllDataForThread)(void);
+//int (ODE_API *dAllocateODEDataForThread)(unsigned int uiAllocateFlags);
+//void (ODE_API *dCleanupODEAllDataForThread)(void);
void (ODE_API *dCloseODE)(void);
//int (ODE_API *dMassCheck)(const dMass *m);
dWorldID (ODE_API *dWorldCreate)(void);
void (ODE_API *dWorldDestroy)(dWorldID world);
void (ODE_API *dWorldSetGravity)(dWorldID, dReal x, dReal y, dReal z);
-//void (ODE_API *dWorldGetGravity)(dWorldID, dVector3 gravity);
+void (ODE_API *dWorldGetGravity)(dWorldID, dVector3 gravity);
//void (ODE_API *dWorldSetERP)(dWorldID, dReal erp);
//dReal (ODE_API *dWorldGetERP)(dWorldID);
//void (ODE_API *dWorldSetCFM)(dWorldID, dReal cfm);
dBodyID (ODE_API *dBodyCreate)(dWorldID);
void (ODE_API *dBodyDestroy)(dBodyID);
void (ODE_API *dBodySetData)(dBodyID, void *data);
-//void * (ODE_API *dBodyGetData)(dBodyID);
+void * (ODE_API *dBodyGetData)(dBodyID);
void (ODE_API *dBodySetPosition)(dBodyID, dReal x, dReal y, dReal z);
void (ODE_API *dBodySetRotation)(dBodyID, const dMatrix3 R);
//void (ODE_API *dBodySetQuaternion)(dBodyID, const dQuaternion q);
//void (ODE_API *dBodyEnable)(dBodyID);
//void (ODE_API *dBodyDisable)(dBodyID);
//int (ODE_API *dBodyIsEnabled)(dBodyID);
-//void (ODE_API *dBodySetGravityMode)(dBodyID b, int mode);
-//int (ODE_API *dBodyGetGravityMode)(dBodyID b);
+void (ODE_API *dBodySetGravityMode)(dBodyID b, int mode);
+int (ODE_API *dBodyGetGravityMode)(dBodyID b);
//void (*dBodySetMovedCallback)(dBodyID b, void(ODE_API *callback)(dBodyID));
//dGeomID (ODE_API *dBodyGetFirstGeom)(dBodyID b);
//dGeomID (ODE_API *dBodyGetNextGeom)(dGeomID g);
dSpaceID (ODE_API *dSimpleSpaceCreate)(dSpaceID space);
dSpaceID (ODE_API *dHashSpaceCreate)(dSpaceID space);
dSpaceID (ODE_API *dQuadTreeSpaceCreate)(dSpaceID space, const dVector3 Center, const dVector3 Extents, int Depth);
-dSpaceID (ODE_API *dSweepAndPruneSpaceCreate)( dSpaceID space, int axisorder );
+//dSpaceID (ODE_API *dSweepAndPruneSpaceCreate)( dSpaceID space, int axisorder );
void (ODE_API *dSpaceDestroy)(dSpaceID);
//void (ODE_API *dHashSpaceSetLevels)(dSpaceID space, int minlevel, int maxlevel);
//void (ODE_API *dHashSpaceGetLevels)(dSpaceID space, int *minlevel, int *maxlevel);
static dllfunction_t odefuncs[] =
{
- {"dGetConfiguration", (void **) &dGetConfiguration},
- {"dCheckConfiguration", (void **) &dCheckConfiguration},
+// {"dGetConfiguration", (void **) &dGetConfiguration},
+// {"dCheckConfiguration", (void **) &dCheckConfiguration},
{"dInitODE", (void **) &dInitODE},
// {"dInitODE2", (void **) &dInitODE2},
- {"dAllocateODEDataForThread", (void **) &dAllocateODEDataForThread},
- {"dCleanupODEAllDataForThread", (void **) &dCleanupODEAllDataForThread},
+// {"dAllocateODEDataForThread", (void **) &dAllocateODEDataForThread},
+// {"dCleanupODEAllDataForThread", (void **) &dCleanupODEAllDataForThread},
{"dCloseODE", (void **) &dCloseODE},
// {"dMassCheck", (void **) &dMassCheck},
// {"dMassSetZero", (void **) &dMassSetZero},
{"dWorldCreate", (void **) &dWorldCreate},
{"dWorldDestroy", (void **) &dWorldDestroy},
{"dWorldSetGravity", (void **) &dWorldSetGravity},
-// {"dWorldGetGravity", (void **) &dWorldGetGravity},
+ {"dWorldGetGravity", (void **) &dWorldGetGravity},
// {"dWorldSetERP", (void **) &dWorldSetERP},
// {"dWorldGetERP", (void **) &dWorldGetERP},
// {"dWorldSetCFM", (void **) &dWorldSetCFM},
{"dBodyCreate", (void **) &dBodyCreate},
{"dBodyDestroy", (void **) &dBodyDestroy},
{"dBodySetData", (void **) &dBodySetData},
-// {"dBodyGetData", (void **) &dBodyGetData},
+ {"dBodyGetData", (void **) &dBodyGetData},
{"dBodySetPosition", (void **) &dBodySetPosition},
{"dBodySetRotation", (void **) &dBodySetRotation},
// {"dBodySetQuaternion", (void **) &dBodySetQuaternion},
// {"dBodyEnable", (void **) &dBodyEnable},
// {"dBodyDisable", (void **) &dBodyDisable},
// {"dBodyIsEnabled", (void **) &dBodyIsEnabled},
-// {"dBodySetGravityMode", (void **) &dBodySetGravityMode},
-// {"dBodyGetGravityMode", (void **) &dBodyGetGravityMode},
+ {"dBodySetGravityMode", (void **) &dBodySetGravityMode},
+ {"dBodyGetGravityMode", (void **) &dBodyGetGravityMode},
// {"dBodySetMovedCallback", (void **) &dBodySetMovedCallback},
// {"dBodyGetFirstGeom", (void **) &dBodyGetFirstGeom},
// {"dBodyGetNextGeom", (void **) &dBodyGetNextGeom},
{"dSimpleSpaceCreate", (void **) &dSimpleSpaceCreate},
{"dHashSpaceCreate", (void **) &dHashSpaceCreate},
{"dQuadTreeSpaceCreate", (void **) &dQuadTreeSpaceCreate},
- {"dSweepAndPruneSpaceCreate", (void **) &dSweepAndPruneSpaceCreate},
+// {"dSweepAndPruneSpaceCreate", (void **) &dSweepAndPruneSpaceCreate},
{"dSpaceDestroy", (void **) &dSpaceDestroy},
// {"dHashSpaceSetLevels", (void **) &dHashSpaceSetLevels},
// {"dHashSpaceGetLevels", (void **) &dHashSpaceGetLevels},
static void World_Physics_Init(void)
{
#ifdef USEODE
-#ifndef ODE_STATIC
+#ifdef ODE_DYNAMIC
const char* dllnames [] =
{
# if defined(WIN64)
Cvar_RegisterVariable(&physics_ode_movelimit);
Cvar_RegisterVariable(&physics_ode_spinlimit);
-#ifndef ODE_STATIC
+#ifdef ODE_DYNAMIC
// Load the DLL
if (Sys_LoadLibrary (dllnames, &ode_dll, odefuncs))
#endif
{
dInitODE();
// dInitODE2(0);
-#ifndef ODE_STATIC
+#ifdef ODE_DNYAMIC
# ifdef dSINGLE
if (!dCheckConfiguration("ODE_single_precision"))
# else
static void World_Physics_Shutdown(void)
{
#ifdef USEODE
-#ifndef ODE_STATIC
+#ifdef ODE_DYNAMIC
if (ode_dll)
#endif
{
dCloseODE();
-#ifndef ODE_STATIC
+#ifdef ODE_DYNAMIC
Sys_UnloadLibrary(&ode_dll);
ode_dll = NULL;
#endif
dVector3 center, extents;
if (world->physics.ode)
return;
-#ifndef ODE_STATIC
+#ifdef ODE_DYNAMIC
if (!ode_dll)
return;
#endif
void World_Physics_RemoveFromEntity(world_t *world, prvm_edict_t *ed)
{
-#ifdef USEODE
// entity is not physics controlled, free any physics data
ed->priv.server->ode_physics = false;
+#ifdef USEODE
if (ed->priv.server->ode_geom)
dGeomDestroy((dGeomID)ed->priv.server->ode_geom);
ed->priv.server->ode_geom = NULL;
if (ed->priv.server->ode_body)
dBodyDestroy((dBodyID)ed->priv.server->ode_body);
ed->priv.server->ode_body = NULL;
+#endif
if (ed->priv.server->ode_vertex3f)
Mem_Free(ed->priv.server->ode_vertex3f);
ed->priv.server->ode_vertex3f = NULL;
Mem_Free(ed->priv.server->ode_element3i);
ed->priv.server->ode_element3i = NULL;
ed->priv.server->ode_numtriangles = 0;
-#endif
}
#ifdef USEODE
matrix4x4_t bodymatrix;
matrix4x4_t entitymatrix;
prvm_eval_t *val;
+ vec3_t angles;
+ vec3_t avelocity;
vec3_t forward, left, up;
vec3_t origin;
vec3_t spinvelocity;
Matrix4x4_FromVectors(&bodymatrix, forward, left, up, origin);
Matrix4x4_Concat(&entitymatrix, &bodymatrix, &ed->priv.server->ode_offsetimatrix);
Matrix4x4_ToVectors(&entitymatrix, forward, left, up, origin);
+
+ AnglesFromVectors(angles, forward, up, true);
+ VectorSet(avelocity, RAD2DEG(spinvelocity[PITCH]), RAD2DEG(spinvelocity[YAW]), RAD2DEG(spinvelocity[ROLL]));
+
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(origin, val->vector);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(forward, val->vector);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(left, val->vector);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(up, val->vector);
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(velocity, val->vector);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(spinvelocity, val->vector);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) AnglesFromVectors(val->vector, forward, up, true);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(forward, val->vector);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(left, val->vector);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(up, val->vector);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(spinvelocity, val->vector);
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(angles, val->vector);
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.avelocity);if (val) VectorCopy(avelocity, val->vector);
+
+ // values for BodyFromEntity to check if the qc modified anything later
+ VectorCopy(origin, ed->priv.server->ode_origin);
+ VectorCopy(velocity, ed->priv.server->ode_velocity);
+ VectorCopy(angles, ed->priv.server->ode_angles);
+ VectorCopy(avelocity, ed->priv.server->ode_avelocity);
+ ed->priv.server->ode_gravity = dBodyGetGravityMode(body);
}
static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
int *oe;
int axisindex;
int modelindex = 0;
- int movetype;
+ int movetype = MOVETYPE_NONE;
int numtriangles;
int numvertices;
- int solid;
+ int solid = SOLID_NOT;
int triangleindex;
int vertexindex;
mempool_t *mempool;
prvm_eval_t *val;
+ qboolean modified = false;
vec3_t angles;
vec3_t avelocity;
vec3_t entmaxs;
vec_t massval = 1.0f;
vec_t movelimit;
vec_t radius;
+ vec_t scale = 1.0f;
vec_t spinlimit;
-#ifndef ODE_STATIC
+ qboolean gravity;
+#ifdef ODE_DYNAMIC
if (!ode_dll)
return;
#endif
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.solid);
- solid = (int)val->_float;
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);
- movetype = (int)val->_float;
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.solid);if (val) solid = (int)val->_float;
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);if (val) movetype = (int)val->_float;
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);if (val && val->_float) scale = val->_float;
+ modelindex = 0;
switch(solid)
{
case SOLID_BSP:
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.modelindex);
- modelindex = (int)val->_float;
+ if (val)
+ modelindex = (int)val->_float;
if (world == &sv.world && modelindex >= 1 && modelindex < MAX_MODELS)
{
model = sv.models[modelindex];
}
if (model)
{
- VectorCopy(model->normalmins, entmins);
- VectorCopy(model->normalmaxs, entmaxs);
+ VectorScale(model->normalmins, scale, entmins);
+ VectorScale(model->normalmaxs, scale, entmaxs);
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mass);if (val) massval = val->_float;
}
else
|| ed->priv.server->ode_mass != massval
|| ed->priv.server->ode_modelindex != modelindex)
{
+ modified = true;
World_Physics_RemoveFromEntity(world, ed);
ed->priv.server->ode_physics = true;
VectorCopy(entmins, ed->priv.server->ode_mins);
ed->priv.server->ode_geom = (void *)dCreateTriMesh(world->physics.ode_space, dataID, NULL, NULL, NULL);
dGeomSetBody(ed->priv.server->ode_geom, body);
dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
- dBodySetMass(body, &mass);
- dBodySetData(body, (void*)ed);
break;
case SOLID_BBOX:
case SOLID_SLIDEBOX:
dMassSetBoxTotal(&mass, massval, geomsize[0], geomsize[1], geomsize[2]);
dGeomSetBody(ed->priv.server->ode_geom, body);
dBodySetMass(body, &mass);
- dBodySetData(body, (void*)ed);
break;
case SOLID_PHYSICS_SPHERE:
Matrix4x4_CreateTranslate(&ed->priv.server->ode_offsetmatrix, geomcenter[0], geomcenter[1], geomcenter[2]);
dMassSetCapsuleTotal(&mass, massval, axisindex+1, radius, length);
dGeomSetBody(ed->priv.server->ode_geom, body);
dBodySetMass(body, &mass);
- dBodySetData(body, (void*)ed);
break;
default:
Sys_Error("World_Physics_BodyFromEntity: unrecognized solid value %i was accepted by filter\n", solid);
// get current data from entity
VectorClear(origin);
- VectorClear(forward);
- VectorClear(left);
- VectorClear(up);
VectorClear(velocity);
- VectorClear(spinvelocity);
+ //VectorClear(forward);
+ //VectorClear(left);
+ //VectorClear(up);
+ //VectorClear(spinvelocity);
+ VectorClear(angles);
+ VectorClear(avelocity);
+ gravity = true;
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(val->vector, origin);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(val->vector, forward);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(val->vector, left);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(val->vector, up);
val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, velocity);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(val->vector, spinvelocity);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(val->vector, forward);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(val->vector, left);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(val->vector, up);
+ //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(val->vector, spinvelocity);
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(val->vector, angles);
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.avelocity);if (val) VectorCopy(val->vector, avelocity);
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.gravity);if (val) { if(val->_float != 0.0f && val->_float < 0.5f) gravity = false; }
// compatibility for legacy entities
- switch (solid)
+ //if (!VectorLength2(forward) || solid == SOLID_BSP)
{
- case SOLID_BSP:
- //VectorClear(velocity);
- VectorClear(angles);
- VectorClear(avelocity);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(val->vector, angles);
- val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, avelocity);
AngleVectorsFLU(angles, forward, left, up);
// convert single-axis rotations in avelocity to spinvelocity
// FIXME: untested math - check signs
- VectorSet(spinvelocity, avelocity[PITCH] * ((float)M_PI / 180.0f), avelocity[ROLL] * ((float)M_PI / 180.0f), avelocity[YAW] * ((float)M_PI / 180.0f));
- break;
+ VectorSet(spinvelocity, DEG2RAD(avelocity[PITCH]), DEG2RAD(avelocity[ROLL]), DEG2RAD(avelocity[YAW]));
+ }
+
+ // compatibility for legacy entities
+ switch (solid)
+ {
case SOLID_BBOX:
case SOLID_SLIDEBOX:
case SOLID_CORPSE:
- //VectorClear(velocity);
VectorSet(forward, 1, 0, 0);
VectorSet(left, 0, 1, 0);
VectorSet(up, 0, 0, 1);
break;
}
+
// we must prevent NANs...
test = VectorLength2(origin) + VectorLength2(forward) + VectorLength2(left) + VectorLength2(up) + VectorLength2(velocity) + VectorLength2(spinvelocity);
if (IS_NAN(test))
{
- Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = '%f %f %f' .velocity = '%f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], velocity[0], velocity[1], velocity[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
+ modified = true;
+ //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
+ Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
test = VectorLength2(origin);
if (IS_NAN(test))
VectorClear(origin);
test = VectorLength2(forward) * VectorLength2(left) * VectorLength2(up);
if (IS_NAN(test))
{
+ VectorSet(angles, 0, 0, 0);
VectorSet(forward, 1, 0, 0);
VectorSet(left, 0, 1, 0);
VectorSet(up, 0, 0, 1);
test = VectorLength2(spinvelocity);
if (IS_NAN(test))
{
+ VectorClear(avelocity);
VectorClear(spinvelocity);
}
}
test = VectorLength2(velocity);
if (test > movelimit*movelimit)
{
+ modified = true;
// scale down linear velocity to the movelimit
// scale down angular velocity the same amount for consistency
f = movelimit / sqrt(test);
VectorScale(velocity, f, velocity);
+ VectorScale(avelocity, f, avelocity);
VectorScale(spinvelocity, f, spinvelocity);
}
spinlimit = physics_ode_spinlimit.value;
test = VectorLength2(spinvelocity);
if (test > spinlimit)
+ {
+ modified = true;
+ VectorClear(avelocity);
VectorClear(spinvelocity);
+ }
- // store the values into the physics engine
+ // check if the qc edited any position data
+ if (!VectorCompare(origin, ed->priv.server->ode_origin)
+ || !VectorCompare(velocity, ed->priv.server->ode_velocity)
+ || !VectorCompare(angles, ed->priv.server->ode_angles)
+ || !VectorCompare(avelocity, ed->priv.server->ode_avelocity)
+ || gravity != ed->priv.server->ode_gravity)
+ modified = true;
+
+ // store the qc values into the physics engine
body = ed->priv.server->ode_body;
- if (body)
+ if (body && modified)
{
dVector3 r[3];
matrix4x4_t entitymatrix;
dBodySetRotation(body, r[0]);
dBodySetLinearVel(body, velocity[0], velocity[1], velocity[2]);
dBodySetAngularVel(body, spinvelocity[0], spinvelocity[1], spinvelocity[2]);
+ dBodySetGravityMode(body, gravity);
+ dBodySetData(body, (void*)ed);
// setting body to NULL makes an immovable object
if (movetype != MOVETYPE_PHYSICS)
dGeomSetBody(ed->priv.server->ode_geom, 0);
dJointID c;
int i;
int numcontacts;
+ prvm_eval_t *val;
+ float bouncefactor1 = 0.0f;
+ float bouncestop1 = 60.0f / 800.0f;
+ float bouncefactor2 = 0.0f;
+ float bouncestop2 = 60.0f / 800.0f;
+ dVector3 grav;
+ prvm_edict_t *ed;
if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
{
if (b1 && b2 && dAreConnectedExcluding(b1, b2, dJointTypeContact))
return;
+ if(b1)
+ {
+ ed = (prvm_edict_t *) dBodyGetData(b1);
+ if(ed)
+ {
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.bouncefactor);
+ if (val!=0 && val->_float)
+ bouncefactor1 = val->_float;
+
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.bouncestop);
+ if (val!=0 && val->_float)
+ bouncestop1 = val->_float;
+ }
+ }
+
+ if(b2)
+ {
+ ed = (prvm_edict_t *) dBodyGetData(b2);
+ if(ed)
+ {
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.bouncefactor);
+ if (val!=0 && val->_float)
+ bouncefactor2 = val->_float;
+
+ val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.bouncestop);
+ if (val!=0 && val->_float)
+ bouncestop2 = val->_float;
+ }
+ }
+
+ // merge bounce factors and bounce stop
+ if(bouncefactor2 > 0)
+ {
+ if(bouncefactor1 > 0)
+ {
+ // TODO possibly better logic to merge bounce factor data?
+ if(bouncestop2 < bouncestop1)
+ bouncestop1 = bouncestop2;
+ if(bouncefactor2 > bouncefactor1)
+ bouncefactor1 = bouncefactor2;
+ }
+ else
+ {
+ bouncestop1 = bouncestop2;
+ bouncefactor1 = bouncefactor2;
+ }
+ }
+ dWorldGetGravity(world->physics.ode_world, grav);
+ bouncestop1 *= fabs(grav[2]);
+
// generate contact points between the two non-space geoms
numcontacts = dCollide(o1, o2, MAX_CONTACTS, &(contact[0].geom), sizeof(contact[0]));
// add these contact points to the simulation
for (i = 0;i < numcontacts;i++)
{
- 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);
+ 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);
contact[i].surface.mu = physics_ode_contact_mu.value;
contact[i].surface.soft_erp = physics_ode_contact_erp.value;
contact[i].surface.soft_cfm = physics_ode_contact_cfm.value;
+ contact[i].surface.bounce = bouncefactor1;
+ contact[i].surface.bounce_vel = bouncestop1;
c = dJointCreateContact(world->physics.ode_world, world->physics.ode_contactgroup, contact + i);
dJointAttach(c, b1, b2);
}