0
Donc, j'essaie de faire un grapher 3D pour une classe. En ce moment je travaille sur la compréhension d'OpenGL et j'échoue horriblement. Je veux déplacer la caméra, mais je ne peux pas du tout, quoi que ce soit. Pourquoi ça ne marche pas?OpenGL ES sur Android
public class G3DRenderer implements GLSurfaceView.Renderer, OnTouchListener {
float[] camera = {0, 0, 0.5f}, focus = {0, 0, 0}, orientation = {0, 1, 0};
Square square;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
gl.glShadeModel(GL10.GL_SMOOTH);
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);
float v = 1.0f;
int c = 0xFFFFFF;
square = new Square(
new float[] {
-v, v, 0,
-v, -v, 0,
v, v, 0,
v, -v, 0,
},
new short[] {0, 1, 2, 3},
new int[] {
c, 0, 0, c,
0, c, 0, c,
0, 0, c, c,
c, c, c, 0,
}
);
}
private void look(GL10 gl) {
GLU.gluLookAt(gl,
camera[0], camera[1], camera[2],
focus[0], focus[1], focus[2],
orientation[0], orientation[1], orientation[2]
);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
int dim = Math.min(width, height);
gl.glViewport(0, 0, dim, dim);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
look(gl);
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
square.draw(gl);
look(gl);
}
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
return false;
}
}