# Quaternion rotation

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

## Recommended Posts

Hi to all. I compute three rotation quaternions and then multiply them for obtain a TOTAL rotation matrix. In this way: // create quaternion for rotation around y axis qYaw.CreateRotationQuaternion(0.0f, 1.0f, 0.0f,yawDegree); // create quaternion for rotation around x axis qPitch.CreateRotationQuaternion(1.0f, 0.0f, 0.0f, pitchDegree); // create quaternion for rotation around z axis qRoll.CreateRotationQuaternion(0.0f, 0.0f, 1.0f, rollDegree); // then i multiply them for obtain total rotation quaternion q = qRoll * qYaw * qPitch; q.CreateQuaternionMatrix(rMatrix); glMultMatrixf(rMatrix); // now after glMultMatrixf(rMatrix); // the rotation seem to work well. // But then i extract view vector form rMatrix in this way: viewVect.x = Matrix[2]; viewVect.y = Matrix[6]; viewVect.z = Matrix[10]; posVect.x +=viewVect.x; posVect.y +=viewVect.y; posVect.z +=viewVect.z; // then i traslate glTranslatef(-posVect.x, -posVect.y, posVect.z); // BUT the traslation seem to be bloked on a certain axis I think that is not the look vector thet i get from rotation matrix. How can i get the look vect at this point? Tnx very much.

##### Share on other sites
I'm wondering why you're negating some of your translation components. Which leads to another question - are you trying to set up an object matrix (say, for rendering your object) or a view matrix? Anyway, parts of your code indicate the former and parts point toward the latter, which is probably why it's not working as you expect.

##### Share on other sites
hei tnx, i have corrected that and traslation now seem to work well BUT...this kind of camera can suffers of gimbal lock or something similar? The camera work well for a lot but when i see the object from backward the rotation on the x axis became a rool. Why?
Tnx.

##### Share on other sites
ya, your camera will suffer gimbal lock. you're still using euler angles, you're just doing your rotations with quaternions. using quaternions is not the magic gimbal lock remover. to me it looks like you're keeping 3 angles and each screen you build a NEW matrix that is yaw, pitch, roll. to avoid gimbal lock you keep your last camera matrix, and you concatinate to it with new rotations. that is to say you dont rebuild it each time using 3 euler angles.

Tim

1. 1
2. 2
3. 3
Rutin
17
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013218
×