2009-05-19 144 views
3

我有一個從.obj文件加載的雪人模型。除了當我使用glRotatef()來旋轉模型時,一切正常,雪人的頭部總是會在身體前面呈現。雪人的鼻子也會始終在頭後。這產生了雪人在旋轉時改變方向的效果,但實際上這些部分不是以正確的z順序呈現。爲什麼會發生這種情況?Opengl ES - 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; 
} 
+0

發佈一些高層次的代碼可能有助於解釋怎麼回事。 – luke 2009-05-19 12:55:59

+0

有沒有其他可能有用的信息? – 2009-05-19 13:20:50

回答

5

檢查你有沒有(錯誤地)施加負(鏡像)縮放至現場。還要檢查你是否在使用Z緩衝,也許你沒有。

This page談論了一些關於Blender的座標系,與另一個3D系統相比較,並且可能半參數模糊不清,但我對它有一定的信心。

0

的UIKit座標的紋理是顛倒的,所以你有兩個選擇:

  1. 調整你的紋理映射中的V座標(1-vcoord)
  2. 拉入前翻轉圖像說明你稍後會加載到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);