2013-09-26 59 views
0

我正在尝试使用旋转和平移来制作包含6个三角形的六角形。我不想多次进行翻译调用,而是希望将三角形向下翻译一次,并围绕Z轴以60度旋转六次(我的草图可能有助于解释:http://i.imgur.com/SrrXcA3.jpg)。重复drawTriangle()和rotate()方法六次后,我应该有一个六边形。如何在OpenGL 2中围绕(0,0,0)处的顶点旋转三角形

目前我的代码看起来是这样的:

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)旋转三角形,其顶点位于哪里?

回答

0

你真的确定你的常数-0.577350269f是三角中心的正确值吗?你的代码看起来还没有完成(你使用了一个mvp句柄,但从来没有在代码中使用它),你能提供更多的信息吗?