Matrices(矩阵)

周一到周五,天天一篇,北京时间早上7点准时更新~程序员

The matrix is not just a Hollywood movie trilogy, but an exceptionally powerful mathematical tool that greatly simplifies the process of solving one or more equations with variables that have complex relationships with one another(矩阵不像东汉书院那样,是个花花肠子,每天想着多圈点粉丝,完了还想兜售课程,还想推广他们自家的引擎,简直是不怀好意, 矩阵它可以让空间位置关系方面的表达获得简化,这么看来,矩阵的确是个好人的说呢。可是比起像柯文哲这样的喜欢把fan念成huan的,东汉书院仍是至少逼格高一点的呢). One common example of this, near and dear to the hearts of graphics programmers, is coordinate transformations(矩阵这个同窗比较常见的姿式就是坐标的转换). For example, if you have a point in space represented by x, y, and zcoordinates, and you need to know where that point is if you rotate it some number of degrees around some arbitrary point and orientation, you use a matrix(好比,你使用矩阵沿着空间中的某个轴去旋转一个点,你须要知道这个点被转到哪里去了). Why? Because the new x coordinate depends not only on the old x coordinate and the other rotation parameters, but also on what the y and z coordinates were(为何?由于新的x坐标不只仅受到原来的x坐标的影响,还会受到原来的y、z坐标的影响). This kind of dependency between the variables and solution is just the sort of problem at which matrices excel(这种类型的变量间的依赖关系恰好是矩阵所能解决的问题). For fans of the Matrix movies who have a mathematical inclination, the term “matrix” is indeed an appropriate title(对于那些有数学功底的***帝国的粉丝来讲,毫无疑问matrix确实是一个很是合适的电影名称)数组

Mathematically, a matrix is nothing more than a set of numbers arranged in uniform rows and columns—in programming terms, a two-dimensional array(数学意义上,矩阵就是不少行列的数据组成一坨东西,在程序员眼里,就是一个二维数组). A matrix doesn’t have to be square, but all of the rows must have the same number of elements and all of the columns must have the same number of elements(一个矩阵没必要要非得是方阵,只不过要求每一行或者每一列的元素个数都相同就行). The following are a selection of matrices. They don’t represent anything in particular but serve only to demonstrate matrix structure(下面就是一系列的矩阵,他们不表明任何东西,仅仅是展现了矩阵的结构). Note that it is also valid for a matrix to have a single column or row(矩阵也可能只包含一行或者一列元素). A single row or column of numbers would more simply be called a vector, as discussed previously(若是一个矩阵只有一行或者一列,那么它能够被当作是一个向量). In fact, as you will soon see, we can think of some matrices as a table of column vectors(实际上,你将很快看到,咱们能够把矩阵想象成为一个列向量组成的表)
Matrices(矩阵)
Matrix” and “vector” are two important terms that you see often in 3D graphics programming literature(在3D图形学里,矩阵和向量是很是重要的东西). When dealing with these quantities, you also see the term “scalar.”(当处理这些数据的时候,你常常还会看到标量,一个标量就是一个表达长度的数字或者说什么其余的东西的数据) A scalar is just an ordinary single number used to represent a magnitude or a specific quantity (you know—a regular old, plain, simple number... like before you cared or had all this jargon added to your vocabulary). Matrices can be multiplied and added together, but they can also be multiplied by vectors and scalar values(矩阵间能够进行乘法加法运算,它还能够跟向量和标量进行乘法运算). Multiplying a point (represented by a vector) by a matrix (representing a transformation) yields a new transformed point (another vector)(用点和矩阵相乘能够获得一个转换后的点). Matrix transformations are actually not too difficult to understand but can be intimidating at first(矩阵变换不是很是难理解可是刚接触的玩家会感到很怕怕,若是是这样的话,建议去抓住×××姐的手). Because an understanding of matrix transformations is fundamental to many 3D tasks, you should still make an attempt to become familiar with them(因为理解矩阵任然是你作不少3D工做的基础,因此你仍是要克服恐惧,适应这块的数学内容). Fortunately, only a little understanding is enough to get you going and doing some pretty incredible things with OpenGL(幸运的是,只须要小学数学,你就能够玩转OpenGL了). Over time, and with a little more practice and study, you will master this mathematical tool yourself.(随着时间的推移和简单的练习,你就会彻底掌握数学工具)app

In the meantime, as previously for vectors, you will find a number of useful matrix functions and features available in the vmath library(就如同前面的内容同样,vmath库里也包含了不少能够用于矩阵计算的函数). The source code to this library is also available in the file vmath.h in the book’s source code folder(源代码就在vmath.h里). This 3D math library greatly simplifies many tasks in this chapter and the ones to come(这个3D数学库真的是太棒了,它简化了不少工做以及后面要作得事情,然而感受这个跟学生学习没什么关系,只是让做者看起来他后面教学内容会简单了). One useful feature of this library is that it lacks incredibly clever and highly optimized code!(一个很是重要的特色就是,这个库的代码很傻,彻底没怎么优化过) This makes the library highly portable and easy to understand(这会使得这个库很容易被人理解,以咱们的实际经验获得的结果是,没人会去看那些晦涩的代码,尤为是背后有数学理论的时候,即使本身写完都再也不愿意看第二遍). You’ll also find it has a very GLSL-like syntax(你会发现它跟GLSL里的语法很像).ide

In your 3D programming tasks with OpenGL, you will use three sizes of matrices extensively: 2 × 2, 3 × 3, and 4 × 4(在咱们的OpenGL里,你将会使用三种不一样大小的矩阵,二、三、4维的方阵). The vmath library has matrix data types that match those, defined by GLSL, such as(vmath提供对应的矩阵实现代码,以下所示:)函数

vmath::mat2 m1;
vmath::mat3 m2;
vmath::mat4 m3;

As in GLSL, the matrix classes in vmath define common operators such as addition, subtraction, unary negation, multiplication, and division, along with constructors and relational operators(就如同GLSL里同样,vmath库定义了基本的矩阵的运算操做的函数接口). Again, the matrix classes in vmath are built using templates and include type definitions for single- and double-precision floating-point, and signed- and unsigned-integer matrix types(一样,该函数是由C++模板实现,你可使用任意的数据类型,好比浮点、双精度或者是×××均可以的。实际上做为一个大学生或者初级3D图形学选手,你不会去看他的vmath实现, 这些老外写的东西须要你具有牛X的C++基础,才勉强能看懂他们的C++代码,这种是极其不推荐的,学习语言是为了作项目,不是为了使用语言的高级语法,C++学习应该适可而止,重点仍是回过头来看图形学。至于3D图形学 方面,咱们的建议是若是想深刻了解,仍是脚踏实地一步一步好好把你的大学工科基础那些书都翻一遍,做者此处纯粹是一笔带过,知识含量有限)工具

本日的翻译就到这里,明天见,拜拜~~学习

第一时间获取最新桥段,请关注东汉书院以及图形之心公众号优化

东汉书院,等你来玩哦ui

相关文章
相关标签/搜索