## World and Object Rotations (Quaternions Are Killing Me)

Member
Posts: 33
Joined: 2002.04
Post: #1
I had been using quaternions in the following manner with success:

Code:
```... GLfloat Matrix[16]; //create temp quaternions from euler angle deltas, these are reset every frame qX.CreateQuaternion(rotX, 1, 0, 0); qY.CreateQuaternion(rotY, 0, 1, 0); qZ.CreateQuaternion(rotZ, 0, 0, 1); baseQuaternion *= qX; baseQuaternion *= qY; baseQuaternion *= qZ; //persistent quaternion baseQuaternion.CreateRotationMatrix(Matrix); glMultMatrixf(Matrix); ...```

What I want to do now is a Y rotation in world coordinates instead of object coordinates.

My thought process was that by taking the current matrix and multiplying it by the world up vector I would get the correct axis in object coords. Like so...

Code:
```Vector mv(0,1,0); //multiply world up vector by current rotation matrix mv.x = Matrix[0] * mv.x + Matrix[1] * mv.y + Matrix[2] * mv.z + Matrix[3]; mv.y = Matrix[4] * mv.x + Matrix[5] * mv.y + Matrix[6] * mv.z + Matrix[7]; mv.z = Matrix[8] * mv.x + Matrix[9] * mv.y + Matrix[10] * mv.z + Matrix[11];              mv.normalize(); //use vector as axis of rotation qWorldY.CreateQuaternion(5,mv.x,mv.y,mv.z); baseQuaternion *= qWorldY;```

This looks like it's working for a moment, but then the object starts to roll around funky. Am I going about this the right way? Feel free to point out anything wrong with my examples.

N.
Nibbie
Posts: 2
Joined: 2006.10
Post: #2
I don't know if this is your problem or not, but one thing to watch out for is that OpenGL does not index its matrix entries the way that you (or at least I) think it would. So if the Matrix[] that you're using to multiply the vector with is the same one that you passed to glMultMatrixf earlier, then you are actually passing in the transpose of your rotation matrix.
Nibbie
Posts: 2
Joined: 2006.10
Post: #3
However, a more serious problem is that your matrix multiplication code is broken. You reassign mv.x and mv.y before they are used in later lines of code.
Member
Posts: 33
Joined: 2002.04
Post: #4
Wow. Thanks for the reality check. That was all it was.