OpenGL 中的矩阵
所以我正在以“红皮书”作为主要资源来学习OpenGL。我正在阅读有关矩阵代数、旋转/缩放/变换矩阵的内容,一切都很棒,但我只是没有得到一件简单的事情。假设函数 glLoadIdentity()。它设置默认矩阵 4x4。所以它设置了3个顶点和1个点:(1,0,0)(0,1,0)(0,0,1)顶点,(0,0,0)点。但我的问题是,这些对应什么?一般来说,OpenGL中的矩阵对应什么?我知道这些是轴的方向。但轴是什么?相机?
So I am learning OpenGL with as the main resource having the "Red book". I am reading about matrix algebra, rotation/scaling/transform matrices and everything is great, but I just don't get one simple thing. Let's say the function glLoadIdentity(). It sets the default matrix of 4x4. So it sets 3 vertices and 1 point: (1,0,0) (0,1,0) (0,0,1) vertices, (0,0,0) point. But my question is, what do those correspond? Generally speaking, what does a matrix correspond in OpenGL? I got an idea that these are the directions of axies. But the axies of what? The camera?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OpenGL矩阵仅对应于一种变换,将一个坐标空间中定义的对象、向量和点移动到另一个坐标空间。如果在一个坐标空间中有一个矩阵 M(m11 - m44,如下所示)和一个向量 V (v1 - v4),那么乘以 M 将转换你的 V 向量(它可以描述运动向量、对象位置或对象顶点) ) 到不同坐标空间中的 W (w1-w4):
其中:
因此,如果我们将 v1 - v3 视为旧的 x、y 和 z 坐标并将 v4 设置为 1,那么我们可以将 w1 - w3 视为新坐标x、y 和 z 坐标我们可以看到一些东西:
m11 是从旧 x 坐标到新 x 坐标的乘数,因此它用于比例变换(m22 和 m33 也类似)
m14 乘以 1 并添加到新的 x 坐标,以便用于平移(对于 m24 和 m34 也类似)。
旋转有点难以概念化,但它们是通过将其他矩阵值设置为适当的值来完成的。您可以在这里阅读更多内容:http://gpwiki.org/index.php/Matrix_math
OpenGL matrices only correspond to a transformation, moving objects, vectors and points defined in one coordinate space to another. If you have a matrix M (m11 - m44 as shown below) and a vector V (v1 - v4) in one coordinate space then multiplying by M will convert your V vector (which could describe a movement vector, object location or an object vertex) to W (w1-w4) in a different coordinate space:
Where:
So if we think of v1 - v3 as the old x, y and z coordinates and set v4 to 1, then we can think of w1 - w3 as the new x, y and z coordinates there are a few things we can see:
m11 is a multiplier from the old x coordinate to the new one so it's used in scale transformations (and similarly for m22 and m33)
m14 multiplied by 1 and added to the new x coordinate so it is used for translations (and similarly for m24 and m34)
Rotations are a little harder to conceptualise but they are done by setting the other matrix values to appropriate values. You can read more here: http://gpwiki.org/index.php/Matrix_math
默认矩阵只是单位矩阵:
在更一般的情况下(忽略透视和可能的其他奇异变换)...
...变换后的坐标系的组成部分如下:
如果将这些与单位矩阵相关联,则可以看到你的“3个顶点和1个点”来自哪里。
除了单位矩阵之外,这还适用于任何将底行保持在 (0 0 0 1) 的变换(旋转、平移等),并提供了一种简单的方法来可视化此类变换。简单地认为上面的四个分量代表轴 (1 0 0)、(0 1 0)、(0 0 1) 和原点 (0 0 0) 在经过矩阵变换后最终的位置(请记住,轴不是绝对的,而是相对于原点的)。
The default matrix is simply the identity matrix:
In the more general case (ignoring perspective and possibly other exotic transforms)...
...the components of the transformed coordinate system are as follows:
If you correlate these to the identity matrix, you can see where your "3 vertices and 1 point" come from.
Beyond the identity matrix, this applies to any transform — rotation, translation, etc. — that keeps the bottom row at (0 0 0 1), and provides a simple way to visualise such transforms. Simply think of the four components above as representing where the axes (1 0 0), (0 1 0), (0 0 1) and the origin (0 0 0) end up after being transformed by the matrix (keeping in mind that the axes are not absolute, but relative to the origin).