A video camera has the following attributes:
1. Observation Point: Position of the camera
2. Target point: the camera faces a certain place
3. Observed range: the angle of the projection range of the conical shape, in radians.
4. The nearest and longest visible distance: The observed range between the two distances is the visible area.
5. aspect ratio: the width and height ratio of the display, which is generally 1.
After understanding the principles of the camera, let's take a look at how we set it in d3d. There are two matrices used to set up the camera. One is the observation matrix, the other is the projection matrix, and the program describes everything.
First, set the observation matrix of the camera:
M_veyept = d3dxvector3 (0.0f, 3.0f,-5.0f); // viewpoint Coordinate
M_vlookatpt = d3dxvector3 (0.0f, 0.0f, 0.0f); // coordinate of the target point
M_vupvec = d3dxvector3 (0.0f, 1.0f, 0.0f); // The upward direction of the current world, usually (0, 1, 0)
// Create an observation matrix based on the left-hand Coordinate System Based on the three values given above
D3dxmatrixlookatlh (& m_matview, & m_veyept, & m_vlookatpt, & m_vupvec );
// Set this matrix to the current observation matrix of d3d
Pd3ddevice-> settransform (d3dts_view, & m_matview );
Set the projection matrix of the camera:
M_ffov = d3dx_pi/4; // angle of the observed range, which is 90 degrees
M_faspect = 1.0f; // the aspect ratio is 1.
M_fnearplane = 1.0f; // The nearest visible distance.
M_ffarplane = 00000000f; // The longest visible distance.
// Create a projection matrix based on the left-hand Coordinate System
D3dxmatrixperspectivefovlh (& m_matproj, ffov, faspect, fnearplane, ffarplane );
// Set this matrix to the current projection matrix of d3d
Pd3ddevice-> settransform (d3dts_projection, & m_matproj );