Problem with Quaternions

Started by
1 comment, last by Chris Wachauf 21 years, 11 months ago
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...
Advertisement
the axis needs to be normalized.. that could be the problem..

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Hi,

huge thanks for your reply, now it works fine.



This topic is closed to new replies.

Advertisement