Bringing it all together - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Bringing it all together

Description:

Then we can build a complete world to play with: The world Textured polygons, vertex buffers ... Quake. Half Life 1/2. 3DS. Etc. Mesh concepts. Subsets ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 28
Provided by: bdug1
Category:

less

Transcript and Presenter's Notes

Title: Bringing it all together


1
Bringing it all together
  • Bryan Duggan
  • Hugh McAtamney

2
Summary
  • We can now use
  • Vectors
  • To represent position and orientation
  • Represent a camera
  • Vector arithmetic
  • To move things
  • Matrices
  • To translate
  • To rotate
  • To scale
  • To program the rendering pipeline
  • DirectX
  • To create a surface for drawing
  • To create and draw textured vertex buffers

3
Whats left
  • Meshes
  • Game entities
  • Collision detection
  • Then we can build a complete world to play with
  • The world Textured polygons, vertex buffers
  • The player The camera
  • Daleks/projectiles - Mesh
  • Ammunition - Mesh

4
Mesh
  • A mesh is a
  • File
  • Memory representation (vertex buffer etc)
  • Loader
  • It holds
  • Vertices
  • Indexes
  • Normals
  • Textures
  • Materials
  • Animation
  • We can create a mesh in a 3D Editor

5
3D Editors
  • Milkshape
  • 3D Studio Max
  • Maya
  • GMax

6
X Files
  • In Direct X, meshes are stored with a .x
    extension
  • Can be binary or text format
  • We can use a 3D editor to export to the .x file
    format
  • There is a .x file viewer with the DirectX SDK

7
xof 0303txt 0032 // DirectX - from
MilkShape3D Frame dalekFrame
FrameTransformMatrix
1.000000,0.000000,0.000000,0.000000,
0.000000,1.000000,0.000000,0.000000,
0.000000,0.000000,1.000000,0.000000,
0.000000,0.000000,0.000000,1.000000
Mesh dalekMesh 15872
0.0774927.0544702.468911,
0.1152847.0469692.468383,
0.1152847.0208392.466543,
0.0674677.0303272.467211,
0.0875177.0786102.470611,
8
Other formats
  • FarCry
  • Quake
  • Half Life 1/2
  • 3DS
  • Etc.

9
Mesh concepts
  • Subsets
  • Meshes are divided into subsets parts of the
    mesh with different materials textures
  • Materials
  • Determine how the light interacts with the subset

10
Mesh API Calls
  • To create a mesh from a file
  • ID3DXBuffer adjBuffer 0
  • ID3DXBuffer mtrlBuffer 0
  • DWORD numMtrls 0
  • hr D3DXLoadMeshFromX(
  • _meshName.c_str(),
  • D3DXMESH_MANAGED,
  • device,
  • adjBuffer,
  • mtrlBuffer,
  • 0,
  • numMtrls,
  • _mesh)

11
Mesh API Calls
  • mtrlBuffer points to a buffer for materials (used
    for lighting) and texture file names
  • We then have to iterate through this buffer and
    load any required textures

12
In code
  • for(int i 0 i lt numMtrls i)
  • // the MatD3D property doesn't have an ambient
    value set
  • // when its loaded, so set it now
  • mtrlsi.MatD3D.Ambient mtrlsi.MatD3D.Diffuse
  • // save the ith material
  • _materials.push_back( mtrlsi.MatD3D )
  • // check if the ith material has an associative
    texture
  • if( mtrlsi.pTextureFilename ! 0 )
  • // yes, load the texture for the ith subset
  • IDirect3DTexture9 tex 0
  • D3DXCreateTextureFromFile(
  • device,
  • mtrlsi.pTextureFilename,
  • tex)

13
Optimise the mesh
  • hr _mesh-gtOptimizeInplace(
  • D3DXMESHOPT_ATTRSORT
  • D3DXMESHOPT_COMPACT
  • D3DXMESHOPT_VERTEXCACHE,
  • (DWORD)adjBuffer-gtGetBufferPointer(),
  • 0, 0, 0)

14
Drawing the mesh
  • We iterate through the subsets and draw each one
    with the appropriate material and texture
  • for(int i 0 i lt _materials.size() i)
  • Device-gtSetMaterial( _materialsi )
  • Device-gtSetTexture(0, 0)
  • Device-gtSetTexture(0, _texturesi)
  • _mesh-gtDrawSubset(i)

15
Other useful Mesh API calls
  • D3DXCreateBox
  • D3DXCreateSphere
  • D3DXCreateCylinder
  • D3DXCreateTeapot
  • D3DXCreatePolygon
  • D3DXCreateTorus

16
Bounding volumes
  • D3DXComputeBoundingBox
  • D3DXComputeBoundingSphere
  • Do these return coordinates in local space or
    world space?

17
In code
  • BYTE v 0
  • _mesh-gtLockVertexBuffer(0, (void)v)
  • D3DXComputeBoundingBox(
  • (D3DXVECTOR3)v,
  • _mesh-gtGetNumVertices(),
  • D3DXGetFVFVertexSize(_mesh-gtGetFVF()),
  • _min,
  • _max)
  • _mesh-gtUnlockVertexBuffer()

18
In code
  • void MeshWrappercomputeBoundingSphere()
  • // Now compute the bounding rectangle
  • BYTE v 0
  • _mesh-gtLockVertexBuffer(0, (void)v)
  • D3DXComputeBoundingSphere(
  • (D3DXVECTOR3)v,
  • _mesh-gtGetNumVertices(),
  • D3DXGetFVFVertexSize(_mesh-gtGetFVF()),
  • _center,
  • _radius)
  • _mesh-gtUnlockVertexBuffer()

19
As we are good OO games programmers
  • We add a MeshWrapper class to the framework
  • Extends DrawableEntity
  • Encapsulate all this messy and repetitive code
  • Simply call setMeshName, before calling setup
  • This leads us onto

20
OO
  • Computer games programmers need to be good OO
    thinkers
  • Games are complicated
  • Games need to be fast
  • Most games naturally fit the OO paradigm
    (European OO)
  • Problems in games (such as asset management etc.
    etc. etc.) can be solved using design patterns
    (USA OO)
  • Games APIs (DirectX/OpenGL) are written in C/C
  • Games are written in C
  • Complex C code can be visualised in UML

21
Games are written in C
  • Almost universally!!
  • Why
  • Access to native code (DirectX/OpenGL)
  • OO
  • Speed
  • Portability?

22
Games engines
  • Written in C
  • Are supported by embedded scripting languages,
    such as Lua
  • Flexibility
  • Ability to create MODs
  • Ability to expose C objects/APIs

23
Dalek World design
  • Based on the functionality of the Dalek World
    game what should our design be?
  • Existing classes
  • Direct3dBase
  • DrawableEntity
  • BoundableEntity
  • MeshWrapper
  • Wall
  • World
  • DalekWorld
  • What else do we need?

24
(No Transcript)
25
New classes
  • MoveableEntity
  • Has position, orientation (look)
  • Can move (walk, strafe)
  • Can look (yaw, roll, pitch)
  • Has speed
  • Camera
  • As above
  • But can also generate a view matrix
  • Projectile
  • As MoveableEntity
  • Has a mesh, so it can draw itself
  • But can be fired and hit things
  • GameEntity
  • As MoveableEntity
  • But also has a MeshWrapper, so it can draw itself

26
New classes
  • Ammo
  • As above
  • But also rotates, respawns, can be picked up
  • AutonomousGameEntity
  • As GameEntity
  • But can make decisions and move autonomously, (to
    come later)
  • Dalek
  • As above
  • But also can fire projectiles
  • Can also pick up ammo
  • Has health and ammo stats

27
UML Class diagram
Write a Comment
User Comments (0)
About PowerShow.com