Remember about one of OpenGL basics - about projections. Look at start of onDraw() method in Colored 3D cube example.

Using java Syntax Highlighting

- //get screen physical size in pixels
- int w = getWidth();
- int h = getHeight();
- //setup OpenGL raster area to whole screen
- gl.glViewport(0, 0, w, h);
- //calculate the ratio between screen width and height (formfactor)
- float ratio = (float)w / h;
- //switch to operations with projection matrix
- gl.glMatrixMode(gl.GL_PROJECTION);
- //init projection matrix with trivial matrix
- gl.glLoadIdentity();
- //setup projection
- gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);

Parsed in 0.013 seconds, using GeSHi 1.0.8.4

The last call is very important. It setups viewing area. glFrustumf() method has the next semantics:

glFrustumf (float left, float right, float bottom, float top, float near, float far)

where left, right, top, bottom, near, far - corresponding bounds of viewing area. So, viewing area is some truncated pyramid, oblique-angled in general case(see picture).

Eye (or camera) is placed in the beginning of coordinates (0,0,0) or in imagine top of this truncated pyramid.

X-axes goes from left to right.

Y - from bottom to top.

Z - from near to far.

If right = - left and top = - bottom, pyramid will be symmetric. Else it will be oblique-angled. In colored 3D cube tutorial left=- ratio, right=ratio, bottom=-1. top=1, near=2, far=12. Hence pyramid is symmetric.

As you can see on the picture, any surface {Z=const} will be a plane, parallel near (z=near] and far(z=far) planes. Particularly near plane is a screen surface, or projection plane. Namely to near plane relays left, right, bottom and top parameters. It sign that if point lays at near plane (has coordinates (x,y,near)), then if x=left then point lays on left screen side, if x=right - on right, if y=bottom on bottom, if y=top on top. This allows to calculate screen coordinates of point that has any value of z.

Be continued tomorrow.