Archived

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

Chris Wachauf

Problem with Quaternions

Recommended Posts

Hi, After I read the quaternions-code from gametutorials.com and implemented it, I wanted to test it, but every time I rotate around more than one axis, there`s a mistake, the object I rotate is somehow stretched. What can be the mistake ? I haven`t found anything wrong in the code. For example, when I rotate the Vectors around 1,1,0 the Vectors scale sometimes. They stretch float matrix[16]; quaternion::CreateAxisFromAngle(1.0f,1.0f,0.0f,angle+=0.5f); // quaternion::CreateMatrix(matrix); glMultMatrixf(matrix); class GLQuaternion { float x; float y; float z; float w; public: CQuaternion(); CQuaternion(float a_x,float a_y,float a_z,float a_w); void CreateMatrix(float* pMatrix); void CreateFromAxisAngle(float X,float Y,float Z,float degree); }; void GLQuaternion::CreateFromAxisAngle(float X,float Y,float Z,float degree) { float angle = DegreeToRadiant(degree); float result = (float)sin( angle / 2.0f ); w = (float)cos( angle / 2.0f ); x = float(X * result); y = float(Y * result); z = float(Z * result); } void GLQuaternion::CreateMatrix(float* pMatrix) { if(!pMatrix) return; // First row pMatrix[ 0] = 1.0f - 2.0f * ( y * y + z * z ); pMatrix[ 1] = 2.0f * ( x * y - w * z ); pMatrix[ 2] = 2.0f * ( x * z + w * y ); pMatrix[ 3] = 0.0f; // Second row pMatrix[ 4] = 2.0f * ( x * y + w * z ); pMatrix[ 5] = 1.0f - 2.0f * ( x * x + z * z ); pMatrix[ 6] = 2.0f * ( y * z - w * x ); pMatrix[ 7] = 0.0f; // Third row pMatrix[ 8] = 2.0f * ( x * z - w * y ); pMatrix[ 9] = 2.0f * ( y * z + w * x ); pMatrix[10] = 1.0f - 2.0f * ( x * x + y * y ); pMatrix[11] = 0.0f; // Fourth row pMatrix[12] = 0; pMatrix[13] = 0; pMatrix[14] = 0; pMatrix[15] = 1.0f; } hope somebody knows this problem too...

Share this post


Link to post
Share on other sites