very simple Bullet library integration question

User avatar
detox
Posts: 12
Joined: Wed Nov 22, 2006 6:52 pm
Location: Ohio, USA

very simple Bullet library integration question

Post by detox »

Hi,

I have a very simple question about integrating Bullet into my software. I have inhereted the btMotionState class and added my necessary data. My question is, what is the best way to translate Bullet's position and orientation data into my graphics sub-system?

I noticed that the btTransform class (m_graphicsWorldTrans in the btMotionState class) has a getOpenGLMatrix() function, which is nice, but doesn't help me as I am not using OpenGL directly for gfx rendering. Can I simply use m_graphicsWorldTrans.getRotation() and m_graphicsWorldTrans.getOrigin()?

Will something like this work?

Code: Select all

    btVector3 origin = m_graphicsWorldTrans.getOrigin();
    btQuaternion rot = m_graphicsWorldTrans.getRotation();
    node->setPosition( origin.x(), origin.y(), origin.z() );
    node->setOrientation( rot.w(), rot.x(), rot.y(), rot.z() );
Great physics library BTW, thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: very simple Bullet library integration question

Post by Erwin Coumans »

Yes, it is a good idea to derive your own version of btMotionState. Then you can just use getOrigin to retrieve the world position from the btTransform. To get the orientation you can use either quaternions (using getOrientation()) or a 3x3 matrix (using getBasis())

It depends what your graphics subsystem 'setOrientation' accepts. Note that not all libraries use the same quaternion convention ('w' component has opposite sign, order is different etc).

Hope this helps,
Erwin

detox wrote:Hi,

I have a very simple question about integrating Bullet into my software. I have inhereted the btMotionState class and added my necessary data. My question is, what is the best way to translate Bullet's position and orientation data into my graphics sub-system?

I noticed that the btTransform class (m_graphicsWorldTrans in the btMotionState class) has a getOpenGLMatrix() function, which is nice, but doesn't help me as I am not using OpenGL directly for gfx rendering. Can I simply use m_graphicsWorldTrans.getRotation() and m_graphicsWorldTrans.getOrigin()?

Will something like this work?

Code: Select all

    btVector3 origin = m_graphicsWorldTrans.getOrigin();
    btQuaternion rot = m_graphicsWorldTrans.getRotation();
    node->setPosition( origin.x(), origin.y(), origin.z() );
    node->setOrientation( rot.w(), rot.x(), rot.y(), rot.z() );
Great physics library BTW, thanks!
User avatar
detox
Posts: 12
Joined: Wed Nov 22, 2006 6:52 pm
Location: Ohio, USA

Post by detox »

Yes that helped, thank you.

I now have Bullet up and running in Ogre3D. Thankfully it appears that Ogre and Bullet use the same conventions for quaternions. btQuanternion.getW() works fine with Ogre anyway. I'll probably modify it later to just copy the matrix elements over, but for now it works well enough for demos and testing.

Now I just do something like this in the init loop to setup the Bullet physics and collision world (with default values) -
bulletworld = new coreBullet( scenemgr );
...
Then add a box like this -
bulletworld->addBox( my_ogrescenenode, Vector3( 2, 2, 2 ), 10 );

...and then add this to an Ogre frame listener:
bulletworld->processNodeList( evt.timeSinceLastFrame );

... and it all just works!

Anway I'm pretty happy, I'll post a demo or screenshots to the proper forum area maybe later.

Thanks again Erwin, great code.