0
\$\begingroup\$

I'm want to control the direction my camera looks, so I'm using Euler angles, so rotating around an axis is relative to rotation around previous axis. Something like this.

Euler Angles

I want to always rotate using the blue axes. So I'm using three separate matrices to track rotation along their respective axes.

... 

glm::vec3 mulVec (glm::mat4 const&, glm::vec3&); 

glm::vec3 camPos = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 target = glm::vec3(0.0f, 0.0f, -5.0f);
glm::vec3 camup  = glm::vec3(0.0f, 1.0f, 0.0f);

tulsi::ModelInput a1;

while (1) {

    ... 

    a1.tick();  // Tracks user input. 

    glm::mat4 lookat = glm::lookAt(
                    camPos,
                    mulVec(a1.yAxis * a1.xAxis, target), 
                    mulVec(a1.yAxis * a1.xAxis, camup)
                    );
    ... 
}

I get the desired output (rotate around x axis then y)

working

But when I switch the order of multiplication, I get different output (rotate around y then x axis)

glm::mat4 lookat = glm::lookAt(
                    camPos,
                    mulVec(a1.xAxis * a1.yAxis, target), 
                    mulVec(a1.xAxis * a1.yAxis, camup)
                    );

not working

So whats happening here. I'm assuming the order should not matter.

\$\endgroup\$
3
\$\begingroup\$

Order does matter. For fps games it should generally be yaw -> pitch -> roll. When using matrices, note that multiplication order might be the complete opposite.

Think about it, doing the pitch first would also rotate the y axis, and rotating around that will make the y coordinate of the direction vector go up and down.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.