【问题标题】:Using projection matrix on GLKMatrixStack在 GLKMatrixStack 上使用投影矩阵
【发布时间】: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


    【解决方案1】:

    作为记录,Apple 确定我关于此问题的错误报告与错误 15419952 重复。我希望人们不会遇到这种情况,因为他们通常会将投影矩阵与模型转换堆栈分开。无论如何,问题中提出的解决方法都可以正常工作。

    【讨论】:

      猜你喜欢
      • 2012-03-27
      • 2014-08-01
      • 2011-02-22
      • 2012-04-24
      • 1970-01-01
      • 2015-04-11
      • 2015-11-01
      • 2013-08-03
      • 1970-01-01
      相关资源
      最近更新 更多