Hi there.
I’m implementing a 3D centipede game (for practice) and I’ve struck an oddity. I use glLookAt to place the camera at the end of the playing field (keyboard controls haven’t been implemented yet), yet when display(GLDrawable draw) is called it treats the camera position as (0,0). The code goes thus:
[i]public void display(GLAutoDrawable draw) {
GL gl = draw.getGL();
GLU glu = new GLU();
char piece;
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
glu.gluLookAt(19.0, 0.0, 100.0, 19.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// drawGun(gl);
drawGround(gl);
for (float i = 0; i < rows ; i++) {
for (float j = 0 ; j < cols ; j++) {
piece = pa.get((int)i,(int)j);
if (piece == Run.MUSHROOM) drawShroom(gl, i, -j);
else if (piece == Run.HIT_MUSHROOM) drawHit(gl, i, -j);
else if (piece == Segment.RIGHT || piece == Segment.LEFT) drawSeg(gl, i, -j);
else if (piece == Run.NAPALM) drawNapalm(gl, i, -j);
}
}
gl.glFlush();
}[/i]
where the first call in each draw* method is a call to this:
private final void moveToLocation(GL gl, float row, float column) {
gl.glLoadIdentity();
gl.glTranslatef(row, 0, column);
}
So what I get is a nice, colourful rendering rotated and translated improperly. Is this a gluLookAt problem, or do I have to manually re-translate each object???