Skip to main content
GameDev.net gamedev.net
🔒 Locked

Constructing a Camera Matrix

Started by Monder Nov 19, 2003 at 5:00 PM 0 replies 450+ views
Original Post
Monder
Monder
Can anyone tell me how I would go about constructing a camera matrix? By camera matrix I mean a matrix that translates vertices from world space to view space and you can define abitrary axes for the view space. I tried google and working things out myself but everything I tried just didn''t seem to work I either got a view that was completely screwed up or the camera didn''t work quite right (Things were rotating round the origin instead of the camera postition etc). I''m sure it''s simple I just can''t seem to get it working
Zakwayda
Zakwayda
There are quite a few ''gotchas'' involved in getting this working, having to do with such things as what order you perform the operations in, whether your matrix is row- or column-major, etc. Are you in OpenGL? Software?

In general, the rows (or columns) of a 3x3 rotation matrix contain the three orthogonal axes of the local coordinate system (for your camera, these would be the forward, up, and left/right vectors). The first question is, how is the orientation of your camera represented? Euler angles? Axis-angle? Quaternions? There are methods for constructing a 3x3 orientation matrix from each of these, and that''s probably where you want to start. The book ''3D Math Primer'' is a good reference.

Once you have such a matrix, you can multiply a vector by it to rotate the vector from world to local or local to world space. Whether the rotation is local to world or world to local depends on how your matrix is set up and whether you''re using row or column vectors. Transposing a matrix (flipping it along its diagonal) will generally change it from a world/local to local/world matrix and vice versa.

If you camera is rotating around the origin rather than it''s own position, you may be rotating and translating in the wrong order. If you''re doing the transformations yourself in software, you can combine rotating and translation together using 4x4 matrices and homogenous 4d vectors.

Ok, so it''s actually fairly complicated. Again I would recommend ''3D Math Primer'', which goes through all this stuff step by step.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.