Change Camera Position From Bird's Eye To 1st Person

Hi,

I’m working on an Android OpenGL ES app following a tutorial I found on the net. I’ve drawn a 3 dimensional rectangle on the screen. When I run the app I appear to be looking down on it (bird’s eye view) and want to change the camera position and make it be more like street view/1st person view. Eventually I’ll let it respond to user input and have the camera move forward, as if they are walking through the scene. I’m new to OpenGL and have been trying to get gluLookAt to work to change the camera position, but haven’t had luck. Below is my code. Any advice on where to use gluLookAt and with what values?


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glDisable(GL10.GL_DITHER);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) height = 1;
    float aspect = (float)width / height;

    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
}

@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(-1.0f, 2.0f, -6.0f);
    gl.glScalef(0.08f, 0.08f, 0.08f);
    rect.draw(gl);
}

Thanks

Is that OpenGL ES 1.0/1.1 code?

I think 1.0 (assuming the references to GL10 are referring to 1.0). I used the tutorials at: https://www3.ntu.edu.sg/home/ehchua/programming/android/Android_3D.html as a basis. These are the imports (and class definition):


import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
import android.opengl.Matrix;

public class glRenderer implements GLSurfaceView.Renderer {

Think I figured it out. My issue was my gluLookAt was getting ignored because I was calling glLoadIdentity afterwards for drawing every model. I didn’t understand the affect that this had, but now I understand it more. I had to change all the translates I had for each model to be relative, rather than absolute as they were, but they’re back in the right spot and I can change to first person view.

Thanks