Original post address: http://ogldev.atspace.co.uk/www/tutorial08/tutorial08.html
The scaling matrix is relatively simple. It aims to scale the object length (or, scale the component of the vertex in the three axes). Of course, you can also select a certain axis direction to scale. The reason for scaling objects is mainly to match the sizes of different objects in the world space, because 3D object modeling is in the model space, usually (x, y, z) the range is (0, 1), while in the world space, objects are large and small, such as small trees and buildings. This requires scaling these models.
The scaling matrix is a diagonal matrix, as shown in. A, B, and C represent the scaling ratio on the X, Y, and Z axes respectively.
We extend it to a 4x4 matrix to match the x-axis.
Major code changes:
World.m[0][0]=sinf(Scale); World.m[0][1]=0.0f; World.m[0][2]=0.0f; World.m[0][3]=0.0f;
World.m[1][0]=0.0f; World.m[1][1]=sinf(Scale); World.m[1][2]=0.0f; World.m[1][3]=0.0f;
World.m[2][0]=0.0f; World.m[2][1]=0.0f; World.m[2][2]=sinf(Scale); World.m[2][3]=0.0f;
World.m[3][0]=0.0f; World.m[3][1]=0.0f; World.m[3][2]=0.0f; World.m[3][3]=1.0f;
Compared with the previous tutorial, we used the zoom matrix as the world matrix and the scale sinf value as the zoom factor in the X, Y, and Z directions, its value changes between [-]. When [] changes, the object keeps shrinking and disappears completely at the point of 0. When [0,-1], the object becomes larger, however, it should be noted that at this time, x, y, and z become negative, which is opposite to the original object.
After the program is executed, the interface is as follows: