简体   繁体   中英

how to add rotate to my 2D object

I draw a simple triangle and I want to learn how to rotate it and move in up and down and left and right . I add gl.glRotatef(0.0f, 1.0f, 0.0f, 0.0f) but it does not rotate.

this is my code :

public class GLrenderer implements 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);

}

}

旋转和运动的描述如下: http : //developer.android.com/resources/tutorials/opengl/opengl-es20.html希望对您有所帮助!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM