I have a model of a snowman that I am loading from a .obj file. Everything works well except that when I use glRotatef() to rotate the model the head of the snowman will always render in front of the body. The nose of the snowman will also always render behind the head. This creates the effect that the snowman changes direction as he is rotating, but really the parts just not rendering in the right z order. Why is this occuring?
NOTE: all parts of the snowman are from the same .obj file created using blender.
rendering the model like this ( in the draw loop)
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);
rotating like this (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;
}