计算一个注视矩阵 [英] Calculating a LookAt matrix

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

问题描述

我在写一个3D引擎的中间,我已经遇到了DirectX文档中描述的注视算法:

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)  l

现在,我得到它是如何工作的旋转侧,但我不完全得到就是为什么它把矩阵的平移分量是那些点的产品。检查它有点看来,它的调节由基于所述新的基础矢量的投影到眼睛/摄像机的位置少量相机位置。

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旋转矩阵作为你在这里做,然后将它用零和在单1扩展到4×4建立一个查阅在矩阵右下角。然后,我建立一个使用负眼点坐标(不点产品)一个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.

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

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