glm ::透视说明 [英] glm::perspective explanation

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

问题描述

我试图了解以下代码的作用:

I am trying to understand what the following code does:

glm::mat4 Projection = glm::perspective(35.0f, 1.0f, 0.1f, 100.0f);

是否创建投影矩阵?剪掉用户视野之外的任何内容? 我在 API页面上找不到任何内容,我唯一能在他们的网站上的pdf文件中找到的是:

Does it create a projection matrix? Clips off anything that is not in the user's view? I wasn't able to find anything on the API page, and the only thing I could find in the pdf on their website was this:

gluPerspective:

gluPerspective:

glm::mat4 perspective(float fovy, float aspect, float zNear,
float zFar);
glm::dmat4 perspective(
double fovy, double aspect, double zNear,
double zFar);
From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>

但是它没有解释参数.也许我错过了一些事情.

But it doesn't explain the parameters. Maybe I missed something.

推荐答案

它将创建一个投影矩阵,即描述一组线性方程的矩阵,该线性方程组将向量从眼空间转换为剪辑空间.矩阵真的不是黑魔法.在OpenGL的情况下,它们恰好是4乘4的数字排列:

It creates a projection matrix, i.e. the matrix that describes the set of linear equations that transforms vectors from eye space into clip space. Matrices really are not black magic. In the case of OpenGL they happen to be a 4-by-4 arrangement of numbers:

X_x Y_x Z_x T_x
X_y Y_y Z_y T_y
X_z Y_z Z_z T_z
X_w Y_w Z_w W_w

您可以将4向量乘以4×4矩阵:

You can multply a 4-vector by a 4×4 matrix:

v' = M * v

v'_x = M_xx * v_x + M_yx * v_y + M_zx * v_z + M_tx * v_w
v'_y = M_xy * v_x + M_yy * v_y + M_zy * v_z + M_ty * v_w
v'_z = M_xz * v_x + M_yz * v_y + M_zz * v_z + M_tz * v_w
v'_w = M_xw * v_x + M_yw * v_y + M_zw * v_z + M_tw * v_w

到达剪辑空间后(即在投影步骤之后),将修剪图元.然后,裁剪产生的顶点将进行透视分割,即

After reaching clip space (i.e. after the projection step), the primitives are clipped. The vertices resulting from the clipping are then undergoing the perspective divide, i.e.

v'_x = v_x / v_w
v'_y = v_y / v_w
v'_z = v_z / v_w
( v_w = 1 = v_w / v_w )

就是这样.实际上,在所有这些转换步骤中,没有什么比普通的矩阵向量乘法更重要了.

And that's it. There's really nothing more going on in all those transformation steps than ordinary matrix-vector multiplication.

现在很酷的事情是,可以使用矩阵来描述一个坐标系在另一个坐标系内的相对对齐.透视变换的作用是使顶点的z值也滑入"其投影的w值.并且通过透视图划分,不统一w将导致顶点坐标变形".具有小z的顶点将被小w划分,因此其坐标爆炸",而具有大z的顶点将被压缩",这就是导致透视效果的原因.

Now the cool thing about this is, that matrices can be used to describe the relative alignment of a coordinate system within another coordinate system. What the perspective transform does is, that it let's the vertices z-values "slip" into their projected w-values as well. And by the perspective divide a non-unity w will cause "distortion" of the vertex coordinates. Vertices with small z will be divided by a small w, thus their coordinates "blow" up, whereas vertices with large z will be "squeezed", which is what's causing the perspective effect.

这篇关于glm ::透视说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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