problem with basic test: box falling through the ground

rogerdv

15-07-2010 22:26:29

Im trying to make a basic test based on tutorial code available in wiki. I use this code to create the shapes:

void btPhysics::createStaticShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node)
{
Vector3 size;
AxisAlignedBox boundingB = mesh->getBoundingBox();
size = boundingB.getSize();
size /= 2.0f; // only the half needed
size *= 0.96f;
OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
// and the Bullet rigid body
OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody(name, mWorld);
defaultBody->setShape(node, sceneBoxShape, 0.6f, // dynamic body restitution
0.6f, // dynamic body friction
1.0f, // dynamic bodymass
node->getPosition(), // starting position of the box
Quaternion(0,0,0,1));// orientation of the box

}


And this one to create a plane, as ground:

void btPhysics::createPlane() {
OgreBulletCollisions::CollisionShape *Shape;
Shape = new OgreBulletCollisions::StaticPlaneCollisionShape(Ogre::Vector3(0,1,0), 0); // (normal vector, distance)
OgreBulletDynamics::RigidBody *defaultPlaneBody = new OgreBulletDynamics::RigidBody("BasePlane", mWorld);
defaultPlaneBody->setStaticShape(Shape, 0.1, 0.8); // (shape, restitution, friction)
// push the created objects to the deques
mShapes.push_back(Shape);
mBodies.push_back(defaultPlaneBody);
};


But, no matter how high I set the object position, it appears half buried in ground plane and quickly sinks. Any idea about what Im doing wrong?

Fish

16-07-2010 02:34:27

How large is your box? If the physics body is too small you will have problems like that. See scaling the world. Physics bodies smaller than 0.05 units will tend to have this problem.

- Fish

rogerdv

16-07-2010 13:00:23

boundingB.getSize() reports Vector3(2.04, 2.04, 2.04). I also tried scaling up and removing
size /= 2.0f;
size *= 0.96f;


The same. The box looks a bit bigger, because I scaled it, but again falls throuhg the ground.

Fish

16-07-2010 16:07:16

Try turning on the debug drawer to make sure the collision shapes are where you think they are:

CollisionsWorld::setShowDebugShapes(true);

- Fish

rogerdv

16-07-2010 16:49:55

Thats worse. I get this error:

An exception has occured: OGRE EXCEPTION(5:ItemIdentityException): Cannot find a group named OgreBulletCollisions in ResourceGroupManager::isResourceGroupInitialised at /home/roger/projects/ogre_src_v1-7-1/OgreMain/src/OgreResourceGroupManager.cpp (line 1889)DefaultWorkQueue('Root') shutting down on thread 0x671d60.
DefaultWorkQueue('Root')::WorkerFunc - thread 0x7c3ab0 stopped

Fish

16-07-2010 20:55:49

Are you using the newest version of OB from the SVN? That error should have been fixed. If you are using the newest version, can you please provide a stack trace?

- Fish

rogerdv

16-07-2010 21:49:16

Ok, updated from svn, error solved. But no debug shapes are displayed, and the box keeps falling. Here is my init code:


mWorld = new OgreBulletDynamics::DynamicsWorld(smgr, AxisAlignedBox (Ogre::Vector3 (-10000, -10000, -10000),Ogre::Vector3 (10000, 10000, 10000)), Vector3(0,-9.81,0));
mWorld->setShowDebugShapes(true);

Fish

17-07-2010 02:06:58

The only difference I can see between your code and my own with respect to planes is that I use RigidBody::setShape with a mass of 0 instead of RigidBody::setStaticShape. Can you try RigidBody::setShape and see if it does anything for you. The debug lines may not be showing because the physics shape is smaller than the mesh, or possibly in an unexpected location.

If you post a compilable test case, I can probably help you more easily.

- Fish

rogerdv

19-07-2010 20:02:50

fixed! I made a terrible mistake: was creating the shape, but missed to associate it to a plane node. Now the box falls on the plane and bounces (dont like that, but can be fixed too).