I created a **ground ( btBoxShape )**, **a box** and **a vehicle** (following the demo). But friction between ground and vehicle wheels seems not working.
As soon as the vehicle is placed in 3d world, it starts moving forward.
START : Steering works for the vehicle, but engineForce and brakingForce does not work (i.e. I cannot speed-up or stop the vehicle) : I create physics world like this :
Code: Select all
void initPhysics()
{
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver();
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, -9.81, 0));
// Debug Drawer
bulletDebugugger.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
dynamicsWorld->setDebugDrawer(&bulletDebugugger);
//groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
groundShape = new btBoxShape(btVector3(50, 3, 50));
fallShape = new btBoxShape(btVector3(1, 1, 1));
// Orientation and Position of Ground
groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -3, 0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
///////////////////////////////////////////////////////////////////////
// Vehicle Setup
///////////////////////////////////////////////////////////////////////
vehicleChassisShape = new btBoxShape(btVector3(1.f, 0.5f, 2.f));
vehicleBody = new btCompoundShape();
localTrans.setIdentity();
localTrans.setOrigin(btVector3(0, 1, 0));
vehicleBody->addChildShape(localTrans, vehicleChassisShape);
localTrans.setOrigin(btVector3(3, 0.f, 0));
vehicleMotionState = new btDefaultMotionState(localTrans);
btVector3 vehicleInertia(0, 0, 0);
vehicleBody->calculateLocalInertia(vehicleMass, vehicleInertia);
btRigidBody::btRigidBodyConstructionInfo vehicleRigidBodyCI(vehicleMass, vehicleMotionState, vehicleBody, vehicleInertia);
vehicleRigidBody = new btRigidBody(vehicleRigidBodyCI);
dynamicsWorld->addRigidBody(vehicleRigidBody);
gVehicleSteering = 0;
vehicleRigidBody->setCenterOfMassTransform(btTransform::getIdentity());
vehicleRigidBody->setLinearVelocity(btVector3(0, 0, 0));
vehicleRigidBody->setAngularVelocity(btVector3(0, 0, 0));
dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(vehicleRigidBody->getBroadphaseHandle(), dynamicsWorld->getDispatcher());
wheelShape = new btCylinderShapeX(btVector3(wheelWidth, wheelRadius, wheelRadius));
{
vehicleRayCaster = new btDefaultVehicleRaycaster(dynamicsWorld);
vehicle = new btRaycastVehicle(vehicleTuning, vehicleRigidBody, vehicleRayCaster);
// never deactivate vehicle
vehicleRigidBody->setActivationState(DISABLE_DEACTIVATION);
dynamicsWorld->addVehicle(vehicle);
float connectionHeight = 1.2f;
bool isFrontWheel = true;
vehicle->setCoordinateSystem(rightIndex, upIndex, forwardIndex); // 0, 1, 2
// add wheels
// front left
btVector3 connectionPointCS0(CUBE_HALF_EXTENT-(0.3*wheelWidth), connectionHeight, 2*CUBE_HALF_EXTENT-wheelRadius);
vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, vehicleTuning, isFrontWheel);
// front right
connectionPointCS0 = btVector3(-CUBE_HALF_EXTENT+(0.3*wheelWidth), connectionHeight, 2*CUBE_HALF_EXTENT-wheelRadius);
vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, vehicleTuning, isFrontWheel);
isFrontWheel = false;
// rear right
connectionPointCS0 = btVector3(-CUBE_HALF_EXTENT+(0.3*wheelWidth), connectionHeight, -2*CUBE_HALF_EXTENT+wheelRadius);
vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, vehicleTuning, isFrontWheel);
// rear left
connectionPointCS0 = btVector3(CUBE_HALF_EXTENT-(0.3*wheelWidth), connectionHeight, -2*CUBE_HALF_EXTENT+wheelRadius);
vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, vehicleTuning, isFrontWheel);
for (int i = 0; i < vehicle->getNumWheels(); i++)
{
btWheelInfo& wheel = vehicle->getWheelInfo(i);
wheel.m_suspensionStiffness = suspensionStiffness;
wheel.m_wheelsDampingRelaxation = suspensionDamping;
wheel.m_wheelsDampingCompression = suspensionCompression;
wheel.m_frictionSlip = wheelFriction;
wheel.m_rollInfluence = rollInfluence;
}
}
///////////////////////////////////////////////////////////////////////
// Orientation and Position of Falling body
fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(-1, 5, 0)));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
fallShape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallShape, fallInertia);
fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
}
Code: Select all
// does not work
vehicle->applyEngineForce(maxEngineForce, WHEEL_REARLEFT);
vehicle->applyEngineForce(maxEngineForce, WHEEL_REARRIGHT);
// these also do not work
vehicle->setBrake(gBreakingForce, WHEEL_REARLEFT);
vehicle->setBrake(gBreakingForce, WHEEL_REARRIGHT);
// this works
vehicle->setSteeringValue(gVehicleSteering, WHEEL_FRONTLEFT);
vehicle->setSteeringValue(gVehicleSteering, WHEEL_FRONTRIGHT);
dynamicsWorld->stepSimulation(1 / 60.0f, 10);
Where am I doing it wrong ?
IDE : Visual Studio 2010 SP1
BulletPhysics version : 2.82
OS : Windows 7 64bit