Rotation around parent?

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

Rotation around parent?

Post by instinct »

I want to rotate a SceneNode around it's parent. The docs say rotation is done relative to its parent, but apparently calling setRotation does not rotate it around the parent :( my problem is best explained using sample code:

Code: Select all

pParent->setPosition(vector3df(0,0,0));

pChild->setParent(pParent);
pChild->setPosition(vector3df(-20,0,0));

//now, i want the child to get on position (20,0,0)
pChild->setRotation(0,180,0);
So basically what Im trying to achieve is to make pChild change position by rotating it around its parent, thus some sort of making half a circle with respect to its parent.

Im obviously doing it wrong, but how to do it correct?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You'd add an empty scene node as parent of the top node, at relative position (0,0,0). Then add your second node as child of this empty node. Now rotate the empty node to (0,180,0) and your child node will rotate around the center of the top node.
instinct
Posts: 87
Joined: Sat May 10, 2008 3:42 pm

Post by instinct »

Doh, why didn't i think of this....thanks hybrid!
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

tried the parent/child thing as described.

as you stated
You'd add an empty scene node as parent of the top node, at relative position (0,0,0).
since i want my camera to rotate around my hero. I chose the hero to setparent->emptyscene node and set position to (0,0,0)
Then add your second node as child of this empty node.
empyscene->addchild(camera)
Now rotate the empty node to (0,180,0) and your child node will rotate around the center of the top node.
it's rotating relatively to (0,0,0) =( not the hero. what do i need to set to make sure it's turning around the hero? also the hero is moving around the axis as well. :oops:
Kamikaze
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Set the empty scene node's position to where you want it the camera circle around.
Post Reply