I tried to implement the vehicle demo using my own rendering engine.
i draw a plane at origin and drop my vehicle from y = 10 units( taking Y axis as up).
other parameters are same as given in vehicle demo.
my tyre are colliding to the plane but my vehicle body in not colliding with the plane.
also body position in WS is coming below the tyre position.
I print the body position and tyre position then it comes --
body y axis ----> -0.234
tyre y axis -----> 0.5
tyre are colliding with plane and never go down but don't know about the vehicle body.
Any suggestion will be of great help.
Raycast vehicle not collided with ground
-
- Posts: 28
- Joined: Mon Aug 29, 2011 11:02 am
-
- Posts: 11
- Joined: Wed Aug 25, 2010 12:57 am
Re: Raycast vehicle not collided with ground
Has the vehicles rigidbody been added to the simulation world?
Many of the demos, including the main vehicle demo, use a function in DemoApplication.cpp to add rigid bodies, and it's within this function that the rigidbody is added to the simulation:
btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
...
m_dynamicsWorld->addRigidBody(body); <<<<
When I first tried to create a vehicle demo I created my own 'chassis' and didn't use this function, and my vehicles dropped though the ground!
So, are you using this function? If not, are you adding your vehicles rigidbody / 'chassis' to the simulation yourself?
Many of the demos, including the main vehicle demo, use a function in DemoApplication.cpp to add rigid bodies, and it's within this function that the rigidbody is added to the simulation:
btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
...
m_dynamicsWorld->addRigidBody(body); <<<<
When I first tried to create a vehicle demo I created my own 'chassis' and didn't use this function, and my vehicles dropped though the ground!

So, are you using this function? If not, are you adding your vehicles rigidbody / 'chassis' to the simulation yourself?
-
- Posts: 28
- Joined: Mon Aug 29, 2011 11:02 am
Re: Raycast vehicle not collided with ground
Skuzz wrote:Has the vehicles rigidbody been added to the simulation world?
Many of the demos, including the main vehicle demo, use a function in DemoApplication.cpp to add rigid bodies, and it's within this function that the rigidbody is added to the simulation:
btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
...
m_dynamicsWorld->addRigidBody(body); <<<<
When I first tried to create a vehicle demo I created my own 'chassis' and didn't use this function, and my vehicles dropped though the ground!
So, are you using this function? If not, are you adding your vehicles rigidbody / 'chassis' to the simulation yourself?
yes i am adding rigid body in simulation world, actually i am doing the same thing as given in the vehicle demo.
The code is shown as below
Code: Select all
btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,0.5f,2.f));//1,0.5,2//2,1,4.5
m_collisionShapes.push_back(chassisShape);
btCompoundShape* compound = new btCompoundShape();
m_collisionShapes.push_back(compound);
btTransform localTrans;
localTrans.setIdentity();
localTrans.setOrigin(btVector3(0,1,0));
compound->addChildShape(localTrans,chassisShape);
tr.setOrigin(btVector3(0,3.f,0));
m_carChassis = localCreateRigidBody(800,tr,compound);//chassisShape);
m_wheelShape = new btCylinderShapeX(btVector3(wheelWidth,wheelRadius,wheelRadius));
// clientResetScene();
// create vehicle
{
m_vehicleRayCaster = new btDefaultVehicleRaycaster(dynamicsWorld);
m_vehicle = new btRaycastVehicle(m_tuning,m_carChassis,m_vehicleRayCaster);
//never deactivate the vehicle
m_carChassis->setActivationState(DISABLE_DEACTIVATION);
dynamicsWorld->addVehicle(m_vehicle);
//Now for the wheels : choose coordinate system
m_vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
float connectionHeight = 1.2f;
//Front wheels : only affected by steering
bool isFrontWheel=true;
btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius);
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius);
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
//Back wheels : only affected by engines
isFrontWheel = false;
connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius);
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
connectionPointCS0 = btVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius);
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
...
...
-
- Posts: 11
- Joined: Wed Aug 25, 2010 12:57 am
Re: Raycast vehicle not collided with ground
Are you calculating the inertia tensor for when you create the rigidbody? Also, disabling deactivation?
Code: Select all
...
btVector3 localInertia(0,0,0);
compoundShape->calculateLocalInertia( mass, localInertia );
btRigidBody::btRigidBodyConstructionInfo rbInfo( mass, motionState, compoundShape, localInertia);
btRigidBody* vehicleBody = new btRigidBody(rbInfo);
vehicleBody->setActivationState(DISABLE_DEACTIVATION); // never deactivate the vehicle
-
- Posts: 28
- Joined: Mon Aug 29, 2011 11:02 am
Re: Raycast vehicle not collided with ground
yes i am doing this in localcreateRigidbody function as givenSkuzz wrote:Are you calculating the inertia tensor for when you create the rigidbody? Also, disabling deactivation?
Code: Select all
... btVector3 localInertia(0,0,0); compoundShape->calculateLocalInertia( mass, localInertia ); btRigidBody::btRigidBodyConstructionInfo rbInfo( mass, motionState, compoundShape, localInertia); btRigidBody* vehicleBody = new btRigidBody(rbInfo); vehicleBody->setActivationState(DISABLE_DEACTIVATION); // never deactivate the vehicle
Code: Select all
btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
shape->calculateLocalInertia(mass,localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
btRigidBody* body = new btRigidBody(cInfo);
body->setContactProcessingThreshold(m_defaultContactProcessingThreshold);
dynamicsWorld->addRigidBody(body);
return body;
}