btMotionState - is worldTrans in local or world coord?

mbykovskyy
Posts: 6
Joined: Fri Jan 30, 2009 4:49 pm

btMotionState - is worldTrans in local or world coord?

Post by mbykovskyy »

Hi all, I'm writing a game for my final year project and I'm using Bullet for physics and Ogre for graphics. I've learned that Bullet can automatically update Entities' positions in the scene graph via btMotionState interface. However, I find it unclear whether the btTransform should contain a global or a local vertex space information. In examples I found they simply set the Ogre's node position via setPosition which sets position relative to its parent.

Code: Select all

void MotionState::setWorldTransform(const btTransform &worldTrans) {
   if(NULL == mVisibleobj) return; // silently return before we set a node
   
   btQuaternion rot = worldTrans.getRotation();
   mVisibleobj->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
   
   btVector3 pos = worldTrans.getOrigin();
   mVisibleobj->setPosition(pos.x(), pos.y(), pos.z());
}
So this will only work if the parent of the mVisibleobj node is the Root node. Otherwise, it will produce wrong results, since I presume that worldTrans returned from getWorldTransform() should be in the world space?
So, just to stress my question again, does Bullet use the world space for simulation?
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: btMotionState - is worldTrans in local or world coord?

Post by sparkprime »

Yes, it's world space in that callback.

However when applying impulses and in other parts of the API, it is not world space.
mbykovskyy
Posts: 6
Joined: Fri Jan 30, 2009 4:49 pm

Re: btMotionState - is worldTrans in local or world coord?

Post by mbykovskyy »

Ok, thanks for clearing that up for me! I've another question though, why can't I set MotionState for SoftBodies? And is there any way to update vertex transform automatically for SoftBodies just like in MotionState?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btMotionState - is worldTrans in local or world coord?

Post by Erwin Coumans »

mbykovskyy wrote:Ok, thanks for clearing that up for me! I've another question though, why can't I set MotionState for SoftBodies? And is there any way to update vertex transform automatically for SoftBodies just like in MotionState?
Softbodies don't have a single world coordinate frame, each vertex is specified in world space.

You can access each individual node (-vertex) position and/or velocity. See Bullet/Demos/SoftDemo/SoftDemo.cpp, SoftDemo::mouseFunc, how to access a node using a ray cast (for picking).

Hope this helps,
Erwin
mbykovskyy
Posts: 6
Joined: Fri Jan 30, 2009 4:49 pm

Re: btMotionState - is worldTrans in local or world coord?

Post by mbykovskyy »

Thanks Erwin, I got it working by querying _softBody->m_nodes. Buy I got a problem the frame rate dropped from 500 to 150 just for one mesh. :(