I'm creating an app, which should draw objects in constant place on the scene, but when i move my phone around, camera should change view and i should see all object around (when i do full rotation with phone).
When i use gl.glMultMatrixf(rotationMatrix, 0) in my onDrawFrame method and then draw object its working perfect (rotation matrix is obtained from SensorManager)
@Override
public void onDrawFrame(GL10 gl) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glMultMatrixf(rotationMatrix, 0);
gl.glTranslatef(0f, 0f, -10f);
//draw object
pyramid.draw(gl);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
But when i try to use:
GLU.gluLookAt( gl, 0.0f, 0.0f, 0.0f, x, y, z, 0.0f, 1.0f, 0.0f );
gl.glPushMatrix();
//draw object
pyramid.draw(gl);
my object is all time in the same place on screen and follow camera movement. What I'm doing wrong in second example ?
gluLookAt
function says you're standing at the origin and looking at (x,y,z), which I'm guessing is coming in from the sensors. If you also want to "walk" around in your world, you'll need to modify the first three parameters ofgluLookAt
as well to update the eye's position. – radical7