A summary of some experience in graphics programming (OpenGL for example)

Source: Internet
Author: User

Due to the complexity of graphics, often encounter a variety of small problems, here to do a summary, easy to find later.

1. coordinate system

In general, the coordinate system is divided into left-handed and right-hand coordinates. 1, the left is the right-hand coordinate and the left-hand coordinate system is shown on the right. Two coordinate systems are rotated, panned, scaled, and there is no way to convert from one to the other. So when processing vertices and other data, pay special attention to the data in what kind of coordinate system environment. For example, I have written a program that imports models from 3dmax into OpenGL. Since 3dmax is a left-handed coordinate system, and OpenGL is in the right-handed coordinate system, direct import will definitely be problematic. The simplest way is to change the order of coordinates and assign <x,y,z> to <z,x,y>.

  

Figure 1

2, line priority and column priority

Row precedence and column precedence are also known as row Main and column main orders, both of which are for two-dimensional arrays. As the name implies, the line main sequence means that when storing a two-dimensional array, the data is filled with rows before filling the columns. The column main order is to fill the column first, and then fill the row. For example, here we have a 4*4 two-dimensional array containing 16 elements (A1,A2,..., A16). In Figure 2, the left image is the method of storing the main sequence of the row, and the right image is the storage method of the column main sequence. Storing a two-dimensional array in C + + is stored in the form of a row main order. So we often deal with some matrices in OpenGL, which can be said to be a two-dimensional array. OpenGL stores the matrix in the same way that C + + is stored in the same way that it is stored in the column master order. Here's another example, OpenGL's shader is also stored in the main sequence of the column, but sometimes we don't have to consider this: when we use Gluniformmatrix () This function to pass the matrix, there is a parameter transpose, If set to gl_true, then the data is read in the order of the row main order, and if it is gl_false, then the data is read in the column main order. so I suggest that when you write a matrix, it's best to express it in a one-dimensional array.

Figure 2

3, the matrix of the left and right multiply

Matrix multiplication is divided into right multiplication and left multiplication, because the matrix multiplication does not support the commutative law, so the left and right multiply must be different. In fact, in my opinion, the difference between the left and right multiplication is not complicated at all, which is the difference between the main sequence and the main sequence of rows. Why do you say that? Let me give you an example. The rotation information in the transform Matrix T is (R1,R2,..., R9), and the translation information is (T1,T2,T3). Figure 3 is a right-multiply example, and the matrix is a row of the main sequence of storage, that is, the left-multiply, matrix, a column of the main sequence. The main note here is the change in the position of the translation information, you can see the difference between the left and right multiplication. OpenGL stores the matrix in the form of a column main order, so the OpenGL matrix is left-multiplying. In addition the 3dmax is also left multiply.

Figure 3

A summary of some experience in graphics programming (OpenGL for example)

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.