2011-11-03 152 views
0

所以,我正在嘗試爲一個課程製作3D繪圖器。現在我正在理解OpenGL,並且我失敗了。我想移動相機,但是我什麼都不能。爲什麼這不起作用?Android上的OpenGL ES

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; 
    } 
} 

回答

0

顯然,與z近/遠值必須> 0。沒有人告訴我這一點。因此,對於想知道爲什麼事情可怕的人,請確保這不是原因。