我有一个雪人的模型,它是从.obj文件中加载的。除了使用glRotatef()旋转模型时,雪人的头部总是在身体前面渲染之外,一切都很正常。雪人的鼻子也总是在头部后面渲染。这会导致在旋转时雪人改变方向的效果,但实际上只是部件没有按正确的z顺序渲染。为什么会发生这种情况?
注意:所有雪人的部件都来自使用blender创建的同一个.obj文件。
像这样渲染模型(在绘制循环中)。
像这样旋转(在touchesMoved中)
注意:所有雪人的部件都来自使用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);
像这样旋转(在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;
}