# OpenGL tutorial (8) object Scaling

Source: Internet
Author: User

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:

Related Keywords:

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.