[solved] set a position into the world (setworldPosition)

Problems building or running the engine, queries about how to use features etc.
Post Reply
shibby
Halfling
Posts: 63
Joined: Sat Dec 15, 2007 6:42 pm
Location: Rennes, France

[solved] set a position into the world (setworldPosition)

Post by shibby »

... in the world and not just in function of his parent node ?

That means create a setWorldPosition(...) function wich would make exactly as the parent node would be the root scene node.
Last edited by shibby on Wed Jan 21, 2009 2:10 pm, edited 1 time in total.

mickeyren
Greenskin
Posts: 142
Joined: Thu Dec 18, 2008 11:32 am

Re: Is it possible to set a node position...

Post by mickeyren »

i don't think so, but why would you do that? The scene nodes were created like that so they can be transformed and culled easily later on.

If you probably want to set its position in the world space not relative to anything, then you probably should create the scene node from the root node.

shibby
Halfling
Posts: 63
Joined: Sat Dec 15, 2007 6:42 pm
Location: Rennes, France

Re: Is it possible to set a node position...

Post by shibby »

I would like to do that because I use Ogre with other library which is able to set a position into relative space or global world.

User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: Princeton, New Jersey, USA
x 13
Contact:

Re: Is it possible to set a node position...

Post by nikki »

Well, you can just subtract the parent position from the position you're setting the SceneNode's position to.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Is it possible to set a node position...

Post by jacmoe »

scenenode->setPosition(position) what's wrong with it?
I use it all the time when loading a scene.
Everything is in world coordinates.
Am I not getting it? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
Thrakbad
Halfling
Posts: 73
Joined: Fri Mar 23, 2007 4:32 pm
Location: Essen, Germany
Contact:

Re: Is it possible to set a node position...

Post by Thrakbad »

I personally haven't worked with deeper node hierarchies than one level, but the API says about setPosition():
Sets the position of the node relative to it's parent.
I haven'T found an API function that sets the position in world space. When implementing such a function yourself you simply would have to go through all the parents until you reach the root node and then add up all of the positions of the nodes. That would get you the world coordinates of the parent node and you can then easily translate the child node to the right coordinates. Unless I'm missing something this doesn't sound very complicated.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Is it possible to set a node position...

Post by jacmoe »

Yes. But that's not a problem if you set the position first, and give it a parent second. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Re: Is it possible to set a node position...

Post by haffax »

Thrakbad wrote:When implementing such a function yourself you simply would have to go through all the parents until you reach the root node and then add up all of the positions of the nodes. That would get you the world coordinates of the parent node and you can then easily translate the child node to the right coordinates. Unless I'm missing something this doesn't sound very complicated.
You're missing orientation.

But it is even easier. A one-liner:

Code: Select all

    childNode->setPosition(parentNode->_getDerivedOrientation().Inverse() * (childNodeWorldPos - parentNode->_getDerivedPosition()));
@shibby, you could have found this solution yourself with a forum search, it is an often asked question.
team-pantheon programmer
creators of Rastullahs Lockenpracht

shibby
Halfling
Posts: 63
Joined: Sat Dec 15, 2007 6:42 pm
Location: Rennes, France

Re: Is it possible to set a node position...

Post by shibby »

Thank you for these answer,

haffax's solution is working very well :-)

Post Reply