|
Author Topic:   Help with inertia matrix problem...
Michael
New Member
posted April 21, 2001 10:55 AM            
I am doing some rigid body dynamics code in OpenGL (it may one day be used for vehicle simulations in a fast action racing game).
Bodies spin and bounce, you can attach two bodies with a spring or elastic, and you can specify an axis along which the body must move (like an abacus).
Anyway I sum together the forces and torques, and I use:

acceleration = F / m and:
angular_acceleration = T / i

...like Newton tells us to. The thing which is fudged is the moment of inertia. This is the same about any axis right now. I know it has something to do with an inertia matrix, and diagonalising it, but I don't really know what diagonalising is (or is that diagonaliZing in America?). Can anybody help?

Michael.

IP:

Dreamer
Member
posted April 21, 2001 11:17 AM         
There are actually two ways to do that...
Either you can take the "physically correct" approach, using a complete inertia matrix (3x3 elements) - handling that baby can be pretty complicated (even if you created seperate ones for all geometric primitives your models consist of).
Or you could
-create a static local coordinate system for each model
-for each force affecting the model:
--seperate the forces components in the local coordinate system
--apply each component seperately using lever equations (not 100% correct, but better than any current 3D game )

Just how you do that remains up to you, but I really recommend the second approach, but if you really wish to do it the hard way, I should be able to help you.

(studying physics can really spoil your mind, ya know)

IP:

Michael
New Member
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).]

IP: