BtOgre - My Own 'Thin' Bullet-Ogre Connection

nikki

01-01-2009 10:06:00

Ok, I know this is the OgreBullet forum, but I thought I'd mention my little 'BtOgre' wrapper I created this saturday for a 'thin' Bullet-Ogre connection. This wrapper does not try to provide its own RigidBody or CollisionShape classes. Instead, you talk directly with Bullet. The only thing it does is connect the btRigidBodies (only rigid bodies for now, I'm still not good with soft bodies) to their SceneNodes, convert Ogre meshes to Bullet convex hulls and triangle meshes etc., provide a debug drawing mechanism (only basic drawing for now, there's no per-object drawing yet), and a Bullet-Ogre vector/quaternion conversion utility.

You can get it here:-
BtOgre 09.01.01

Just include the needed header files, and compile and link BtOgre.cpp with your project.

For a quick test, just follow this tutorial, but instead of the default motion state, use BtOgre::RigidBodyState(pos, rot, node). For example, here's some rigid body creation code from one of my own test apps:-

//Create Ogre stuff.
mEntity = mSceneManager->createEntity(idStr + "sphereEntity", "Sphere.mesh");
mNode = mSceneManager->getRootSceneNode()->createChildSceneNode(idStr + "sphereSceneNode", pos, rot);
mNode->attachObject(mEntity);

//Create shape.
BtOgre::StaticMeshToShapeConverter converter(mEntity);
mShape = converter.createSphere(); //You can also just use btSphereShape(5) or something.

//Calculate inertia.
btScalar mass = 5;
btVector3 inertia;
mShape->calculateLocalInertia(mass, inertia);

//Create BtOgre MotionState (connects Ogre and Bullet).
BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(btTransform(BtOgre::Convert::toBullet(rot), BtOgre::Convert::toBullet(pos)), mNode);

//Create the Body.
mBody = new btRigidBody(mass, state, mShape, inertia);
/*btDynamicsWorld*/ mDynWorld->addRigidBody(mBody);

Here's an example of triangle-mesh-making (the shape converters are adapted from tuan's code, thanks tuan! ;) ):-

BtOgre::StaticMeshToShapeConverter converter(mEntity);
/*btBvhTriangleMeshShape*/ mShape = converter.createTrimesh();

Here's how you can use the debug-drawer:-

/*BtOgre::DebugDrawer*/ mDebugDrawer = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode());
/*btDynamicsWorld*/ mDynWorld->setDebugDrawer(Globals::dbgdraw);

BtOgre encourages raw Bullet usage. :D

nikki

01-01-2009 19:33:16

Check the post in the Ogre forums. It's more accurate and up to date.

tuan kuranes

05-01-2009 10:21:14

You're welcome ;)

Very nice idea indeed.

I wonder if it would be possible to base ogrebullet on that, so that user have the choice of "wrapping" level and get some benefits of sharing code (svn, converter, state, debug)

nikki

14-01-2009 17:35:10

I wonder if it would be possible to base ogrebullet on that, so that user have the choice of "wrapping" level and get some benefits of sharing code (svn, converter, state, debug)
Actually, it was based on OgreBullet, and is more a subset of OgreBullet than something you'd base OgreBullet on. There's nothing special in BtOgre, it dos the usual MotionState stuff, mesh conversion stuff, vector/quaternion conversion etc.