BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.

BtOgre - Simple, Thin Bullet-Ogre Connection (now on git!)

Postby nikki » Thu Jan 01, 2009 3:47 pm

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, and a Bullet-Ogre vector/quaternion conversion utility.

Here's a screenshot of a quick app I made by editing the NGF demo (don't mind the FPS, I'm on a laptop now). You can see the debug draw in action. The two spiky balls are joined, there's a joint line between them:-

Image

You can get it at the BtOgre github repository. If you don't want to use git, there's also an option to download an archive (zip/tarball) there.

Just include the needed header files, and compile and link BtOgre.cpp with your project. A small demo application is included in the archive.

For a quick start, check out the demo application or follow this tutorial, and also initialise Ogre along with the physics. Instead of the default motion state, use BtOgre::RigidBodyState(btTransform, Ogre::SceneNode), passing the SceneNode you want it to move. Of course, you can skip the entire MotionState idea and update it per-frame if you want. Here, you're in control. ;) For example, here's some rigid body creation code from one of my own test apps:-

Code: Select all
//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(1.2) 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(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! ;) ):-

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

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

Code: Select all
Setup:
/*BtOgre::DebugDrawer*/ mDebugDrawer = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode(), mDynWorld);
/*btDynamicsWorld*/ mDynWorld->setDebugDrawer(mDebugDrawer);

Per-frame:
mDebugDrawer->step();

BtOgre encourages raw Bullet usage. :D
Last edited by nikki on Sat Dec 26, 2009 9:47 pm, edited 15 times in total.

For this message the author nikki has received 2 kudos
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nullsquared » Thu Jan 01, 2009 5:54 pm

Very intriguing :D. Out of curiosity, how do you draw the debug geometry? I'm more of a Newton guy myself, but I'm sure someone will come across in need of a not-so-heavy integration for Bullet.
User avatar
nullsquared
Old One
 
Posts: 3245
Kudos: 9
Joined: 24 Apr 2007
Location: NY, NY, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Thu Jan 01, 2009 6:05 pm

nullsquared wrote:Very intriguing :D. Out of curiosity, how do you draw the debug geometry? I'm more of a Newton guy myself, but I'm sure someone will come across in need of a not-so-heavy integration for Bullet.

If you're asking how one can use BtOgre to draw it, its mentioned at the end of the first post. ;)

If you're asking how its implemented in BtOgre itself, Bullet provides an abstract 'btIDebugDraw', from which you inherit and implement the 'drawLine', 'drawContactPoint' etc. methods.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Thu Jan 01, 2009 7:14 pm

I was wondering, what's the best way to get quick 3d text? Ok, there are a few methods on the wiki, but these are mainly 'create an object and keep it attached to a SceneNode and update the SceneNode' kinds of things. The problem is, Bullet just calls a callback function giving the position and the string whenever needed. There's no concept of a a 'long-term text object', its more on a 'per-frame basis'. A wire-frame text should be enough.
Last edited by nikki on Mon Mar 09, 2009 11:05 pm, edited 1 time in total.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby rebol » Wed Jan 14, 2009 7:17 am

Nikki, I put a player on top of my ground, but the player didn't fall down, I don't know why.
in createScene
Code: Select all
                Globals::gom->createObject<Player>(Vector3(5,5,5), Quaternion::IDENTITY);
      //Create shape.
      Entity* mEntity = Globals::smgr->getEntity("0_playerEntity");
      SceneNode* mNode= Globals::smgr->getSceneNode("0_playerObjectSceneNode");
      Vector3 pos      = mNode->getPosition();
      Quaternion rot   = mNode->getOrientation();
      BtOgre::StaticMeshToShapeConverter converter(mEntity);
      //btCollisionShape* mShape = converter.createSphere(); //You can also just use btSphereShape(1.2) or something.
      btCollisionShape* mShape = new btSphereShape(1.0);
      //Calculate inertia.
      btScalar mass = 1;
      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);
      
      Globals::gDebugDrawer = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode(), Globals::gDynsWorld);
      Globals::gDynsWorld->setDebugDrawer(Globals::gDebugDrawer);
      //Create the Body.
      btRigidBody::btRigidBodyConstructionInfo player_rbInfo(mass, state, mShape, inertia);

      Globals::mBody = new btRigidBody(player_rbInfo);
      Globals::gDynsWorld->addRigidBody(Globals::mBody);
      // add ground
      Globals::gom->createObject<LevelGeometry>(Vector3::ZERO, Quaternion::IDENTITY,
      NGF::PropertyList::create("brushMeshFile","TestLevel_b0.mesh"));

      Entity* mGroundEntity = Globals::smgr->getEntity("1_levelGeometryEntity");
      SceneNode* mGroundNode= Globals::smgr->getSceneNode("1_levelGeometryObjectSceneNode");
      Vector3 ground_pos      = mGroundNode->getPosition();
      Quaternion ground_rot   = mGroundNode->getOrientation();
      BtOgre::StaticMeshToShapeConverter ground_converter(mGroundEntity);
      //btCollisionShape* mShape = ground_converter.createSphere(); //You can also just use btSphereShape(1.2) or something.
      btCollisionShape* mGroundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
      //Calculate inertia.
      btScalar ground_mass = 0;
      btVector3 ground_inertia(0,0,0);
      BtOgre::RigidBodyState *ground_state = new BtOgre::RigidBodyState(btTransform(BtOgre::Convert::toBullet(ground_rot), BtOgre::Convert::toBullet(ground_pos)), mGroundNode);
      btRigidBody::btRigidBodyConstructionInfo rbInfo(ground_mass, ground_state, mGroundShape, ground_inertia);

      Globals::groundRigidBody = new btRigidBody(rbInfo);
      Globals::gDynsWorld->addRigidBody(Globals::groundRigidBody);

in frameStarted
Code: Select all
Globals::gDynsWorld->stepSimulation(1/100.f,7);
      btTransform trans;
      Globals::mBody->getMotionState()->getWorldTransform(trans);
      std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;

I've initiated the global variables.
In contrast, the sphere in the bullet's hello world demo is falling down.
rebol
Kobold
 
Posts: 34
Kudos: 0
Joined: 09 Sep 2008

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby Statement » Wed Jan 14, 2009 1:58 pm

This looks nice, easy and minimalistic. Just what I'm looking for. Is there any license to the code? Can I use it for whatever I like?

Keep up the good work!
Statement
Gnoblar
 
Posts: 13
Kudos: 0
Joined: 18 Dec 2008

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Wed Jan 14, 2009 3:50 pm

@Statement: Haven't thought about the license yet. Right now, its under a 'whatever' license.

@rebol: I'm creating a test application now, and I'll put in your code and check it. Hold on. ;)
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby Statement » Wed Jan 14, 2009 4:52 pm

@Nikki Sorry, I'm not sure I understand what you mean by a "whatever" license :) Is it ok to use commercially?
Statement
Gnoblar
 
Posts: 13
Kudos: 0
Joined: 18 Dec 2008

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Wed Jan 14, 2009 4:54 pm

Statement wrote:@Nikki Sorry, I'm not sure I understand what you mean by a "whatever" license :) Is it ok to use commercially?

Sure, I'd be honoured! :D

I think I'm going to make it BSD, so you can check the terms of that license out.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Wed Jan 14, 2009 5:11 pm

rebol, try this simple application and see if it works for you. Its quite similar to what you're trying to accomplish:-

Code: Select all
/*
 * =====================================================================================
 *
 *       Filename:  main.cpp
 *
 *    Description:  BtOgre test application, main file.
 *
 *        Version:  1.0
 *        Created:  01/14/2009 05:48:31 PM
 *
 *         Author:  Nikhilesh (nikki)
 *
 * =====================================================================================
 */

#include "ExampleApplication.h"
#include "BtOgrePG.h"
#include "BtOgreGP.h"
#include "BtOgreExtras.h"

/*
 * =====================================================================================
 *    Namespace:  Globals
 *  Description:  A dirty 'globals' hack.
 * =====================================================================================
 */

namespace Globals
{
    btDynamicsWorld *phyWorld;
    BtOgre::DebugDrawer *dbgdraw;
}

/*
 * =====================================================================================
 *        Class:  BtOgreTestFrameListener
 *  Description:  Derives from ExampleFrameListener and overrides stuf.
 * =====================================================================================
 */

class BtOgreTestFrameListener : public ExampleFrameListener
{
    protected:

    public:
   BtOgreTestFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
       : ExampleFrameListener(win, cam, false, false)
   {
   }

   bool frameStarted(const FrameEvent &evt)
   {
       //Update Bullet world. Don't forget the debugDrawWorld() part!
       Globals::phyWorld->stepSimulation(evt.timeSinceLastFrame, 10);
       Globals::phyWorld->debugDrawWorld();

       //Shows debug if F3 key down.
       Globals::dbgdraw->setDebugMode(mKeyboard->isKeyDown(OIS::KC_F3));
       Globals::dbgdraw->step();

       return ExampleFrameListener::frameStarted(evt);
   }
};

/*
 * =====================================================================================
 *        Class:  BtOgreTestApplication
 *  Description:  Derives from ExampleApplication and overrides stuff.
 * =====================================================================================
 */

class BtOgreTestApplication : public ExampleApplication
{
    protected:
   btAxisSweep3 *mBroadphase;
   btDefaultCollisionConfiguration *mCollisionConfig;
   btCollisionDispatcher *mDispatcher;
   btSequentialImpulseConstraintSolver *mSolver;

   Ogre::SceneNode *mNinjaNode;
   Ogre::Entity *mNinjaEntity;
   btRigidBody *mNinjaBody;
   btCollisionShape *mNinjaShape;

   btRigidBody *mGroundBody;
   btCollisionShape *mGroundShape;

    public:
   BtOgreTestApplication()
   {
       //Create Bullet stuff.
       mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
       mCollisionConfig = new btDefaultCollisionConfiguration();
       mDispatcher = new btCollisionDispatcher(mCollisionConfig);
       mSolver = new btSequentialImpulseConstraintSolver();

       //Create DebugDrawer.
       Globals::phyWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
       Globals::phyWorld->setGravity(btVector3(0,-9.8,0));
   }

   ~BtOgreTestApplication()
   {
       //Free Bullet stuff.
       delete mSolver;
       delete mDispatcher;
       delete mCollisionConfig;
       delete mBroadphase;
   }

    protected:
   void createScene(void)
   {
       //Some normal stuff.
       mSceneMgr->setAmbientLight(ColourValue(0.7,0.7,0.7));
       mCamera->setPosition(Vector3(40,40,40));
       mCamera->lookAt(Vector3::ZERO);

       //----------------------------------------------------------
       // Debug drawing!
       //----------------------------------------------------------

       Globals::dbgdraw = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode(), Globals::phyWorld);
       Globals::phyWorld->setDebugDrawer(Globals::dbgdraw);

       //----------------------------------------------------------
       // Ninja!
       //----------------------------------------------------------

       Vector3 pos = Vector3::ZERO;
       Quaternion rot = Quaternion::IDENTITY;

       //Create Ogre stuff.
       mNinjaEntity = mSceneMgr->createEntity("ninjaEntity", "ninja.mesh");
       mNinjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ninjaSceneNode", pos, rot);
       mNinjaNode->attachObject(mNinjaEntity);

       //Create shape.
       BtOgre::StaticMeshToShapeConverter converter(mNinjaEntity);
       mNinjaShape = converter.createConvex();

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

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

       //Create the Body.
       mNinjaBody = new btRigidBody(mass, ninjaState, mNinjaShape, inertia);
       Globals::phyWorld->addRigidBody(mNinjaBody);

       //----------------------------------------------------------
       // Ground! (can't see it though)
       //----------------------------------------------------------

       //Create the ground plane shape.
       mGroundShape = new btStaticPlaneShape(btVector3(0,1,0), -50);

       //Create MotionState (no need for BtOgre here, you can use it if you want to though).
       btDefaultMotionState* groundState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));

       //Create the Body.
       mGroundBody = new btRigidBody(0, groundState, mGroundShape, btVector3(0,0,0));
       Globals::phyWorld->addRigidBody(mGroundBody);
   }

   void createFrameListener(void)
   {
       mFrameListener = new BtOgreTestFrameListener(mWindow, mCamera, mSceneMgr);
       mRoot->addFrameListener(mFrameListener);
   }
};

/*
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  main() function. Need say more?
 * =====================================================================================
 */

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    BtOgreTestApplication app;

    try {
   app.go();
    } catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
   MessageBox( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
   fprintf(stderr, "An exception has occurred: %s\n",
      e.what());
#endif
    }

    return 0;
}

(you can get the new version from Jan 29, 2009 above, which includes this demo)
BtOgreTest.tar.bz2
A little BtOgre test application
(2.14 KiB) Downloaded 613 times

EDIT: rebol, you're using NGF? :D Just noticed. If you are, I can send you the NGF demo modified to use BtOgre. That was my original BtOgre test application actually.

EDIT (Jan 29, 2009): The new version now includes this demo, just get the new version.
Last edited by nikki on Thu Jan 29, 2009 10:14 am, edited 2 times in total.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby reptor » Wed Jan 14, 2009 9:45 pm

When it's to be used with Bullet then I suggest the license be the same as what Bullet has.
reptor
Ogre Magi
 
Posts: 1120
Kudos: 4
Joined: 15 Nov 2006
Location: Finland

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby zarfius » Fri Jan 16, 2009 12:40 am

I just wanted to point out that the date in the thread title is a little misleading.

I'm all for universal date format but to make it clear that's what your using I suggest putting the full year.

Instead of 09.01.02.. perhaps use 2009.01.02

Currently, the date could be misread as 9th Jan 2002 (australian), 1st Sep 2002 (american), and of course the correct date 2nd Jan 2009 (universal)

Cheers :)
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
zarfius
Gnome
 
Posts: 367
Kudos: 13
Joined: 03 Jan 2007
Location: Brisbane, Australia

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Fri Jan 16, 2009 3:52 pm

zarfius wrote:I just wanted to point out that the date in the thread title is a little misleading.

I'm all for universal date format but to make it clear that's what your using I suggest putting the full year.

Instead of 09.01.02.. perhaps use 2009.01.02

Currently, the date could be misread as 9th Jan 2002 (australian), 1st Sep 2002 (american), and of course the correct date 2nd Jan 2009 (universal)

Cheers :)

Heh, that's not a date really, that's a version format I borrowed from Ubuntu (may be I should've put 9.1.2), which uses dates. I had it this way so that the left-most 'part' is incremented last (sub-version numbers increment in a right-left order). If you still think I should have '2009' there, do tell me.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby jacmoe » Fri Jan 16, 2009 7:58 pm

It should be 9.01, if you follow the Ubuntu version numbering scheme. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, Fueled by Passion.
Ogre AppWizards - Ogre project wizards for VC 8-10, Code::Blocks and KDevelop.
OgreAssimpConverter - command-line to convert models to Ogre format.
TwOgreGUI - wrapper for AntTweakBar GUI library.
I accept donations | Me on Google+
User avatar
jacmoe
OGRE Moderator
OGRE Moderator
 
Posts: 21024
Kudos: 162
Joined: 22 Jan 2004
Location: Denmark

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Fri Jan 16, 2009 10:06 pm

jacmoe wrote:It should be 9.01, if you follow the Ubuntu version numbering scheme. :)

Hmm, yeah, but I modified it to my liking. :P I added the day part because of releases within the same month. Ubuntu usually has 'big' releases every 6 months or so, so they have it that way.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby zarfius » Sat Jan 17, 2009 12:54 am

nikki wrote:Heh, that's not a date really, that's a version format I borrowed from Ubuntu (may be I should've put 9.1.2), which uses dates. I had it this way so that the left-most 'part' is incremented last (sub-version numbers increment in a right-left order). If you still think I should have '2009' there, do tell me.


Heh, yeh.. well that makes sense now. I have used dates as version numbers myself. I guess the leading zero makes it look a little odd for a version number, but who am I to say, anything goes for version numbers these days. Remember the good old days of Doom v1.666 or something like that :)

When you think about it, a version number only serves the purpose of helping the developer figure out what bugs have been fixed in a particular release. However, there is a certain degree marketing psychology involved.

For example, if I see version 0.87 I immediatly assume that the software is unfinished. On the other hand, if I see version 9.11 I assume that the software is very stable and has been developed and revised over a long period of time. Of course, if you see version (11.8237.8211 SP1) it's safe to assume it's Micro$oft trying to take more of your money :P

Anyway, let's not get off topic.. it's good to see a trend towards thin wrappers. I often find that using too much middleware is more hassle than it's worth. I played with Bullet for a few weeks before I decided to go with PhysX and both times I wrote the code to join it with Ogre myself.

Perhaps I will follow your lead and write a thin wrapper for PhysX :)
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
zarfius
Gnome
 
Posts: 367
Kudos: 13
Joined: 03 Jan 2007
Location: Brisbane, Australia

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby lickstab » Mon Jan 19, 2009 3:37 pm

hello, just curious about something.

if i make two shapes with .createTrimesh(), they won't collide/stop when coming in contact with eachother.
is this for a particular reason? using one .createTrimesh and one regular btwhateverShape works fine.
i guess i myself don't have any need for more than one trimesh at a time so it's not a problem.

awesome library though!
User avatar
lickstab
Kobold
 
Posts: 26
Kudos: 0
Joined: 19 Jan 2009
Location: Stockholm, Sweden

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Mon Jan 19, 2009 3:43 pm

lickstab wrote:if i make two shapes with .createTrimesh(), they won't collide/stop when coming in contact with eachother.
is this for a particular reason? using one .createTrimesh and one regular btwhateverShape works fine.

AFAIK, in Bullet, trimeshes are for static bodies only, so collision detection between them is meaningless. Check out the Bullet manual, it has a collision detection yes/no table. You can use createConvex for convex rigid bodies, and createSphere/Box/Cylinder for the 'closest-fit' of these shapes. GIMPACT allows concave rigid bodies.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby zarfius » Mon Jan 19, 2009 10:52 pm

lickstab wrote:if i make two shapes with .createTrimesh(), they won't collide/stop when coming in contact with eachother.
is this for a particular reason? using one .createTrimesh and one regular btwhateverShape works fine.
i guess i myself don't have any need for more than one trimesh at a time so it's not a problem.


Hi lick stab, just so you know most physics libraries have this restriction. There is very good reason for it too, imagine you have an 2 objects with 100 triangles in them each. You could surround them with bounding spheres and the collision detection would be a simple distance test between them.

But, if you try compare every triangle in one object with every triangle in the other object you need about 10,000 tests. There are ways to reduce this number but regardless, it's still a lot of tests for very little gain.

However, in the case of a sphere to a static triangle mesh you are back down to 100 tests at the most, and this can be reduced again by putting the triangles into "areas". In other words, you would only need to test against the triangles in the area your moving object is in.

Most professional games afaik use these same principles. Although, I have simplified them a lot.
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
zarfius
Gnome
 
Posts: 367
Kudos: 13
Joined: 03 Jan 2007
Location: Brisbane, Australia

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nullsquared » Mon Jan 19, 2009 11:10 pm

Also, you can also form concave objects using compound objects.
User avatar
nullsquared
Old One
 
Posts: 3245
Kudos: 9
Joined: 24 Apr 2007
Location: NY, NY, USA

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby lickstab » Tue Jan 20, 2009 2:15 pm

aha. thanks for the replies! makes absolute sense.
i have another question since i'm here anyway, what's an appropriate size for a mesh to use as a trimesh?
that is, if i have a huge piece of terrain and want to make a trimesh out of it.. is there a limit to the size where i should optimize it somehow?
User avatar
lickstab
Kobold
 
Posts: 26
Kudos: 0
Joined: 19 Jan 2009
Location: Stockholm, Sweden

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby jacmoe » Tue Jan 20, 2009 6:08 pm

Bullet has support for terrain, AFAIK. Look into that. :wink:
<edit> Yes: Heightfield shape </edit>
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, Fueled by Passion.
Ogre AppWizards - Ogre project wizards for VC 8-10, Code::Blocks and KDevelop.
OgreAssimpConverter - command-line to convert models to Ogre format.
TwOgreGUI - wrapper for AntTweakBar GUI library.
I accept donations | Me on Google+
User avatar
jacmoe
OGRE Moderator
OGRE Moderator
 
Posts: 21024
Kudos: 162
Joined: 22 Jan 2004
Location: Denmark

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby Shockeye » Wed Jan 21, 2009 12:59 pm

For terrain collision, check out this thread on the Bullet Forum:

http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1554&view=previous

In particular, see the post by Spangle - he attached some code of his implementation of a Terrain collisionshape for use with ogrebullet. It's easy enough to use his technique with bullet directly( or with BtOgre)
User avatar
Shockeye
Gremlin
 
Posts: 154
Kudos: 1
Joined: 24 Nov 2008
Location: 'Straya

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby JeDi » Wed Jan 21, 2009 5:27 pm

Nikki, you made my day :D

We decided to switch to Bullet in our 3D research framework, because it suits our work better then NVidia PhysX (the one we used before). because our framework is component based, and graphics and physics are separated completely, most full wrappers aren't suited for me.

But this provides all the functionality I need to put this in our framework very quickly. Thanks a lot.

Greetz,
JeDi
JeDi
Gnome
 
Posts: 351
Kudos: 3
Joined: 21 Oct 2004
Location: Diepenbeek, Belgium

Re: BtOgre - Simple, Thin Bullet-Ogre Connection (09.01.02)

Postby nikki » Wed Jan 21, 2009 7:22 pm

JeDi wrote:Nikki, you made my day :D

We decided to switch to Bullet in our 3D research framework, because it suits our work better then NVidia PhysX (the one we used before). because our framework is component based, and graphics and physics are separated completely, most full wrappers aren't suited for me.

But this provides all the functionality I need to put this in our framework very quickly. Thanks a lot.

Glad you like it. You might want to look into the code and modify it to suit your needs.
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Next

Return to Using OGRE in practice

Who is online

Users browsing this forum: No registered users and 3 guests