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;
}
Code: Select all
temptorque = temptorque*(0.5/MomentOfInertia);
Code: Select all
Rotate (AngularVelocity+0.5*temptorque);
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;
}
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.