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.
Post Reply
reptor
Ogre Magi
Posts: 1120
Joined: Wed Nov 15, 2006 7:41 pm
Location: Finland
x 5

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

Post by reptor »

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.

Greetz,
JeDi
Perhaps you switched away from NxOgre? I don't see how else could it have been a problem that graphics and physics are not separated. So it's not really the fault of the PhysX. Just saying. I am using both Bullet and PhysX (not at the same time in the same application) and writing my own binding code.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

A small update: Added a demo application, and made it easier to create 'BtOgre::RigidBodyState's by just giving it the SceneNode.
User avatar
Shockeye
Gremlin
Posts: 154
Joined: Mon Nov 24, 2008 10:34 am
Location: 'Straya
x 1

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

Post by Shockeye »

I'm having trouble with BtOgre::StaticMeshToShapeConverter.createTrimesh().
My program is crashing when I try to convert my mesh to a btBvhTriangleMeshShape. (BtOgre::createConvex() works fine) When I run it, it asserts somewhere in Bullet - btQuantizedBvh::buildTree(int startIndex,int endIndex) If I choose ignore it continues and runs successfully.

My mesh is a room with holes for doors (for portals, its meant to be used as a zone with PCZSM). The normals point inwards so that the mesh is scene from the inside. The mesh has different textures for walls, ceiling & floor, so as an Ogre mesh I guess it has submeshes. It was exported from Blender.

I've tried using the same mesh with the normals flipped, with a single texture, and without the holes in the mesh; all with the same result.

Then I tried using a simple cube – still asserts.

Has anyone else had a problem with this?
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Hmm... I'm not sure what the problem might be. I'm using triangle meshes and they work fine. The method I use is similar to that which OgreBullet uses. I'm also a little busy with school right now, so I don't think I can be of much help. Try asking in the Bullet forums, you might get better results (there are, of course, more and better experienced Bullet people there).

By 'when I try to convert my mesh', you mean convert it manually or using BtOgre? Does the provided demo application work for you?

If you could give me the mesh, then I can try and find what's wrong.
User avatar
Shockeye
Gremlin
Posts: 154
Joined: Mon Nov 24, 2008 10:34 am
Location: 'Straya
x 1

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

Post by Shockeye »

Thanks for the quick reply!

Yes, I mean convert it using BtOgre (ie: BtOgre::StaticMeshToShapeConverter.createTrimesh())

I haven't tried the demo yet, but everything else in BtOgre is working in my app. I'll try the demo and see if there's something wrong with my bullet setup.
Given that even a simple cube didn't work for me, that might be the case.

I realise I'll probably get more answers from the Bullet forums, but I'm not registered there yet, soI thought I'd try here first. (Also, it might be some Ogre specific problem anyway )


Thanks for your help
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

You're using the latest Bullet? I remember having an assert somewhere like that too. That was on Windows. It never happened to me under Linux with the latest Bullet. Odd.

EDIT: Ahh, no. The one I had was an access violation, shown here.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Update (9.2.4): Very, very small bugfix update.
User avatar
Shockeye
Gremlin
Posts: 154
Joined: Mon Nov 24, 2008 10:34 am
Location: 'Straya
x 1

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

Post by Shockeye »

Solved It - a cut and paste error. :oops:
I accidently left in a calculateLocalInertia from a dynamic rigidbody.

The strange thing is, if you make a static rigidbody with a convex collisionshape it works fine with the inertia settings enabled. But if you use a trimesh it chucks a wobbly.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Shockeye wrote:Solved It - a cut and paste error. :oops:
I accidently left in a calculateLocalInertia from a dynamic rigidbody.

The strange thing is, if you make a static rigidbody with a convex collisionshape it works fine with the inertia settings enabled. But if you use a trimesh it chucks a wobbly.
Bullet can be a bit funny at times. :) Glad you got it fixed though.
darke
Halfling
Posts: 94
Joined: Mon Sep 08, 2008 3:30 am

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

Post by darke »

Download link is broken. Looks like that willhostforfood place will be suffering server issues for a few days. :(
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Update (9.2.9): Nothing much new, just uploaded to a different place. Hopefully, it'll stick around for a while.
unkonstant
Gnoblar
Posts: 1
Joined: Fri Feb 13, 2009 12:05 pm

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

Post by unkonstant »

Hi,
I managed to compile BtOgre and the demo, but when I ran it the sphere was not falling. So I made a little change:

Code: Select all

	    
//mNinjaShape = converter.createSphere();
mNinjaShape = new btSphereShape(1);
It worked and the sphere acted correct, but after closing VC++ 2008 and rebuilding the project, the same code doesnt work anymore -> Sphere is not falling. I built bullet 2.73 SP1 with the VC8-project thats included.
Any ideas what could be wrong here?

EDIT: Seems to be a VC++ settings issue, I made a new project based on a Ogre-Example and it works there. My first test used a empty project.
User avatar
lickstab
Kobold
Posts: 26
Joined: Mon Jan 19, 2009 3:11 pm
Location: Stockholm, Sweden
Contact:

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

Post by lickstab »

hmm, i was having some trouble with bullet, so as part of trying to fix them, i got the latest btogre aswell (9.2.9), but it seems to be acting rather strange.

i have a static plane surface (from a mesh) which i converted to a TriMesh using btogre, and then some boxes, which i converted to box shapes, also using btogre, but after falling to the ground, they bounce around for a bit and then fall right through.
i tried making it use a convex shape instead, which works for a while, but then things start falling through again.. any ideas?

also, if i run in debug mode and try to use a trimesh, i get some failed assertion from bullet, while in release mode it works.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

lickstab wrote:i have a static plane surface (from a mesh) which i converted to a TriMesh using btogre, and then some boxes, which i converted to box shapes, also using btogre, but after falling to the ground, they bounce around for a bit and then fall right through.
i tried making it use a convex shape instead, which works for a while, but then things start falling through again.. any ideas?
You'd want to ensure that your plane isn't just a single face, but a solid object with a reasonable thickness. Also, make sure your objects aren't excessively massive, or the gravity too high.
User avatar
lickstab
Kobold
Posts: 26
Joined: Mon Jan 19, 2009 3:11 pm
Location: Stockholm, Sweden
Contact:

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

Post by lickstab »

nikki wrote:You'd want to ensure that your plane isn't just a single face, but a solid object with a reasonable thickness. Also, make sure your objects aren't excessively massive, or the gravity too high.
hmm, okay. i used a plane before and it worked though. what about terrain, isn't that normally just a plane with a heightmap? i'll try using a more solid mesh for a floor though.
User avatar
Shockeye
Gremlin
Posts: 154
Joined: Mon Nov 24, 2008 10:34 am
Location: 'Straya
x 1

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

Post by Shockeye »

Hi, lickstab
You other problem about the trimesh asserting in debug mode, might be similar to troubles I had.
Are you setting inertia values for your trimesh plane? That'll cause an assert, because a static object shouldn't have inertia.

Also, if your gound plane is just a plane, why not use a Bullet plane for your collisionshape rather than a trimesh? Or if you do need a more complex ground surface, try using the Bullet heightmap collisionshape.

And try searching the Bullet forum and wiki for "tunneling" and how to prevent it.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Continuous collision detection might help. Are you sure you're using reasonable mass and gravity though?
User avatar
lickstab
Kobold
Posts: 26
Joined: Mon Jan 19, 2009 3:11 pm
Location: Stockholm, Sweden
Contact:

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

Post by lickstab »

hmm, setting the inertia to 0,0,0 for Trimeshes seems to have fixed the assertion thing - thanks!
i set the gravity to 0,-9.8,0 and the mass on the boxes to 20 and they still fall through.
however - if i set the boxes to use a convex shape instead of a plain box, it seems to work.
i'm using btogre::convert to make all the shapes, just passing in a variable to the constructor for my objects to choose which shape i want to use.

actually, i enabled the debug drawer and noticed that all the box shapes created (even using = new btBoxShape directly) are just shaped like flat planes.
Image

if i use a convex shape however, it encapsulates the box correctly.
now i just need to fix my character controller which apparently broke when i upgraded to 2.73.. that's a matter for the bullet forum though
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Well, the BtOgre converter just sees the farthest points on the local axes and makes the smallest box that fits the whole entity. Anyway, you say it doesn't work even if you make the shape manually (using new btBoxshape). Does using a sphere work?

You could also try asking in the Bullet forums, it may be a Bullet-specific problem.
User avatar
lickstab
Kobold
Posts: 26
Joined: Mon Jan 19, 2009 3:11 pm
Location: Stockholm, Sweden
Contact:

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

Post by lickstab »

yeah, i'll stick to convex for now and ask on the bullet forums if i need simpler shapes and can't get them to work. spheres didn't work either.
rebol
Kobold
Posts: 34
Joined: Tue Sep 09, 2008 2:28 am

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

Post by rebol »

nikki wrote: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
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.
I've tried the demo, but the ninja player didn't fall down, I logged out the height, it was always 10.
Yes, I'm using NGF, it's easy understanding, I'm pleased you'd like to share the NGF demo to me.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

@rebol: May be you're having this problem (posted by unkonstant above)?:-
unkonstant wrote:I managed to compile BtOgre and the demo, but when I ran it the sphere was not falling. So I made a little change:

Code: Select all

	    
//mNinjaShape = converter.createSphere();
mNinjaShape = new btSphereShape(1);
It worked and the sphere acted correct, but after closing VC++ 2008 and rebuilding the project, the same code doesnt work anymore -> Sphere is not falling. I built bullet 2.73 SP1 with the VC8-project thats included.
Any ideas what could be wrong here?

EDIT: Seems to be a VC++ settings issue, I made a new project based on a Ogre-Example and it works there. My first test used a empty project.
Krokotill
Gnoblar
Posts: 3
Joined: Wed Mar 21, 2007 2:21 pm

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

Post by Krokotill »

I also had a strange problem with the demo (built with VC8, Bullet 2.74):
The ninja fell down but didn't collide with the mesh. If I put a simple plane (btStaticPlaneShape) on the ground, the ninja did stop... very mysteriously! I didn't manage to get meshes (btBvhTriangleMeshShape) working.
Well, in the end the solution was simple, after some hours of headache: WIN32 was not defined!
Quite strange that this caused the bug.

@rebol: Perhaps this is also the solution to your problem. Try to simply set WIN32 in the preprocessor definitions in the project settings.

@nikki: Please put the following lines into premake.lua in the next release of BtOgre:

Code: Select all

if (windows) then
	table.insert(package.defines, "WIN32")
end
By the way, why don't you commit BtOgre into SVN (i.e. to Ogre-Addons or GoogleCode)? That would be nice!
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

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

Post by nikki »

Krokotill wrote:@nikki: Please put the following lines into premake.lua in the next release of BtOgre:

Code: Select all

if (windows) then
	table.insert(package.defines, "WIN32")
end
Ah, so that's the problem? Fine, I'll do that soon, kinda busy now because of school (exams). :(

BTW, is the rest of the premake.lua working fine for you guys?
By the way, why don't you commit BtOgre into SVN (i.e. to Ogre-Addons or GoogleCode)? That would be nice!
Yeah, I'll do that. Probably with 'git' or something. I can't say when though, but there probably won't be many updates this month anyway.
rebol
Kobold
Posts: 34
Joined: Tue Sep 09, 2008 2:28 am

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

Post by rebol »

Krokotill wrote:I also had a strange problem with the demo (built with VC8, Bullet 2.74):
The ninja fell down but didn't collide with the mesh. If I put a simple plane (btStaticPlaneShape) on the ground, the ninja did stop... very mysteriously! I didn't manage to get meshes (btBvhTriangleMeshShape) working.
Well, in the end the solution was simple, after some hours of headache: WIN32 was not defined!
Quite strange that this caused the bug.

@rebol: Perhaps this is also the solution to your problem. Try to simply set WIN32 in the preprocessor definitions in the project settings.

@nikki: Please put the following lines into premake.lua in the next release of BtOgre:

Code: Select all

if (windows) then
	table.insert(package.defines, "WIN32")
end
By the way, why don't you commit BtOgre into SVN (i.e. to Ogre-Addons or GoogleCode)? That would be nice!
Thanks, I also found this problem last Saturday.
By debugging, I found something wrong when new btSphereShape, if you don't set WIN32, the btVector3 will have m_floats as its member instead of an union, however, I don't know the further reason.
Post Reply