- Code: Select all
`void PhysicsSystem::ApplyImpulses (float Time) {`

Vector temptorque = Time*NetTorque;

Vector tempforce = Time*NetForce;

int i;

for ( i = 0; i<NumActiveTorques; ++i)

{

if (Time>=ActiveTorques[i].t)

{

temptorque += ActiveTorques[i].t*ActiveTorques[i].F;

ActiveTorques[i].F = ActiveTorques[NumActiveTorques-1].F;

ActiveTorques[i].t = ActiveTorques[NumActiveTorques-1].t;

--NumActiveTorques;

--i;//so the loop goes through the active force that was just switched places with

}

else

{

temptorque+= Time*ActiveTorques[i].F;

ActiveTorques[i].t -= Time;

}

}

for (i=0; i<NumActiveForces; ++i)

{

if (Time>=ActiveForces[i].t)

{

tempforce += ActiveForces[i].t*ActiveForces[i].F;

ActiveForces[i].F = ActiveForces[NumActiveForces-1].F;

ActiveForces[i].t = ActiveForces[NumActiveForces-1].t;

NumActiveForces--;

i--;//so the loop goes through the active force that was just switched places with

}

else

{

tempforce+= Time*ActiveForces[i].F;

ActiveForces[i].t -= Time;

}

}

//Vector temp = 0.5*GetElapsedTime()*NetTorque*(1.0/MomentOfInertia);//assume force is constant throughout the time

temptorque = temptorque*(0.5/MomentOfInertia);

Rotate (AngularVelocity+0.5*temptorque);

AngularVelocity+= temptorque;

tempforce = tempforce *(0.5/mass);//acceleration

//now the fuck with it... add relitivity to the picture here

if (fabs (Velocity.i)+fabs(Velocity.j)+fabs(Velocity.k)> co10)

{

float magvel = Velocity.Magnitude();

float y = (1-magvel*magvel*oocc);

tempforce = tempforce * powf (y,1.5);

}

*pos += (Velocity+.5*tempforce).Cast();

Velocity +=tempforce;

}

Now, the previous coder did some very confusing things, but if you follow what is actually happening to the variables, you will see that temptorque is actually not a torque at all. It is actually a torque*time which is a change in angular momentum. But we continue to follow and see that goes through the active torques on the object and adds on more changes in angular momentum. He then gets down to

- Code: Select all
`temptorque = temptorque*(0.5/MomentOfInertia);`

Now temptorque has become an angular velocity. But the next line is where the actual error is.

- Code: Select all
`Rotate (AngularVelocity+0.5*temptorque);`

If you look at the code for Rotate

- Code: Select all
`void PhysicsSystem::Rotate (const Vector &axis) {`

float theta = axis.Magnitude();

if(theta==0.0f)

return;

float ootheta = 1/theta;

float s = cos (theta * .5);

Quaternion rot = Quaternion(s, axis * (sin (theta*.5)*ootheta));

Quaternion rotprime = rot.Conjugate();

Quaternion pquat = rot * Quaternion(0, *p) * rotprime;

Quaternion qquat = rot * Quaternion(0, *q) * rotprime;

Quaternion rquat = rot * Quaternion(0, *r) * rotprime;

*p = pquat.v;

*q = qquat.v;

*r = rquat.v;

}

you will see that Rotate does not multiply by dt, and, in fact, doesn't even know the time. So, essentially, the Rotate() call is telling the ship to rotate through an angle = to angular_velocity+change_in_angular_velocity. This is simply wrong. The rotation should be angular_velocity*time. Since temptorque now contain change in angular velocity over the time step..you could call rotate ((angular_velocity+.5*temptorque)*Time). That would be implementing a midpoint method. But regardless, this Rotate is causing ships to rotate WAAAAYY too fast. In fact, it is exactly Hz times too fast..where Hz is the rate at which update is called.

Anyway, that is what I am seeing, but quaternions confuse me and the code, as written, is very difficult to read, so I may have missed something. But I wanted to let you guys know in case someone who is in charge of fixing bugs wants to fix this and see how it changes things.

Now I still have to figure out how to store the object's orientation and then how to change it.