[glm] Use quaterions to move the camera direction according to mouse movement

I am trying to use quaterions to move the camera direction vector in the following way.

This code is perfectly working


        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) );

        Camera1.SetCameraDirection(temp2 * (temp1 * Camera1.GetCameraDirection() * glm::inverse(temp1)) * glm::inverse(temp2));

this code is 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;
        Camera1.SetCameraDirection(temp3 * Camera1.GetCameraDirection() * glm::inverse(temp3));

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.

Why I cannot multiply quaterions successfully? Am I using GLM in a wrong way?

Try:


glm::quat temp3 = glm::normalize(temp2 * temp1);

(ab)^-1=(ab)/||ab||^2=ba*/||ab||^2
which is not equal to
b^-1 a^-1 = ba /(||b||^2||a||^2) unless when ||ab||=||a||=||b||=1

[QUOTE=nickels;1255112]Try:


glm::quat temp3 = glm::normalize(temp2 * temp1);

(ab)^-1=(ab)/||ab||^2=ba*/||ab||^2
which is not equal to
b^-1 a^-1 = ba /(||b||^2||a||^2) unless when ||ab||=||a||=||b||=1[/QUOTE]

Actually, I think this is wrong since ||ab||^2=(ab)(ab)=abba*=-abab=–aabb=||a||^2||b||^2=1x1=1

I would make sure that Camera1.SetCameraDirection takes a const reference to a quaternion and that Camera1.GetCameraDirection() returns a quaternion by value (weird things could happen if it returns a reference…).
No more ideas…

[QUOTE=nickels;1255115]I would make sure that Camera1.SetCameraDirection takes a const reference to a quaternion and that Camera1.GetCameraDirection() returns a quaternion by value (weird things could happen if it returns a reference…).
No more ideas…[/QUOTE]

The issue was that mamo had wrong expectation for the quaternion constructors. It doesn’t take an axis and an angle but there is a function for that called angleAxis.