get direction vector from btScalar matrix

Post Reply
b0gd4n
Posts: 14
Joined: Thu Nov 07, 2013 2:38 am

get direction vector from btScalar matrix

Post by b0gd4n »

I have created a bullet vehicle with a compound as the chassis and the compound is formed of 2 bodies, a chassis and a turret.


I can obtain the turret transform and opengl matrix like this:

Code: Select all

    // get chassis and turret transforms
	btTransform chassisTransform = m_vehicle->getChassisWorldTransform();
	btTransform turretTransform = compound->getChildTransform(1);
	// multiply transforms to get updated turret transform
	turretTransform *= chassisTransform;

	// get turret matrix
	btScalar turretMatrix[16];
	turretTransform.getOpenGLMatrix(turretMatrix);
I am trying to get the turret forward/direction vector from this matrix. I need this so that I will have the camera fixed to the turret's position and direction.

What I have tried is this:

Code: Select all

btVector3 turretForwardVector = btVector3(turretMatrix[2], turretMatrix[6], turretMatrix[9]);
But this doesn't give me the right vector.
Could someone please point out where exactly do I have to look for the vector in this matrix?


EDIT:

I managed to find this [link](http://www.opengl.org/discussion_boards ... ix-or-Quat). It explained where I would find the direction vector in the matrix (3rd column).

So I got the 8th, 9th and 10th matrix elemets and created the turretForwardMatrix from that like this:

Code: Select all

btVector3 turretForwardVector = btVector3(turretMatrix[8], turretMatrix[9], turretMatrix[10]);
Post Reply