編集2:
解決策: コピー ペーストの誤り: カラー バッファを位置バッファとして送信しました。
ピラミッドを表す .obj (ウェーブフロント) を解析し、必要な場所で三角測量を行い、すべてをバッファーに渡します。バッファは次のようになります。
頂点バッファ:
private FloatBuffer mPositionBuffer = null;
// from looping through buffer + print:
#0 = -0.5, 0.0, -0.5
#3 = 0.5, 0.0, -0.5
#6 = 0.5, 0.0, 0.5
#9 = -0.5, 0.0, 0.5
#12 = 0.5, 0.0, 0.5
#15 = 0.5, 0.0, -0.5
#18 = 0.0, 1.0, 0.0
#21 = 0.5, 0.0, -0.5
#24 = -0.5, 0.0, -0.5
#27 = 0.0, 1.0, 0.0
#30 = -0.5, 0.0, -0.5
#33 = -0.5, 0.0, 0.5
#36 = 0.0, 1.0, 0.0
#39 = -0.5, 0.0, 0.5
#42 = 0.5, 0.0, 0.5
#45 = 0.0, 1.0, 0.0
カラーバッファ:
private ByteBuffer mColorBuffer = null;
#0 = 1, 1, 1, 1
#4 = 1, 1, 1, 1
#8 = 1, 1, 1, 1
#12 = 1, 1, 1, 1
#16 = 1, 1, 1, 1
#20 = 1, 1, 1, 1
#24 = 1, 1, 1, 1
#28 = 1, 1, 1, 1
#32 = 1, 1, 1, 1
#36 = 1, 1, 1, 1
#40 = 1, 1, 1, 1
#44 = 1, 1, 1, 1
#48 = 1, 1, 1, 1
#52 = 1, 1, 1, 1
#56 = 1, 1, 1, 1
#60 = 1, 1, 1, 1
通常のバッファ:
private FloatBuffer mNormalBuffer = null;
#0 = 0.0, 0.0, 0.0
#3 = 1.0, 0.0, 0.0
#6 = 1.0, 1.0, 0.0
#9 = 0.0, 1.0, 0.0
#12 = 0.0, 0.0, 0.0
#15 = 1.0, 0.0, 0.0
#18 = 0.5, 1.0, 0.0
#21 = 0.0, 0.0, 0.0
#24 = 1.0, 0.0, 0.0
#27 = 0.5, 1.0, 0.0
#30 = 0.0, 0.0, 0.0
#33 = 1.0, 0.0, 0.0
#36 = 0.5, 1.0, 0.0
#39 = 0.0, 0.0, 0.0
#42 = 1.0, 0.0, 0.0
#45 = 0.5, 1.0, 0.0
インデックス バッファ:
private ShortBuffer mIndexBuffer = null;
#0 = 0, 1, 3
#3 = 1, 2, 3
#6 = 4, 5, 6
#9 = 7, 8, 9
#12 = 10, 11, 12
#15 = 13, 14, 15
私の頭の中で頂点と面を組み合わせると、ピラミッドに等しいです。シンプルなモデル。以下のように描いています。
// data above are put in these buffers
mColorBuffer.position(0);
mNormalBuffer.position(0);
mIndexBuffer.position(0);
mPositionBuffer.position(0);
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_POSITION), 3, GLES20.GL_FLOAT, false,
0, mColorBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_POSITION));
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_COLOR), 4, GLES20.GL_BYTE, false,
0, mColorBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_COLOR));
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_NORMAL), 3, GLES20.GL_FLOAT, false,
0, mNormalBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_NORMAL));
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mShader.getGLLocation(BaseShader.U_MVPMATRIX), 1, false, mMVPMatrix, 0);
GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, mIndexBuffer.capacity(), GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
しかし、実際にはピラミッドのようには見えず、結果として「不安定」なオブジェクトがあります。つまり、それを変換すると(回転なしですが、コードは次のようになります(そして、描画の前に実行されます):
Matrix.translateM(mModelMatrix, 0, mTranslation[0], mTranslation[1], mTranslation[2]);
Matrix.scaleM(mModelMatrix, 0, mScale[0], mScale[1], mScale[1]);
Matrix.rotateM(mModelMatrix, 0, mRotation[0], 0, 1, 0);
Matrix.rotateM(mModelMatrix, 0, mRotation[1], 1, 0, 0);
Matrix.rotateM(mModelMatrix, 0, mRotation[2], 0, 0, 1);
Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
インデックスが適切に送信されていないように見えますか? 残念ながら、ピラミッドの片側だけが描かれています。
glDrawElements 関数に他の値を使用する必要がありますか? 必要に応じて、翻訳アニメーションのスクリーンショットまたはスクリーン キャプチャを投稿できます。助けてくれてありがとう!
編集:
これが何か関係がある場合:
私はこれらを呼んでいます:
GLES20.glClearColor(0, 0, 0, 1);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glDepthFunc(GLES20.GL_LEQUAL);