我有一个从 .obj 文件加载的雪人模型。一切正常,除了当我使用 glRotatef() 旋转模型时,雪人的头部将始终呈现在身体前面。雪人的鼻子也会一直渲染到脑后。这会产生雪人在旋转时改变方向的效果,但实际上这些部件并未以正确的 z 顺序渲染。为什么会出现这种情况?
注意:雪人的所有部分都来自使用搅拌机创建的同一个 .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);
像这样旋转(在 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;
}