Page 1 of 1

Rotate scene node around local axis

Posted: Sat Nov 28, 2009 5:49 pm
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.

Posted: Sun Nov 29, 2009 10:33 am
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

Posted: Mon Nov 30, 2009 3:35 pm
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);

Posted: Tue Dec 01, 2009 1:11 am
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.

Posted: Tue Dec 01, 2009 6:03 pm
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.

Posted: Tue Dec 01, 2009 8:45 pm
by arras
Your welcome :)

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