我有来自此库https://github.com/kshoji/STLViewer
的此代码我必须改变什么,以便我的物体围绕其中心旋转。
@Override
public void onDrawFrame(GL10 gl) {
if (bufferCounter < 1) {
return;
}
bufferCounter--;
gl.glLoadIdentity();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glTranslatef(positionX, -positionY, 0);
// rotation and apply Z-axis
if (stlObject != null) {
gl.glTranslatef(-(stlObject.maxX + stlObject.minX) / 2, -(stlObject.maxY + stlObject.minY) / 2, -(stlObject.maxZ + stlObject.minZ)-distanceZ);
} else {
gl.glTranslatef(0, 0, -distanceZ);
}
gl.glRotatef(angleX, 0, 1, 0);
gl.glRotatef(angleY, 1, 0, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glMatrixMode(GL10.GL_MODELVIEW);
// draw object
if (stlObject != null) {
// FIXME transparency applying does not correctly
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[] { 0.75f, 0.75f, 0.75f, 0.95f }, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[] { red, green, blue, alpha }, 0);
stlObject.draw(gl);
}
}