3

我有一个从 .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;
}
4

2 回答 2

5

检查您是否(错误地)对场景应用了负(镜像)比例。还要检查你是否使用了 Z 缓冲,也许你没有。

与另一个 3D 系统相比,此页面讨论了 Blender 的坐标系,并且作为参考可能是半模糊的,但我对它有一定的信心。

于 2009-05-19T13:07:08.753 回答
0

纹理的 UIKit 坐标是颠倒的,所以你有两个选择:

  1. 将纹理映射的 V 坐标调整为 (1-vcoord)
  2. 在绘制到您稍后将加载到 gl.contex 中的上下文之前翻转图像。

如果你使用 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);
于 2010-06-03T06:13:59.013 回答