3D Game NLE-Second: Basic 3D concepts

Source: Internet
Author: User
Tags float range

: Golden point time and space ::

Second: Basic 3D concepts

The last time we set up the d3d programming environment, but don't worry about coding. Let's take a look at some basic concepts in 3D. These things are the foundation of 3D programming and must be kept in mind.
All those who have used 3dmax know that a 3D scenario is composed of many models, and a model is usually called a mesh, which is a triangle) and each triangle surface is composed of three vertex.

Material and texture ):

A grid-light model looks like an outline of an item. To make the model realistic, we need to assign materials and textures to the model.
The material contains colors, which are defined in d3d as follows:

Typedef struct d3dxcolor
{
Float R, G, B, A; // corresponding to red, green, blue, and transparency respectively
} D3dxcolor;

Material is defined:

// Material
Typedef struct _ d3dmaterial8
{
D3dcolorvalue diffuse; // reflected light
D3dcolorvalue ambient; // ambient light, which is interpreted as the overall brightness
D3dcolorvalue specular; // mirror reflection, generally used for Smooth Plane
D3dcolorvalue emissive; // radiation light, which is generally used for self-emitting body (Sun, lamp ...)
Float power; // specify the intensity of the mirror highlight.
} D3dmaterial8;

The texture is the skin attached to the model. In d3d, The idirect3dtexture8 interface is used to manage the texture.
The following is a model with material and texture specified. It seems that it is more real.

 

Vector ):

Let's say that a model is an object:
Objects have their locations and directions. In 3D space, they are defined by three values: X, Y, and Z.
The positions and directions in d3d are vectors and the vectors are defined:

Typedef struct _ d3dvector
{
Float X; // X coordinate
Float y; // y coordinate
Float Z; // zcoordinate
} D3dvector;

Matrix ):

After an object has a direction and a position, a matrix is required to move, scale, or rotate the object. The definition of a matrix in d3d is as follows:

Typedef struct _ d3dmatrix
{
Union {
Struct {
Float _ 11, _ 12, _ 13, _ 14;
Float _ 21, _ 22, _ 23, _ 24;
Float _ 31, _ 32, _ 33, _ 34;
Float _ 41, _ 42, _ 43, _ 44;
};
Float M [4] [4];
};
} D3dmatrix;

This is a 4*4 matrix, which can implement various object processing through matrix transformation. For more information about matrices, see linear algebra. What? You have never learned linear algebra. It doesn't matter. Just remember several important transformation formulas (translation, contraction, and rotation ), any other complex transformations are combined by these basic transformations.
Let's take a try again. Even if you can't remember these formulas, d3d has already done them well. Through a few simple function calls, you can implement troublesome matrix operations, microsoft is considerate to everyone.

Light ):

With an object, there must also be lights, otherwise we will not see anything. There are two or four types of lights in d3d:
Ambient Light: provides fixed lighting for all objects in the scenario.
Point Light Source: light emitted from a point. The light bulb can be understood as a light source.
Poly Light Source: like its name, it has a direction and a strength, and is a typical poly light source.
Direction light: It is often used to simulate the sun and other infinite light sources. This type of light source is seen as from infinity, and its intensity does not change as it approaches the object. In the only direction, the brightness is fixed. D3d light sources are defined as follows:

Typedef struct _ d3dlight8
{
D3dlighttype type; // light source type, which can be light, concentrating, or direction light.
D3dcolorvalue diffuse; // diffuse color
D3dcolorvalue specular; // mirror reflection color
D3dcolorvalue ambient; // ambient light color
D3dvector position; // The Position of the light source.
D3dvector direction; // direction (only for direction light and concentration)
Float range; // The range of light, that is, how far the light can be taken.
Float falloff; // the intensity of the aperture inside and outside the concentration.
Float attenuation0; // The distance attenuation is 0.
Float attenuation1; // The distance attenuation is 1.
Float attenuation2; // The distance attenuation is 2.
Float Theta; // specify the angle of the concentration inner ring (0-phi)
Float Phi; // specify the angle of the concentration outer ring (0-Pi)
} D3dlight8;

Camera (CAMERA ):

To see objects, d3d defines cameras to represent users watching the 3D world. Cameras have a position and a direction that defines where and what the observer sees in the 3D world. In the 3D world, moving the camera and changing its direction make the world we see actually move.
In d3d, the structure of the camera is not defined. We control the camera by setting an observation matrix.

Pd3ddevice-> settransform (d3dts_view, & m_matview); // m_matview is the observation matrix of the camera.

Today I have talked about a lot of conceptual things. I think you are also tired of reading them. I guess you should switch to another website. Now, let's get here today. In the evening, I want to go to the bookstore to read books. It's a long way to ride a bike. The weather is hot and annoying ~~
Next time we start to build your first d3d program.

Home: http://www.gpgame.com
Mail: softboy@sina.com
Soft in afternoon


Return

Golden point time and space 2000/7/7

Www.gpgame.net

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.