OpenGL shader program analysis -- scaling transformation

Reprinted to: https://blog.csdn.net/cordova/article/details/52558804

background

The scaling transformation is very simple, its purpose is to increase or decrease the size of an object. For example, you want to use the same model to make many different objects (a forest of trees of different sizes, using the same model), or you want to make the objects proportional to the real world size. In the above case you would need to scale the vertex positions equally across all three axes. Of course, sometimes it is also desirable to scale objects in only one or two axes to make the model thinner, thinner or taller, etc.

Performing scaling transformations is actually quite simple. Looking at the original transformation matrix at the beginning, recalling the appearance of the translation transformation matrix, the way we keep V1, V2 and V3 in the resulting matrix as they are is to make the values ​​on the main diagonal of the transformation matrix all '1', so that After the original vector is multiplied by 1 , it remains unchanged, and the components do not affect each other. Therefore, for the scaling transformation here, as long as the '1' is replaced with the value we want to scale, the components of the original vector will be scaled correspondingly on the corresponding coordinate axis after multiplying these values. If the value is greater than 1, it will be enlarged. Values ​​less than 1 scale down.

write picture description here

write picture description here

Detailed source code

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, the code still only changes the content of the transformation matrix according to the above description. It can be seen that here we use a scaling value between -1 and 1 to scale the object on each coordinate axis. The triangle in the range of (0,1) will change between the original size and the minimum size. When the transformation matrix The triangle disappears completely when the value on the diagonal is 0. The effect looks the same in the range [-1,0) but the triangle is flipped because the value on the diagonal changes the sign of the vertex coordinates.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325773474&siteId=291194637