You are on page 1of 24

Computer Graphics 471

Project Report
In fulfillment of Comp 471 winter 2009- ver 1.2

4/10/2009

Team Members:

Date Rev. Description Author(s) Contributor(s)

08/04/2009 0.5 First Draft The Team

10/04/2009 1.0 Document Review The Team

10/04/2009 1.1 Added reflection/shadow The Team

Cleaned up layout. Added


10/04/2009 1.2 Build & User manual The Team

Concordia University Montreal

Winter 2009
Concordia University Project Report Comp 471
CS & SE Winter 2009

Table of Contents
Table of Figures ......................................................................................................................................... 3
1. Introduction ........................................................................................................................................... 4
2. Methodology ......................................................................................................................................... 4
2.1. Team Approach ............................................................................................................................. 4
2.2. Implementation Details ................................................................................................................. 4
Game Engine: ........................................................................................................................................ 4
Physics Engine: ...................................................................................................................................... 5
Modeling and Texturing: ....................................................................................................................... 5
Visual Effects: ........................................................................................................................................ 7
Collision Detection and Animation: ...................................................................................................... 8
Camera: ................................................................................................................................................. 9
Sound Effects: ....................................................................................................................................... 9
2.3. Elements uncompleted ................................................................................................................ 10
Constructive Solid Geometry: ............................................................................................................. 10
GUI and game play components: ........................................................................................................ 11
3. Results ................................................................................................................................................. 11
4. Discussion ........................................................................................................................................... 21
5. User Manual ........................................................................................................................................ 22
5.1. Build instructions ........................................................................................................................ 22
5.2. Game Guide: ............................................................................................................................... 22
6. Conclusion ........................................................................................................................................... 23
Appendix A .................................................................................................................................................. 24
Individual contribution (design and implementation): .............................. Error! Bookmark not defined.

2|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

Table of Figures
Figure 1 Ball with marble 3D texture. ........................................................................................................... 6
Figure 2 Excel and mat lab were utilized to develop to develop functions to generate the contours of the
pin procedurally. ........................................................................................................................................... 6
Figure 3 Since the model is procedural different parameters can be adjusted to develop more or less
detailed silhouette as needed for the balance of performance and model detail. ...................................... 7
Figure 4 Sample image of constructive solid geometry modeling the three finger holes .......................... 10
Figure 5: The game registering a gutter hit and accompanying the appropriate actions .......................... 12
Figure 6: reflections and proportional shadows on the games procedurally generated pins .................... 12
Figure 7: Translucency could easily be managed due to flexibility of the design....................................... 13
Figure 8: Example of end visual fidelity three colored lights change completely the ambience of the game
.................................................................................................................................................................... 14
Figure 9: “Bracing for impact” the game prepares to conduct collision detection .................................... 15
Figure 10: The game can handle both ball pin and inter pin collisions ...................................................... 15
Figure 11: A successful hit causes the pins to fall and take down any pins the falling trajectory. ............. 16
Figure 12: Walls and Ceiling though not designed to garner visual attention utilize a plethora like
efficient texture utilization. ........................................................................................................................ 17
Figure 13: Wire frame mode sample: there was tremendous effort put into optimization towards the
later stages, performance increase from roughly 10fps to a consistent 55fps+ ........................................ 18
Figure 14: Side by side: (R) Retraced Pre rendered image used as inspiration for visual cues (L) in game
image showing many if the same effects in real time. ............................................................................... 19
Figure 15: Image from one the middle lane preset camera ....................................................................... 19
Figure 16: Shadows and reflections are major highlights of the game they are utilized everywhere
including: bowling balls, pins, floors and arrows. ....................................................................................... 20

3|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

1. Introduction

As stated the goal of the project was to develop a game highlighting the concepts taught in the
classroom lectures. From the onset the team had high ambitions to develop eye catching
attributes packaged in a game environment. The initial discussion centered on a skimmer based
racer but gradually shifted to simpler setup where the emphasis would lay on complex graphics
rather than game play mechanics.

2. Methodology

2.1. Team Approach

As with any software project, it is possible to utilize a vast array of existing libraries and
solution to get the job done. Our team laid emphasis on getting things done ourselves
rather than be dependent on external agents as a way to showcase our skills and
enhance our own learning.

For the project the following major elements were needed for a successful effort.

1) A modular game engine, efficient and extensible.

2) An accurate procedural model on the ball and pin with associated texturing.

3) Visual effects, namely shadows and reflections.

4) Functional collision detection and animation sequences.

2.2. Implementation Details

Game Engine:
The game engine was designed for efficiency, flexibility and extensibility using an object-
oriented approach. Every object in the scene is implemented as a stand-alone object
and it is added to the scene graph at runtime. This has allowed us to implement effects
with great flexibility. For example, shadows and reflections are no more than an
interface that can be applied to any object. Once the interface is implemented, the
engine takes care of actually performing the rendering in the right order to obtain the
desired effect.

4|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

Physics Engine:
The Physics Engine implemented allows flexible manipulation of objects in the scene in
terms of animation, collision detection, and game play. An instance of a physics engine
controls exactly one lane which includes 10 pins, bowling ball and an arrow. A reference
of these objects is passed before the rendering the scene. The Physics engine contains
functions that control these objects and how they interact with each other in the scene.
A user can switch between the lanes at runtime by switching to control the desired
physics engine. Therefore any update to the animation, collision detection, and game
play is done only once but can be used in as many lanes as needed.

Physics Engine:
The Physics Engine implemented allows flexible manipulation of objects in the scene in
terms of animation, collision detection, and game play. An instance of a physics engine
controls exactly one lane which includes 10 pins, bowling ball and an arrow. A reference
of these objects is passed before the rendering the scene. The Physics engine contains
functions that control these objects and how they interact with each other in the scene.
A user can switch between the lanes at runtime by switching to control the desired
physics engine. Therefore any update to the animation, collision detection, and game
play is done only once but can be used in as many lanes as needed.

Modeling and Texturing:


The modeling of the balls and pins started off as simple flat shaded spheres and
cylinders. There was much discussion on the direction to take further some suggested
that the model be built in external package and be imported into the game. This would
be simple though it would not show much effort on our part or contribute to the
learning process. A challenging goal was set to develop the pins and textures of bowling
ball procedurally.

A function for the contour of the pins was extracted by mapping curves on pin image in
editing program feeding the coordinated into excel spread sheet program and utilizing
the built in curve mapping functionality to derive a mathematical formulae to generate
points on the curve . Matlab was also utilized to make optimizations.

With these coordinate points a mesh could be generated by utilizing a Quad function
provided by GLUT. This led to performance issues and further optimizations were made
by utilizing Quad Strips. Additionally normals were also specified for the faces to mesh.

The Bowling ball remained a sphere and the focus shifted to texturing. Here to the
simple option of simple importing a texture was avoided in favor of more challenging
task of generating it procedurally. We used Perlin noise to create the textures for two of
the balls using two different techniques.

The first texture was created using three Perlin noise functions blended together with
different amplitudes and frequencies. This resulted in the lava texture, where the black

5|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

patches are blended with red to create a glowing effect, like a lava ball that is cooling
down.

However, our goal from the beginning has been to


create a realistic marble texture. We realized that
a 2D texture would never give the desired result,
so we applied a different formula to create a 3D
texture with Perlin noise. While this gave us a very
good result, the fact that the texture coordinates
were automatically generated for the sphere, we
had to use GL_SPHERE_MAP to apply the texture.
The drawback of this is that the texture
appearance is relative to the position of the
camera in space, so we cannot actually animate
the sphere when it is rolling down the lane.

Figure 1: Ball with marble 3D texture. Outside loading of images was made possible
using SDL_Image.

Figure 2: Excel and mat lab were utilized to develop to develop functions to generate the contours of
the pin procedurally.

6|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 3: Since the model is procedural different parameters can be adjusted to develop more or less
detailed silhouette as needed for the balance of performance and model detail.

Visual Effects:

Reflections were implemented using the standard approach of scaling the reflected
object by -1 against the plane of reflection. The reflection is actually blended into the
"mirror" based on the reflectivity of the surface (the alpha value - in our case the value
245 was used for the bowling lanes to make the reflection realistic). The stencil buffer
was used to contain the reflection in the desired plane and to speed up the rendering
process.

Shadows were implemented using a shadow matrix computed for every object. The
shadow itself is an unshaded representation of the object that is blended into the
surface on which the shadow is cast. Since the shadows are dependent on the position
of the light source, we could also vary the intensity of the shadow based on the distance
from the light to get a more realistic effect.

A lot of effort was put into optimizing the rendering of all these effects. Some examples
of such optimizations are the use of shared display lists to render every object in the

7|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

scene, using preprocessing for all types of texture generation and optimizing the
number of rendering passes for every object on which effects are applied.

Collision Detection and Animation:

Collision detection is inherently a hard problem and algorithmic nature is exponential.

Among the most popular approaches a bounding box implementation was initially
considered. It would have been ideal but the process was unfamiliar to us and the time
short. We estimated that distance mapping would be suitable in our case to know if and
when the objects are close enough to register a collision. This was done and shifted
focus focused on calculating the angle of collision. This was achieved by the arctan
function provided in the C++ math library.

With these parameters available to us the animation sequence for the pins was
generated using interpolation functions this was the simplest alternative to importing
animation data from an external source.

Lastly the same approach was extended to manage the inter pin collisions and the code
optimized to not affect performance.

The game is designed to simulate collisions with the appropriate angle

8|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

Camera:

We wanted to provide the user with the ability to move around the scene with complete
freedom. Therefore a camera was implemented which would allow the user 360
degrees of freedom as well as the ability to travel on any axis. There was an obvious
solution to this problem using the mouse to look and the keyboard to navigate. The
angles of rotation would then be calculated using sin/cos functions and the scene would
be appropriately rotated before it is drawn.

Sound Effects:

Basic sound effects were added to the simulation to slightly enhance the realism.
Currently sound is played when the ball is rolling on the lane as well as during a collision
with the pins. This was made possible by SDL_Mixer.

9|Page
Concordia University Project Report Comp 471
CS & SE Winter 2009

2.3. Elements uncompleted

As time progressed and the due date approached not all planned features made it to the
final game. Here are few of the near misses.

Constructive Solid Geometry:

It was intended the bowling ball model could be further enhanced if the finger holes
were correctly modeled procedurally, efforts were made to utilize a stencil mask and ray
intersection algorithms to conduct CSG, unfortunately toward the end time ran out and
the feature didn’t make it into the final version.

Figure 4.2: Sample image of constructive solid geometry modeling the three finger holes

10 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

GUI and game play components:

The game play components (score boards, game menu and AI) were the last pieces of
the puzzle that were not implemented.

1) Efforts were made to develop a UI using the “glui” toolkit, though this was
successful efforts to port the glut system calls to SDL were not successful.
2) The effort of the project shifted from the notion of game to that of simulator
highlighting more visual fidelity and more realism as opposed to game play.

Towards the latter half of the development cycle the team changed its focus from a
game play design to achieving the maximum visual fidelity. The screen shots clearly
indicate that team efforts played off in delivering a convincing visual atmosphere of
bowling game.

3. Results
Measuring result in graphics is highly subjective. The best way to know is to show and tell, as the
days progressed and more elements in the engine became functional it is readily apparent we were
achieving what we intended to do. Even friends and companions who saw the work had high
praises.

We had the following goals to meet:

1) Acceptable frame rate on university laboratory computers

2) Error free functionality on the Mac, Linux and Windows platforms.

3) Minimal visible visual artifacts hindering the end user experience.

4) Keeping the architecture simple and extensible for future work.

All these goals were met.

Illustrations Follow:

11 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 5: The game registering a gutter hit and accompanying the appropriate actions

Figure 6: reflections and proportional shadows on the games procedurally generated pins

12 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 7: Translucency could easily be managed due to flexibility of the design

13 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 8: Example of end visual fidelity three colored lights change completely the ambience of the
game

14 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 9: “Bracing for impact” the game prepares to conduct collision detection

Figure 10: The game can handle both ball pin and inter pin collisions

15 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 11: A successful hit causes the pins to fall and take down any pins the falling trajectory.

16 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 12: Walls and Ceiling though not designed to garner visual attention utilize a plethora like
efficient texture utilization.

17 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 13: Wire frame mode sample: there was tremendous effort put into optimization towards the
later stages, performance increase from roughly 10fps to a consistent 55fps+

18 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 14: Side by side: (R) Retraced Pre rendered image used as inspiration for visual cues (L) in game
image showing many if the same effects in real time.

Figure 15: Image from one the middle lane preset camera

19 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Figure 16: Shadows and reflections are major highlights of the game they are utilized everywhere
including: bowling balls, pins, floors and arrows.

20 | P a g e
4. Discussion

Even at this stage the sky is the limit to where to take the project further, the architecture
supports expansion in any way possible.

All members enhanced and reinforced concepts learnt in class and increased their capacity to
take on challenging Graphics related projects additionally lessons were learned in management
and software processes essential to deliver quality code on time.

We have no regrets over the decision we made in regards to development of individual


components. If more time given more functionality would be present. Use of libraries
worked in both ways for us, SDL allowed us to add cross platform features and sound though it
also didn’t allow us to port the GUI component in game on time. Incidents like this are natural
and not unexpected.

In future work aspects listed in unimplemented features could be completed additionally since
all components were built individually it would be worth to begin utilizing more robust external
libraries in areas of physics and graphics engine.
Concordia University Project Report Comp 471
CS & SE Winter 2009

5. User Manual

5.1. Build instructions

Building the project requires:

 SDL (http://www.libsdl.org/)
 SDL_Mixer(http://www.libsdl.org/projects/SDL_mixer)
 SDL_Image (http://www.libsdl.org/projects/SDL_image)
 Glut (http://www.xmission.com/~nate/glut.html)

A tutorial on how to configure your system can be found at:


http://gpwiki.org/index.php/SDL:Tutorials:Setup

We will provide the solution files for Visual Studio as well as Eclipse and Xcode project
files.

A makefile will be provided for linux. It will be located in the Release folder. The
expected targets clean and all will be provided.

5.2. Game Guide:

Key Description

F1 Toggle Wireframe

F2 Toggle lighting

F10 Toggle Reflections

F11 Toggle Shadows

Move the camera


forward/backward/left/right
W,S,A,D respectively

Move the camera up / down


Space/Ctrl respectively

22 | P a g e
Concordia University Project Report Comp 471
CS & SE Winter 2009

Keys 1-3 Switch between lanes

Keys 4-6 Switch between cameras

Context Button. Use it to activate


Enter and launch the bowling ball

Mouse
Movement Use to look around the scene

Mouse
Scroll Use to zoom in and our

6. Conclusion

The project on the whole presented a challenge, the course is different from other programming
courses offered since there is a subjective parameter that’s hard to measure. The team took on
many challenges to bring the deliverable to this stage and all are pleased with the effort and the
end result.

23 | P a g e
Appendix A

You might also like