Transformation (2) (notes)


Three, three-dimensional transformation

Preview : Transformation(1) (notes)

Three-dimensional rotation transformation : The Insert picture description hereabove figure shows the formula for rotating a three-dimensional object around the x-axis, y-axis, and z-axis. When rotating around the x-axis, for any point, the x-axis does not change, and the same is true for y and z. Note that the formula for rotation around the y axis is a bit strange and seems to be the opposite. The reason is because the rotation around y is from z to x, while around x and z are from y to z and x to y, respectively.

Euler angles : Insert picture description hereIn order to facilitate the understanding of three-dimensional rotation, three-dimensional rotation is regarded as the result of a combination of rotation around the x-axis, y-axis, and z-axis.

Rodrigues' Rotation Formula : Rodrigues' Rotation Formula Insert picture description here
can express any rotation by decomposing the rotation into x, y, and z axes.

Four, view/camera transformation (View/Camera Transformation)

View transformation : the
Insert picture description herethree-dimensional object needs to be transformed to the two-dimensional screen to be displayed. View transformation is the transformation of two-dimensional view/camera. To understand what a view transformation is, you can think about how we take pictures in reality:
first we select the location and arrange the objects to be photographed (model transformation), and then place the camera at a good angle (view transformation) , And finally press the shutter button (projection transformation)

The execution of the view transformation : Insert picture description here
1. To execute the view transformation, first define the position of the camera, the direction the camera looks at, and the upward direction of the camera.
Insert picture description here
2. If the camera and all objects move together, the image obtained is unchanged, so we will always transform the camera to the origin of the coordinate, and always look in the -z direction, with the y axis as the upward direction, and all other objects will follow The camera changes together. Putting the camera in this so-called "standard position" can simplify operations.
Insert picture description here
3. For camera e, in order to perform the above operations, we need to perform Mview transformation on the camera. Mview transformation requires us to first translate the camera to the origin, then rotate g to -Z, t to Y, and (g X t) To X.
Insert picture description here
4. Transform the camera according to the Tview matrix and move it to the origin.
Insert picture description here
5. For rotation, rotating g to -Z does not seem to be very good, but rotating -Z to g seems to be easy to write. In other words, the transformation we want is not easy to find, but his inverse transformation is easy to find, so we can write his inverse transformation first. Next, just invert his inverse matrix.
6. Since the model transformation of other objects needs to perform the same transformation together with the view transformation of the camera, the above process is also called ModelView Transformation.

5. Projection Transformation

Projection transformation : Insert picture description hereIn computer graphics, projection refers to the process from 3D to 2D, which is divided into perspective projection (Perspective Projection) and orthogonal (orthogonal) projection (Orthographic Projection).

Perspective projection and orthogonal projection : Insert picture description hereFor perspective projection, we think that the camera is a point and the line of sight is a quadrangular pyramid. The perspective projection is closer to the observation effect of the human eye, and has the characteristics of near large and small. For orthographic projection, we assume that the camera is placed at infinity, so the distance of the object no longer affects the size of the object.

A simple way to understand orthogonal projection : the Insert picture description herecamera is at the origin, looking in the -Z direction, discarding the z-axis information, and then moving the resulting image with only x and y axis information to a rectangle from -1 to 1 (do this It can be convenient for subsequent calculations), and the result is an orthogonal projection.

The formal operation method of orthogonal projection : Insert picture description here
1. First define a cube in space. We need to determine how much its left and right are on the X axis, how much is up and down on the Y axis, and how much is the distance on the Z axis, and map it To the standard cube ([-1,1]^3), that is, place its center at the origin, and pull the x, y, and z axes to -1 to 1 respectively. The formula is as above. In this way all objects will be pulled up into a standard cube.
Note: Since we are looking at -Z, the near is actually greater than the far (n>f). This is why the OpenGL API uses the left-handed coordinate system.
Insert picture description here
2. After doing the above, there will be a thing called viewport transformation, and then stretch again. Not mentioned here.

Perspective projection : Insert picture description here
Perspective projection is the most widely used projection method. It meets the requirements of near-large and far-small. In terms of visual effects, parallel lines are no longer parallel, but converge to one point.

A property of homogeneous coordinates : Insert picture description here
(x,y,z,1), (kx,ky,kz,k != 0), (xz,yz,z^2,z != 0) all represent the three-dimensional space The same point (x, y, z). This is a simple but useful property.

The operation method of perspective projection : Insert picture description here
1. "Squeeze" a frustum in the space into a cuboid (after doing this, the near plane is still that big, and the far plane is smaller).
2. Do orthogonal projection.

How to "squeeze" the frustum into a cuboid :
Insert picture description here
1. First find the point (x', y', z') after the transformation (to be reached) and the original point (x, y, z) Relationship. As far as x and y are concerned, they are obviously similar triangles, n/z.
Insert picture description here2. Write the homogeneous coordinate formula. At this time, we don't know the transformation relationship of the z axis.
Insert picture description here3. Since we don't know the transformation of the z axis, we can get a part of the transformation matrix M (persp->ortho) by aligning the secondary coordinates with some transformations.
Insert picture description here4. Through observation, it can be found that the z-axis has not changed regardless of the distance on the screen.
Insert picture description here
5. For the case of near point, since n/z is 1, z=n, so replace z with n, you can directly get the result after near point transformation, from which the third line of the result is inferred as n^2, The form of the third row of the matrix is ​​0 0 AB, AB cannot be determined, but An+B=n ^2.
Insert picture description here
6. For the far point (0,0,f) (the midpoint of the far plane of the frustum) the same remains unchanged after the transformation. You can also get the formula Af + B = f^2.
Insert picture description here
7. Solve A and B through two formulas, and the matrix is ​​complete.


The end of the course

Insert picture description here
How does the middle Z point change after squeezing?

Guess you like

Origin blog.csdn.net/qq_37856544/article/details/112909064