For positioning, rotation, and scaling the general method is:
1) For each object start by resetting any previous translations:
----------------------------------------------------------------
gl.glLoadIdentity
Alternatively, you can use
gl.glPushMatrix and
gl.glPopMatrix:
With this method you first 'push' the current translations to the stack. Next, set your own translations,scaling,rotations. Render the object. Finally, 'pull' (or Pop) the previous translations from the stack to restore the previous settings
2) Set desired position of the object in 3D space via x,y,z coordinates
----------------------------------------------------------------
gl.glTranslatef(x,y,z)
X is Left to right
Y is bottom to top *
Z is near to far
0,0,0 is center of the display by default
* NOTE: OpenGL uses inverted Y coordinate system
3) Set the rotation of the object where applicable
----------------------------------------------------------------
gl.glRotatef(rotX,1,0,0) -- Rotate around X axis (PITCH) by rotX units
gl.glRotatef(rotY,0,1,0) -- Rotate around Y axis (YAW) by rotY units
gl.glRotatef(rotZ,0,0,1) -- Rotate around Z axis (ROLL) by rotZ units
4) Set the scale of the object where needed
----------------------------------------------------------------
gl.glScalef(x,y,z) --- 1.0,1.0,1.0 is the default size
Have a look at my GLObjects demo. You will see these actions take place in the
glsv_Draw sub
Here is a basic example:
gl.glPushMatrix ' capture current translations
gl.glScalef(0.5,0.5,0.5) ' make object half its size
gl.glTranslatef(0.6,0.0,0) ' move it a little to the right
gl.glRotatef(1.5,0,1,0) ' rotate objects Y (YAW) axis
GLObject_Draw(obj1,gl) ' draw object
gl.glPopMatrix ' reset translations