gluLookAt规格 [英] gluLookAt specification

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

问题描述

我在理解gluLookAt的规范时遇到一些问题. 例如,z轴定义为:

I have some problems understanding the specification for gluLookAt. For example the z-axis is defined as:

F =(centerX-eyeX,centerY-eyeY,centerZ-eyeZ)

F = ( centerX - eyeX, centerY - eyeY, centerZ - eyeZ )

以中心为相机所瞄准的点,以眼睛为相机所处的位置.

with center being the point the camera looks at and eye being the position the camera is at.

f = F/| F |

f = F / |F|

和View-Matrix M定义为:

and the View-Matrix M is defined as:

( x[0]   x[1]   x[2]  0 )
( y[0]   y[1]   y[2]  0 )
(-f[0]  -f[1]  -f[2]  0 )
( 0        0      0   1 )

x和y为x,y轴,f为z轴

with x and y being the x,y-axis and f being the z-axis

如果我的相机位于(0,0,5)并且相机朝中心看.然后,由于第一个方程(中心-眼睛),f沿着z轴负方向看,所以f向量为:(0,0,0)-(0,0,5)=(0,0,-5 )

If my camera is positioned at (0, 0, 5) and the camera looks at the center. Then f would look along the negative z-axis because of the first equation (center - eye) the f-vector would be: (0,0,0) - (0,0,5) = (0,0,-5)

到目前为止,所有事情对我来说都是有意义的,但是在上面的M-Matrix中,f-矢量乘以-1. 这样,f向量沿z轴正方向并远离中心.

So far everything makes sense to me, but then the f-vector is multiplied by -1 in the M-Matrix above. That way the f-vector looks along the positive z-axis and away from the center.

我发现透视矩阵gluPerspective还会将camrea的z轴乘以-1,这会使z轴再次旋转并使其朝向世界的负z轴.

I found that the perspective matrix gluPerspective will also multiply the z-axis of the camrea with -1 which turns the z-axis again and makes it look toward the world's negative z-axis.

那么乘以-1的意义是什么?

So what is the point of multiplying it with -1?

推荐答案

因为gluLookAt是惯用右手系统的视图矩阵.在此空间中,Z坐标随着其离开屏幕或在相机后面而增加.因此,摄像机可以看到的所有对象在视图空间中的负Z值.

Because gluLookAt is a View Matrix for a right-handed system. In this space, Z-coordinate increments as it goes out of screen, or behind the camera. So all objects that the camera can see have negative Z in view space.

您应该复习数学.您暴露的矩阵缺少平移到摄像机的位置.

遵循以下标记 :

获得 f 归一化, up 归一化, s 归一化和 u = sn x f.请注意,必须对 s 进行归一化,因为 f up 可能不垂直,并且它们的叉积不是length = 1的向量.上面的链接中没有提及.

You should review your maths. The matrix you exposed lacks the translation to camera position.

Following this notation let's do:

Obtain f normalized, up normalized, s normalized, and u=sn x f. Notice that s must be normalized because f and up may be not be perpendicular and then their cross-product is not a vector of length=1. This is not mentioned in the link above.

形成矩阵并乘以平移到摄像机位置,即L = M·T

生成的lookAt矩阵为:

Form the matrix and pre-multiply by the translation to camera position, L= M · T

The resulting lookAt matrix is:

 s.x   s.y   s.z  -dot(s, eye)
 u.x   u.y   u.z  -dot(u, eye)
-f.x  -f.y  -f.z  dot(f, eye)
  0     0     0      1

根据您的数据:camera=(0,0,5)target=(0,0,0)up=(0,1,0),矩阵为:

With your data: camera=(0,0,5), target=(0,0,0), and up=(0,1,0), the matrix is:

1  0  0  0
0 -1  0  0
0  0  1 -5
0  0  0  1

让我们将此转换应用于点A =(0,0,4).我们得到A'=(0,0,-1).
再次对于B =(0,0,20),B'=(0,0,15).
A'的负值为Z,因此相机可以看到它. B'为正值,相机看不到.

Let's apply this transformation a the point A=(0,0,4). We get A'=(0,0,-1).
Again for B=(0,0,20), B'=(0,0,15).
A' has a negative Z, so the camera sees it. B' has a positive value, the camera can not see it.

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

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