I have a very simple world, where i have a ground object (static) with the collision shape of a cube mesh that the user provides, and another cube (dynamic), smaller than the ground cube, with the collision shape provided also by the user.
I place the dynamic cube on top of the static one and run the simulation with no forces, nothing happen, as expected, i just run this step to make sure that no collisions occur.
However, when i set the gravity to (0,-9.8,0), the dynamic cube seems to rollover and slide on the ground cube for no obvious reason!!
both cubes are in contact at the x/z plane, so the expected behavior should be, than the dynamic cube remains still, however, it doesn't, and i don't know why, can anyone help me out with this?
This is the constructor of my class, and the initphysics() function
Code: Select all
mechanism::mechanism(bool enable_gravity)
{
if(enable_gravity)
gravity=btVector3(0,-9.8,0);
else
gravity=btVector3(0,0,0);
initPhysics();
joints_size=0;
}
Code: Select all
void mechanism::initPhysics()
{
//1
broadphase = new btDbvtBroadphase();
//2
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
//3
solver = new btSequentialImpulseConstraintSolver();
//4
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
//5
dynamicsWorld->setGravity(gravity);
}
Code: Select all
void mechanism::set_up_models(vector<Model> m,graph g,vector<descriptor> state,vector<int> movable)
{
btRigidBody* trb;
btDefaultMotionState* tms;
btCollisionShape* tcs;
btTriangleMesh* ttm;
btConvexTriangleMeshShape* tctms;
btTypedConstraint* ttc;
//btHingeConstraint* ttc;
double pi=3.14159265359;
vector<int>::iterator it;
//create fall shape(s) and set them up
for(int i=0;i<m.size();i++)
{
fallRigidBodies.push_back(trb);
fallMotionStates.push_back(tms);
fallShapes.push_back(tcs);
T.push_back(ttm);
////new
T[i]=new btTriangleMesh();
for(int j=0;j<m[i].f.size();j++)
{
int a=m[i].f[j].a-1;
int b=m[i].f[j].b-1;
int c=m[i].f[j].c-1;
btVector3 v0(m[i].v[a].x,m[i].v[a].y,m[i].v[a].z);
btVector3 v1(m[i].v[b].x,m[i].v[b].y,m[i].v[b].z);
btVector3 v2(m[i].v[c].x,m[i].v[c].y,m[i].v[c].z);
T[i]->addTriangle(v0,v1,v2);
}
fallShapes[i]=new btConvexTriangleMeshShape(T[i]);
fallShapes[i]->setMargin(0.f);
fallMotionStates[i] =new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
////end new
btScalar mass;
btVector3 fallInertia(0, 0, 0);
it=std::find(movable.begin(),movable.end(),i);
if(it==movable.end())
{
mass=0;
}
else
{
mass=m[i].get_bb_volume();
}
fallShapes[i]->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionStates[i], fallShapes[i], fallInertia);
fallRigidBodyCI.m_restitution=0.0f;
//fallRigidBodyCI.m_friction=0.0f;
fallRigidBodies[i] = new btRigidBody(fallRigidBodyCI);
fallRigidBodies[i]->setRestitution(0.0f);
//fallRigidBodies[i]->setFriction(0.0f);
dynamicsWorld->addRigidBody(fallRigidBodies[i]);
}
fallRigidBodies_size=m.size();
}