计算 LookAt 矩阵 [英] Calculating a LookAt matrix

查看:31
本文介绍了计算 LookAt 矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 3d 引擎,并且遇到了 DirectX 文档中描述的 LookAt 算法:

I'm in the midst of writing a 3d engine and I've come across the LookAt algorithm described in the DirectX documentation:

zaxis = normal(At - Eye)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)

 xaxis.x           yaxis.x           zaxis.x          0
 xaxis.y           yaxis.y           zaxis.y          0
 xaxis.z           yaxis.z           zaxis.z          0
-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  1

现在我了解了它在旋转方面的工作原理,但我不太明白的是为什么它将矩阵的平移分量设为那些点积.稍微检查一下,它似乎根据新基向量在眼睛/相机位置上的投影对相机位置进行了少量调整.

Now I get how it works on the rotation side, but what I don't quite get is why it puts the translation component of the matrix to be those dot products. Examining it a bit it seems that it's adjusting the camera position by a small amount based on a projection of the new basis vectors onto the position of the eye/camera.

问题是为什么需要这样做?它有什么作用?

The question is why does it need to do this? What does it accomplish?

推荐答案

我通过创建一个 3x3 旋转矩阵来构建一个观察矩阵,就像你在这里所做的那样,然后将它扩展到一个 4x4 的 0右下角.然后我使用负眼点坐标(无点积)构建一个 4x4 平移矩阵,并将两个矩阵相乘.我的猜测是,这种乘法产生的结果与示例底行中的点积等效,但我需要在纸上进行计算以确保.

I build a look-at matrix by creating a 3x3 rotation matrix as you have done here and then expanding it to a 4x4 with zeros and the single 1 in the bottom right corner. Then I build a 4x4 translation matrix using the negative eye point coordinates (no dot products), and multiply the two matrices together. My guess is that this multiplication yields the equivalent of the dot products in the bottom row of your example, but I would need to work it out on paper to make sure.

3D 旋转会改变您的轴.因此,您不能直接使用视点而不将其转换为这个新的坐标系.这就是矩阵乘法——或者在本例中为 3 个点积值——的作用.

The 3D rotation transforms your axes. Therefore, you cannot use the eye point directly without also transforming it into this new coordinate system. That's what the matrix multiplications -- or in this case, the 3 dot-product values -- accomplish.

这篇关于计算 LookAt 矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆