Graceful leaving and reentering OgreNewt::World

Project5

27-04-2006 22:48:39

When an OgreNewt::Body leaves the world, and then reenters it again, what must be done to it so that its callbacks will register once more? Is it just a matter of unfreezing it, or is there more?

--Ben

walaber

28-04-2006 06:23:58

as long as you put the body back within the world limits, (and call unfreeze), you should be all set.

runevision

11-05-2006 14:05:40

How do you make an OgreNewt::Body leave the world? The body is bound to the world in its constructor, but I can't find any method in either the body or in the world which detaches the body from the world.

What I want is to temporarily control the position and alignment of a node and entity with complete disregard for physics and collisions, and then later make the body reenter the world and take control of the node again. How is this done?

Thanks in advance,
Rune

danharibo

11-05-2006 16:21:33

mbody->setpositionorientation

runevision

11-05-2006 17:49:03

mbody->setpositionorientation
No, that doesn't make the body leave the world. It will still collide with other bodies. Even if the body itself won't be affected, since its positions and orientation is constantly overwritten, it will still have effect on the other bodies. I want the body to be completely non-existant in the physical world, and then later reinsert it again. How can this be done?

Thanks in advance,
Rune

danharibo

11-05-2006 18:14:47

delete mbody;
and when you need it again make a new collision?

Project5

13-05-2006 05:03:02

Set it to use Newton's NULL collision.

When it needs to be tangible again, set it to use the original collision body.

--Ben

runevision

13-05-2006 16:10:36

Set it to use Newton's NULL collision.

When it needs to be tangible again, set it to use the original collision body.

Hmm okay, I can use NewtonCreateNull(mWorld->getNewtonWorld()) but how do I turn the resulting NewtonCollision into an OgreNewt::Collision ?

Rune

walaber

15-05-2006 18:01:58

NULL has been added to the latest version of OgreNewt.

runevision

15-05-2006 19:36:23

NULL has been added to the latest version of OgreNewt.
Oh right, there it is indeed! It's just the docs that don't seem to be updated then. Thanks for pointing this out.

By the way, I don't find it trivial to know if I have the latest version. The docs for the version I have has the caption "OgreNewt Library version 0.07" - and below that a smaller caption that says "0.06" - which is kind of confusing in itself. On the webpage http://walaber.com/?action=showitem&id=9 I can find no version number at all.

runevision

15-05-2006 20:29:55

Okay, new problem.

I get some problems when I use getCollision() and setCollision().

To demonstrate, try to add the following two lines to Demo01_TheBasics - OgreNewtonApplication.cpp right after the line that says Delete col;
const OgreNewt::Collision* myCol = bod->getCollision();
bod->setCollision(myCol);

...and the program crashes when run. If the two lines are placed before the Delete col; line, then it doesn't crash. Does the body not keep a copy of the collision object, since it allows me to call getCollision()? I'm still rather new to C++, so I might have misunderstood something fundamental...

Rune

praetor

15-05-2006 21:11:26

If you place it after the delete call then the collision shape being referenced doesn't actually exist. C++ does not protect you from trying to use memory that does not exist any more. Basically getCollision at that point is returning junk, and so you are using junk. Eventually the junk is just too much....

runevision

15-05-2006 21:27:10

If you place it after the delete call then the collision shape being referenced doesn't actually exist.
Okay. I thought the body used the collision for all collision detection and thus ought to store a copy of it in order to work.

But as I understand it now, the body only uses the collision object in the setCollision() method (and the constructor). After that it doesn't need the collision object but only stores a reference to it for the convenience of the programmer.

Rune

artm

22-08-2006 11:33:04

and what's the correct procedure to remove the body from the world for good? I'm trying to get the character eat snacks, i made a material pair for character vs. snack, and installed custom collision callback into it, in which i decrement hunger and attempt to destroy the snack (Ogre::Entity and OgreNewt::Body) but the game crashes afterwards. This is how i attempt to accomplish that (in ~Snack()):


mBody->attachToNode(NULL);
mBody->setCollision(NULL);
delete mBody;
mEntity->getParentSceneNode()->detachObject(mEntity);
delete mEntity;
// we leave parent SceneNode floating in the scene, but who cares

artm

22-08-2006 13:30:39

ok, this was two fold:

1. i was attempting to do that inside the collision callback which probably wasn't such a good idea.

2. something else which i couldn't debug (see other thread)

my solution to 1 was obvious: instead of destroying / removing the snack's body in the collision callback i just mark it as eaten and then destroy all eaten callbacks right after world->update().

my solution to 2 was to not do

mBody->attachToNode(NULL);
mBody->setCollision(NULL);


but simply:


delete mBody;
mEntity->getParentSceneNode()->detachObject(mEntity);
delete mEntity;


I'm not sure if that's not gonna cause havoc in the long run but it works so far.

artm

22-08-2006 13:35:19

scrap that. it was only (2) - now that I don't setCollision(NULL) I have no problem deleting mBody in the contact callback.

:oops: