I'm doing an application and I use btConvexHullShapes but I encounter a problem.
The collision is well calculated but not the moves.
Here's a video of my problem with a simple cube :
http://www.youtube.com/watch?v=zMasdqb6z34
As you can see, it looks like the Center of gravity is outside of the shape.
All in all, it has a weird behaviour.
As you'll see in my code, I didn't do anything else than creating the object, and giving it a mass and an inertia.
I didn't modify the CoG, thinking it was automatically initialized in the middle of the cube (is it wrong ? Do I have do initiate it ?)
Here's the constructor of the class that buil the btConvexHullShapes :
Code: Select all
ConvexHullShape::ConvexHullShape(btVector3 * tab, btTransform &TransformCHS)
{
CHS = new btConvexHullShape();
for(int i=0; i<8; i++)
{
CHS->addPoint(tab[i]);
}
TransformCHS.setIdentity();
TransformCHS.setOrigin(btVector3(0.0,25.0,0.0));
TransformCHS.setRotation(btQuaternion(1,0,0,2));
localInertia=btVector3(0,0,0);
mass = 0.5f;
CHS->calculateLocalInertia( mass, localInertia );
MotionStateCHS = new btDefaultMotionState(TransformCHS);
btRigidBody::btRigidBodyConstructionInfo myBoxRigidBodyConstructionInfo(0.5, MotionStateCHS, CHS, localInertia );
bodyCHS = new btRigidBody(myBoxRigidBodyConstructionInfo);
}
Code: Select all
myWorld->setGravity( btVector3(0,-9.8,0) );
//vertices of the cube
tab[0] = btVector3 (0.0,0.0,0.0);
tab[1] = btVector3 (10.0,0.0,0.0);
tab[2] = btVector3 (10.0,0.0,10.0);
tab[3] = btVector3 (0.0,0.0,10.0);
tab[4] = btVector3 (0.0,10.0,0.0);
tab[5] = btVector3 (10.0,10.0,0.0);
tab[6] = btVector3 (10.0,10.0,10.0);
tab[7] = btVector3 (0.0,10.0,10.0);
CHS_mon_Model=ConvexHullShape(tab,myTransform);
myWorld->addRigidBody(CHS_mon_Model.bodyCHS);
/// FLOOR ===================================================
btCollisionShape* shape_sol = new btBoxShape( btVector3(100,0,100) );
myTransform.setIdentity();
myTransform.setOrigin( btVector3(0,0,0) );
btVector3 localInertiaSol(0,0,0);
btScalar mass = 0.0f;
myMotionState_Sol = new btDefaultMotionState(myTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo_sol( mass, myMotionState_Sol, shape_sol, localInertiaSol );
body_sol = new btRigidBody(rbInfo_sol);
myWorld->addRigidBody(body_sol);
//=====================================================================
InitCallbacks();
glutDisplayFunc(Display);
glutMainLoop();
}
Code: Select all
if (myWorld && aff==true) //si myWorld est instancié et si 'a' a été appuyée
{
myWorld->stepSimulation(1.f/60, 10);
myWorld->debugDrawWorld();
}
CHS_mon_Model.MotionStateCHS->m_graphicsWorldTrans.getOpenGLMatrix(CHS_mon_Model.MatrixCHS);
glPushMatrix();
glMultMatrixf(CHS_mon_Model.MatrixCHS);
if(mod==true){
DrawBox();
}
glPopMatrix();
DrawFloor();
Is it really a problem of CoG and how do I modify it if that's the case ?
Thank you