Opengl ES - Incorrect display on the z axis?

I have a snowman model that I am loading from a .obj file. Everything works well, except that when I use glRotatef () to rotate the model, the snowman’s head will always protrude in front of the body. The snowman's nose will also always protrude behind his head. This creates an effect that the snowman changes direction when he rotates, but in fact the parts simply do not appear in the correct z order. Why is this happening?

NOTE: all parts of the snowman are from the same .obj file created with the blender.

model rendering (in a drawing cycle)

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);

rotates like this (in touches movd)

- (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;
}
+3
source share
2 answers

, ( ) () . , Z-, , .

, 3D-, , , , .

+5

UIKit , :

  • V (1-vcoord)
  • , gl.

CG , ScaleCTM:

CGContextRef context = CGBitmapContextCreate( imageData, ....
CGContextClearRect( context, ...
CGContextScaleCTM( context, 1.0, -1.0);  // flip the texture vertically
CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), image.CGImage );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
0

Source: https://habr.com/ru/post/1708652/


All Articles