posted April 21, 2001 12:14 PM
Hmmm... I'd quite like to do it the hard way! Right now I have something like this (sorry about the formatting!):float dt; // Delta-time for frame
class Body
{
float mass;
float matrix[16]; // orientation
vector F; // Resultant force
vector T; // Resultant torque
vector v; // Velocity
vector omega; // Angular velocity
...
void Update(void);
void ApplyForce(vector o,vector d);
...
};
This bit gets called once per frame to re-orientate the body:
void Body::Update(void)
{
v += (F / mass) * dt;
omega += (T / 100) * dt; // HACK!!!
//Translate body:
matrix[12] += v.x * dt;
matrix[13] += v.y * dt;
matrix[14] += v.z * dt;
//Rotate body:
RotateMatrix(matrix,omega.x,omega.y,omega.z);
//Reset force & torque for next frame:
F = T = vector(0,0,0);
}
There is also a function that applies a force something like this:
// o=point of application
// d=direction and magnitude of force
void Body::ApplyForce(vector o,vector d)
{
F+=d;
// Do an inverse transforms to get into
// the object's frame of reference:
T+=Cross(invtrans(o),invtrans(o+d));
}
Phew! What needs doing to do it the hard way?
[This message has been edited by Michael (edited April 21, 2001).]