Page 1 of 1
Box falls on its edge. It doesn't come to rest on its face
Posted: Thu Mar 01, 2007 8:10 pm
by sridhar
Hi,
In my application, i have modelled a simple cube as a BOX-PROXY_SHAPE and am using discrete dynamics. The cube falls under gravity on a groundplane and doesnt come to rest on its face.
I tried implementing this by using the ccdphysicsdemo application as my guideline.
The cube comes to rest with its edge in contact with the gorundplane....and not the face. So the simulation is not realistic.
Kindly help me in this regard.
Thanx,
Sridhar.
Posted: Thu Mar 01, 2007 8:24 pm
by Dirk Gregorius
Well in a perfect mathematical world if you drop a box on the edge it comes indeed to rest on the edge.
Posted: Thu Mar 01, 2007 9:37 pm
by bone
... assuming the CG is directly above the edge, yes?
Posted: Thu Mar 01, 2007 9:45 pm
by Dirk Gregorius
yes, otherwise you introduce of course a torque and the box will come to rest on its side
Posted: Thu Mar 01, 2007 10:33 pm
by Erwin Coumans
This is a 'Bullet' specific topic, so I moved it to the Bullet section.
Can you reproduce this in the CcdPhysicsDemo? Do you have any screenshot, or a movie of your simulation?
Is the object deactivated when at rest? Please try to press 'd' to disable sleeping to see what happens.
Thanks,
Erwin
Posted: Thu Mar 01, 2007 11:11 pm
by sridhar
yes.....the Center of gravity(CG) is not above the edge of the box. Even then it rests on the edge, instead of resting on one of the 6 faces of a cube.
I tried to drop the box such that it makes a point contact with the groud plane. Even then immediately after making the contact, it doesnt topple and doesnt come to rest on one of the faces.
I checked the ccdphysics demo, in that demo, the boxes come to rest on one of the faces.
This is my code,
Code: Select all
btCollisionShape* boxShape = new btBoxShape(btVector3((M.x-m.x)*0.5f, (M.y-m.y)*0.5f, (M.z-m.z)*0.5f)); //need to give btVector3 of halfExtents
boxShape->setMargin(gCollisionMargin);
s = mObjMgr->ObjInstances[i]->Scale;
boxShape->setLocalScaling(btVector3(s, s, s));
btRigidBody* BTWorld::LocalCreateRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape)
{
//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
//btMotionState allows the dynamics world to synchronize the updated world transforms with graphics objects
//#define USE_MOTIONSTATE 1
//#ifdef USE_MOTIONSTATE
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
myMotionState->setWorldTransform(startTransform);
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
body->setCenterOfMassTransform(startTransform);
//#else
// btRigidBody* body = new btRigidBody(mass,startTransform,shape,localInertia);
//#endif
assert(mDynamicsWorld);
assert(body);
mDynamicsWorld->addRigidBody(body);
return body;
}