iOS 5 文档显示其GLKMatrix4MakeLookAt
操作方式与gluLookAt
.
此处提供了定义:
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);
有两个问题:
观察向量在他们定义时似乎被否定了,因为它们执行
(eye - center)
而不是(center - eye)
. 事实上,当我GLKMatrix4MakeLookAt
使用 的相机位置和我提取(0,0,-10)
的外观中心调用时,即是我所期望的负值。那么我应该否定我提取的内容吗?(0,0,1)
(0,0,-1)
我提取的相机位置是视图变换矩阵预乘视图旋转矩阵的结果,因此是其定义中的点积。我认为这是不正确的 - 任何人都可以建议我应该如何计算位置?
非常感谢您的时间。