1, there is a cube in the world coordinate system, the world transformation matrix is Worldmatrix, if the Worldmatrix is the unit matrix, then the center of the cube is located in the world coordinate system origin.
2, when the observation matrix is set, the relationship between the world coordinate system and the screen can be determined.
Initialize the view matrix
D3dxvector3 Eye (0.0f, 0.0f, -8.0f);
D3dxvector3 at (0.0f, 0.0f, 0.0f);
D3dxvector3 up (0.0f, 1.0f, 0.0f);
D3DXMATRIXLOOKATLH (&g_view, &eye, &at, &up);
G_view is the observation matrix of the output, the vector eye,at is the point in the world coordinate system, the eye is the position of the camera, at is the observation point, is the position of the eyes, no matter how to set this point, this point is always in the center of the screen. According to this condition, you can know the position of the world coordinate system in the screen.
For example at (0,0,0), the origin of the world coordinate system is the center of the screen, and at (3,0,0), the origin of the world coordinate system is shifted to the left (x-axis) in the screen by 3.
3, the position of the object in the world coordinate system
Worldmatrix Transform
1 0 0 0
0 1 0 0
0 0 1 0
a b c 1
(a,b,c) is the position of the cube in the world coordinate system.
Related functions:
Builds a matrix using the specified offsets.
D3DXMATRIX * D3DXMatrixTranslation (
d3dxmatrix * pOut,
float x,
float y,
float z
);
Parameters
POut
(in, out) Pointer to the D3DXMATRIX structure, which is the result of the operation.
x
[in] x-coordinate offset.
Y
[in] y-coordinate offset.
Z
[in] z-coordinate offset.
Return Values
Pointer to a D3DXMATRIX structure that contains a translated transformation matrix.
Remarks The return value for this function was the
same value returned in the POut parameter. The d3dxmatrixtranslation can used as a parameter for another function.
This function enables the object to be translated, that is, to set the position of the object in the world coordinate system.
4,rotation Object Rotation
Worldmatrix Transform
Cos? 0 -sin? 0
0 1 0 0
sin? 0 cos? 0
0 0) 0 1
Adjust these four parameters to achieve rotation.
Related functions:
Builds a matrix that rotates around the x-axis.
D3DXMATRIX * D3dxmatrixrotationx (
d3dxmatrix *pout,
FLOAT Angle
);
Parameters
POut
(in, out) Pointer to the D3DXMATRIX structure, which is the result of the operation.
Angle
[in] Angle of rotation in radians. Angles is measured clockwise when looking along the rotation axis toward the origin.
Return Values
Pointer to a D3DXMATRIX structure rotated around the x-axis.
Remarks The return value for this function was the
same value returned in the POut parameter. The D3dxmatrixrotationx function can used as a parameter for another function.
This function realizes that the object rotates around the world coordinate system x axis. (If you want to rotate around the x-axis itself, you should first place the object in the center of the x-axis of the world coordinate system, the x-axis of the local and world coordinate systems, and then set the rotation.) )
Similar functions:
D3dxmatrixrotationy
D3DXMatrixRotationZ
5, Object scaling Scaling
Worldmatrix Transform
P 0 0 0
0 q 0 0
0 0 r 0
0 0 0 1
The scaling parameter p,q,r corresponds to the x, Y, z direction.
Related functions:
Builds a matrix that scales along the x-axis, the y-axis, and the z-axis.
D3DXMATRIX * d3dxmatrixscaling (
d3dxmatrix *pout,
float sx,
float sy,
float sz
);
Parameters
POut
(in, out) Pointer to the D3DXMATRIX structure, which is the result of the operation.
SX
[in] Scaling factor This is applied along the x-axis.
Sy
[in] Scaling factor This is applied along the y-axis.
SZ
[in] Scaling factor This is applied along the z-axis.
Return Values
Pointer to the scaling transformation d3dxmatrix.
Remarks The return value for this function was the
same value returned in the POut parameter. The D3dxmatrixscaling function can used as a parameter for another function.
This function implements the scaling of the object.
6, the change of the object in the world coordinate system.
A series of changes, such as translation, rotation, and zooming, can be distributed, and then the final Worldmatrix is obtained by multiplying the matrix.
In particular, the results from different sequences are different. The image object starts at the origin, 1, rotates around the x axis, 2, and pans to point A, and the result is that the object rotates around its x axis at point A,
If the step becomes 2,,1, the effect is that the object is in a circular motion around the x axis of the world coordinate system, and the radius is the vertical distance from point A to the X axis.
Matrix multiplication Correlation function:
Determines the product of the matrices.
D3DXMATRIX * d3dxmatrixmultiply (
d3dxmatrix *pout,
const D3DXMATRIX *PM1,
const D3DXMATRIX *pm2
);
Parameters
POut
(in, out) Pointer to the D3DXMATRIX structure, which is the result of the operation.
PM1
[in] Pointer to a source D3DXMATRIX structure (left hand side).
PM2
[in] Pointer to a source D3DXMATRIX structure (right hand side).
Return Values Pointer to a D3DXMATRIX structure, which is the product of the
matrices.
Remarks The
result represents the transformation M1 followed by the transformation M2 (out = M1 * M2).
The return value for this function was the same value returned in the POut parameter. The D3DXMatrixMultiply function can used as a parameter for another function.
7, example
D3dxmatrix mtranslate;
D3dxmatrix Morbit;
D3dxmatrix Mspin;
D3dxmatrix Mscale;
D3DXMatrixRotationZ (&mspin,-t);
D3dxmatrixrotationy (&morbit,-T * 2.0f);
D3DXMatrixTranslation (&mtranslate, -4.0f, 0.0f, 0.0f);
D3dxmatrixscaling (&mscale, 0.3f, 0.3f, 0.3f);
D3DXMatrixMultiply (&g_world2, &mscale, &mspin);
D3DXMatrixMultiply (&g_world2, &g_world2, &mtranslate);
D3DXMatrixMultiply (&g_world2, &g_world2, &morbit);
First, the rotation matrix in the z,y axis mspin,morbit, the translation matrix mtranslate, the scaling matrix Mscale, all of which are based on the world coordinate system origin.
The first step, d3dxmatrixmultiply (&g_world2, &mscale, &mspin); Gets the matrix of scaling and z-axis rotation, when the object size changes and rotates around its own z-axis (because the object's own z-axis and world coordinate system z coincide).
The second step, d3dxmatrixmultiply (&g_world2, &g_world2, &mtranslate); Note that the second parameter is the g_world2 itself, that is, panning on the basis of the first step scaling and rotation. At this point the object is in the world coordinate system ( -4,0,0,).
The third step, d3dxmatrixmultiply (&g_world2, &g_world2, &morbit); On the basis of the first two, the object rotates around the world coordinate system Y, which is the circular motion. The RADIUS is 4.
Note the order, the different order will get different results.
Note: matrix multiplication will accumulate information and will not lose the original information.