2012-04-03 22 views
1

我畫了一個簡單的三角形,我想學習如何旋轉它並上下左右移動。我添加gl.glRotatef(0.0f,1.0f,0.0f,0.0f),但它不旋轉。如何添加旋轉到我的2D對象

這是我的代碼:

公共類GLrenderer實現渲染{ 公共GLqueue三;

public GLrenderer() { 
    tri = new GLqueue(); 

} 

@Override 
public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) { 
    // TODO Auto-generated method stub 
    gl.glDisable(GL10.GL_DITHER); 
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 
    gl.glClearColor(.8f, .0f, .2f, 1); 
    gl.glClearDepthf(1f); 
} 

@Override 
public void onDrawFrame(GL10 gl) { 
    // TODO Auto-generated method stub 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT); 
    gl.glMatrixMode(GL10.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
    GLU.gluLookAt(gl, 0, 0, 10f , 0 , 0 , 0 , 0 ,2, 0); 
    tri.draw(gl); 
} 

@Override 
public void onSurfaceChanged(GL10 gl, int width, int height) { 
    // TODO Auto-generated method stub 
    gl.glViewport(0, 0, width, height); 
    float ratio = (float) width/height; 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    gl.glFrustumf(-ratio, ratio , -1, 1, 1, 25); 

} 

}

回答

0
gl.glPushMatrix(); 
gl.Translatef(x,y,0) 
gl.Rotatef(45,0,0,1)//rotate the object 45 degress in z axis 
DrawObjuect(); 
gl.glPopMatrix();