However, I just cannot get it to move, might be something to do with the connection points of the wheels or something.
Code: Select all
btVector3 inertia;
btTransform shift(btQuaternion::getIdentity(), btVector3(0.f, 0.55f, 0.f));
btCollisionShape* boxShape = new btBoxShape(btVector3(4.f, 3.f, 10.f));
btCompoundShape* chassisShape = new btCompoundShape();
chassisShape->addChildShape(shift, boxShape);
chassisShape->calculateLocalInertia(mChassisMass, inertia);
btTransform trans(btQuaternion::getIdentity(), btVector3(0,0,0));
btDefaultMotionState* motionState = new btDefaultMotionState(trans);
mCarBody = new btRigidBody(mChassisMass, motionState, chassisShape, inertia);
mCarBody->translate(btVector3(0, 7, 0));
world->addRigidBody(mCarBody);
mCarBody->setDamping(mChassisLinearDamping, mChassisAngularDamping);
mCarBody->setActivationState(DISABLE_DEACTIVATION);
mTuning.m_frictionSlip = mWheelFriction;
mTuning.m_maxSuspensionForce = mMaxSuspensionForce;
mTuning.m_maxSuspensionTravelCm = mMaxSuspensionTravelCm;
mTuning.m_suspensionCompression = mSuspensionCompression;
mTuning.m_suspensionDamping = mSuspensionDamping;
mTuning.m_suspensionStiffness = mSuspensionStiffness;
mVehicleRaycaster = new btDefaultVehicleRaycaster(world);
mVehicle = new btRaycastVehicle(mTuning, mCarBody, mVehicleRaycaster);
mVehicle->setCoordinateSystem(0, 1, 2); // rightIndex, upIndex, forwardIndex
float mSuspensionRestLength = 0.5f;
float mConnectionHeight = 0.5f;
float mWheelRadius = 1.5f;
float wheelBaseLength = 8.f;
float wheelBaseHalfWidth = 3.7f;
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
bool isFrontWheel = true;
// Wheel 0 - Front Left
btVector3 connectionPointCS0 (wheelBaseHalfWidth, mConnectionHeight, wheelBaseLength);
mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );
// Wheel 1 - Front Right
connectionPointCS0 = btVector3(-wheelBaseHalfWidth, mConnectionHeight, wheelBaseLength);
mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );
isFrontWheel = false;
// Wheel 2 - Rear Right
connectionPointCS0 = btVector3(-wheelBaseHalfWidth, mConnectionHeight, -wheelBaseLength);
mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );
// Wheel 3 - Rear Left
connectionPointCS0 = btVector3(wheelBaseHalfWidth, mConnectionHeight, -wheelBaseLength);
mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );
for( int i=0; i < mVehicle->getNumWheels(); i++ )
{
btWheelInfo& wheel = mVehicle->getWheelInfo( i );
wheel.m_suspensionStiffness = mSuspensionStiffness;
wheel.m_wheelsDampingRelaxation = mSuspensionDamping;
wheel.m_wheelsDampingCompression = mSuspensionCompression;
wheel.m_maxSuspensionForce = mMaxSuspensionForce;
wheel.m_frictionSlip = mWheelFriction;
wheel.m_rollInfluence = mRollInfluence;
}
world->addVehicle(mVehicle);
Thanks.