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
bulareanuadrian
Gnoblar
Posts: 15
Joined: Tue Jan 06, 2009 11:00 pm
Location: Baicoi && Brasov
Contact:

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

Post by bulareanuadrian »

Well I think i miss something. I made some test with the demo and i notice that if i move the phyworld from Globals to class, the demo has the same behavior like my test.
Here is the code in my test

Code: Select all

namespace Globals
{
     btDynamicsWorld *phyWorld;
  BtOgre::DebugDrawer *dbgdraw;
}
in the constructor fizica
mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
     mCollisionConfig = new btDefaultCollisionConfiguration();
	 mDispatcher = new btCollisionDispatcher(mCollisionConfig);
	 mSolver = new btSequentialImpulseConstraintSolver();

	 Globals::phyWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
	    Globals::phyWorld->setGravity(btVector3(0,-9.8,0));
in the frameStarted
   Globals::phyWorld->stepSimulation(evt.timeSinceLastFrame, 10);
	//Update Bullet world. Don't forget the debugDrawWorld() part!

   Globals::phyWorld->debugDrawWorld();

Lumea nu crede in puterea programelor open source.
The world do not believe in power of open sources programs.

Sorry for my bad english.
bulareanuadrian
Gnoblar
Posts: 15
Joined: Tue Jan 06, 2009 11:00 pm
Location: Baicoi && Brasov
Contact:

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

Post by bulareanuadrian »

Solved.
Really i dont know what happen. I remade the test and bingo, it'works.
Lumea nu crede in puterea programelor open source.
The world do not believe in power of open sources programs.

Sorry for my bad english.
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 (now on git!)

Post by nikki »

The 'Globals' etc. is just a quick hack to make things easier in the demo. You don't have to do things that way. It's a simple API, use it any way you wish. Most of the code you'll write is plain Bullet anyway.
dustinlee
Kobold
Posts: 25
Joined: Sat Jan 14, 2006 1:11 pm

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

Post by dustinlee »

Using BtOgre, I'm implementing Ninja vs Wall collisions. But, regarding the bounding box, strange things happened.
The following video explains it well.

http://www.youtube.com/watch?v=vstBxo7yEJ0

Even if I made the collision shape ( using createBox/createTrimesh/createConvex) for the walls ( shown in transparent gray thin box with border ), the collision occurred between Ninja and Ogre Bounding Box (the big one which is shown by showBoundingBox()), not the exact collision shape.

I've created collision object and collision shape for each entity, and add the collision object to the collision world.
For checking collisions, used the following code as suggested in the bullet collision interface demo.
if (mCollisionWorld)
mCollisionWorld->performDiscreteCollisionDetection();

Thanks for any help..
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 (now on git!)

Post by Shockeye »

It looks to me like the bounding box is centred around the feet of the ninja. I guessing, but perhaps that mesh's origin is not in its centre, but at its feet. Thus the that is the point at which it is attached to the scenenode, and the Bullet collision box is centred around the scenenode, not the mesh.
<Edit:
Have just done a quick test and it does seem that ninja.mesh has its origin at its feet.>

But if its not some thing about the mesh, maybe its the way you set it up. Maybe you could post a snippet of code showing how you set up that particular btRigidBody?
dustinlee
Kobold
Posts: 25
Joined: Sat Jan 14, 2006 1:11 pm

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

Post by dustinlee »

Shockeye:

Thanks for your comment. I know Ninja's pivot is between the two foots. My concern is that Ninja cannot collide with the the wall exactly. The video shows Ninja collides with the big bonding box ( shown by SceneNode::showBoundingBox(true)).

My code is like the following:


Collision world set-up:

Code: Select all

	    //Bullet initialisation.
	    mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
	    mCollisionConfig = new btDefaultCollisionConfiguration();
	    mDispatcher = new btCollisionDispatcher(mCollisionConfig);
	    mSolver = new btSequentialImpulseConstraintSolver();
            mCollisionWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
CollisionObject class to link SceneNode and btCollisionObject:

Code: Select all

   class CollisionObject : public btCollisionObject
    {
    public:
        CollisionObject(Ogre::SceneNode *node) 
        {
            mSceneNode = node;
            this->getWorldTransform().setOrigin(BtOgre::Convert::toBullet(mSceneNode->getPosition()));
            this->getWorldTransform().setRotation(BtOgre::Convert::toBullet(mSceneNode->getOrientation()));
        }
        virtual ~CollisionObject() {}


        Ogre::SceneNode *mSceneNode;
    };
Ninja set-up:

Code: Select all

	//Create shape.
	BtOgre::StaticMeshToShapeConverter converter(mCharacterEntity);
        mCharacterShape = converter.createBox();
        mCharacterShape->setLocalScaling(BtOgre::Convert::toBullet(mCharacterNode->getScale()));

        // Create collision object and assign shape
        mCharacterCollObject = new CollisionObject(mCharacterNode);
        mCharacterCollObject->setCollisionShape(mCharacterShape);

        // add character collision objec to world 
        mCollisionWorld->addCollisionObject(mCharacterCollObject);
Wall set-up:

Code: Select all

                CollisionObject* collObj = new CollisionObject(mWallNode));
                BtOgre::StaticMeshToShapeConverter aConverter(ent);
                btCollisionShape *shape = aConverter.createBox();
                collObj->setCollisionShape(shape);
                mCollisionWorld->addCollisionObject(collObj);
Collision detection and resolution:

Code: Select all

       Ogre::Vector3 curPos = mCharacterNode->getPosition();
        mCharacterCollObject->getWorldTransform().setOrigin(btVector3(curPos.x, curPos.y, curPos.z));

        if (mCollisionWorld)
            mCollisionWorld->performDiscreteCollisionDetection();

        int numManifolds = mCollisionWorld->getDispatcher()->getNumManifolds();
        if (numManifolds > 0)
            PRINTF("%d Collisions occurred", numManifolds);
        for (int i=0;i<numManifolds;i++)
        {
            btPersistentManifold* contactManifold = mCollisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
            CollisionObject* obA = static_cast<CollisionObject*>(contactManifold->getBody0());
            CollisionObject* obB = static_cast<CollisionObject*>(contactManifold->getBody1());

            if (obA == mCharacterCollObject || obB == mCharacterCollObject)
            {
                PRINTF("Collistion Hit between %s and %s\n", obA->mSceneNode->getName().c_str(), obB->mSceneNode->getName().c_str());
                mCharacterNode->setPosition(prevPos);
                mCharacterCollObject->getWorldTransform().setOrigin(btVector3(prevPos.x, prevPos.y, prevPos.z));
            }
        }
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 (now on git!)

Post by nikki »

You could try attaching the Ninja to a child SceneNode instead to get the intended offset (a bit down on Y to get origin in centre). But other than that I don't see where the problems is, could you explain further?
dustinlee
Kobold
Posts: 25
Joined: Sat Jan 14, 2006 1:11 pm

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

Post by dustinlee »

Nikki: Thanks for your comment.

It seems that my explanation is not correct enough. Let me describe the problem with the following picture:
Image

As you can watch the video, Ninja collides with the bounding box #2 ( which is drawn by showBoundingBox(true) ). But that is not what I want. I want Ninja collides with the bounding box #1 ( this is drawn by the BtOgre debug drawer ) which is created by createBox(). I tried createConvex() and createTrimesh() as well for the walls. But Ninja still collides with the bounding box #2. Hope this explains the problem clearly.
dustinlee
Kobold
Posts: 25
Joined: Sat Jan 14, 2006 1:11 pm

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

Post by dustinlee »

I'm still struggling to solve the problem. I guess Bullet supports only ABB collision detection? Even so, the same problem occured for trimesh or convex shaped walls.
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 (now on git!)

Post by Shockeye »

Its AABB in the broadphase sweep, but it should detect arbritrarily aligned collision shapes during the narrowphase.
I don't know much about colllison only setups (I use dynamics - its easier coz everything is done for you), but maybe only the broadphase is working for some reason. :?:
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 (now on git!)

Post by nikki »

Of course it does support complex shapes. I use it in my project, and it works beautifully. I think it's something to do with the way you handle collisions, maybe it's only doing broadphase. You should try asking in the Bullet forums.
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 (now on git!)

Post by Shockeye »

Slightly off topic, from dustinlee's posts I've just realized that they've added debug draw to btCollisionWorld. (I've been using the previous version, where debug draw is only in btDynamicsWorld.)

Now back on topic with a crazy idea: dustinlee, if by chance you are using an older version like me, then you would have had to use some clever trick to get debug drawer working. Which could mean it might not be set up quite right and thus is not drawing what's really in the simulation. ie: the debug drawer is showing one set of data but collisionshape don't match.

(I know this is a loony theory, but I just thought I'd mention it :lol: )
dustinlee
Kobold
Posts: 25
Joined: Sat Jan 14, 2006 1:11 pm

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

Post by dustinlee »

Nikki, Shockeye:

Thanks for your kind comments. Seems that simple collision interface doesn't do exact OBB checking. I've tested the "CollisionInterfaceDemo" included in the bullet SDK. In order to checkout OBB collision check is working, I modified the size and orientation of two boxes. Surprisingly but as expected, it reports collision even if the two box doesn't collide. Now I'm moving to use the KinematicCharacterController class in the bullet SDK, and up to the point, it's working very very well.
I wanted to post this issue in the bullet forum, but registering is impossible due to the registration mail system doesn't work.
MusgooD
Gnoblar
Posts: 15
Joined: Wed Nov 07, 2007 11:47 am
Contact:

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

Post by MusgooD »

How to debug drow Rays ?
tsmithtree
Gnoblar
Posts: 4
Joined: Sun May 10, 2009 12:05 am

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

Post by tsmithtree »

nikki, thank you so much for releasing this library. This is exactly how I think an ogre-physics connection should be written.

And also, if you are using windows make sure you define WIN32 in the preprocessor settings. While porting my game from linux, I spent forever trying to figure out why it would crash in the btogre code until finding something in this thread about the WIN32 definition.
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 (now on git!)

Post by nikki »

tsmithtree wrote:nikki, thank you so much for releasing this library. This is exactly how I think an ogre-physics connection should be written.
You're welcome. :)
tsmithtree wrote:And also, if you are using windows make sure you define WIN32 in the preprocessor settings. While porting my game from linux, I spent forever trying to figure out why it would crash in the btogre code until finding something in this thread about the WIN32 definition.
Ah, I see. I haven't really tested this library much on Windows. I'm a little busy now with schoolwork, but when I'm done I'll add 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 (now on git!)

Post by nikki »

MusgooD wrote:How to debug drow Rays ?
Sorry for the late reply, but do you mean raycasts? I think you might have to do that manually. Or you could just call one of the interface functions (such as 'drawLine') in the BtOgre debug drawer.
evrenbingol
Gnoblar
Posts: 1
Joined: Mon Jul 27, 2009 11:56 am

Error with begin/end tags

Post by evrenbingol »

Hi
I dunno if this has been posted but I get
An exception has occurred: OGRE EXCEPTION(2:InvalidParametersException): You must call begin() before this method in ManualObject::position

when i include BulletDebugDrawer (http://www.ogre3d.org/wiki/index.php/BulletDebugDrawer) in my project,
I know what the error means. Is this the latest version of the source.

I am running it on Mac precompiled ogre sdk

Thanks
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 (now on git!)

Post by nikki »

I'll look into it, but I must point out that BtOgre already has it's own debug drawer, you can see how to use it in the first post.
Fred
Halfling
Posts: 46
Joined: Thu Nov 02, 2006 11:06 pm
Location: Germany

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

Post by Fred »

If I change the position of the SceneNode while moving the body, will the shape and the body move, too?
Or what are possible solutions to chnage the position of a bullet object. In RigidBody I can't find any methods to set and get the position of this body.
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 (now on git!)

Post by nikki »

Fred wrote:If I change the position of the SceneNode while moving the body, will the shape and the body move, too?
Or what are possible solutions to chnage the position of a bullet object. In RigidBody I can't find any methods to set and get the position of this body.
Use:-

Code: Select all

btRigidBody::setWorldTransform(trans);
Fred
Halfling
Posts: 46
Joined: Thu Nov 02, 2006 11:06 pm
Location: Germany

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

Post by Fred »

Ah okay! Thank you!
And thank you for your work! I had to write my own bullet lib, if there wasn't your's ;)
User avatar
wacom
Gnome
Posts: 350
Joined: Sun Feb 10, 2008 2:07 pm

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

Post by wacom »

nikki wrote:
Fred wrote:If I change the position of the SceneNode while moving the body, will the shape and the body move, too?
Or what are possible solutions to chnage the position of a bullet object. In RigidBody I can't find any methods to set and get the position of this body.
Use:-

Code: Select all

btRigidBody::setWorldTransform(trans);
Yeah, but don't forget to remove and re-add the rigid body. See http://www.bulletphysics.com/Bullet/php ... orm#p14564 for reference.
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 (now on git!)

Post by nikki »

wacom wrote:
nikki wrote:
Fred wrote:If I change the position of the SceneNode while moving the body, will the shape and the body move, too?
Or what are possible solutions to chnage the position of a bullet object. In RigidBody I can't find any methods to set and get the position of this body.
Use:-

Code: Select all

btRigidBody::setWorldTransform(trans);
Yeah, but don't forget to remove and re-add the rigid body. See http://www.bulletphysics.com/Bullet/php ... orm#p14564 for reference.
Hmm.... I always did it without the remove-and-re-add. Never had any problem. I'll do some research, thanks for the tip! ;)
User avatar
boyamer
Orc
Posts: 459
Joined: Sat Jan 24, 2009 11:16 am
Location: Italy
x 6

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

Post by boyamer »

How can i convert Bullet Matrix3x3 to Ogre Matrix3?

And btTransform to Ogre Matrix4?

Thanks
Post Reply