【发布时间】:2014-01-20 01:09:51
【问题描述】:
鉴于此设置:
GLKMatrixStackRef transformHierarchy = GLKMatrixStackCreate (kCFAllocatorDefault);
float aspect = (float)self.drawableWidth / (float)self.drawableHeight;
float fov = PI * 0.125;
float height = 10.0f;
float cameraOffset = -height / (2.0f * tanf (fov / 2.0f));
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective (fov, aspect, 0.01f, 1000.0f);
GLKMatrix4 T = GLKMatrix4MakeTranslation (0.0f, 0.0f, cameraOffset);
我希望这两个选项能够在堆栈顶部创建一个相同的矩阵。选项 A:
GLKMatrixStackLoadMatrix4 (transformHierarchy, projectionMatrix);
GLKMatrixStackTranslate (transformHierarchy, 0.0f, 0.0f, cameraOffset);
选项 B:
GLKMatrixStackLoadMatrix4 (transformHierarchy, GLKMatrix4Multiply (projectionMatrix, T));
选项A给我一个黑屏:
3.351560 0.000000 0.000000 0.000000
0.000000 5.027339 0.000000 0.000000
0.000000 0.000000 -1.000020 25.117201
0.000000 0.000000 -1.000000 0.000000
选项 B(否则相同的矩阵但具有非零 m44)给了我我期望的视觉结果:
3.351560 0.000000 0.000000 0.000000
0.000000 5.027339 0.000000 0.000000
0.000000 0.000000 -1.000020 25.117201
0.000000 0.000000 -1.000000 25.136698
所以我找到了解决黑屏的方法,但使用GLKMatrixStackTranslate() 的结果让我感到惊讶。我在这里错过了什么吗?将投影+世界矩阵放在堆栈底部(后面是模型变换)不是一个好习惯吗?
更新
纠正了我的 cameraOffset 数学中的错误并更新了矩阵输出以匹配,尽管它对所描述的问题没有影响。同样为了清楚起见,我将矩阵值(从 xcode 复制/粘贴,以行优先顺序显示它们)转换为列优先(如 OpenGL 解释它们)。
还向 Apple 提交了一个错误,以询问这是否是预期的行为。
【问题讨论】:
标签: ios matrix opengl-es glkit