Callback & btMotionState performance [Known Issue]

User avatar
lazalong
Posts: 10
Joined: Fri Mar 06, 2009 6:55 am
Location: Australia - Canberra

Callback & btMotionState performance [Known Issue]

Post by lazalong »

Hey

I am learning Bullet and a quick search/doc didn't help me.

* Is there a callback method that is called only when the body moved or rotated?

This callback would be used to update the mesh position.

I tried to create a custom MyMotionState but it seems that setWorldTransform() is called even if the position*orientation is the same so this doesn't seem the solution.

Regards
Last edited by lazalong on Mon Mar 16, 2009 11:30 pm, edited 1 time in total.
User avatar
lazalong
Posts: 10
Joined: Fri Mar 06, 2009 6:55 am
Location: Australia - Canberra

Re: Callback & btMotionState

Post by lazalong »

Any idea?

Or is MyMotionState::setWorldTransform() really the method that must be use for callback?

And if yes why must I calculate myself if the position/orientation didn't change?
User avatar
kenshin
Posts: 36
Joined: Fri Oct 31, 2008 5:10 pm

Re: Callback & btMotionState

Post by kenshin »

a difficult problem
User avatar
lazalong
Posts: 10
Joined: Fri Mar 06, 2009 6:55 am
Location: Australia - Canberra

Re: Callback & btMotionState

Post by lazalong »

Not sure to understand your answer.

Do you mean there is no obvious way?
Or it is hard to implement in the Bullet code?

In both case I would have thought one of the primary goal of a physics library is precisely to have such a callback.

Regards
Dominik
Posts: 32
Joined: Fri Dec 19, 2008 2:51 pm

Re: Callback & btMotionState

Post by Dominik »

I'm not sure if I understand your problem.

The btMotionState should in fact only be called when your object's transform was changed, and thus should do exactly what you ask for.
Are you sure setWorldTransform() is called for non-moved objects (maybe the movement was only very small).
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Callback & btMotionState

Post by AlexSilverman »

As I understand it, there is currently no callback for when objects have moved since the last frame. btMotionState::setWorldTransform() is currently called fairly often (once per frame per body per simulation substep, plus once more per frame per body after all simulation has been done). Note that this is not once per active body, but once per body, so if you have a large number of bodies in your scene, this can start to add up, but that's a separate issue.

In the bug discussion, there's mention of a "dirty" flag (Set to true when the object has moved, and if true, update the motion state) so maybe this will serve you a bit better, but it could also end up being called more often than you need. It may be better to just build something yourself that performs this check for each active object.

Hope this helps.

- Alex
User avatar
lazalong
Posts: 10
Joined: Fri Mar 06, 2009 6:55 am
Location: Australia - Canberra

Re: Callback & btMotionState

Post by lazalong »

Thanks Alex

Until this issue is resolved I will keep my solution to store the previous state and only update the graphics part when necessary. Not ideal. I hope this issue will be tackled soon.

It surprises me that such an obvious callback was not central to the library design.

My temporary solution:

Code: Select all

    virtual void setWorldTransform(const btTransform& centerOfMassWorldTrans)
    {
        if (m_graphicsWorldTrans == centerOfMassWorldTrans * m_centerOfMassOffset)
            return;

        m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset ;
        btQuaternion rot = m_graphicsWorldTrans.getRotation();
        btVector3 pos = m_graphicsWorldTrans.getOrigin();

        // Notify the rest of the engine of the object change
        ObjectManager::getSingleton().postMessage(
            ObjectMessage::SET_POSITION_ORIENTATION, 
            Vector3(pos.x(), pos.y(), pos.z()), 
            Quaternion(rot.w(), rot.x(), rot.y(), rot.z()),
            mPtr, mId );

    }