The view matrix is the easiest to visually
conceptualize, as it has only three components: the position of the
camera in world space, where the camera looks, and what direction is up.
In the example you used a moment ago, the camera is located at a point
(2,3,–5) in world space, looking at the origin (0,0,0), with the up
direction being the constant up direction on the Vector class (0,1,0);
you can visualize this as seen in Figure 1.
Notice how you see a portion of
the cube? What if you moved the camera somewhere else to see a different
portion of the cube? Try replacing that first vector with a new Vector3(3,–2,4) and see how your view changes. Notce that you’re looking at a completely different angle of the cube, as seen in Figure 2.
The second parameter to CreateLookAt
is also easy to conceptualize because it is the position the camera
looks toward. In the example given, the box is located at (0,0,0), and
the camera looks there, too, so the box is in the center of the screen.
If you changed the second parameter instead to a vector of (–2,0,0), you
would expect that the camera would be looking more to the left
(negative x is to the left when the camera is in the positive Z axis),
so the box should be more to the right. By extension, using a vector of
(2,0,0) would make the box appear to the left (because the camera looks
to the right of it).
Of course, if you changed the
location of the camera to the opposite side of the Z axis (3,–2,4), then
the look at point of (2,0,0) would cause the box to appear on the right
because the camera looks to the left of it (positive x is to the left
when the camera is in the negative Z axis).
The final parameter to the CreateLookAt method is the vector that describes what up is. In the previous example, you used Vector3.Up,
which is a vector of (0,1,0), which means the up direction of the
camera follows the positive Y axis. Imagine the camera is your eyes
(because after all, that is what it is), and you’re standing on a flat
surface. The positive Y axis (0,1,0), is up to you. If you stood on your
head, up to you would be the negative Y axis, and everything would
appear upside down. Change your last parameter in the CreateLookAt method to Vector3.Down,
and notice that you’re still looking at the box in the same way; it’s
just upside down now, much like it would be if you looked at it while
standing on your head.
By the same mechanism, if you tilted your head to the right, so up was Vector3.Right,
you’d still see the same image, but instead of being right-side up or
upside down, it would be rotated 90 degrees. You can visualize the up
vector as the imaginary ray that runs from the center of the camera
through the top of the camera, as you can see in Figure 3.