I have recently started to acquaint myself with Bullet Physics, but I have stumbled upon a problem that I haven't managed to solve yet - I can not get the chassis of a vehicle to move, not even to fall down. (Though I can get the chassis to fall down if I add it into the world as a rigid body)
This is what I have bunched together from various tutorials and from the vehicle demo so far:
Code: Select all
// The world itself
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0.0f, -9.81f, 0.0f));
// The vehicle
btScalar chassisMass(1.0f);
btVector3 chassisInertia(0.0f, 0.0f, 0.0f);
btCollisionShape* chassisShape = new btBoxShape(btVector3(1.0f, 0.5f, 2.0f));
btDefaultMotionState* chassisMotionState = new btDefaultMotionState(btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f), btVector3(0.0f, 5.0f, 0.0f)));
chassisShape->calculateLocalInertia(chassisMass, chassisInertia);
btRigidBody::btRigidBodyConstructionInfo chassisRigidBodyCI(chassisMass, chassisMotionState, chassisShape, chassisInertia);
btRigidBody* chassisRigidBody = new btRigidBody(chassisRigidBodyCI);
chassisRigidBody->setActivationState(DISABLE_DEACTIVATION);
btRaycastVehicle::btVehicleTuning tuning;
btVehicleRaycaster* raycaster = new btDefaultVehicleRaycaster(dynamicsWorld);
btRaycastVehicle* vehicle = new btRaycastVehicle(tuning, chassisRigidBody, raycaster);
vehicle->setCoordinateSystem(0, 1, 2);
btVector3 wheelDirection(0.0f, -1.0f, 0.0f);
btVector3 wheelAxis(-1.0f, 0.0f, 0.0f);
btScalar suspensionRestLength(0.6f);
btScalar wheelRadius(0.5f);
vehicle->addWheel(btVector3(-0.5f, 1.2f, 1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, true);
vehicle->addWheel(btVector3(0.5f, 1.2f, 1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, true);
vehicle->addWheel(btVector3(-0.5f, 1.2f, -1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, false);
vehicle->addWheel(btVector3(0.5f, 1.2f, -1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, false);
dynamicsWorld->addAction(vehicle);
// This is done every frame to update physics
dynamicsWorld->stepSimulation(1.0f / 60.0f, 10, 1.0f / 60.0f);
// And that's how I get the transformation of the vehicle chassis
GLfloat matrix[16];
vehicle->getChassisWorldTransform().getOpenGLMatrix(&matrix[0]);
Any help would be greatly appreciated.
EDIT: If I do both: add the vehicle into the world as an action and add the chassis of the vehicle into the world as a rigid body - then the graphical representation of my vehicles descends slowly until it reaches the ground plane. Just as the rigid body physics tries to pull it down, but the vehicle physics tries to hold it in one place.
(BTW: I am using Bullet 2.78, compiled on MinGW-w64, if it matters)