View Full Version : Manual Tranformation?

04-15-2004, 01:18 PM
I'm having a problem, and as a newbie, have fled to the forums. :)

I'm learning OpenGL by writing a game: 3D asteroids clone. So, anyway, I need to apply the ship rotation matrix to an accelleration vector because the thruster has to be oriented properly.
I've tried a lot of things. Most recently, I did a glGet for the matrix and tried to do the transformation manually.

Since the thrust is only in Z, I thought I could just do a manual matrix multiplication pretty easily, but it doesn't seem to work. It seems more irratic as the number of transformations on the shipRotMatrix grow.

I hope I've explained this well enough. Any advice will be appreciated.


/* shipRotMatrix is the from glGet with only the ship's rotations applied.
/* Use orientation to fire thruster */
if (thrusterOn)
acc_vector[0] = THRUSTER_STRENGTH * shipRotMatrix[2];
acc_vector[1] = THRUSTER_STRENGTH * shipRotMatrix[6];
acc_vector[2] = THRUSTER_STRENGTH * shipRotMatrix[10];


velX += acc_vector[0];
velY += acc_vector[1];
velZ += acc_vector[2];

tranX += velX;
tranY += velY;
tranZ += velZ;

04-15-2004, 07:36 PM
Your question is how to transform your ship? In 2D, it might be easier to keep a heading angle A, used with your position:

glTranslatef( pos.x, pos.y, pos.z );
glRotatef( A, 0,0,1 );

for example, where A = 0 corresponds to moving down the positive x axis. Turning this angle A into a direction vector for physics would be trivial.

04-16-2004, 04:11 AM
Definitely that's easier, but I'm trying to do it in 3D and have a matrix with the rotation transformation in it. I need this information so that the thruster will push in the right direction.