Introduction To 3D Game Programming With Directx 9.0C: A Shader Approach (Wordware Game and Graphics Library)

Introduction To 3D Game Programming With Directx 9.0C: A Shader Approach (Wordware Game and Graphics Library)

Language: English

Pages: 544

ISBN: 1598220160

Format: PDF / Kindle (mobi) / ePub

Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach presents an introduction to programming interactive computer graphics, with an emphasis on game development, using real-time shaders with DirectX 9.0. The book is divided into three parts that explain basic mathematical and 3D concepts, show how to describe 3D worlds and implement fundamental 3D rendering techniques, and demonstrate the application of Direct3D to create a variety of special effects. With this book understand basic mathematical tools used in video game creation such as vectors, matrices, and transformations; discover how to describe and draw interactive 3D scenes using Direct3D and the D3DX library; learn how to implement lighting, texture mapping, alpha blending, and stenciling using shaders and the high-level shading language (HLSL); explore a variety of techniques for creating special effects, including vertex blending, character animation, terrain rendering, multi-texturing, particle systems, reflections, shadows, and normal mapping;f ind out how to work with meshes, load and render .X files, program terrain/camera collision detection, and implement 3D object picking; review key ideas, gain programming experience, and explore new topics with the end-of-chapter exercises.











ku z ) The D3DXVECTOR3 class provides a scalar multiplication operator: D3DXVECTOR3 u(1.0f, 1.0f, -1.0f); D3DXVECTOR3 scaledVec = u * 10.0f; // = (10.0f, 10.0f, -10.0f) Dot Products The dot product is one of two products that vector algebra defines. It is computed as follows: u × v = u x v x + uy v y + uz v z = s The above formula does not present an obvious geometric meaning. Using the law of cosines, we can find the relationship u × v = u v cos J, which says that the dot product between two

normalized first. We use the following D3DX function to do this: D3DXPLANE *D3DXPlaneTransform( D3DXPLANE *pOut, // Result CONST D3DXPLANE *pP, // Input plane. CONST D3DXMATRIX *pM // Transformation matrix. ); Sample code: D3DXMATRIX T(...); // Init. T to a desired transformation. D3DXMATRIX inverseOfT; D3DXMATRIX inverseTransposeOfT; D3DXMatrixInverse( &inverseOfT, 0, &T ); D3DXMatrixTranspose( &inverseTransposeOfT, &inverseOfT ); D3DXPLANE p(...); // Init. Plane. D3DXPlaneNormalize( &p, &p );

IDirect3DSurface9 are: n LockRect—This method allows us to obtain a pointer to the surface memory. Then, with some pointer arithmetic, we can read and write to each pixel in the surface. n UnlockRect—After you have called LockRect and are done accessing the surface’s memory, you must unlock the surface by calling this method. n GetDesc—This method retrieves a description of the surface by filling out a D3DSURFACE_DESC structure. Locking a surface and writing to each pixel can be somewhat

third vertices are ignored with flat shading. ColorVertex t[0]._color t[1]._color t[2]._color t[3]; = D3DCOLOR_XRGB(255, 0, 0); = D3DCOLOR_XRGB(0, 255, 0); = D3DCOLOR_XRGB(0, 0, 255); Flat shading tends to make objects appear blocky because there is no smooth transition from one color to the next. A much better form of shading is called Gouraud shading (also called smooth shading). With Gouraud shading, the colors at each vertex are interpolated linearly across the face of the primitive. Figure

0.0f, 1.0f, 0.0f, 0.707f, 0.707f, 0.0f); v[8] = Vertex( 1.0f, 0.0f, 1.0f, 0.707f, 0.707f, 0.0f); // back v[9] = v[10] = v[11] = face Vertex( 1.0f, 0.0f, Vertex( 0.0f, 1.0f, Vertex(-1.0f, 0.0f, 1.0f, 0.0f, 0.707f, 0.707f); 0.0f, 0.0f, 0.707f, 0.707f); 1.0f, 0.0f, 0.707f, 0.707f); Pyramid->Unlock(); After we have generated the vertex data of our object, we describe how the object interacts with light by describing its materials. In this sample, the pyramid reflects white lights, emits no light,

Download sample