weird absolute position

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
instinct
Posts: 87
Joined: Sat May 10, 2008 3:42 pm

weird absolute position

Post by instinct »

I've been trying to understand why my SceneNode has a weird absolute position for a couple of hours but i just cant find the reason why.

Situation:
I have a 'pallet', which is an AnimatedMeshSceneNode, with an emptySceneNode as parent. It's position is correct.

I also have a 'box', which also is an AnimatedMeshSceneNode, with the pallet as parent. This box has a weird absolute position.

Code: Select all

emptySceneNode->addChild(pallet); 
pallet->setPosition(RelativePositionPallet);
pallet->addChild(box);
box->setPosition(RelativePositionBox);
box->updateAbsolutePosition();

vector3df AbsolutePos = box->getAbsolutePosition();
Some debug info:

Absolute position pallet: (118, -36 , -410)
Relative position box: (-5, 10, -4)

Absolute position box: (68, -10, -475)

How is this possible? What am I doing wrong?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: weird absolute position

Post by Acki »

I didn't check this, but maybe this box->updateAbsolutePosition(); should be

Code: Select all

pallet->updateAbsolutePosition();
(or maybe both ???)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
instinct
Posts: 87
Joined: Sat May 10, 2008 3:42 pm

Post by instinct »

Unfortunately that didnt solve the problem :(
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you need to call updateAbsolutePosition on all(!) nodes up to the root.
instinct
Posts: 87
Joined: Sat May 10, 2008 3:42 pm

Post by instinct »

Can i do this by simply calling smgr->getRootSceneNode()->updateAbsolutePosition() or do i have to do it individually?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Wow, that's something I had missed so far... I always thought of that as recursive. I guess I was lucky so far it didn't mess stuff up (or I didn't notice).

You have to start with the root, so the easiest way is probably to do it recursively:

Code: Select all

//! update absolute positions for node including all it's parents, starting from the top-most parent
void RecursiveUpdateAbsolutePosition(irr::scene::ISceneNode * node)
{
	if ( node )
	{
		if ( node->getParent() )
		{
			RecursiveUpdateAbsolutePosition(node->getParent());
		}
		node->updateAbsolutePosition();
	}
}

IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
instinct
Posts: 87
Joined: Sat May 10, 2008 3:42 pm

Post by instinct »

thanks CuteAlien :)
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

CuteAlien wrote:Wow, that's something I had missed so far... I always thought of that as recursive. I guess I was lucky so far it didn't mess stuff up (or I didn't notice).

You have to start with the root, so the easiest way is probably to do it recursively:

Code: Select all

//! update absolute positions for node including all it's parents, starting from the top-most parent
void RecursiveUpdateAbsolutePosition(irr::scene::ISceneNode * node)
{
	if ( node )
	{
		if ( node->getParent() )
		{
			RecursiveUpdateAbsolutePosition(node->getParent());
		}
		node->updateAbsolutePosition();
	}
}

Wouldn't we have to process all tree nodes to move the scene, not just the path to root?
L/
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Arcoroc wrote: Wouldn't we have to process all tree nodes to move the scene, not just the path to root?
The idea here isn't to move the scene but to ensure that the absolute position of just that node is up-to-date. But the calculation does access the positions of the parent so those have to be updated first. Note that you only need that if you need to access changed positions before the drawAll call which will update the whole scene.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

CuteAlien wrote:
Arcoroc wrote: Wouldn't we have to process all tree nodes to move the scene, not just the path to root?
The idea here isn't to move the scene but to ensure that the absolute position of just that node is up-to-date. But the calculation does access the positions of the parent so those have to be updated first. Note that you only need that if you need to access changed positions before the drawAll call which will update the whole scene.
thanks - makes sense.
L/
Post Reply