Can anyone shed some light on this as to why it's not acting as I think it should? I honestly thought it would shrink the object as the z got further away (further negative) and inflate the object as the z got closer (to zero), though I feel I should have to do these calculations myself somewhere.
Anyway here's some code to work with, if you can work with it:
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
public class zMovement {
private float z = -.5f;
public void pollInput() {
while (Keyboard.next()) {
if (Keyboard.isKeyDown(Keyboard.KEY_Q)) {
z -= 1;
}
if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
z += 1;
}
}
}
public void start() {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("Moving in Z");
Display.create();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Initialize openGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// left, right, bottom, top, znear, zfar
glOrtho(0, 640, 480, 0, 100, -100);
glMatrixMode(GL_MODELVIEW);
while (!Display.isCloseRequested()) {
// Clear screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
// Set the color of the square
// Red, Green, Blue
GL11.glColor3f(.5f, .5f, .5f);
glLoadIdentity();
// Draws the square
glBegin(GL11.GL_QUADS);
glVertex3f(320 - 50, 240 - 50, z);
glVertex3f(320 + 50, 240 - 50, z);
glVertex3f(320 + 50, 240 + 50f, z);
glVertex3f(320 - 50f, 240 + 50f, z);
glEnd();
pollInput();
Display.update();
}
Display.destroy();
}
/**
* @param args
*/
public static void main(String[] args) {
zMovement disp = new zMovement();
disp.start();
}
}