0

我正在尝试使用旋转和平移制作一个带有 6 个三角形的六边形。我不想进行多次平移调用,而是想将三角形​​向下平移一次并围绕 Z 轴旋转 60 度六次(我的草图可能有助于解释:http: //i.imgur.com/SrrXcA3.jpg) . 重复 drawTriangle() 和 rotate() 方法六次后,我应该有一个六边形。

目前我的代码如下所示:

public void onDrawFrame(GL10 unused) 
{
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); //start by clearing the screen for each frame

    GLES20.glUseProgram(mPerVertexProgramHandle); //tell OpenGL to use the shader program we've compiled

    //Get pointers to the program's variables. Instance variables so we can break apart code
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "uMVPMatrix");
    mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "aPosition");
    mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "aColor");

    //Prepare the model matrix!
    Matrix.setIdentityM(mModelMatrix, 0); //start modelMatrix as identity (no transformations)
    Matrix.translateM(mModelMatrix, 0, 0.0f, -0.577350269f, 0.0f); //shift the triangle down the y axis by -0.577350269f so that its top point is at 0,0,0
    drawTriangle(mModelMatrix); //draw the triangle with the given model matrix
    Matrix.rotateM(mModelMatrix, 0, 60f, 0.0f, 0.0f, 1.0f);
    drawTriangle(mModelMatrix);
}

这是我的问题:看来我的三角形不是围绕(0,0,0)旋转,而是围绕三角形的中心旋转(如图所示:http: //i.imgur.com/oiLFSCE.png) .

是否可以围绕(0,0,0)旋转三角形,它的顶点所在的位置?

4

1 回答 1

0

你真的确定你的常数 -0.577350269f 是三角形中心的正确值吗?

此外,您的代码看起来未完成(您使用 mvp 句柄但从未在代码中使用它),您能否提供更多信息?

于 2013-10-03T10:50:46.870 回答