0
votes

I'm trying to make a hexagon with 6 triangles using rotation and translation. Rather than making multiple translate calls, I instead want to translate the triangle downward once and rotate around the Z axis at 60 degrees six times (my sketch may help with that explanation: http://i.imgur.com/SrrXcA3.jpg). After repeating the drawTriangle() and rotate() methods six times, I should have a hexagon.

Currently my code looks like this:

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);
}

Here's my problem: it appears my triangle isn't rotating around (0,0,0), but instead it rotates around the triangle's center (as shown in this picture: http://i.imgur.com/oiLFSCE.png).

Is it possible for to rotate triangle around (0,0,0), where its vertex is located?

1

1 Answers

0
votes

Are you really be sure that your constant -0.577350269f is the correct value for the triangle center?

Also your code looks unfinish (You use an mvp handle but never use it in the code), could you provide more information?