get btCollisionShape current transform

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

get btCollisionShape current transform

Post by b0gd4n »

Hey guys,

I have made a compound shape

Code: Select all

compound = new btCompoundShape();
Then I have a collision shape added to the compound:

Code: Select all

btCollisionShape* turretShape = new btBoxShape(btVector3(0.4f, 0.2f, 1.2f));
btTransform turretTrans;
turretTrans.setIdentity();
turretTrans.setOrigin(btVector3(0.0f, 2.2f, 0.0f));
compound->addChildShape(turretTrans, turretShape);
The compund shape is then transformed into a rigid body and then added to a vehicle raycaster as a chassis:

Code: Select all

m_carChassis = CreateRigidBody(2000, tr, compound);
m_vehicle = new btRaycastVehicle(m_tuning, m_carChassis, m_vehicleRayCaster);


The vehicle is moving along, together with it's wheels, chassis and turret, but I cannot seem to get hold of the updated turret transform.
Whenever I try something like this:

Code: Select all

compound->getChildTransform(1).getOpenGLMatrix(mturret);
I always get the initial position of the turret, where it was first created.

Now, for the wheels I can do this:

Code: Select all

m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(mwheel);
And for the chassis I can do this:

Code: Select all

m_vehicle->getChassisWorldTransform().getOpenGLMatrix(mchassis);
But I don't know how do I get hold of that turret collision shape updated transform?

Please note that where I need this information I have access to both the compound and the turretShape (the actual btCollisionShape).

EDIT:

I found the answer. Here's what I did:

Code: Select all

	btTransform chassisMatrix = m_vehicle->getChassisWorldTransform();
	btTransform turretMatrix = compound->getChildTransform(1);
	turretMatrix *= chassisMatrix;
	turretMatrix.getOpenGLMatrix(mturret);