根据视平面计算透视投影矩阵 [英] Calculating the perspective projection matrix according to the view plane

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

问题描述

我正在使用openGL,但这基本上是一个数学问题. 我正在尝试计算投影矩阵,我在视图平面R(x,y,z)和该平面N(n1,n2,n3)的法线向量上有一个点. 我也知道眼睛在(0,0,0),从技术上讲,它是透视参考点. 如何从这些数据中获得透视投影?我知道如何以常规方式获取FOV,纵横比和近,远平面.

解决方案

我认为您将此问题放在"opengl"标签下引起了一些困惑.问题在于,在计算机图形学中,从严格的数学意义上理解术语"<投影>".

在数学中,定义了一个投影(以下不是精确的数学定义,而只是我自己的措辞),因为两次应用后,它们不会进一步改变结果.想一想.当您将3d空间中的点投影到2d平面(仍在该3d空间中)时,每个点的投影将最终在该平面上.但是已经在该平面上的点不再移动了,因此您可以根据需要多次应用此点,而无需进一步更改结果.

计算机图形学中的经典投影"矩阵无法做到这一点.他们转换空间,将普通的平截头体映射到立方体(或长方体).为此,您基本上需要所有参数来描述平截头体,通常是纵横比,视角,到近,远平面的距离以及投影方向和中心点(后两个通常是隐式的).按照惯例定义).在一般情况下,还存在水平和垂直不对称性组件(考虑它就像是投影机的镜头移位").所有这些都是计算机图形学中典型的投影矩阵所代表的.

实际上不可能从给定的参数构造这样的矩阵,因为您缺少很多参数.另外-我认为这很能说明问题-您给出了视图平面.但是到目前为止讨论的投影矩阵还没有定义一个视平面-可以将平行于近视平面或远视平面并且在相机前面的任何平面想象为视平面(在驼峰后面也可以工作,但是图像会被镜像) ),如果您需要一个.但是从严格的意义上讲,如果所有投影点也都将落在该平面上,则它只会是一个视图平面",而计算机图形透视矩阵显然不会这样做.相反,它保留其3d距离信息-这也意味着该操作是可逆的,而经典的数学投影通常不是.

从所有方面来看,我只是想知道您正在寻找的是从3D空间到2D平面的透视投影,而不是用于计算机图形学的透视变换.所需的所有参数仅仅是视点和平面.请注意,这恰好是您给出的 :投影中心应为原点,并且RN定义平面.

p这样的投影也可以用4x4均匀矩阵表示.您的问题中没有定义一件事:法线的方向.我再次假设使用标准的数学惯例,并假定将视平面定义为<N,x> + d = 0.通过在该等式中使用R,我们可以得到d = -N_x*R_x - N_y*R_y - N_z*R_z.所以投影矩阵就是

(   1       0       0     0   )
(   0       1       0     0   )
(   0       0       1     0   )
(-N_x/d  -N_y/d  -N_z/d   0   )

此矩阵有一些属性.列为零,因此不可逆.还要注意,对于每个点(s*x, s*y, s*z, 1),将其应用于该点,无论s是什么,结果(当然要除以结果w之后)都是相同的-因此,原点和原点之间的直线上的每个点(x,y,z)将产生相同的投影点-这就是透视投影应该执行的操作.最后要注意w=(N_x*x + N_y*y + N_z*z)/-d,因此对于每个满足上述平面方程的点,都会得到w= -d/-d = 1.结合用于其他维度的恒等变换,这仅意味着该点不变.

I'm working with openGL but this is basically a math question. I'm trying to calculate the projection matrix, I have a point on the view plane R(x,y,z) and the Normal vector of that plane N(n1,n2,n3). I also know that the eye is at (0,0,0) which I guess in technical terms its the Perspective Reference Point. How can I arrive the perspective projection from this data? I know how to do it the regular way where you get the FOV, aspect ration and near and far planes.

解决方案

I think you created a bit of confusion by putting this question under the "opengl" tag. The problem is that in computer graphics, the term projection is not understood in a strictly mathematical sense.

In maths, a projection is defined (and the following is not the exact mathematical definiton, but just my own paraphrasing) as something which doesn't further change the results when applied twice. Think about it. When you project a point in 3d space to a 2d plane (which is still in that 3d space), each point's projection will end up on that plane. But points which already are on this plane aren't moving at all any more, so you can apply this as many times as you want without changing the outcome any further.

The classic "projection" matrices in computer graphics don't do this. They transfrom the space in a way that a general frustum is mapped to a cube (or cuboid). For that, you basically need all the parameters to describe the frustum, which typically is aspect ratio, field of view angle, and distances to near and far plane, as well as the projection direction and the center point (the latter two are typically implicitely defined by convention). For the general case, there are also the horizontal and vertical asymmetries components (think of it like "lens shift" with projectors). And all of that is what the typical projection matrix in computer graphics represents.

To construct such a matrix from the paramters you have given is not really possible, because you are lacking lots of parameters. Also - and I think this is kind of revealing - you have given a view plane. But the projection matrices discussed so far do not define a view plane - any plane parallel to the near or far plane and in front of the camera can be imagined as the viewing plane (behind the camere would also work, but the image would be mirrored), if you should need one. But in the strict sense, it would only be a "view plane" if all of the projected points would also end up on that plane - which the computer graphics perspective matrix explicitely does'nt do. It instead keeps their 3d distance information - which also means that the operation is invertible, while a classical mathematical projection typically isn't.

From all of that, I simply guess that what you are looking for is a perspective projection from 3D space onto a 2D plane, as opposed to a perspective transformation used for computer graphics. And all parameters you need for that are just the view point and a plane. Note that this is exactly what you have givent: The projection center shall be the origin and R and N define the plane.

Such a projection can also be expressed in terms of a 4x4 homogenous matrix. There is one thing that is not defined in your question: the orientation of the normal. I'm assuming standard maths convention again and assume that the view plane is defined as <N,x> + d = 0. From using R in that equation, we can get d = -N_x*R_x - N_y*R_y - N_z*R_z. So the projection matrix is just

(   1       0       0     0   )
(   0       1       0     0   )
(   0       0       1     0   )
(-N_x/d  -N_y/d  -N_z/d   0   )

There are a few properties of this matrix. There is a zero column, so it is not invertible. Also note that for every point (s*x, s*y, s*z, 1) you apply this to, the result (after division by resulting w, of course) is just the same no matter what s is - so every point on a line between the origin and (x,y,z) will result in the same projected point - which is what a perspective projection is supposed to do. And finally note that w=(N_x*x + N_y*y + N_z*z)/-d, so for every point fulfilling the above plane equation, w= -d/-d = 1 will result. In combination with the identity transform for the other dimensions, which just means that such a point is unchanged.

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

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