Center of mass of vehicle

Murphy
Posts: 32
Joined: Fri Aug 31, 2007 6:36 am

Center of mass of vehicle

Post by Murphy »

Most of my vehicle code is taken directly from the Vehicle Demo. I have been trying to change the center of mass of the chassis.

My vehicle tires are not at each corner of the chassis. The front of the vehicle has the wheels slightly pushed back which makes the whole chassis lean down from the back to the front (as I would except).

How would I go about changing the center of mass from the direct center of the chassis (as in "car 1" to the center of the wheels (as in car 2)? The following picture shows what I mean (sorry for the paint diagram, but it is the reason I am a programmer).

Image

It is my understanding that I need to change the origin for the chassis shape of the compound shape in order to do this but whenever I do the whole chassis simple translates relative to the wheels and I still see the same problem. I assume I am just missing something here.

Code: Select all

btCollisionShape * chassisShape = new btBoxShape(btVector3(0.5f, 0.4f, 0.625f));
btCompoundShape * compound = new btCompoundShape();
btTransform localTrans;
localTrans.setIdentity();
//localTrans effectively shifts the center of mass with respect to the chassis

//LINE OF INTEREST
/****************************************************
*****************************************************
*****************************************************
//Doesn't seem to actually change the way the vehicle "leans" with
localTrans.setOrigin(btVector3(0, 0.4, 0.3));
//Or
localTrans.setOrigin(btVector3(0, 0.4, -0.3));
//It just changes how it is displayed relative to the wheels
*****************************************************
*****************************************************
*****************************************************/

compound->addChildShape(localTrans, chassisShape);

btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(0, 0, 0));
carChassis = CreateRigidBody(vehicleMass, tr, compound);

carChassis->translate(btVector3(0.0, 1.0, 0.0));

//create vehicle
vehicleRayCaster = new btDefaultVehicleRaycaster(BulletPhysicsSystem::getSingleton().GetWorld().get());
vehicle = new btRaycastVehicle(tuning, carChassis, vehicleRayCaster);

//never deactivate the vehicle
carChassis->setActivationState(DISABLE_DEACTIVATION);

BulletPhysicsSystem::getSingleton().GetWorld()->addVehicle(vehicle);
I wish I could explain my problem better (it seems pretty simple but I am just missing some key part of it). Thanks
lily
Posts: 3
Joined: Fri Jul 27, 2007 4:23 pm

Re: Center of mass of vehicle

Post by lily »

Hi, I think you need to change the coords of the wheels too, relative to the new origin.
Murphy
Posts: 32
Joined: Fri Aug 31, 2007 6:36 am

Re: Center of mass of vehicle

Post by Murphy »

Thanks! That did it.

My question now is, because of changing the center of mass, it shifts the entire chassis and so my drawing is off from the collision shape. Is there a way to shift the collision shape back to the origin while still maintaining the correct center of mass or should I just shift the position it is being drawn at?