Module 1 GP
Module 1 GP
3D Computer Graphics
One of the biggest reasons why games reach huge audiences today has
to do with game mechanics. In order to better understand what
game mechanics are, we have to think of a game system. Imagine
there are various sub-parts that this system controls.
As you can see in the diagram above, the game system takes on the
following tasks:
•Handles the loading and saving of files.
•It then enables the intro animation to run using the audio and graphic
elements.
•While the game interface is being used, user input ensures that the
graphics and sound parts work in harmony.
•Finally, the game system ensures that the graphics, sound, user input,
artificial intelligence and network parts work in harmony in the game .
Resources
• The Resources describe the necessary files for the game
located on the hard disk.
• These resources contain configuration files that describe
the default settings in which the game will run.
• If available, it contains the video file for the intro that will
be played when the game first starts.
• Contains files where the user gets information about the
game before the game begins.
• It contains the graphics, music and chapter information
in the game, alongside every other element the game will
require to display audio and visual data to the player.
Game Model
• C++
• Since C++ is a high-level language that will teach
you the basics of object-oriented programming
(OOP), it’s a good idea to learn it. It is also the
language used to create console and Windows
games. Also, it uses OpenGL or a similar
framework (We cover OpenGL in greater detail
later in this guide).
Continue…
• C#
• The benefit of C# for video game development
lies in the XNA framework. This is a set of tools
and workspaces by Microsoft that are
particularly suitable for developing games on
Xbox or Windows platforms.
Continue…
• Java
• Game programmers often use Java because Java
supports multithreading and sockets.
Multithreading uses less memory and makes the
most of available CPU resources without
blocking the user while intensive processes are
running in the background. Sockets help in the
creation of multiplayer games. Also, Java runs in
a virtual machine (the JVM) so the game is
easier to deploy to different platforms.
Continue…
• APIs for Game Development
• What is an API? It stands for Application Programming
Interface. APIs are libraries that help us perform specific
tasks with a number of functions and methods.
• The APIs we will use in our games will be libraries that
allow us to take advantage of them by providing an
interface to the graphics and sound hardware. For
example OpenGL, GLUT, GLU
DirectX (Direct3D, DirectDraw, DirectShow, DirectInput,
DirectPlayer, DirectSound, DirectMusic), Java2D, Java3
D, JavaMusic, JavaNET, JavaMedia, and FMOD are all
examples of game development APIs.
OpenGL for Game Development
1.0 0 .0 0 .0 0 .0 X
0.0 cos() sin() 0.0 Y
X ' Y ' Z ' 1.0
0.0 sin() cos() 0 .0 Z
0. 0 0 .0 0 .0 1.0 1.0
Rotate Z
To “rotate” a point (X, Y, Z) about the Z axis by an angle Θ:
1.0
1.0 0.0 0.0 X
tan()
Y
0.0 1.0 0.0 0.0 X ' Y ' Z ' 1.0
0.0 Z
0.0 1.0 0.0
1.0
0.0 0.0 0.0 1.0
Shear Y
To “shear” a point (X, Y, Z) in the Y direction by an angle Θ:
1 .0 0 .0 0 .0 0 .0 X
0 .0 1 .0 0.0 0.0 Y
1 .0 X ' Y ' Z ' 1.0
0 .0
1 .0 0 .0 Z
tan()
0.0 0 .0 0.0 1.0 1.0
Combining matrices
Rotate -Θ about X Rotate -Θ about Y
Translate to point
. 1.0 0.0 0.0 0.0
1
0 0 P
x 0.0 cos() sin() 0.0
cos() 0.0 sin() 0.0
0.0 0.0
0 1 0 Py 1.0 0.0
0 0.0 sin() cos() 0.0
0 1 P
z
sin() 0.0 cos() 0.0
0 0 0 1 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
0 0 0 1
Problems
• Rotation based on matrix operations [potentially] suffers
some afflictions
▫ Difficult to interpolate between rotations when you want to create
a smooth sequence
▫ Gimbal lock – when one of the three axes rotates to align with
another essentially rendering it redundant (reduces the number
of degrees of freedom)
▫ Non-linear speed of rotation – objects don’t rotate smoothly with
constant velocity
• These afflictions are due to the use of Euler angles and
trigonometric functions that don’t always behave well
(sign changes at quadrant changes, asymptotic behavior)
Quaterions
• Another method for performing rotations
• Based on complex arithmetic (complex numbers – not
complicated numbers)
• Straight forward conversion from Euler (matrix based)
operations to Quaternions
• The underlying concepts are nasty
• The implementation is easy
▫ Just a bunch of multiplications and additions
• Handles the constant velocity rotation issue
▫ SLERP (Spherical LinEaR interPolation)
▫ Ken Shoemake is credited for coming up with the approach
3D → 2D Transformation
Projections – Orthographic
• Projectors are perpendicular to the projection plane
• Project plane is parallel to one of the principal faces
• Projectors are perpendicular to the projection plane
• Project plane is parallel to one of the principal faces
Projections – Axonometric
Projectors are perpendicular to the projection plane
Project plane has any desired orientation with respect to
the object faces
Projections – Oblique
• Projectors are arbitrary with respect to the
projection plane
Projections – Perspective
• Projectors converge at the center of projection
Projections
• Each has advantages and disadvantages dealing
with
▫ Retention of angles between lines
▫ Retention of distances between points
▫ Visibility of surfaces
▫ Realization via camera models
▫ Realistic synthesis of scenes
Triangulation
• Problem: given a set of points, find a set of
triangles that connects those points in a mesh
• Solution: computational geometry provides us with
the Voronoi Diagram and (it’s dual) the Delaunay
Triangulation
Summary
• This is all stuff that is fundamental to computer
graphics (with the possible exception of
triangulation – that’s computational geometry)
▫ Typical 1 semester undergraduate course spends
most of it’s time on these topics
▫ Lots of good books on this material
Bibliography
• Interactive Computer Graphics 4th edition
▫ Angel
▫ Addison-Wesley
• Computer Graphics Principles and Practice 2nd edition
▫ Foley, van Dam, Feiner, Hughes
▫ Addison-Wesley
• Java 2D Graphics
▫ Knudsen
▫ O’Reilly
• Computer Graphics for Java Programmers
▫ Ammeraal
▫ Wiley