This section describes the basic concepts of observing transformations in Direct3D and how to set the observation matrix.
The viewport transform places the observer in the world coordinate system and transforms the vertex into the camera space. In camera space, the camera or the observer is at the origin, and the direction of the observation is the z-axis forward. Direct3D uses a left-handed coordinate system, so the z-axis is entering the scene. The observation matrix transforms the objects in the world, the camera position, the camera space origin and the direction.
There are many ways to create an observation matrix. The logical position and direction of the camera in world space is used as the starting point to create the observation matrix, and the observed matrix is applied to the three-dimensional modeling in the scene. Watch the matrix shift and rotate the model in the camera space, placing them in the camera space, the camera at the origin. One way to create an observation matrix is to combine the translation matrix and the rotation matrix on each axis. This method can be viewed with the following matrix equation
In this equation,V is the observation matrix to be created, andT is the translation matrix for repositioning objects in the world, andRx to RZ is the rotation matrix of rotating objects around the x-axis, y-axis, and z-axis, respectively. This transformation and rotation is based on the camera's south position and direction. So if the camera is in world coordinates (10,20,100), then the transformation matrix moves the model on the x-axis to move the -10,y axis to move the -20,z axis-100. The rotation matrix is based on the equation and the orientation of the camera, depending on the angle of the camera space axis and the axes of the world coordinate system. For example, as mentioned above, the camera is vertically downward, then his Z axis has a 90 angle angle to the z axis of world space, as shown in
The rotation matrix applies the same angular, but opposite, rotation amount to modeling in the scene. The camera's observation matrix contains a 90-degree rotation around the x-axis. The rotation matrix and the translation matrix are combined to generate the observation matrix, and the matrix adjusts the position and orientation of the item in the scene, so that their top is toward the camera and looks as if the camera is above the model.
Setting the observation matrix
D3DXMATRIXLOOKATLH and D3DXMATRIXLOOKATRH These functions can create a matrix based on camera position and viewing direction.
The following example creates an observation matrix that is applied to the left-handed coordinate system.
D3dxmatrix out;
D3dxvector3 Eye (2,3,3);
D3dxvector3 at (0,0,0);
D3dxvector3 up (0,1,0);
D3DXMATRIXLOOKATLH (&out, &eye, &at, &up);
Direct3D uses the world transformation matrix and the observation transformation matrix to calculate some internal data structures. Each time you give a transformation matrix, the relevant internal data structure is recalculated. Setting these matrices frequently can be more time-consuming. By stringing the world matrix and observation matrix into a world/observation matrix and setting it as the world matrix, and then set the observation matrix to the unit matrix, the application can minimize the amount of computation required. It is best to save a separate copy of the World Matrix and observation matrix in the cache so that you can modify, thread, and reset the world matrix as needed. For clarity, the Direct3D example rarely uses this optimization.
[Translate] Watch transform view Transform (Direct3D 9)