Notifications
Clear all

[Closed] [SDK] Quaternion rotation

Hi, am I using this formula correct?
I want to use quaternions for rotation to avoid jimbolo effect:

[...]
Quat q(x, y, z, w);
Matrix3 mat_knots_rotation;

mat_knots_rotation.SetRotate(q);
mat_knots_rotation.TransformPoints(.. my vertex bufers..)
[...]

Well its actually works, the mesh is rotating, but I am confused about values that should I use for creating Quat q. for example if I am increasing ‘w’ value from 0 to 20, the mesh rotates but slows down and stops…

the x,y,z makes a vector, should I put thees numbers already normalized? what values can by put as ‘w’. Its a degree of rotation but should I convert degrees to radians first?

Should I also use q.Normalize() for some reason? or when?

Thanks in advance!

3 Replies

hmm… I found more informatin and used this formula for x,y,z and w

x = RotationAxis.x * sin(RotationAngle / 2)
y = RotationAxis.y * sin(RotationAngle / 2)
z = RotationAxis.z * sin(RotationAngle / 2)
w = cos(RotationAngle / 2)

and so in the code:

[...]
float rot_angle = DEG_TO_RAD(w) / 2.0f;
float sin_rot_angle = sinf(rot_angle);

Quat q(x * sin_rot_angle, y * sin_rot_angle, z * sin_rot_angle, cosf(rot_angle));
Matrix3 mat_knots_rotation(1);

mat_knots_rotation.SetRotate(q);
[...]

I think it works now… its a pity that they didn’t mention about it in the sdk reference …

there would be no need as they already provide

Quat& Quat::SetEuler  (  float  X,    float  Y,  float  Z )

and

Quat &  Quat::Set (const AngAxis &aa)

also you can circumvent Quat altogether and use

void Matrix3::SetAngleAxis ( const Point3 & axis, float angle )

Thanks Klvnk!