rotation on an axis

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
drulz
Posts: 11
Joined: Thu Jun 09, 2005 5:08 am

rotation on an axis

Post by drulz »

is there a helper fucntion that accepts a 3d vector tp perfrom rotation on an axis?
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi,

Can you be more precise. Do you want to rotate around that vector or around the x, y, z axis.

There are lots of posts on the subject of rotation. You can search for these keywords:
Euler angle
Gimbal lock
Quaternion
Guest

Post by Guest »

i want to rotate aronund an vector
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

In that case quaternions are the answer. I am not an expert in its use, but you may get some ideas from this example:

Code: Select all

const irr::f64    GRAD_PI = 180.0 / 3.1415926535897932384626433832795;
core::vector3df   Target;
core::quaternion  QuatStart(0,0,0,1);				// Initial rotation, set to 0 in example
core::vector3df   Rotation(1.0f, 0.0f, 0.0f);		// Your rotation vector
irr::f64          Degrees = 90.0f / GRAD_PI; 		// 90 degrees around vector
core::quaternion  QuatRotation(Rotation.X,Rotation.Y,Rotation.Z,Degrees);

QuatStart.toEuler(Target);
Target	*= GRAD_PI;
printf("Before xyz=%2.4f,%2.4f,%2.4f\n", Target.X, Target.Y, Target.Z);

QuatStart *= QuatRotation;				// calculate rotation
QuatStart.toEuler(Target);				// store in new vector as Euler rotation 															// for use with irrlight setRotation function
Target	*= GRAD_PI;					// convert back to degrees
printf("After xyz=%2.4f,%2.4f,%2.4f\n", Target.X, Target.Y, Target.Z);
If you search the forum or google for the terms I mentioned in my previous post you will find lots of useful links to sites explaining the use of quaternions like:

http://www.euclideanspace.com/maths/alg ... /index.htm
http://www.isner.com/Transform/IsnerTra ... nip_04.htm

Maybe some wise person has time to write a tutorial on the subject of rotations and quaternions as it leads to questions often :idea:
Raymond

but how to rotate a node about an axis

Post by Raymond »

I got similar problem and what I want is to rotate about a vertical axis instead of its own y axis of the node. How can I do that ?
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi Raymond,

Not sure if this is what you want, but these quaternions give you a rotation about the x, y or z axis.

Code: Select all

core::quaternion QuatX(sin(degrees / 2),0             ,0             ,cos(degrees / 2));
QuatX.normalize();

core::quaternion QuatY(0             ,sin(degrees / 2),0             ,cos(degrees / 2));
QuatY.normalize();

core::quaternion QuatZ(0             ,0             ,sin(degrees / 2),cos(degrees / 2));
QuatZ.normalize();

and then multiply like this:

Code: Select all

QuatStart *= QuatY;             // for example around Y xis

Still nobody inclined to write a tutorial about quaternions :?: :roll:
Post Reply