Problem with bodies position

Virginie

18-05-2009 12:21:51

Hello,

I see that bodies have got the same hierarchy that the node wich they are attached. So for exemple
I've got a node car wich have for child node wheel and bodycar.
My bodies related must be set by the position of node relatively to the node parent and not to the world coordinates.

I've not wrong?

melven

18-05-2009 13:45:09

If you want to implement such a hirarchy (I think I'm always using nodes attached to the root-node), you should set a custom transform callback (OgreNewt::Body::setCustomTransformCallback)...
Just have a look at the code of the standardTransformCallback-function and the attachNode-function in OgreNewt::Body to get an idea how to implement that.

I think, I'll consider implementing this case in the standard-callback too (in the unofficial OgreNewt version for newton 2.0 beta)...

Virginie

18-05-2009 14:06:26

Thank you melven.

Yes I use ogrenewt for the 2.0 version of newton.

But I just use ogrenewt for collision so I use only contactsCallback and updateCollision.
I don't have a very good english so I just want to know if the bodies have the same hierarchy of node wich they are attached and when I do setPositionOrientation it's for the local position or not ( I think it's yes but I want a confirmation).

Virginie

18-05-2009 14:39:10

Yes setpositionOrientation of ogrenewt calls setPosition setOrientation of Ogre::Node so it's relative to it's parent.

melven

18-05-2009 17:17:24

No it's not... Or not really. It'll set the specified position/orientation for the newton body and the newton body uses world coordinates... There is no hirarchy for the newton bodies!
So I think you are kind of missinterpreting the relationship between an OgreNewt::Body and an Ogre::Node:
You attach a node to a body, so if the bodie's position changes, it'll set the node's position. The body doesn't know (or doesn't care) about the properties of the node, it'll only call sometimes Node::setPosition and Node::setOrientation

Virginie

19-05-2009 08:28:50

OgreNewt::Body::setPositionOrientation() calls Ogre::Node::setPosition() and Ogre::Node::setOrientation(); and those methods are in local coordinates so if I put world coordinates in setPositionOrientation() my nodes are move in bad positon. So I don't know if the mistake is in commentary or in programmation but there are a mistake :)

Virginie

19-05-2009 08:52:29

I see that there are a new code with the update, when I can pik boost correctly I test this.

...

Now I solved all my problems with the update.

So I set position and orientation of my bodies with the position and orientation of my nodes so my nodes should not move!

I do this :
m_Node->_update(NULL,NULL);
m_BodyCollision->setPositionOrientation(m_Node->_getDerivedPosition(),m_Node->_getDerivedOrientation());

with
m_BodyCollision->setPositionOrientation(m_Node->getPosition(),m_Node->getOrientation());
Before update this code was nearly good (just a little translation)
Now there are an orientaion too!!!

Are you sure of your computation for node with parent node?

melven

19-05-2009 14:05:34

I'm thinking about the node-hirarchy stuff at the moment...
It's probably not possible to get it working correctly in all cases:
Imagine the following scenario:
The child node ist not moving any more (in sleeping state), the position won't be updated by newton/OgreNewt.
When the parent node is moved now, the child node will be moved too...

So I'll probably remove the code for the derived position and orientation again, I didn't think about this problem before...
It would be the best not to use hirarchies of nodes with OgreNewt (and it doesn't make sense too, because newton always sets the position
in global space).

Virginie

19-05-2009 14:24:20

Yes, I know the problem.

So I haven't got other solution as comment the set of position and orientation of node.
I just use OgreNewt for collision, I move my objects by mouse and keybord.
I work in a software that use Ogre and my work is to insert collision.

melven

19-05-2009 14:45:30

Ok now I have a better understanding of what you are doing...
Couldn't you just remove the node from the body? The intention of attaching a node to a body is that the node is moved with the body...
So if you don't attach any node to the body, you can just set the bodies position without any further effects on the node.
Or am I missing something here?

Virginie

19-05-2009 14:55:31

Hum I think it's possible but I use in contactCallback : p_ContactJoint.getBody0()->getOgreNode()->getName()
And I don't know how to take node without this :(

So for my work I would prefer that is node wich set body :D

melven

19-05-2009 17:45:32

You could also save the node as userdata if you don't already use it for something different...