# Why do these quaterion multiplications produce different results?

I am trying to use quaterions to modify the camera direction vector.

This code works perfectly:

glm::quat temp1 = glm::normalize( glm::quat((GLfloat)( -Input1.MouseMove.x  * mouse_sens * time_step), glm::vec3(0.0, 1.0, 0.0)) );
glm::quat temp2 = glm::normalize( glm::quat((GLfloat)( -Input1.MouseMove.y  * mouse_sens * time_step), dir_norm) );

This code does not:

glm::quat temp1 = glm::normalize( glm::quat((GLfloat)( -Input1.MouseMove.x  * mouse_sens * time_step), glm::vec3(0.0, 1.0, 0.0)) );
glm::quat temp2 = glm::normalize( glm::quat((GLfloat)( -Input1.MouseMove.y  * mouse_sens * time_step), dir_norm) );

glm::quat temp3 = temp2 * temp1;

Why can I not multiply quaterions successfully? Am I using GLM wrong?

• – danijar Sep 22 '13 at 11:51
• How is it not working? – ltjax Sep 23 '13 at 16:06
• The two pieces of code, from my understanding of glm, should produce the same result. However, they are not. The first piece of code produce expected result. In the second piece of code when i move the mouse I get extremely small movements in an apparently random direction. – Marco Sep 23 '13 at 19:24
• Have you tried flipping temp2 and temp1 ? Don't forget that quaternion multiplication is not commutative*( AB != B*A ). – akaltar Dec 24 '13 at 1:43
• Try to normalize your quaternions after each multiplication. – kolenda Mar 6 '14 at 16:03

t2 * (t1 * direction * inverse(t1)) * inverse(t2)