0

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.

Atul
  • 101
  • 1
  • 2

1 Answers1

3

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.

Bálint
  • 14,887
  • 2
  • 34
  • 55