The coordinate system in which the objects in OpenGL are rendered (screen space) has an range of [-1,1]
for x
, y
, and z
.
With viewMatrix.setLookAt(g_eyeX, g_eyeY, g_eyeZ, 0, 0, 0, 0, 1, 0);
your example creates a transform matrix that is used to transforms the coordinates of the triangles from world space to camera space (the direction from which you look onto that object).
Because this transformation will change the coordinates of the triangles these may not be in the range of [-1,1]
anymore, in your example this happens for the z
coordinate (moving behind your screen).
To solve this issue you can use an orthographic to change the range of the z
coordinates without changing the perspective look, only the current z
values of the screen spaces are scaled.