A probe into the matrix in game development 1. The role of matrices in 3d space
(1) box A wants to rotate the 50° around (10,3,4) and twice times in the x direction and 2 units in the direction of (9,-1,8), then after the above transformation, the new box of the coordinates of the various points? The application matrix makes it easy to figure out the answer.
(2) Knowing the position of the sub-coordinate system in the parent coordinate system, you can find the location of the store in the child coordinate system in the parent coordinate system.
2. Basic knowledge of matrices
Matrices can describe arbitrary linear transformations. Linear transformations retain lines and parallel lines, while linear transformations retain lines while other geometric properties such as length, angle, area, and volume may be transformed. Simply put, a linear transformation may "stretch" the coordinate system, but not the "bend" or "curl" coordinate system.
(1) Panning
The following matrices translate a point toward the T vector direction:
(2) Rotation
The positive direction is the counterclockwise direction of the past from the axis of rotation, such as rotation around the z-axis [0,0,1], positive direction x to Y axis direction
Knowing the rotation matrix around the three axes, the following is the matrix around any vector. Set M as the matrix of the unit matrix after the rotation of vector a , and a = (xa, ya, za), the angle of rotation is α, then
M=
Don't ask why, just remember.
(3) Zoom
Scaling point for r,x axis scaling sx,y axis scaling sy,z axis scaling sz, the new coordinates are:
(4) Comprehensive
For example, to translate all the points in the coordinate system [2,3,4] (x-axis translation 2,y axis translation 3,z Axis translation 4),
Rotate 90 ° around the z axis,
X, y, Z axes are magnified twice times,
The resulting transformation matrix is
Note: Scaling does not only multiply the sx,sy,sz position, but the modulus of that axis is the zoom value
The resulting transformation matrix is not equal to multiplication
3. Transformation of subspace to parent space
The mc-p can be written by transforming the point or direction from any sub-coordinate system C to the matrix of the parent coordinate system p. This matrix represents the transformation of a point or direction from a subspace to a parent space. The following equation transforms any subspace position vector pc to the parent space position Vector pp,pp = pcmc-p
Mc-p =
- The IC is the unit base vector of the x-axis of the subspace, which is represented by the coordinate of the parent space
JC is the unit base vector for the y-axis of the subspace, which is expressed in parent-space coordinates
KC is the unit base vector for the z-axis of the subspace, which is expressed in parent-space coordinates
- TC is the translation of a sub-coordinate system relative to the parent coordinate system
4. RST (rotated panning zoom) in the midpoint of the coordinate system
OpenGL Super Treasure Fourth Edition P101 Page said: If a 4x4 matrix contains a different coordinate system position and direction (can be regarded as the above mc-p), then a vertex pp and this matrix is multiplied, The result is a new vertex pc (coordinate or relative to the original coordinate system) that transforms into the coordinate systems. This looks like the formula PC =pp mc-p, wrong wrong wrong! This with PP is completely misleading, the PP to name a, coordinate V, because it is a linear transformation, so in the new coordinate system A's coordinates or V, so this is the same as PP = Pcmc-p, pp is a in the new coordinate system V in the coordinates of the original coordinates.
Matrix transformations in 5.OpenGl
The transformation of the matrix in OpenGL is superimposed, and each time a matrix transformation is made, the 0 points are moved to the new coordinate system. The next transformation affects only the current coordinate system and its sub-coordinate system, and does not affect its parent coordinate system. The Load unit matrix resets the 0 point back to the original 0 point.
Simple matrix operations do not move 0-point positions, so multiplying with the unit matrix has no effect.
Reference:
1.OpenGl Super Treasure Fourth edition P101
2. Game Engine Architecture P151
3. What exactly does the Glrotatef () function do to the matrix in OpenGL?
Geometric interpretation of 4.3D mathematical----matrices-days of the virtuous gentleman when self-improvement and endless-C + + Blog
A probe into the matrix in game development