When you render a triangle, the vertices' coordinates are interpreted as follows:
- The x-coordinate will influence the horizontal position on the viewport. -1 is the left edge and +1 is the right edge.
- The y-coordinate will influence the vertical position on the viewport. -1 is the bottom edge and +1 is the top edge.
- The z-coordinate will influence the depth information. -1 is the position at the camera's plane (near) and +1 is the far plane. This value is usually used to write to the depth-buffer.
That's why your simple example renders a visible triangle at the far plane.
Now let's come to the view transformation. The transformation will be constructed from four vectors. The image of (1, 0, 0), the image of (0, 1, 0), the image of (0, 0, 1) and a translation vector. However, since the view transformation is an inverse transformation, the resulting matrix has to be inverted.
You are right that the view direction is center - eye
. However, that is not what we need for the matrix. We need the image of (0, 0, 1). Usually, OpenGL programs use a right-handed coordinate system. In that system the camera looks into negative z-direction. So center - eye
is actually the image of (0, 0, -1). The image of (0, 0, 1) is then just eye - center
. That's what you need.
With this definition you will also need an appropriate projection transformation. Otherwise you will only see things behind the camera (because that's where the z-coordinate is positive and, hence, have a positive depth value). The projection transformation is responsible for turning negative z-coordinates into positive depth values.