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;
}
Check that you haven't (by mistake) applied a negative (mirroring) scale to the scene. Also check that you're using Z buffering, perhaps you're not.
This page talks a bit about Blender's coordinate system, compared to another 3D system's, and is perhaps semi-obscure as a reference but I place a certain amount of confidence in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With