1 / 23

# 3D Programming and DirectX API - PowerPoint PPT Presentation

3D Programming and DirectX API. Content. Mathematics Prepare to Write a 3D program Program Structure How does the computer calculate 3D image? Illustration Other Features in DirectX Library. Mathematics.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' 3D Programming and DirectX API' - jerome-chapman

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 3D Programming and DirectX API

• Mathematics

• Prepare to Write a 3D program

• Program Structure

• How does the computer calculate 3D image?

• Illustration

• Other Features in DirectX Library

• Don’t worry! If you see this chapter in the book, just skip it, because you’ve learned.

• Importance of “Transform”

• Translation

• Rotation

• Scaling

• ……

• Vector & Matrix

• Using Direct3D

• Compiler - VS.NET 2003

• http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp

• DirectX 9.0 SDK Update - (February 2005)

• An Easy Book

• MSDN – http://www.msdn.com

• Initialize D3D Library – Create Device

• Set Light, Material, and Texture

• Calculate Transform Matrix, View Matrix , and Projection Matrix

• Render!

• IDirect3D9*

• Direct3DCreate9(D3D_SDK_VERSION)

• IDirect3DDevice9*

• CreateDevice()

3D Device( 3D Card)

Direct3DCreate9()

CreateDevice()

IDirect3DDevice9*

IDirect3D *

D3DLibrary

• CPU and GPU (Graphic Process Unit)

• 3D Library – OpenGL and Direct3D

• Pipeline

CPU

GPU

Light, Texture, Material

Vertex Data

Data in Model Space

World Space

Camera Space

World Matrix

View Matrix

View Space

Projection Matrix

• Vertex/Index Buffer

• The Structure of Vertex

V1

V3

V3

V1

V2

V4

Vertex Buffer

V4

1

2

3

1

4

2

Index Buffer

V2

nZ

U

struct Vertex

{

float x, y, z;

float nx, ny, nz;

float u, v; // texture coordinates

};

#define FVF_VERTEX (D3DFVF_XYZ | D3DFVF_NORMAL| D3DFVF_TEX1)

Demo 1-TexCube

X

Y

Z

nX

nY

V

• X-file

• When the model is complex, we can’t build it in our code.

• Using 3D graphic tool, ex. Maya, 3D studio MAX, Lightwave, MilkShake

• Static Model and Animation Model

• Light - light source

D3DLIGHT9 light;

light.Type = D3DLIGHT_DIRECTIONAL;

light.Ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

light.Specular = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);

light.Direction = D3DXVECTOR3(1.0f, -1.0f, 0.0f);

Demo 2-TexCube 3-TexCube 4-TexCube

• Material – reflection of light

{0.0, 1.0, 1.0, 1.0}

{1.0, 1.0, 0.0, 1.0}

{1.0, 0.0, 1.0, 1.0}

Demo EffetEdit

• Texture – surface of 3D object

Demo 4-Tex 5-Tex

• World Matrix

• D3DXMatrixTranslation(…)

• D3DXMatrixRotationX(…)

• D3DXMatrixIdentity(…)

• D3DXMatrixScaling(…)

• View Matrix

• D3DXMatrixLookAtLH(&V, &position, &target, &up);

• Projection Matrix

D3DXMatrixPerspectiveFovLH();

• Prepare for render

Device->SetTransform(D3DTS_VIEW, &V);

Device->SetTransform(D3DTS_WORLD, &V);

Device->SetTransform(D3DTS_PROJECTION, &V);

• Start and Finish Render

Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);

Device->BeginScene();

……./* render render render !!!! */….

Device->EndScene();

if( mtrl )

device->SetMaterial(mtrl);

if( tex )

device->SetTexture(0, tex);

device->SetStreamSource(0, _vb, 0, sizeof(Vertex));

device->SetIndices(_ib);

device->SetFVF(FVF_VERTEX);

device->DrawIndexedPrimitive(

D3DPT_TRIANGLELIST,

0,

0,

24,

0,

12);

Set Material

Set Texture

Set Index Buffer

Just Draw It!!

• Terrain – Height Map

• Other Algorithm…

• Good website :www.gamedev.net

• Airplane

• Walking Man

• BasicHLSL