Can anybody spot the problem(s) in my code? I am using bullet 2.76
Code: Select all
class pBtVehicleObjectInstance : public pVehicleObjectInstance {
public:
pBtVehicleObjectInstance(unsigned int objid, unsigned int objinstid, evtTbl * evts, btDiscreteDynamicsWorld * dy, btCollisionShape * cShape, btCollisionShape * wShape){
objID = objid;
instID = objinstid;
lEvts = evts;
dynam = dy;
Chassis_mass = 800;
ChassisShape = new btBoxShape(btVector3(1.f,0.5f,2.f));//cShape;
WheelShape = wShape;
}
void addWheel(unsigned int eid, unsigned int einst, float * cPoint, bool front){
int tmp=0;
while(wheelBool[tmp]==true){
tmp++;
}
wheelBool[tmp]=true;
wheelID[tmp]=eid;
wheelInst[tmp]=einst;
wheelPos[tmp]=cPoint;
wheelFront[tmp]=front;
}
void init(){
btVector3 localInertia(0,0,0);
ChassisState = new btVehicleBodyMotionState(objID,instID,lEvts,btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
ChassisRigidBody = new btRigidBody(Chassis_mass,ChassisState,ChassisShape,localInertia);
ChassisRigidBody->setCenterOfMassTransform(btTransform::getIdentity());
ChassisRigidBody->setLinearVelocity(btVector3(0,0,0));
ChassisRigidBody->setAngularVelocity(btVector3(0,0,0));
dynam->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(ChassisRigidBody->getBroadphaseHandle(),dynam->getDispatcher());
mVehicleRayCaster = new btDefaultVehicleRaycaster(dynam);
mVehicle = new btRaycastVehicle(mTuning,ChassisRigidBody,mVehicleRayCaster);
//ChassisRigidBody->setActivationState(DISABLE_DEACTIVATION);
mVehicle->setCoordinateSystem(0,1,2);
// Other Wheel Stuff
dynam->addVehicle(mVehicle);
int tmp=0;
while(wheelBool[tmp]==true){
btScalar suspensionRestLength(0.6);
btVector3 connectionPointCS0 = btVector3(wheelPos[tmp][0],wheelPos[tmp][1],wheelPos[tmp][2]);
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
btWheelInfo& wheel = mVehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,0.25,mTuning,wheelFront[tmp]);
// Set Properties
wheel.m_suspensionStiffness = 20.f;
wheel.m_wheelsDampingRelaxation = 2.3f;
wheel.m_wheelsDampingCompression = 4.4f;
wheel.m_frictionSlip = 1000;
wheel.m_rollInfluence = 0.1f;
tmp++;
}
for(int i=0;i<mVehicle->getNumWheels();i++){
btWheelInfo& wheel = mVehicle->getWheelInfo(i);
if(wheel.m_bIsFrontWheel == true){
mVehicle->applyEngineForce(1000.f, i);
}
}
}
void setPosRot(float xP, float yP, float zP, float wR, float xR, float yR, float zR){
;
}
std::map<unsigned int, unsigned int> wheelID;
std::map<unsigned int, unsigned int> wheelInst;
std::map<unsigned int, float *> wheelPos;
std::map<unsigned int, bool> wheelFront;
std::map<unsigned int, bool> wheelBool;
private:
float Chassis_mass;
unsigned int objID;
unsigned int instID;
evtTbl * lEvts;
btDiscreteDynamicsWorld * dynam;
// Vehicle stuff
btCollisionShape * ChassisShape;
btVehicleBodyMotionState * ChassisState;
btRigidBody * ChassisRigidBody;
btCollisionShape* WheelShape;
btRaycastVehicle::btVehicleTuning mTuning;
btVehicleRaycaster* mVehicleRayCaster;
btRaycastVehicle* mVehicle;
};