World and Object Rotations (Quaternions Are Killing Me) - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: World and Object Rotations (Quaternions Are Killing Me) (/thread-5882.html) World and Object Rotations (Quaternions Are Killing Me) - Nickolei - Feb 14, 2005 03:08 PM 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. World and Object Rotations (Quaternions Are Killing Me) - belthaczar - Feb 14, 2005 04:18 PM 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. World and Object Rotations (Quaternions Are Killing Me) - belthaczar - Feb 14, 2005 05:44 PM 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. World and Object Rotations (Quaternions Are Killing Me) - Nickolei - Feb 14, 2005 06:12 PM Wow. Thanks for the reality check. That was all it was.