get direction vector from btScalar matrix
Posted: Mon Nov 18, 2013 11:44 am
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:
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:
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:
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);What I have tried is this:
Code: Select all
btVector3 turretForwardVector = btVector3(turretMatrix[2], turretMatrix[6], turretMatrix[9]);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]);