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

1. [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
Code :
```        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 is not
Code :
```        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;
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?

2. Try:

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

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

3. Originally Posted by nickels
Try:

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

(ab)^-1=(ab)*/||ab||^2=b*a*/||ab||^2
which is not equal to
b^-1 a^-1 = b*a* /(||b||^2||a||^2) unless when ||ab||=||a||=||b||=1
Actually, I think this is wrong since ||ab||^2=(ab)(ab)*=abb*a*=-aba*b*=--aa*bb*=||a||^2||b||^2=1x1=1

4. 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....

5. Originally Posted by nickels
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....
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.

6. interesting theory!

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•