Current location - Training Enrollment Network - Mathematics courses - Three-dimensional mathematics of OpenGL
Three-dimensional mathematics of OpenGL
In the development process, the graphic transformation we are involved in will involve the calculation of matrix/vector. For example, when we use CAnimation to realize affine transformation, we use OpenGL rendering technology.

There are two data types in math3D that can represent three-dimensional or four-dimensional vectors.

Usually, the w coordinate is set to 1.0. The value of x, y, z y, z divided by w, then? Zoom line by line. And dividing by 1.0 will not change the values of x, y, z, y and z in essence.

Between two unit vectors. The point multiplication operation will get a scalar (not a three-dimensional vector, but a scalar), which represents the cosine value of the included angle between two vectors [- 1,1];

If the vector is not a unit vector, we can unitize the vector.

Unit vector 1 (x 1, y 1, z 1) multiplied by unit vector 2(x2, y2, z2) equals x1x2+y1y2+z/kloc-0.

The result is that both u and v are unit vectors. Find the cosine of the angle between u and v..

The result is the angle between u and v.

Two vectors can be cross-multiplied to get another vector, and the new vector will be perpendicular to the plane defined by the original two vectors. (Cross multiplication does not require two vectors to be identity vectors.)

The new vector is perpendicular to the original two vectors, and we can get new vectors in two directions. Obviously, it is wrong to get two vectors, and we should use the right-hand rule to judge here.

The result is the result of u crossing v.

The two definitions are only different in accuracy, and they are all three-dimensional matrices.

Four-dimensional matrices with different accuracies

Will. Multiplying a vector by a cell matrix is equivalent to multiplying a vector by 1. Nothing will change.

Transform vertex vector = M_pro * M_view * M_model * V_local.

Transform vertex vector = projection matrix? View the transformation matrix? Model matrix? pinnacle

A versus a? It is the process from row matrix to column matrix, which is called matrix transposition.

So the column matrix is used in openGL.

Application of vertex shader

Mode conversion:? Manipulate models and specific transformations. These transformations move the object to the desired position. By rotation, scaling and translation.

M: Set the converted matrix.

X: translation distance in the x-axis direction.

Y: the translation distance in the y-axis direction.

Z: the translation distance in the z-axis direction.

Set the rotated matrix.

Angle: Set the rotation angle.

X: If it is 1, it will rotate along the X axis; If 0, the x axis will not rotate.

Y: if it is 1, it rotates along the y axis; If 0, the y axis will not rotate.

Z: If it is 1, it will rotate along the z axis; If 0, the z axis will not rotate.

Set the rotated matrix.

XScale: the coordinates of the x axis are scaled by xscale. If it is-1, the x-axis will be flipped.

Y scale: the coordinates of the y axis are scaled by y scale. If it is-1, the y axis is flipped.

Zxscale: the coordinates of the z axis are scaled by zScale. If it is-1, the z axis is flipped.

Product: the result of two model changes.

A: First, change according to matrix A..

B: Then change it according to the B matrix.

* * In fact, we can know that it is bxa by manual calculation after the breakpoint. Why? The reason is that OpenGL defaults to column matrix, and the value we set manually is set according to mathematical laws, because it is transposed, so it is equal to * *