她是我的代码帮助我如何实现touchlistner
并用手指旋转立方体。我创建了单独的多维数据集类,其中绘制了多维数据集。还有MainActivity
类SurfaceView
也是声明,并且从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);
}