Advertisement Jump to content


This topic is now archived and is closed to further replies.


My Quat Rotations

This topic is 5883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It seems my quaternion rotations only work if I do them in this order z,x,y, (creating the z,x,y, rotations quaternions and multiplying them together in that order). Is that right? I thought it wasn''t supposed to matter what order they were applied in.

Share this post

Link to post
Share on other sites
Are you multiplying quaternions or quaternion matrices?
q_x*q_y*q_z=q_xyz -> R_xyz


q_x -> R_x, q_y -> R_y, q_z-> R_z


Share this post

Link to post
Share on other sites
It goes something like this:


Quat.Rotatef(z, 0.f, 0.f, 1.f);

Quat.Rotatef(x, 1.f, 0.f, 0.f);

Quat.Rotatef(y, 0.f, 1.f, 0.f);

float matrix[16];



The function Rotatef creates a new quaternion and then applies it to the current quaternion. So basically I have created 3 quat's and multiplied them together.

[edited by - mindcode on December 5, 2002 3:37:43 PM]

[edited by - mindcode on December 5, 2002 3:38:37 PM]

Share this post

Link to post
Share on other sites
couple things to check:

1) sanity check of quat multiplication. work some examples out by hand and then plug them in make sure you get the same answers

2) make sure that you are correctly revesing the row/column ordering of your quaternion generated rotation matrix. openGL has backwards ordering to the rest of the world. hopefully you've already taken that into account.

also, and i'm surprised no one has asked yet: define "doesn't work". do you mean visually wrong rotation or do you mean no rotation at all?

oh, and you are aware that ordering of rotations always matters, right? taking 3 different rotation angles on the same object and applying them in different orders will result in different final orientations. (sorry if this is patronizing, i'm just working on various guesses of what "doesn't work" means)


[edited by - Palidine on December 5, 2002 3:45:21 PM]

[edited by - Palidine on December 5, 2002 3:47:01 PM]

Share this post

Link to post
Share on other sites
By "doesn't work" (I should've been more specific to start) I mean that the rotations are bad; not what you would expect them to look like. How warped they are depends on how the ordering of my transformations goes.

I read that opengl doesn't make any assumption on the row/column ordering of a matrix, as long as you were consistent in how you sent them to opengl.

[edited by - MindCode on December 6, 2002 8:52:54 PM]

Share this post

Link to post
Share on other sites
Maybe this will shed light on things (btw it's api emulates the opengl matrix api):

void MultQuaternion( float* quaternion ) {

float w1, x1, y1, z1;
float w2, x2, y2, z2;

x1 = g_Quaternion4fv[0];
y1 = g_Quaternion4fv[1];
z1 = g_Quaternion4fv[2];
w1 = g_Quaternion4fv[3];

x2 = quaternion[0];
y2 = quaternion[1];
z2 = quaternion[2];
w2 = quaternion[3];

g_Quaternion4fv[0] = w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2;
g_Quaternion4fv[1] = w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2;
g_Quaternion4fv[2] = w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2;
g_Quaternion4fv[3] = w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2;

void Rotatef( float degree, float x, float y, float z ) {

float q[4], r, s;

r = (degree / 180) * 3.14;

s = (float) sin((double) r);

q[0] = x * s;
q[1] = y * s;
q[2] = z * s;
q[3] = (float) cos((double) r);


void GetMatrix( float *matrix ) {

float w, x, y, z;

x = g_Quaternion4fv[0];
y = g_Quaternion4fv[1];
z = g_Quaternion4fv[2];
w = g_Quaternion4fv[3];

matrix[ 0] = 1.f - 2.f * (y * y + z * z);
matrix[ 1] = 2.f * (x * y + w * z);
matrix[ 2] = 2.f * (x * z - w * y);
matrix[ 3] = 0.f;
matrix[ 4] = 2.f * (x * y - w * z);
matrix[ 5] = 1.f - 2.f * (x * x + z * z);
matrix[ 6] = 2.f * (y * z + w * x);
matrix[ 7] = 0.f;
matrix[ 8] = 2.f * (x * z + w * y);
matrix[ 9] = 2.f * (y * z - w * x);
matrix[10] = 1.f - 2.f * (x * x + y * y);
matrix[11] = 0.f;
matrix[12] = 0.f;
matrix[13] = 0.f;
matrix[14] = 0.f;
matrix[15] = 1.f;

[edited by - MindCode on December 6, 2002 10:21:06 PM]

Share this post

Link to post
Share on other sites
Quaternions are not commutative under multiplication i.e. q1*q2 =/= q2*q1 just as the matrices are, M1*M2=/=M2*M1. So the order does matter.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!