Structure

The overall program contains 10 header files and 8 main files. These cover all of the following features: Textures, Materials, Lighting, Stencil and Depth buffering, World, View and Projection transformations and Meshes (loading and animating).

The files are baseplane.h, camera.h, d3dUtil.h, d3dUtility.h, ExtendStructure.h, MeshHierarchy.h, pSystem.h, structures.h, unitcube.h, XFileEntity.h, baseplane.cpp, d3dUtility.cpp, unitcube.cpp, MeshHierarchy.cpp, pSystem.cpp, camera.cpp, XFileEntity.cpp and main.cpp.

d3dUtil.h, ExtendStructure.h, MeshHierarchy.h, structures.h, XFileEntity.h, MeshHierarchy.cpp and XFileEntity.cpp primarily deal with the animation. The others deal with achieving the effects performed.

The general structure follows that of the programs found in [ A ] but with a few exceptions. The majority of the programs deal with one specific area.

Description of Code Organisation

The main file performs the following actions:

Initialises Global Variables.

Initialises the Lights.

Initialises the Materials.

Initialises the Camera. Specifies Land.

Updates the Camera.

Initialises the Stencil Buffer.

The Setup Function setup’s up the various objects:

Snow System

Static Mesh. This mesh object stores the mesh data.

- Materials for the Mesh

- Optimises the Mesh

Cube

Base

Animation This is set on animation 2.

Lights

Materials

Camera

Perspective

Stencil Buffer

It then cleans up

Cube

Base

Static Mesh

Snow System

The display function displays the relevant data onto the screen. All objects have to be applied to the world transform.

Camera

Cube

Base

Materials For the House

Shadow

Snow System – The snow system must be rendered last.

baseplane.h and baseplane.cpp deal with rendering the baseplane. Unitcube.h and unitcube.cpp deal with rendering the cube. These were given in the labs.

Camera.h and camera.cpp deal with the camera functionality. Psystem.h and psystem.cpp deal with the snow systems functionality. These can be found in [ A ].

Camera:

Four camera vectors are used to define a local coordinate system for the camera relative to the world coordinate system: right vector, up vector, look vector and position vector.

The camera can perform the following operations:

  • Rotate around the right vector (pitch)
  • Rotate around the up vector (yaw)
  • Rotate around the look vector (roll)
  • Strafe along the right vector
  • Fly along the up vector
  • Move along the look vector

The camera can support 2 types of models: LANDOBJECT or AIRCRAFT. The air model allows more freedom but the land model is more suitable for the purposes of this program. The view space transformation must transform the geometry in the world so that the camera is centred at the origin and the axis aligned with the other coordinate axes. To find this, a translation that takes the camera position to the origin and a rotation that aligns the camera vectors with the world’s axes is required. The Camera::getViewMatrix method performs this operation.

Effects

The following effects are present:

Textures, Lighting, Shadow, Particle System – Snowflakes. There are 2 meshes present, animated and static.

Shadow:

This is taken from the cube shadow program from [ C ]. The light and baseplane positions are used as inputs. The D3DXMatrixShadow() function flattens the world matrix and the object is rendered into the plane. The textures must be removed and alpha blending is enabled. The depth buffer must be disabled to avoid issues in the z-axis. The stencil buffer is enabled to ensure that only one layer is rendered. A semi transparent material is added to give the resulting shadow.

Lighting:

There are 2 main lights, one us attached to the camera whilst the other is the main light.

The steps involved in creating the lights

1. Enable lighting.

2. Create a material for each object and set the material before rendering

the corresponding object.

3. Create one or more light sources, set the light sources, and enable

them.

4. Enable any additional lighting states, such as specular highlights.

In camera.cpp, a light is attached. In main.cpp, the other light is set up and both are initialised here.

Particle System – Snowflakes:

In pSystem.h, the Snow system’s class is defined. In pSystem.cpp, the constructor takes a pointer to a bounding box structure and the number of particles the system will have. The bounding box describes the volume that the snowflakes will fall in. All snowflakes outside of this volume are killed and respawned. This keeps the number of active particles the same at all times.

The size of the vertex buffer, the batch size, and the starting offset must all be defined. The resetParticle method creates snowflakes with random x- and z-coordinate positions inside the bounding box and sets the y-coordinate to be equal to the top of the bounding box. It then gives the snowflakes a velocity so that the snowflakes fall downward and

slightly toward the left. The snowflakes are white in colour.

The update method updates the position of the particle and then tests if the particle has gone outside the system’s bounding box. If it has gone outside the bounding box, it is respawned.

This method is then called from the main file.

Meshes:

There are 2 types of meshes rendered, static and animated. The static mesh was derived using Luna’s methods whilst the animation was created using [ D ].

Static Mesh – House:

An ID3DXMesh object is created and the geometric data of the XFile loads into it. As the texture is not embedded but rather the filename, it is automatically loaded with the .X file.

The mesh is loaded such that each entry point has a corresponding subset and this loops until all entries have been rendered. The setup, display, render and cleanup functions are all implemented.

Animated Mesh – Skeleton:

For animation a model hierarchy must be implemented. ID3DXAllocateHierarchy is created for the frame and mesh data. This class defines the following functions:

1. CreateFrame – requests allocation of a frame object

2. CreateMeshContainer – requests allocation of a mesh container object

3. DestroyFrame – deallocation of frame object

4. DestroyMeshContainer – deallocation of mesh container object

The main method for loading animation data, skin info and hierarchy is D3DXLoadMeshHierarchyFromX. The hierarchy is loaded as a frame and mesh data tree. There is a pointer to the animation controller and to the top of the frame hierarchy. The trees are traversed and the meshes data is rendered accordingly.

Skinning is then performed which takes data in a mesh-skeleton hierarchy and applies geometry blending to transform the mesh vertices. Each bone is positioned to its parent via a local bone matrix. exFrameCombinedMatrixPointer contains pointers to the correct frames combined matrix. A bone offset matrix is used to wrap the mesh skin around the bones. These 2 matrices are combined resulting in a matrix which is inputted into the UpdateSkinnedMesh function. This alters the vertices based on the input and a set of weights which carries out the skinning.

Software skinning is used to render the mesh. The animation itself contains 4 different scenes.

References

[ A ] Frank D. Luna (2003) Introduction to 3D Programming with DirectX 9.0, Wordware Publishing, ISBN : 1-55622-913-5

[ B ] Frank D. Luna (2006) Introduction to 3D Programming with DirectX 9.0c, A Shader Approach, Wordware Publishing, ISBN -13: 978-1-59822-016-2

[ C ] Dr. Louis Natanson (2007) Games Programming Course and Laboratory Notes, University of Abertay, Dundee.

[ D ] Keith Ditchburn, http://www.toymaker.info/Games/html/load_x_hierarchy.html.

VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.8_1072]
Rating: +1 (from 1 vote)