Night Elf
17-10-2006 20:20:22
I'm implementing triggers in my game and I'd need some way to add and remove triggers during the game.
Since triggers don't have a visual representation, do OgreNewt bodies need to be attached to a Node or can I have standalone bodies? If I can, how would I remove a body from the world?
OvermindDL1
17-10-2006 22:14:07
The Ogrenewt bodies are standalone, always. You can however link an Ogre visual Node to a body so it moves in sync, but the OgreNewt body itself doesn't care about it. So no, you do not need visual nodes attached.
Night Elf
18-10-2006 16:31:37
OK, thanks.
So, in that case, how would I remove a body from the physics world? I haven't found any method for that... Or should I destroy the body?
What I want is to be able to remove the trigger's body when the trigger is disabled to prevent all processing on that body and then re-add it when the trigger becomes enabled again.
Night Elf
18-10-2006 20:38:09
I've been reading a bit of OgreNewt's code... but it hasn't gotten me too far... I couldn't find where in the code a body is added or removed from the world. So I would like to change my question:
How are bodies added and removed from the Newton world?
Is the body added as soon as it is constructed? Is the only way of removing a body deleting it?
HexiDave
18-10-2006 21:03:02
It's most likely added to the world as soon as you create it and, yes, you just use delete to remove it:
//Create the collision object
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Cylinder(m_World, 1, 1);
//Create the Body
OgreNewt::Body* body = new OgreNewt::Body( m_World, col );
//The Body with collision is now in the World
//Destroy the collision (should do this after creation of the body normally)
delete col;
//Destroy the body when you're done with it
delete body;
Night Elf
19-10-2006 15:42:17
Mmmh... OK. I don't really like it much. I was hoping for something like World::removeBody() which just would prevent the body from being included in physics calculations or triggering callbacks, rather than having to destroy and recreate it each time I want to disable/enable a trigger.
Well, I just found a post in the Newton forum where they talk about a feature like this:
http://newtondynamics.com/forum/viewtop ... emove+body
I believe the suggestion at the end of that post should be able to be implemented using OgreNewt. I'll try that.
EDIT: Indeed, that worked just fine.
HexiDave
19-10-2006 22:12:41
Oh, I'm sorry - I thought you meant destroy when you said remove. Must've read too fast there