Box falls on its edge. It doesn't come to rest on its face

sridhar
Posts: 3
Joined: Thu Mar 01, 2007 5:52 am

Box falls on its edge. It doesn't come to rest on its face

Post 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.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Post 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.
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Post by bone »

... assuming the CG is directly above the edge, yes?
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Post by Dirk Gregorius »

yes, otherwise you introduce of course a torque and the box will come to rest on its side
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post 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
sridhar
Posts: 3
Joined: Thu Mar 01, 2007 5:52 am

Post 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;
}