3D Game NLE d3d (4)

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.