Simulating objects in a box.

SnT2k
Posts: 3
Joined: Fri Aug 15, 2008 9:12 am

Simulating objects in a box.

Post by SnT2k »

I want to simulate objects placed in a constrained space (in, this case... a box, but in can be anything like a sphere). So, what I did was that I used a btBoxShape as my "ground" shape, made it big and... uh.. placed objects "in it".

I tried it and... it fails because the objects keep on wanting to go "out" of the box (which I assume is part of preventing interpenetrations).

A possible alternative is to make 6 btStaticPlanes or near-flat btBoxShape, one for each side to make it work.

In any case, are there better methods than the one I stated above? Like is possible to just "reverse" the normals of the faces of the box so that the interpenetration tests go the other way around? Thanks.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Simulating objects in a box.

Post by sparkprime »

boxes, spheres, cones, etc are solid. convex hulls are also solid. compound shapes are supposed to be solid but sometimes things can get jammed between the primitives comprising them and wobble violently. Planes are also "solid" in the sense that they fill all of the volume on one side of them. This is probably the best way to enclose the level if you don't want anything to move about outside the level. Don't use a plane constant of 0 though, when you construct the btStaticPlaneShape. It doesn't work for some reason.

btBvhTriangleMeshShape is not solid and stuff will happily move around inside and outside, bouncing off the triangles. They can only be used for static rigidbodies though. Also note that since the triangles are essentially infinitely thin, stuff can go through them quite easily if you don't cap the max velocity, make dynamic rigid bodies large enough, or use the ccd dynamics world (which isn't finished yet).
SnT2k
Posts: 3
Joined: Fri Aug 15, 2008 9:12 am

Re: Simulating objects in a box.

Post by SnT2k »

Thanks for the tip.

May I ask what's the "plane constant" parameter in btStaticPlaneShape? Is it the d in "ax + by + cz + d = 0"?
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Simulating objects in a box.

Post by sparkprime »

Yeah, something like that.
SnT2k
Posts: 3
Joined: Fri Aug 15, 2008 9:12 am

Re: Simulating objects in a box.

Post by SnT2k »

I had another problem... well... I forgot to mention earlier that the box moves...

So I have things launching faster than a rocket ship and bouncing around the space when the box moves a little bit. More accurately, there's a gravity of (0,-98,0) so when I move the box by (0,1,0)... well.. things fly....

I tried increasing the max number of steps and.. same problems.

I made the "box" into a kinematic rigidbody but here's the code just in case if I screwed up its initialization:

Code: Select all

m_groundShape = new btStaticPlaneShape(btVector3(0,1,0), .01f);
	
	//Create the Ground
	{
		btScalar mass(0.);
		
		btVector3 localInertia(0,0,0);

		//back
		{
			m_groundTransform[0].setIdentity();
			m_groundTransform[0].setOrigin(btVector3(0,0,0));
			btDefaultMotionState *myMotionState = new btDefaultMotionState(m_groundTransform[0]);
			
			btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,m_groundShape,localInertia);
			rbInfo.m_restitution = FLOOR_RESTITUTION;
			rbInfo.m_friction = 1;
			rbInfo.m_linearDamping = 100;
			rbInfo.m_angularDamping = 10;
			rbInfo.m_additionalDamping = 2;
			m_groundBody[0] = new btRigidBody(rbInfo);
			m_groundBody[0]->setCollisionFlags(m_groundBody[0]->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
			m_groundBody[0]->setActivationState(DISABLE_DEACTIVATION);
			m_dynamicsWorld->addRigidBody(m_groundBody[0]);
		}
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Simulating objects in a box.

Post by sparkprime »

The fact that it moves is rather crucial. Planes cannot be moved (I've never actually tried...), hence the "static" in the title. If you want moving walls then you'll have to use a convex shape, maybe 6 thick boxes to enclose the space. Thick enough that nothing can penetrate them.