Rotate scene node around local axis

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
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Rotate scene node around local axis

Post by happilylazy »

How would I rotate scene node around local axis (not world ones like rotateYZBy does)?

So, for example, that if I want to rotate around target up and down no matter at what side of target I am I always rotate around X axis.

Of course I would always have to turn to face the target so that my Y axis points towards the target.
What now??? =_=''
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You have to use matrices or quaternions.
You can find some useful bits here:
Free Flight (space flight) functions
and here:
Turn to target in 3D
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post by happilylazy »

I successfully circle around with my scene node (cube object) but it always circle around (0, 0, 0).
What do I have to do to make it circle around some specified point like (100, 100, 100)?

My current code

Code: Select all

core::vector3df my_rotation4 = my_cube4->getPosition();
core::matrix4 n;

if(receiver.IsKeyDown(irr::KEY_KEY_W))
	n.setRotationDegrees(core::vector3df(0.1, 0, 0));
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
	n.setRotationDegrees(core::vector3df(-0.1, 0, 0));

if(receiver.IsKeyDown(irr::KEY_KEY_A))
	n.setRotationDegrees(core::vector3df(0, -0.2, 0));
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
	n.setRotationDegrees(core::vector3df(0, 0.2, 0));

n.rotateVect(my_rotation4);
my_cube4->setPosition(my_rotation4);
What now??? =_=''
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You confuse position and rotation. Line

Code: Select all

my_rotation4 = my_cube4->getPosition();
should tell you that something is just not right.
but it always circle around (0, 0, 0)
You use no origin in your calculation, that is why its circling around 0,0,0.

And there is also distance to origin which you need to take in to account somehow.

I made tutorial which shows two methods to turn node around origin: Turn around origin in 3D

I hope its what you are looking for.
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post by happilylazy »

arras wrote:
but it always circle around (0, 0, 0)
You use no origin in your calculation, that is why its circling around 0,0,0.

And there is also distance to origin which you need to take in to account somehow.

I made tutorial which shows two methods to turn node around origin: Turn around origin in 3D

I hope its what you are looking for.
You are my savior. Method rotateAround1 is exactly what I need.
Thank you once more and please comment the code more extensively and make that thread into a tutorial about rotation because it rules and I found a lot of questions on that topic.
What now??? =_=''
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Your welcome :)

As for making it tutorial ...if there is something you wish to be commented more extensively, just let me know...
Post Reply