0

回転と平行移動を使用して、6 つの三角形で六角形を作ろうとしています。複数の変換呼び出しを行うのではなく、三角形を下向きに 1 回変換し、Z 軸を中心に 60 度で 6 回回転させたいと考えています (私のスケッチがその説明に役立つかもしれません: http://i.imgur.com/SrrXcA3.jpg ) . drawTriangle() メソッドと rotate() メソッドを 6 回繰り返した後、六角形ができているはずです。

現在、私のコードは次のようになっています。

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 に答える