Module 1 GP

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

Module - 1

3D Computer Graphics

Dr. Venkata Ramana Mancha


ASSISTANT PROFESSOR
Department of CSE, GST,
GITAM UNIVERSITY
[Deemed to be University]
Game Programming Fundamentals
How to Develop a Game:
First of all, we are not going to talk about the need to learn
a programming language or game engines to program
video games, because developing a game is about
much more than just coding and game engines.
The game industry is a field that includes many different
industries, including mathematics, art, psychology,
and even cinema. In other words, it is never enough to
just master game engines and learn a programming
language. So what, exactly. do we need to know?
Video Game Mechanics Explained

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.

To picture this better, you can examine the diagram below:


Game System

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

• The game model is the state of the game


graphics, music and text files loaded into
memory from the resource.
• Image files are stored in memory or in the
texture memory of the video card.
• Section, score, etc. information is kept in
variables and data structures within the game
model.
Upload and Save

• This is the part that takes the graphics, music and


other information from the source and puts it into the
memory (game model) and undertakes the process of
saving it back to the source in case of changes in
scores, when the game is saved – or the save state –
or when the game is recorded.
• Upload: Configuration files, chapter files, image files,
music and sound files, 3D model files, video files, and
help files.
• Save: Score files and other documents to be saved
during the game.
Graphics

• This is the most important and hardest part of the


game in my opinion. Because it is impossible to have a
game without visuals (unless you are creating an old
school text-based video game). This part is responsible
for painting the screen and the following:
• Playing any video,
• Displaying the game interface.
• Viewing and displaying scores, help and configuration
information.
• Displaying the game’s own graphics and visual
elements.
User Input
• A game without interaction would be like watching a movie.
User Interaction is definitely one of the sine qua non of game
mechanics that connects users to the game. The system is
constantly interacting with the user. Keyboards, mice, cameras,
and so forth are all capable of taking in user input. User input
is the part of the game mechanic where we’re going to use the
hardware and equipment that lets the user interact with the
game. User input allows a player to:
• Use the Game Interface.
• Review Help Files.
• Review Score Files.
• Configure the system and game related features.
• Control the user’s character in the game.
Sound and Music

• If you truly want to understand the importance


of sound and music in a video game, try turning
off the sound while playing your favorite game.
You will notice that the value of the game drops
significantly when there is no sound. To me, the
value of the sound is as valuable as the graphics
of the game.
• Music playing in the background
• Sound effects for collisions and movements
Artificial intelligence (AI)

• Let’s consider the intelligence level of the enemies in


the game. The more humanoid they look and the more
intelligent the behavior, the more fun the game will
be. It doesn’t just have to be the enemy either. In an
open world game, citizens passing by look at their
wristwatches, wipe the sweat on their foreheads in
sunny weather, give way to you, even argue with you,
attack you when you treat animals badly, and so forth.
All of these elements can fall into the category of
artificial intelligence.
Network Listening and Sending
• Network listening and sending is the part of the game mechanic
that allows the game to be played by more than one person, also
known as multiplayer or online play. In this part, the parties send
information to the game server and the information received by
listening to the server is updated in the game. Network listening
and sending is responsible for:
• Establishing the Session: The players who will participate in the
game agree on which protocol and on which port they will
communicate at first.
• Packet Delivery: The moves made in the game are sent to the
server in packets. Then the server distributes it to all parties after
making the necessary change.
• Package Pickup: Simultaneously, the parties are aware of the
changes made by listening to the server and reflect this to the
game.
Hardware

• Many different categories of hardware can fall


into this section, including the following:
• Graphics cards
• Processors
• Motherboards
• Sound cards
• Monitors, speakers and other input devices
Best Programming Languages for Game Development

• Depending on what you want to create, you can develop


games with pretty much all programming languages, albeit
to different degrees. There will be those who insist you
learn C++, especially if you want to code games for
consoles like the PlayStation 5 or Xbox. This, however, is
absolutely not true. You can make great games
with JavaScript, C#, Python (thanks to modules like
PyGame) or even C. A choice-based adventure game that
only works on the console screen can be great fun.
However, if you want to program games beyond that and
that are capable of being more professional and reaching a
larger audience, continue reading.
Continue…

• 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

• OpenGL resides within graphics hardware and


provides an interface to that hardware. This
interface contains 250 different instruction sets.
200 of them are in the OpenGL core and the
other 50 are in the OpenGL Utility Library. You
can develop 3D interactive applications thanks
to the OpenGL graphics API.
Game Development Tutorials

• Game development is not just about learning


programming languages and game engines.
• You have to master a lot of technology. Among the
technologies we did not mention are programs such as
Adobe Premier, Adobe After Effects, 3D Studio Max, Light
wave, Maya and Poser. Learning and mastering each of
these is only possible with experience.
• That’s why we talked about hardware and OpenGL. Love
your computer and keyboard rather than focusing on one
thing. The best and only rule of thumb to master game
development is this:Be curious, read a lot and code
without fear!
What you need to know…
• There’s really only a couple of things
▫ Coordinate systems
▫ Matrices
▫ 3D → 2D transformation
Coordinate systems
• To represent a location (point) in 3D space one
needs 3 numbers
(X, Y, Z)
• Each value specifies a distance along the
respective coordinate axis
• The resultant location (point) is the sum of the
axis unit vectors multiplied by the values
Manipulating points

• As we will see soon, manipulations of points


in 3 space are generally performed using
matrix notation
• But, as it turns out, this is not readily done
using points represented by 3 values
• Something better is needed
Homogeneous Coordinates
• Homogeneous coordinates were introduced as a means of
facilitating matrix-based transformations applied to points
• It is a 4D representation of a 3D point
(X, Y, Z) → (X, Y, Z, 1.0)
(X/W, Y/W, Z/W) → (X, Y, Z, W)
• That’s really all you need to know about homogeneous
coordinates
Matrix Operations
• Uses of Matrix Multiplication
Translation
To move a point (X, Y, Z) by amounts (x, y, z):

1.0 0.0 0.0 x   X 


0.0 1.0 0.0 y   Y 
  X ' Y ' Z ' 1.0
0.0 0.0 1.0 z   Z 
  
0.0 0.0 0.0 1.0 1.0
Scale
To “scale” a point (X, Y, Z) by sizes (x, y, z):

 x 0.0 0.0 0.0  X 


0.0 y 0.0 0.0  Y 
  X ' Y ' Z ' 1.0
0.0 0.0 z 0.0  Z 
  
0.0 0.0 0.0 1.0  1.0
Rotate X :
To “rotate” a point (X, Y, Z) about the X axis by an angle Θ:

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 Θ:

cos()  sin() 0.0 0.0  X 


 sin() cos() 0.0 0.0  Y 
  X ' Y ' Z ' 1.0
 0.0 0.0 1.0 0.0  Z 
  
 0.0 0.0 0.0 1.0  1.0
Shear X
To “shear” a point (X, Y, Z) int the X direction 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 


 1.0 
0.0 1.0 0.0  Y 
tan()    X ' Y ' Z ' 1.0
 
0.0 0.0 1.0 0.0  Z 
 
0.0 0.0 0.0 1.0  1.0

Shear Z
To “shear” a point (X, Y, Z) in the Z 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 Py  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 

Rotate Θ about Z Rotate Θ about Y Rotate Θ about X Translate to origin

cos()  sin() 0.0 0.0


 cos() 0.0 sin() 0.0 1.0 0.0 0.0 0.0 1 0 0  P 
 sin() 0.0 0.0 cos()  sin() 
x

 cos() 0.0  0.0 1.0 0.0 0.0  0.0 0 1 0 P 


 y
 0.0 0.0 1.0 0.0  sin() 0.0 cos() 0.0 0.0 sin() cos() 0.0 0 0 1  P 
       z

 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

You might also like