2012-01-29 87 views
2

iOS 5文档显示GLKMatrix4MakeLookAtgluLookAt的操作相同。iOS:有关GLKMatrix4MakeLookAt结果内相机信息的问题

的定义在这里提供:

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 = { u.v[0], v.v[0], n.v[0], 0.0f, 
        u.v[1], v.v[1], n.v[1], 0.0f, 
        u.v[2], v.v[2], n.v[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. 看起来向量似乎是否定的d,因为他们执行(eye - center)而不是(center - eye)。事实上,当我拨打GLKMatrix4MakeLookAt,摄像机位置为(0,0,-10),中心为(0,0,1)时,我提取的视图是,即我期望的负值。那么我应该否定我提取的东西?

  2. 我提取的摄像头位置是视图转换矩阵预乘的视图旋转矩阵的结果,因此它们的定义点产品。我相信这是不正确的 - 任何人都可以建议我应该如何计算位置?


非常感谢您的时间。

回答

2

根据its documentation,gluLookAt计算中心眼,将其用于某些中间步骤,然后对其进行否定处理以放置到结果矩阵中。所以如果你想要回中心,那么采取否定就是明确的。

您还会注意到,返回的结果等同于结果旋转部分的multMatrix,后跟glTranslate by -eye。由于经典的OpenGL矩阵运算后乘,这意味着gluLookAt被定义为将旋转乘以平移。所以苹果的实施是正确的,和第一次移动相机一样,然后旋转 - 这是正确的。所以如果你定义R =(定义你的指令的旋转部分的矩阵),T =(平移模拟),你得到R.T.如果你想提取T,你可以预乘R的倒数,然后将结果从最后一列中取出,因为矩阵乘法是关联的。

作为奖励,因为R是正交的,所以倒数就是转置。

+0

我以某种方式未能发现'm'定义中的否定,哎呀。至于其他,感谢您的详细解释,确实非常明确,现在我完全理解发生了什么。非常感谢:) – KomodoDave 2012-01-29 16:52:59

+0

链接已损坏。 – aledalgrande 2014-09-25 03:54:30