Your Method on FPS Camera

What is your method for creating a FPS camera?

There are a lot, and none of them have proper commenting that explains the through process through it. I used to have code for an FPS style, including moving left and right, but I lost the code and it has escaped my mind. :frowning: Then it brought up the question of methods for FPS styled cameras! :slight_smile:

Pseudo-code:


// Some needed fields:
Matrix4f m;
Vector3f pos;
float angleX, angleY;

// Moving forward:
forward = (-m02, 0, -m22); // i.e. the third row of <m> negated, with y restricted to 0
pos += forward * dt;
// moving backward is just: pos -= forward * dt

// Moving right:
right = (m00, m10, m20); // i.e. the first row of <m>
pos += right * dt;
// moving left is just: pos -= right * dt

// update angleX/angleY based on mouse motion delta:
angleX += mouseDY
angleY += mouseDX
// additionally, clamp/restrict angleX to -90/+90 degrees

// Building view matrix:
m = identity
m = m * rotate(angleX)
m = m * rotate(angleY)
m = m * translate(-pos.x, -pos.y, -pos.z)

where: