.obj ファイルから読み込んでいる雪だるまのモデルがあります。glRotatef() を使用してモデルを回転させると、雪だるまの頭が常に体の前にレンダリングされることを除いて、すべてがうまく機能します。雪だるまの鼻も常に頭の後ろにレンダリングされます。これにより、雪だるまが回転しながら方向を変える効果が生まれますが、実際にはパーツが正しい z オーダーでレンダリングされません。なぜこれが起こっているのですか?
注: 雪だるまのすべてのパーツは、blender を使用して作成された同じ .obj ファイルからのものです。
このようにモデルをレンダリングします(描画ループ内)
glVertexPointer(3 ,GL_FLOAT, 0, model_verts);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, model_normals);
glDrawElements(GL_TRIANGLES, num_model_indices*3, GL_UNSIGNED_SHORT, &model_indices);
このように回転します (in touchesMoved)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
touchBeginPos = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchEndPos = [[touches anyObject] locationInView:self];
glMatrixMode(GL_MODELVIEW_MATRIX);
glRotatef(10, (touchBeginPos.y - touchEndPos.y)/4, -(touchBeginPos.x - touchEndPos.x)/4, 0.0f);
touchBeginPos = touchEndPos;
}