她是我的代码,可以帮助我实现touchlistner并用手指旋转立方体。我创建了绘制立方体的立方体的单独类。还创建了MainActivity的类,其中还声明了SurfaceView并从中调用了Renderer类MainActivity

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

最佳答案

您可以使用爵士乐的视角鳍状肢。
这是链接https://github.com/jfeinstein10/JazzyViewPager

10-08 02:25