在Android中用手指旋转3D对象

时间:2013-11-25 07:23:29

标签: java android opengl-es

她是我的代码帮助我如何实现touchlistner并用手指旋转立方体。我创建了单独的多维数据集类,其中绘制了多维数据集。还有MainActivitySurfaceView也是声明,并且从MainActivity调用Renderer类。

public class GLCubeRenderer implements Renderer {

//private float oldX; //valor anterior de X, para rotación
//private float oldY; //valor anterior de Y, para rotación
private GLCube  cube;
static float ratio;
private final float[] mAccumulatedRotation = new float[16];
private final float[] mCurrentRotation = new float[16];
float[] mModelMatrix;

public GLCubeRenderer(){

    cube = new GLCube();
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig eglconfig) {
    gl.glDisable(GL10.GL_DITHER);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
    gl.glClearColor(.8f, 0, .7f, 1);
    gl.glClearDepthf(1f);
    Matrix.setIdentityM(mAccumulatedRotation, 0);

}

@Override
public void onDrawFrame(GL10 gl) {
    gl.glDisable(GL10.GL_DITHER);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0);
    long time =SystemClock.uptimeMillis() %4000L ;
    float angle = .090f *((int) time);
    gl.glRotatef(angle, 1, 0, 2);
    gl.glRotatef(angle, 0, 0, 1);
    cube.Draw(gl);
}

@Override
public  void onSurfaceChanged(GL10 gl, int width, int height) {

    gl.glViewport(0, 0, width, height);
     ratio = (float) width/height ;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 25);
}

1 个答案:

答案 0 :(得分:3)

您可以使用jazzy view flipper。 这是链接https://github.com/jfeinstein10/JazzyViewPager