Transform operations
Model transformation (vertex shader stage of the process)
View transform (vertex shader stage of the process)
Model view transform (vertex shader stage of the process)
Projective transformation (vertex shader stage of the process)
In this step, we get the final coordinates of the object looks in the camera, but the human eye can see, and we still differ scene, such as we see things in the world are from a perspective near the far smaller effect, projection transformation is used to achieve these effects of transformation;
Orthogonal projection
Orthogonal projection, can be seen as a parallel projection of the object is not near the far smaller visual effects in the orthogonal projection, looks the same regardless of distance large, the projection is generally used in a 2D or 2.5D (typically 3D characters 2D scene) in games, 3D games of the UI will be used to achieve this projection;
Gl-matrix created using an orthogonal projection library code is as follows:
. 1 var M4 = glMatrix.mat4.create (); 2 // by setting the size of each face of the projection area determination . 3 glMatrix.mat4.ortho (M4, -100, 100, -100, 100, -100, 100) ;
Perspective projection
Perspective projection, can simulate the human eye to see the 3D world near the far smaller visual effects, the projection is generally used in 3D games;
Creating a perspective projection using the following codes gl-matrix library:
1 var M4 = glMatrix.mat4.create (); 2 // Method 1: The vertical extent, and the aspect ratio of the projection area determined mesiodistal plane . 3 glMatrix.mat4.perspective (M4, 1, 1, 0, 100 ); 4 // method 2: projection area determined by setting the size of each face . 5 glMatrix.mat4.frustum (M4, -100, 100, -100, 100, -100, 100);
Perspective division (primitive assembly stage of the process)
I.e. the w component perspective division divided by x, y, z components (w default value is 1), to produce a three-dimensional perspective effect.
More information can be found: https://www.jianshu.com/p/7e701d7bfd79
Viewport transformation (primitive assembly stage of the process)
The viewport transformation is a projection of the main object in three-dimensional space onto a two dimensional plane, in computer graphics, which is defined through the geometric transformation, projective transformation of the object after clipping and transform screen displayed in the specified area.
User may control the transformation step by calling two methods:
gl.viewPort
Determining a final display position and size, in pixels;
gl.depthRange
Determining a final depth region can be displayed, selected from the range [0-1];
Complete conversion line (transformed lines) as shown below
The importance of transform order
Transformation matrix stack
Stack
Pop
- Pressed into the matrix table;
- Stack matrix multiplication with a matrix on the desktop, to obtain global coordinates of the matrix table top;
- Pressed into the matrix table, when an object needs to be drawn on the table, the top of the stack may be used in the matrix multiplication of the matrix need to draw the object;
- Desktop has no need to draw the object, the pop stack matrix (i.e., matrix desktop);
- At this time, i.e., the table top of the stack matrix matrix matrix multiplication with the top of the stack in the first leg of the matrix, the matrix obtained global coordinates of the first leg;