# Understanding view matrix

I've been reading several sources in the web about transforming world-space points into camera-space ones. I am building my view-matrix from the following parameters

1. Camera position
2. Point the camera is looking at
3. Up vector


I perfectly understand the meaning of each of the parameters, however, there are still some doubts.

1. How is the direction vector built? We have camera position and lookat position, is it camPos-lookatPos or lookatPos-camPos? In other words, does the direction vector aligns with (goes in the same direction of) the world +z-axis or is opposite to it? Direction is a bit confusing since it makes me think it goes the direction the camera lens is pointing to.
2. What's the reasoning behind translating the camera to the origin? How does this simplifies math?

My view matrix looks like follows

$$V = \begin{matrix} Rx & Ry & Rz & 0 \\ Ux & Uy & Uz & 0 \\ Fx & Fy & Fz & 0 \\ -CamPosx & -CamPosy & -CamPosz & 1 \end{matrix}$$

1. Will this V matrix convert from camera to world or from world to camera coordinates? How can I understand which direction it is going?

There is no relation between direction's direction and the world axis. And that's fortunate otherwise it would mean your camera is not a free view, it's some kind of a axis bound camera, which has its usages but most likely nothing in your mind right now.

The default camera matrix is looking at +z when everything is Identity, that's most surely where you got confused. Know that this is purely a convention, but sticking to a widely adopted convention allows for easy compatibility with libraries like glm.

the direction vector goes outward, so its normalize(lookat - campos).

The view matrix can be constructed directly with TBN vectors in rows 0 1 2 :)
• @BRabbit27 your image is interesting, it does mention the default word which is important. I'm curious as to why the cam is pointing to -z, maybe a row matrix vs column matrix thing again ? – v.oddou Jun 2 '16 at 6:07
• @BRabbit27 oh right, we can think of it this way: an identity camera matrix is the same as no view matrix. therefore we end up with the default basis of the API. In OpenGL we definitely see towards -z by default. In DirectX historically I've used LeftHanded systems I guess which made me reverse z. – v.oddou Jun 2 '16 at 6:09
• In Scratchapixel the authors use row-major matrix and right-hand system. So actually when you say "camera looking along" it means the direction the lens points to? Maybe a mistake in the image? I think, if they say "looking along -z", the direction vector is as you just said lookat - campos ? – BRabbit27 Jun 2 '16 at 6:14