[solved]Disabling objects

luffy

11-03-2006 13:14:57

Hi!
I have a lot of objects in my game. I need to "enable" and "disable" it. What is the best way to do it?

I see the attachToNode method but there isn't an detachNode.

I tried remove the TransformCallback. With this the nody stay fixed but the OgreNewt::Body stay in movement. I need to deactivate both...

Epimetheus

11-03-2006 13:53:58

why not just destroy the object?

walaber

11-03-2006 19:11:52

depends on what you mean by disable.

you can call the freeze() method on a body and it will stop updating until another body comes in contact with it.

Bren

11-03-2006 19:16:14

It's common wisdom that for best performance, you shouldn't create/destroy objects at run time. You should create all needed instances at "level load," and enable/disable them at run-time.

That said, Newton doesn't allow you to enable/disable objects easily, like say ODE does. Freezing/unfreezing gets you halfway there, but of course collisions/forces will "wake up" the object, so it's not entirely disabled.

I brought this up on the Newton forums, and was able to come up with a hacky sort of method for emulating enable/disable. Basically to disable, you assign a material to the object that doesn't collide with any other materials, and NULL all the callbacks for that object, then freeze it. To enable, you assign a "correct" material and callbacks, and then unfreeze. I wrapped all this hoop jumping up in enable() and disable() functions, and it works pretty well.

Check this thread: http://www.physicsengine.com/forum/viewtopic.php?t=2201

walaber

11-03-2006 21:01:59

another option is to do this:

create a single NULL collision object.

when you want to "disable" a body, replace it's collision shape with the NULL object, and call Freeze() on the body. now nothing will collide with it, and it won't move.

that reminds me I need to add the NULL collision shape to OgreNewt.

[edit] Added to CVS. [/edit]

luffy

12-03-2006 14:57:42

collision shape not working, it crashes


mBody->setCollision(NULL);

The error line:
NewtonBodySetCollision( m_body, col->getNewtonCollision() );



i'll try with the nullmaterial trick

[edited]

The nullmaterial works perfect. Thanks

walaber

12-03-2006 18:01:00

you don't actually pass "NULL", you create a "null" collision shape... which I added to the most recent OgreNewt. a material solution will also work though.

OvermindDL1

14-03-2006 06:49:18

Could always make a setCollision override function that accepts nothing and will set the collision to the nullbody. Maybe a more appropriatly named function, or just use the original and test if pointer is null?

walaber

14-03-2006 07:17:15

it's called NullCollision, so what can I say. it should work fine, no need to make the wrapper add too much functionality.