【问题标题】:Android: Open GL ES: Shape not rotating as expectedAndroid:Open GL ES:形状未按预期旋转
【发布时间】:2015-03-14 07:37:36
【问题描述】:

我正在尝试从三角形中心沿 Z 轴旋转三角形。但是在这里我从三角形边缘的中心而不是从它的中心进行三角形旋转。

渲染器代码:

@Override
public void onDrawFrame(GL10 gl) {

    float scratch[] = new float[16];

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    int time = (int) (SystemClock.uptimeMillis() % 4000l);
    float angle = 0.090f * time;

    Matrix.setRotateM(mRotationMatrix, 0, angle, 0.0f, 0.0f, -1.0f);

    Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);
    triangle.draw(scratch);
}

【问题讨论】:

    标签: android opengl-es rendering renderer


    【解决方案1】:

    问题更可能是由构成三角形的顶点引起的。

    解决方案 1:在旋转三角形之前,先平移它,使其中心与场景中心对齐。

    解决方案 2:提供围绕中心的顶点。例如:

    glVertex(0,0,0); 
    glVertex(1,0,0); 
    glVertex(0,1,0); // will produce rotation around the first vertex
    

    ...所以将它们偏移一半:

    glVertex(0-0.5,0-0.5,0-0.5); 
    glVertex(1-0.5,0-0.5,0-0.5); 
    glVertex(0-0.5,1-0.5,0-0.5); // will produce rotation around the approximate center
    

    最好的方法是在旋转之前计算中心并平移。

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2015-05-11
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多