Modle Transformation

Model transformation: Objects in 3D space can be expanded, rotated and translated to change the size, position and other information of the object to meet the requirements of design and creation. In the actual operation requirements, the operation is usually carried out in the order of scale -> rotation -> translation, which is more convenient for matrix construction and calculation.

2D translations

  • Scale

  • Shear

  • Rotate

All rotation matrices are orthogonal, so their inverse is the transpose matrix, which geometrically means that a vector rotated 30 degrees counterclockwise from the origin is rotated 30 degrees clockwise.

  • Affine

Affine transformation is equal to linear transformation + translation operation, and here you can see that affine operations are not linear transformations, which leads to the concept of homogeneous coordinates, so that all transformation operations can be represented in terms of a matrix.

Homogeneous Coordinates

  • 3Dpoint=(x,y,z,1)T: When the w component of homogeneous coordinates is 1, this vector is regarded as the point (x,y,z)
  • 3Dvector=(x,y,z,0)T: when the w component of homogeneous coordinates is 0, this vector is treated as the vector (x,y,z).
  • 3Dpoint=(xw,yw,zw,w)T: When the w component of homogeneous coordinates is not 0, the vector is regarded as a vector (xw/w,yw/w,zw/w).
  • point – point =vector
  • vector + vecotr =vector
  • point + vetor = point
  • Point + point = mid point

In the homogeneous coordinate system, the transformation matrix of the vector can be multiplied: Acompose=A1A2A3… And the affine transformation can also be represented by a matrix

3D translations

  • Scale

  • Rotate

R (n,α) : n is the vector starting at the origin, and α is the rotation Angle I: the identity matrixCopy the code
  • Translate

Camera Transformation

Observation space coordinates can be obtained by view transformation of world space coordinates. View transformation can be understood as transforming an object’s position in the world coordinate system (including angles) to its position in the camera coordinate system (including angles), in other words, finding the object’s position relative to the camera (including angles). Once you get the relative position, it’s easier to get the depth relationship of the object for later rendering.All we need to do is first translate the camera to the original origin and then rotate it. For the matrix solution of these two transformations we can use the inverse matrix, which simplifies a lot of operations.

Projection Transformation

The coordinates of the Clip Space can be obtained by projection transformation. The projection change can be understood as the transformation of the coordinates in 3D space into the coordinates on the projection plane, that is, the things in 3D space are projected on the projection plane where we finally present the picture.

Orthographic Projection

Orthogonal projection can be understood as parallel projection, and objects of the same size can be projected onto the screen. The actual operation is usually to map the cuboid illuminated by the camera to the standard cube. The actual operation can be simplified into two steps:

  • Move the center of the cube to the origin
  • Stretch the cuboid into the gauge cube [-1,1]³

Where l and r are the maximum and minimum values of the visual body on the X-axis, t and b are the maximum and minimum values on the Y-axis, and f and n are the maximum and minimum values on the Z-axis

Perspective Projection

Projection projection is in line with the projection mode of real human eyes. The typical feature is near large, far small. Most 3D games use perspective projection mode. The actual operation of perspective projection is also only two steps

  • Compress the truncated cone into a cuboid
  • Orthogonal projection

The transformation matrix can be obtained according to the triangle similarity principle and constant z values of the near and far planesSince the above orthogonal transformation matrix is known, Mpersep=MorthoMpersp−> Ortho, the final perspective transformation matrix is as follows

Viewport Transformation

The viewport transform maps the coordinates in the clipping space (range [-1,1], [-1,1]) to the screen coordinates (range [0,width], range [0,height]). To do this, define the screen resolution (for example,width =1200,height =1080).

Clipping the x and y of the spatial coordinates is also known as the normalized device coordinates (NDC) because the values range from [-1,1] to eliminate the dependence on the aspect ratio of the screen, which can then be stretched to the appropriate screen resolution by simply using viewport transformationCopy the code

conclusion

Model Transformation -> Camera Transformation in World space Projection Transformation -> Viewport Transformation Cut space coordinates -> screen space coordinates V '=Mviewport * Mpersepctive * Mview * Mmodel * VCopy the code

reference

Transformation – KillerAery – Bloggarden (CNblogs.com)

Computer Graphics 2: View transformation (coordinate system transformation, orthogonal projection, perspective projection, viewport transformation)