2

I have made a compound shape compound = new btCompoundShape();

Then I have a collision shape added to the compound:

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:

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:

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:

m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(mwheel);

And for the chassis I can do this:

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).

bogdan.css
  • 355
  • 6
  • 17

1 Answers1

3

I don't remember for sure now, but I think you have to multiply the matrices of the chasis world transform and childs (turrets) because getChildTransform() returns in parents reference frame. Can't find it in the docs though.

Szymon Kuczur
  • 5,783
  • 3
  • 16
  • 14
  • 1
    That worked!! Here's what I did: `btTransform chassisMatrix = m_vehicle->getChassisWorldTransform();` `btTransform turretMatrix = compound->getChildTransform(1);` `turretMatrix *= chassisMatrix;` `turretMatrix.getOpenGLMatrix(mturret);` Thanks! – bogdan.css Nov 17 '13 at 19:22