3D Graphics

In order to display characters, rooms, outdoor environments, etc, you need to understand how 3D graphics works.

3D graphics involves a lot of mathematics. This includes concepts such as vectors, trigonometry and matrices. Luckily DirectX contains mathematical functions that you can use to process and manipulate 3D graphics.

3D Coordinates

The graphics in 3D is displayed as a pixel which I will also refer to also as a point or vertex. In 2D graphics, the coordinates are referred to as (x,y) while in 3D graphics, the coordinates are referred to as (x,y,z)

The diagram below compares 2D screen coordinates and 3D coordinates as represented by DirectX:

he 3D coordinate system has an x-axis, y-axis as in the 2D system. The 3D system also includes a z-axis, which goes into the screen (this is called a left-handed coordinate system). It is always hard to visualise 3D coordinates – if you stick 3 rulers together, it might be easier to visualise a point in 3D space. In the above diagram, the point (5,10,5) is obtained by travelling 5 units along the x-axis, 10 units along the y-axis and then 5 units along the z-axis (into the screen).

Overview for 3D Graphics in a game

These topics will be explained in more detail, but I just wanted to give a brief overall picture of what is going on in 3D games, particularly in displaying 3D graphics.

  1. The game universe (ie. what the player sees in a particular level) is a 3D model called a 3D scene.
  2. Inside this 3D scene, objects (3D models) are placed inside.
  3. The player is represented as a 3D model (eg: showing player’s hands, player’s body)
  4. The game needs to take into account of the player colliding with the 3D scene or other objects, players or bots (computer driven players).
  5. The computer needs to show on screen only those objects that the player can see. This needs to be done, otherwise the game will slow to a crawl. 3D computer graphics is very computer intensive, you need to take shortcuts to display the graphics with any speed. The displaying of 3D objects to the screen is called rendering.The 3D scenes and other 3D objects are created using 3D modeling software (eg: 3D Studio Max, Maya, Blender). The 3D objects or models are created as a mesh which has a skin or texture applied to it.

3D Primitives

3D graphics includes some 3D primitives – these are objects that are just basic and used to build other 3D objects.

DirectX has the following graphics primitives that are part of Direct3D graphics engine:

  • point lists – a set of points (x,y,z). Could be used for starfields for a space game.
  • line lists   – a set of lines, each connected by two points. Could be used as rain in a scene.
  • line strips – a set of lines connected to each other (eg: a zigzag).
  • triangle lists – a set of 3 points (x,y,z) makes up a triangle. Many of these triangles make up a triangle list. Useful to build 3D objects.
  • triangle strips – a number of triangles that have at least one side connected to another triangle. Useful to build some 3D objects.
  • triangle fans – triangles are joined together in a fan shape. Useful to build some 3D objects.

These primitives are shown below. I have emphasised the points so that you can see that some of the objects were created from joined up points.

3D objects

3D objects are built from vertices of triangles. Each point (or corner) of a triangle is a vertex and 3 vertices make up one triangle. More information about vertices is here. These vertices are what the graphics engine uses to display graphics on the screen. The process of displaying an object on the screen is called rendering. The triangle is a closed figure and hence is a polygon.

A 3D object that has been built with many triangles joined together is called a mesh.  Once you have the basic mesh for the object, you then create a skin or texture and wrap it around the mesh. When you are talking about the number of polygons in a 3D object, you are really talking about how many triangles it contains.

An example of a 3D object is shown below. It is a tiger taken from one of the DirectX SDK sample files using a program called Meshview. It’s from the DirectX 9 SDK (which is now old software).

Now have a look at the tiger below when you take the “skin” off it. You should be able to see the triangles! This is called wireframe view.

The tiger above, which is a 3D object, was created using  3D modelling software such as 3D Studio Max or Blender. Within this software package, you can apply textures (or skins) as well.

Some 3D modelling software packages are below:

3D Modelling Software

  • Blender (Free 3D modeller – runs on Linux too)
  • 3D Studio Max (3D modeller by Autodesk)
  • Maya (3D modeller by Autodesk)
  • Gmax (Free 3D modeller – not supported by Autodesk anymore – “cut down” version of 3D studio max)
  • Milkshape (3D modeller)
  • Lightwave (3D modeller)
  • ZBrush – fantastic for modelling characters
  • Google Sketchpad – an easy to learn 3D modeller
  • Anim8tor free software

A 3D object is also called a 3D model. You can either buy or download royalty free 3D models. For example, you can get them at CG Trader. Other places are on the resource page as well or you can search online.