如何将旋转添加到我的2D对象

时间:2012-04-03 09:06:36

标签: android opengl-es

我绘制一个简单的三角形,我想学习如何旋转它并上下左右移动。我添加gl.glRotatef(0.0f,1.0f,0.0f,0.0f),但它不会旋转。

这是我的代码:

public class GLrenderer实现Renderer {     public GLqueue tri;

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

}

}

2 个答案:

答案 0 :(得分:0)

此处描述了旋转和移动:http://developer.android.com/resources/tutorials/opengl/opengl-es20.html希望它有所帮助!

答案 1 :(得分: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();