[WebGL Primer] Five, basics of matrices

Source: Internet
Author: User

Note: The article is translated from http://wgld.org/, the original author Sambonja 広 (doxas), the article if there is my additional instructions, I will add [Lufy:], in addition, The WEBGL research is not deep enough, some professional words, if the translation is wrong, you are welcome to correct.


not to get you in front of the store .

Lufy: You must be surprised, why call this topic, because the matrix in Japanese is called "the column", so the author makes a joke to the reader, I so direct translation, everybody knows what meaning is OK.

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

The matrix in this case is the matrix in mathematics. It is called Matrix in English.

Although the matrix sounds simple, there are many kinds of matrices, and the computational method is very difficult or cumbersome. Simply put, the matrix is the number like a box of the arrangement, the numbers are arranged vertically and then form a matrix. In the ordinary life is not used, but in the 3D rendering of the world is an indispensable element.


Why do I need matrices

Although the matrix in the 3D rendering is indispensable, but there may be no contact with it is not a few people. So why is the matrix so important?

Simulating three-dimensional space requires a lot of computation. What kind of things, where, what angle, size, just how many models you want to draw, and so on, need to be very complex and a lot of calculations.

The matrix, as we just said, arranges numbers in rows and columns, and in practical applications a matrix can contain a lot of intelligence.

For example, where do you want the model to be placed in the world, whether it has been rotated, whether it has been enlarged and shrunk, where the lens of the camera is, what the direction of the lens, the final image of the picture after the ratio of the proportions ... And so on, all this information can be represented by a matrix.

If you read the previous article (three, the basic knowledge of 3D drawing), and you are a careful person, you should be aware of it, the model in the world, where the direction of the lens, etc., have been introduced before.

In other words, the model coordinate transformation, the view coordinate transformation, the projection coordinate transformation, these series of coordinate transforms if uses the matrix, can complete all coordinates transformation processing in a matrix. Anyway, why the matrix is so important, you should probably understand it. Mainly, the calculation efficiency of matrix is very high, and it is convenient.


3D Rendering and matrices

It says that matrices are combined by numbers, so what is a matrix?

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


A matrix like this is called a phalanx.

Such a phalanx, the general 3D rendering of the world using a 4x4 matrix. Just like the diagram you just gave, rows and columns are composed of 4 elements, which is the type of matrix used in 3D rendering.

That's why it's not a 3x3 square or other matrix, but a 4x4 phalanx, for a reason. But let's not worry about that right now. Just remember that the matrix is a simple mechanism to make the calculations in 3D rendering easier.

matrices are completely mathematical topics, so it can be very difficult to understand them. Although it is better to learn carefully, but now the stage, just need to know what the matrix is a thing to do. In fact, I am not a major in mathematics, nor can I fully understand every detail of the matrix.

The actual 3D rendering, as said above, prepare the model coordinate transformation, view coordinate transformation, projection coordinate transformation of the various matrices. More specifically, the matrix of various coordinate transformations is prepared and then multiplied. Pass the resulting matrix to the vertex shader of WebGL.

The vertex shader obtains the coordinates of the model from the transmitted matrix, and the processing is displayed on the screen. In other words, the matrix of the Operation coordinate transformation can determine how the model is drawn on the screen.


what the matrix can do

The former also said, the coordinate transformation has the model transformation, the view transformation, the projection transformation and so on many.

The matrix can save the above mentioned transformations, for example, if the matrix of the model transformation, the location of the 3D model to be drawn, the enlargement, and the rotation of the information, can be defined in a matrix. the view transformation matrix, the position of the lens, the direction of the lens, and the point at which the lens is aligned (note viewpoint) can be defined in a matrix. Projection transformation matrix, the display of the ratio and angle of view and other information can be defined in a matrix.

Moreover, these three matrices can be combined with each other, the resulting transformation matrix to the shader, but there is a point to note, if it is a common mathematical calculation, when multiplying, do not need to pay attention to the order of multiplication, such as 2x3 equals 6,3x2 is equal to 6. However, the result of the matrix is different according to the order of multiplication. Because of this nature of the matrix, it is important to pay special attention to the order of multiplication when the matrix is multiplied by the model, view, and projection.

To actually write the program, I will further elaborate, first of all to remember that the order of matrix multiplication is very important.


Summary

Well, say so much, the matrix is also somewhat familiar with it.

This time, not to let you fully understand the matrix, that is, first introduced, if you want to the matrix of the explanation, you have to step into the mathematical world of the door.

The matrix is indispensable for 3D rendering, and it is very difficult to understand the matrix thoroughly. So let's get to the bottom of the matrix.

Later, I may be specialized in the interpretation of the matrix, first of all, a simple understanding of it. It is important to know the usefulness of matrices first, compared to the 0 basis. If you are interested, there are a lot of related introductions on the internet, the deeper the understanding is definitely the better. If you have time, you can see for yourself first.


Next, describe the term vertices and polygons in 3D.


reprint Please specify: transfer from Lufy_legend's blog Http://blog.csdn.net/lufy_legend

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.