[Fix] Revert the silly hack and change dynamic bodies to have spherical
mass distribution to prevent horrible exploding errors in angular velocity.
This commit is contained in:
parent
c8a7e1ac94
commit
c578942682
@ -29,6 +29,10 @@ void DynamicBody::SetRotation(const matrix4x4d &r) {
|
||||
}
|
||||
|
||||
void DynamicBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
||||
/*
|
||||
* XXX: This is silly. the radius of mass distribution should be
|
||||
* defined on the model, not cooked up in some stupid way.
|
||||
*/
|
||||
vector3d min = vector3d(FLT_MAX);
|
||||
vector3d max = vector3d(-FLT_MAX);
|
||||
for(int i = 0; i < 3*m->nv; i += 3) {
|
||||
@ -39,7 +43,11 @@ void DynamicBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
||||
max.y = MAX(m->pVertex[i+1], max.y);
|
||||
max.z = MAX(m->pVertex[i+2], max.z);
|
||||
}
|
||||
dMassSetBox(&m_mass, 1, max.x-min.x, max.y-min.y, max.z-min.z);
|
||||
float size = ((max.x-min.x) + (max.y-min.y) + (max.z-min.z)) / 6.0f;
|
||||
printf("size %f\n", size);
|
||||
dMassSetSphere(&m_mass, 1, size);
|
||||
/* Boxes go mental after a while due to inertia tensor being fishy. */
|
||||
//dMassSetBox(&m_mass, 1, max.x-min.x, max.y-min.y, max.z-min.z);
|
||||
dBodySetMass(m_body, &m_mass);
|
||||
}
|
||||
|
||||
@ -53,19 +61,6 @@ DynamicBody::~DynamicBody(void) {
|
||||
dBodyDestroy(m_body);
|
||||
}
|
||||
|
||||
void DynamicBody::TimeStepUpdate(const float timeStep) {
|
||||
/*
|
||||
* XXX Horrible hack.
|
||||
* Prevent large ang velocities because ode hates them!
|
||||
*/
|
||||
const dReal* v = dBodyGetAngularVel(m_body);
|
||||
vector3d vel;
|
||||
vel.x = CLAMP(v[0], -50.0, 50.0);
|
||||
vel.y = CLAMP(v[1], -50.0, 50.0);
|
||||
vel.z = CLAMP(v[2], -50.0, 50.0);
|
||||
dBodySetAngularVel(m_body, vel.x, vel.y, vel.z);
|
||||
}
|
||||
|
||||
vector3d DynamicBody::GetVelocity(void) {
|
||||
const dReal* v = dBodyGetLinearVel(m_body);
|
||||
return vector3d(v[0], v[1], v[2]);
|
||||
|
@ -18,7 +18,6 @@ public:
|
||||
virtual bool OnCollision(Body* b, Uint32 flags) { return true; }
|
||||
vector3d GetAngularMomentum(void);
|
||||
void SetMassDistributionFromCollMesh(const CollMesh* m);
|
||||
virtual void TimeStepUpdate(const float timeStep);
|
||||
virtual void Disable(void);
|
||||
virtual void Enable(void);
|
||||
|
||||
|
@ -98,7 +98,6 @@ void Ship::CalcStats(shipstats_t* stats) {
|
||||
}
|
||||
|
||||
void Ship::TimeStepUpdate(const float timeStep) {
|
||||
DynamicBody::TimeStepUpdate(timeStep);
|
||||
dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0);
|
||||
/* ODE tri mesh likes to know our old position. */
|
||||
TriMeshUpdateLastPos();
|
||||
|
Loading…
Reference in New Issue
Block a user