Question

I am using OpenGL to create a graphics engine. However, when I apply rotations to rotate my camera in place, the world turns instead.

See here (please excuse some clipping issues - the remnant cubes don't exist):

I use quaternions to rotate my camera which has an initial rotation. Every time the user hits Q or E, I multiply the original quaternion with a rotation around the Y-axis.

The following is my camera to clip matrix, based on the camera's quaternions:

1 - 2y^2 - 2z^2    2xy - 2wz    2xz + 2wy    0
2xy + 2wz    1 - 2x^2 - 2x^2    2yz - 2wx    0
2xz - 2wy    2yz + 2wx    1 - 2x^2 - 2^2     0
-xt    -yt    zt    0

where x/y/zt are the camera's current position, and w,x,y,z are the camera's current quaternion rotation vector.

My matrices are multiplied as such:

cameraToClip * worldToCamera * modelToWorld * position

where position is the location of the vertex being transformed.

Should I be multiplying every vertex by the camera matrix? How do I debug this issue further?

Was it helpful?

Solution

As I said in the comments, I simply had to call inverse on my worldToCamera matrix. This is because, as datenwolf states, I'm transforming in the opposite direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top