围绕对象中心的OpenGL旋转 - STL

时间:2016-06-13 15:15:57

标签: opengl rotation

我有来自此库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);
    }
}

0 个答案:

没有答案