[Getting started with WebGL] 5. Basic matrix knowledge and basic webgl knowledge

Source: Internet
Author: User

[Getting started with WebGL] 5. Basic matrix knowledge and basic webgl knowledge

Note: The article is translated from http://wgld.org/, the original author shanbenya (doxas). If I have additional instructions in the article, I will add [lufy:]. In addition, the research on webgl is not in-depth enough, and some professional words are required, if the translation is incorrect, please correct me.


Not to queue you in front of the store

Lufy: You must be wondering why this question is called. Because the matrix in Japanese is called "column and column", the author made a joke to the readers, So I translated it directly, everyone knows what it means.

In the world of 3D rendering, matrices are frequently used.

The matrix mentioned here is a matrix in mathematics. It is called Matrix in English.

Although the matrix sounds very simple, there are many kinds of matrices, and the calculation method is very difficult or very troublesome. To put it simply, the matrix is to arrange numbers like a box, and arrange the numbers in vertical and horizontal directions to form a matrix. It is not used in ordinary life, but it is an indispensable element in the world of 3D rendering.


Why matrix?

Although the matrix is indispensable in 3D rendering, there may not be a few people who have never touched it. Why is matrix so important?

Simulating 3D space requires a lot of computing. What kind of things, where, how angle, size, and only the number of models to be drawn all require very complex and massive computation.

A matrix is a matrix that sorts numbers by row and column. In practice, a matrix can contain a lot of intelligence.

For example, if you want to draw a model where it is placed in the world, whether it is rotated, whether it is zoomed in or out, where the camera is, and how the camera is directed, what is the ratio of the final image after imaging ...... and so on. All these intelligence can be expressed using a matrix.

If you read the previous article (3, basic knowledge of 3D plotting) and you are a careful person, you should pay attention to the location of the model in the world, the camera direction, which has been described earlier.

That is to say, model coordinate transformation, view coordinate transformation, and projection coordinate transformation. If a matrix is used for these series of coordinate transformations, all coordinate transformations can be completed in a matrix. In any case, we should probably understand why matrices are so important. Mainly, the matrix computing efficiency is very high and convenient.


3D rendering and Matrix

The matrix is composed of numbers. So what is a matrix?

Although there are many types of matrices, one of them is called a square matrix. Is the matrix with the same number of rows and number of columns.


The matrix above is called a square matrix.

Such a square matrix uses a 4x4 matrix in the world of 3D rendering. Just like the given graph, rows and columns are composed of four elements, which is the type of matrix used in 3D rendering.

That's why it's not a 3x3 matrix or another matrix, but a 4x4 matrix. However, you don't need to worry about it now. Just remember that the matrix is a simple mechanism that can make the calculation in 3D rendering easier.

Matrix is a topic of mathematics, so it may be difficult to understand. Although it is best to study it carefully, you only need to know what the matrix is. * In fact, I am not a major in mathematics, nor can I fully understand every detail of the matrix.

In actual 3D rendering, as mentioned above, prepare various matrices for model coordinate transformation, view coordinate transformation, and projection coordinate transformation. To be specific, prepare the matrix of various coordinate transformations and multiply them. Pass the final matrix to the vertex shader of WebGL.

The Vertex coloring tool obtains the coordinates of the model from the passed matrix and processes the model to display the model on the screen. That is to say, the matrix of coordinate transformation can determine how the model is drawn on the screen.


What can a matrix do?

As mentioned above, coordinate transformations include model transformations, view transformations, and projection transformations.

A matrix can save the transformation mentioned above. For example, if it is a matrix of model transformation, the location of the 3D model to be drawn, the information such as expansion and reduction, and rotation, can be defined in a matrix. The view transformation matrix, the camera position, the camera direction, and the point at which the camera is aligned (the watching point) can be defined in a matrix. If the projection transformation matrix is used, the displayed information such as the ratio and angle of view can be defined in a matrix.

In addition, these three matrices can be combined, and the final transformation matrix is transmitted to the coloring machine. However, note that if it is a common mathematical calculation, when multiplying, do not pay attention to the order of multiplication. For example, 2x3 equals 6 and 3x2 equals 6. However, the result of the matrix is different according to the order of multiplication. Because of this nature of the matrix, pay special attention to the order of multiplication when multiplying models, views, and projection matrices.

When writing a program, I will further elaborate on it. First of all, we must remember that the order of matrix multiplication is very important.


Summary

Well, I 've said so much about the Matrix.

This time, it is not for you to fully understand the matrix, but to introduce it first, if you want to really explain the matrix, you must step on the door of the mathematical world.

Matrix is indispensable for 3D rendering, and it is very difficult to fully understand the matrix. So now let's clarify what the matrix is.

In the future, I may give a special explanation of the matrix. First of all, simply understand it. It is important to know the usefulness of the matrix first, instead of having zero Foundation. If you are interested, there are many related introductions on the Internet. The deeper you understand, the better you will be. If you have time, take a look at it first.


Next, we will introduce the terms vertices and polygon in 3D.


Reprinted Please note:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.