iOS:有关GLKMatrix4MakeLookAt结果内相机信息的问题

iOS 5文档显示, GLKMatrix4MakeLookAtGLKMatrix4MakeLookAt操作相同。

定义在这里提供:

 static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { GLKVector3 ev = { eyeX, eyeY, eyeZ }; GLKVector3 cv = { centerX, centerY, centerZ }; GLKVector3 uv = { upX, upY, upZ }; GLKVector3 n = GLKVector3Normalize(GLKVector3Add(ev, GLKVector3Negate(cv))); GLKVector3 u = GLKVector3Normalize(GLKVector3CrossProduct(uv, n)); GLKVector3 v = GLKVector3CrossProduct(n, u); GLKMatrix4 m = { uv[0], vv[0], nv[0], 0.0f, uv[1], vv[1], nv[1], 0.0f, uv[2], vv[2], nv[2], 0.0f, GLKVector3DotProduct(GLKVector3Negate(u), ev), GLKVector3DotProduct(GLKVector3Negate(v), ev), GLKVector3DotProduct(GLKVector3Negate(n), ev), 1.0f }; return m; } 

我试图从这个提取相机信息:

 1. Read the camera position GLKVector3 cPos = GLKVector3Make(mx.m30, mx.m31, mx.m32); 2. Read the camera right vector as `u` in the above GLKVector3 cRight = GLKVector3Make(mx.m00, mx.m10, mx.m20); 3. Read the camera up vector as `u` in the above GLKVector3 cUp = GLKVector3Make(mx.m01, mx.m11, mx.m21); 4. Read the camera look-at vector as `n` in the above GLKVector3 cLookAt = GLKVector3Make(mx.m02, mx.m12, mx.m22); 

有两个问题:


  1. 看起来向量似乎否定了,因为他们执行(eye - center)而不是(center - eye) 。 实际上,当我调用GLKMatrix4MakeLookAt (0,0,-10)的摄像机位置和(0,0,1)的中心时,我提取的GLKMatrix4MakeLookAt(0,0,-1) ,也就是我期望。 所以我应该否定我提取的东西?

  2. 我提取的摄像机位置是视图转换matrix将视图旋转matrix预乘的结果,因此在其定义中是点积。 我相信这是不正确的 – 任何人都可以build议我应该如何计算位置?


非常感谢您的时间。

根据它的文档 ,gluLookAt计算中心眼睛,用于一些中间步骤,然后否定它放置到matrix中。 所以,如果你想要中心回来,那么采取消极的态度是明确的。

您还会注意到,返回的结果等同于结果旋转部分的multMatrix,后跟glTranslate by -eye。 由于传统的OpenGLmatrix操作后乘,这意味着gluLookAt被定义为将旋转乘以平移。 所以苹果的实现是正确的,和第一次移动相机一样,然后旋转它 – 这是正确的。

所以如果你定义R =(定义你的指令的旋转部分的matrix),T =(平移模拟),你得到RT如果你想提取T你可以预乘R的逆,然后将结果从最后一列,因为matrix乘法是关联的。

作为一个奖励,因为R是正交的,逆就是转置。