Custom conditional ForceAndTorqueCallback only called once??

avee

16-07-2006 07:02:26

Hi all,

In my app, I created a custom force and torque callback, which has a conditional statement like this:
void callback(OgreNewt::Body* me)
{
if(This->_status == OBJ_STATUS_MOVING)
{
me->addForce(Vector3(10,0,0));
}
}

The problem is, the callback is called only once, when the object is created.

When I study more about this, I found out that when a callback doesn't affect the body in the simulation, it will only be called once. Even when at the next iteration, the callback will affect the simulation...
I conclude the statement above because, when I erased the if statement, the callback works just fine, it is called each time the world updates..

Can anyone help me with this?
Does this behaviour come from Newton or OgreNewt?
How can we overcome this?

Thanks guys..

HexiDave

16-07-2006 08:55:25

In what context are you setting _status? Is it a single object or for many objects? Do you set it per object (say you have a class of falling boxes, you set OBJ_STATUS_MOVING for each box object - that is, per class?)

I see you checking with This->_status, so make sure that your object isn't changing _status on its own (like a toggle.)

If you can provide the code for the class (what This is pointing to and where callback is defined) and for where you activate _status, there's a much better chance for a solution. Could also search your code for "_status =" - I have a funny habit of doing that sometimes when trying to type "=="

avee

20-07-2006 03:46:46

After I do more work on my code, it seems that I forgot to put Body->SetAutoFreeze(0); when I created the body, so when the callback doesn't affect the body, it's frozen.. Sorry guys, it's really my bad..

@HexiDave
Thanks man, I tried your suggestions when debugging the code.. Helped me find the bug faster :)