# Can a 4x4 matrix describe a camera's perspective?

I'm working with a closed-source 3D engine, and it only allows you to set the view projection via a 4x4 matrix. Can this matrix describe the camera's translation, rotation & perspective?

I turned perspective on/off in the engine using a function call, and the matrix values are as follows.

Without perspective:

``````1   0   0   -0.0559203194265751
0   1   0   -0.0251115292255206
0   0   1   -0.016129
0   0   0   0.0926626011715394
``````

With perspective:

``````1   0   0   -0.0560158276396793
0   1   0   -0.0251013526176432
0   0   1   -0.016129
0   0   0   0.0308875337238465
``````
-

Yes, it can. You should simply calculate a View Matrix and Projection Matrix separately (which are both 4x4 matrices), multiply them together in that order and pass the result (which is still a 4x4 matrix) to your 3D engine.

Do you know the difference between a View Matrix, a Projection Matrix, and Perspective? You seem to be using those terms a bit too loosely, but they're all different concepts.

The View Matrix describes the position and orientation of your camera, which is usually just a series of translations, rotations and scalings. It works by moving the entire world back in the inverse direction around the camera, so that the camera becomes the new origin.

The Projection Matrix describes how to perform the mapping between 3D and 2D coordinates. However, this mapping does not happen by applying the matrix - the matrix only prepares the values for the projection. The actual projection is done in a separate step called the homogeneous divide (or perpsective divide) which is basically doing the following:

``````(x,y,z,w) => (x/w, y/w, z/w) // Homogenize Vector = Divide everything by last component
``````

The are many different types of Projection Matrices, with the most popular ones being the Perspective Projection and the Orthographic Projection.

A Perspective Projection sets up a W value so that when doing the homogenous divide, objects further away from the camera will look smaller. The easiest way to do this is just to divide everything by Z.

The Projection Matrices used in real applications are typically a bit more complex than that because they also have to deal with field of view, aspect ratio and the near/far planes, but the underlying concept is still the same, it just has a few scaling calculations thrown into the mix.

-