Ok, I'll give it a shot...
Your camera will need much of the same functionality as your regular entities in the game. Specifically, it will need to have both a position and orientation in your game world.
A simple 3D vector can be used to store the world position whilst a unit quaternion can be used to represent its rotation from some reference direction. I should stress here that only unit quaternions can be used to represent rotations. This is to say that the norm/magnitude/length of the quaternion should be equal to 1.0.
The unit quaternion represents a rotation from some reference vector - usually the "forward" vector (0, 0, 1). OpenGL uses a right-handed coordinate system where the z-axis points out of the screen. So unless you have a good reason for using something different, I would choose (0, 0, 1) to be your reference "forward" vector. Together, the quaternion rotation and forward vector represent an orientation.
This is really all that you need for the positioning and orientation of a camera. A suitable maths library should provide the functions necessary for manipulating the camera's rotation quaternion. For example, Unity provides the Quaternion.LookRotation function. With a similar function you can orient your camera to point in a given direction:
Vector3 direction = new Vector3(1.0, 0.0, 0.0); // Right
camera.rotation = Quaternion.LookRotation(direction);
To rotate the camera by some given unit quaternion q
, you can simply multiply this by the camera's unit quaternion rotation on the left:
camera.rotation = q * camera.rotation;
Note that you don't need to normalise the result since the Hamilton product of two unit quaternions is itself a unit quaternion. Suitable 3D maths libraries will provide a constructor or static factory function for creating unit quaternions from Euler angles or from an angle about a given axis (angle-axis).
When rendering you will need to supply OpenGL or DirectX with a view matrix. This is in fact the inverse of the camera's transformation matrix. Now, if you are using a quaternion for the camera's rotation, you will need to convert this quaternion to a rotation matrix, R
. You will also need to convert the camera's position into a translation matrix, T
. Multiply these two matrices together in order to find the camera's transformation matrix. Matrix multiplication is not commutative; the order of multiplication matters and which order you choose depends on the kind of behavior you want.
Finally, your camera will need a projection matrix. You can think of this as the lens of the camera. You will probably want to use a perspective projection for a FPS game. For other games you may or may not want to use an orthographic projection. There is plenty of information available on finding/calculating these matrices so I won't elaborate.
That's all you really need. I should mention that you can use matrices instead of quaternions to represent the camera's rotation. This is generally more of a personal preference than a performance or memory efficiency consideration.
You can take a look at the small 3D maths library I am currently working on if you are interested in the mathematics side; such as how to calculate a "look at" quaternion.