Packman 2
Packman 2
docx
1 / 40
CHAPTER 1
INTRODUCTION
Graphics provides one of the most natural means of communicating with a computer, since our highly
developed 2D and 3D pattern recognition abilities allow us to perceive and process pictorial data rapidly
and efficiently. Interactive computer graphics is the most important means of producing pictures since
the invention of photography and television. It has the added advantage that, with the computer, we
can make pictures not only of concrete real world objects but also of abstract, synthetic objects, such as
mathematical surfaces and of data that have no inherent geometry, such as survey results.
1.3 OpenGL
1.4
OpenGL (Open Graphics Library) is a standard specification defining a cross language cross platform API
for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250
different function calls which can be used to draw complex 3D scenes from simple primitives. OpenGL
was developed by Silicon Graphics Inc. (SGI) in 1992 and is widely used in CAD, virtual reality, scientific
visualization, information visualization and flight simulation. It is also used in video games, where it
competes with direct 3D on Microsoft Windows Platforms.OpenGL is managed by the non profit
technology consortium, the Khronos group Inc.
Ø To hide the complexities of interfacing with different 3D accelerators, by presenting programmer with
a single, uniform API
Ø To hide the differing capabilities of hardware platforms , by requiring that all implementations support
the full OpenGL feature set.
2 / 40
3 OpenGL has historically been influential on the development of 3D accelerator, promoting a base
level of functionality that is now common in consumer level hardware:
Ø Z buffering .
Ø Texture Mapping.
Ø Alpha Blending.
Display Lists :
All data, whether it describes geometry or pixels, can be saved in a display list for current or later use.
When a display list is executed, the retained data is sent from the display list just as if it were sent by the
application in immediate mode.
Ø Evaluators :
All geometric primitives are eventually described by vertices. Parametric curves and surfaces may be
initially described by control points and polynomial functions called basis functions.
4 / 40
5
For vertex data, next is the “per-vertex operations” stage, which converts the vertices into primitives.
Some vertex data are transformed by 4 x 4 floating-point matrices. Spatial coordinates are projected
from a position in the 3D world to a position on your screen.
Ø Primitive Assembly :
Clipping, a major part of primitive assembly, is the elimination of portions of geometry which fall outside
a half space, defined by a plane.
Ø Pixel Operation:
While geometric data takes one path through the OpenGL rendering pipeline, pixel data takes a
different route. Pixels from an array in system memory are first unpacked from one of a variety of
formats into the proper number of components. Next the data is scaled, biased, and processed by a
pixel map. The results are clamped and then either written into texture memory or sent to the
rasterization step.
Ø Rasterization:
Rasterization is the conversion of both geometric and pixel data into fragments. Each fragment square
corresponds to a pixel in the framebuffer. Color and depth values are assigned for each fragment
square.
Ø Fragment Operations :
Before values are actually stored into the framebuffer, a series of operations are performed that may
alter or even throw out fragments. All these operations can be enabled or disabled.
The aim of this project is to develop a 3D Game which supports basic operations
4 / 40
Which include Movement, Artificial Intelligence, collision Detection and also transformation operations
like translation, rotation, scaling etc on objects. The package must also have a user friendly interface .
1.4 Scope
It is developed in ECLIPSE. It has been implemented on UBUNTU platform. The 3-D graphics package
designed here provides an interface for the users for handling the display and manipulation of Pac-Man
Movements. The Keyboard is the main input device used.
Pac-Man :
The game was developed primarily by a young Namco employee Tōru Iwatani, over a year, beginning in
April of 1979, employing a nine-man team. The original title was pronounced pakku-man and was
inspired by the Japanese onomatopoeic phrase paku-paku taberu where paku-paku describes (the
sound of) the mouth movement when widely opened and then closed in succession.
Although it is often cited that the character’s shape was inspired by a pizza missing a slice, he admitted
in a 1986 interview that it was a half-truth and the character design also came from simplifying and
rounding out the Japanese character for mouth, kuchi as well as the basic concept of eating. Iwatani’s
efforts to appeal to a wider audience beyond the typical demographics of young boys and teenagers-
eventually led him to add elements of a maze.
The result was a game he named Puck Man.
CHAPTER 2
LITERATURE SURVEY
The Pac-Man game has its roots as a Japanese arcade game developed by Namco (now Namco Bandai)
and licensed for distribution in the U.S. by Midway, first released in Japan on
6 / 40
7 May 22, 1980. Pac-Man is universally considered as one of the classics of the medium, virtually
synonymous with video games, and an icon of 1980s popular culture. When it was released, the
game became a social phenomenon.
The Pac-Man game is often credited with being a landmark in video game history, and is among the
most famous arcade games of all time. The character also appears in more than 30 officially licensed
games asequels, as well as in numerous unauthorized clones and bootlegs.
The player controls Pac-Man through a maze, eating dots. When all dots are eaten, Pac-Man game is
over. Four ghosts roam the maze, trying to catch Pac-Man. If a ghost touches Pac-Man, a life is lost.
When all lives have been lost, the game ends. Near the corners of the maze are four larger, flashing dots
known as “Energizers” or “Power Pills”, which provide Pac-Man with the temporary ability to eat the
ghosts.
The ghosts turn deep blue, reverse direction, and usually move more slowly till it returns to the normal
state. When Pac-Man eats ghost during vulnerable state, ghost traverses back to the jail and re-
initializes to start a new attack. Collision Detection for Pac-Man and Ghost, and Artificial Intelligence for
Ghost has been implemented. A total of 260 points are assigned (1 point for normal pebble and 5 points
for super pebble) and max lives of 3 is being setup with a 3-D Maze.
CHAPTER 3
6 / 40
This graphics package has been designed for UBUNTU Platform and uses ECLIPSE integrated
environment.
Development Platform
UBUNTU 10.10
Development tool
ECLIPSE
C++
CHAPTER 4
DESIGN
To achieve three dimensional effects, OpenGL software is proposed. It is software which provides a
graphical interface. It is an interface between application program and graphics hardware. The
advantages are:
Ø With OpenGL, we can draw a small set of geometric primitives such as points, lines and polygons etc.
8 / 40
9 Ø It provides double buffering which is vital in providing transformations.
Detailed Design
Translation is done by adding the required amount of translation quantities to each of the points of the
objects in the selected area. If P(x,y) be the a point and (tx, ty) translation quantities then the translated
point is given by glTranslatef(dx,dy,dz) ;
Ø Rotation:
The rotation of an object by an angle ‘a’ is accomplished by rotating each of the points of the object.
The rotated points can be obtained using the OpenGL functions glRotatef(angle, vx,vy,vz); Ø Scaling:
The scaling operation on an object can be carried out for an object by multiplying each of the points
(x,y,z) by the scaling factors sx, sy and sz.
glScalef(sx,sy,sz);
CHAPTER 5
IMPLEMENTATION
Pacman_Move ( )
Pacman_Draw()
8 / 40
And the eyes of the pacman is rendered using a combination of Random coloring and glutSolidSphere ()
function.
Bool open()
Monster_init()
Here , all the variable values are initialized at the beginning of the Game.
}
Monster_Move ()
Both the x and y updated coordinates are calculate using the speed of the Monster and trigonometric
functions.
Monster_Updation()
10 / 40
11 If the monster is eaten, then the jail timer starts & The monster is sent to jail.
Monster_Vulnerable()
Monster_Chase()
Here , depending on the edible condition for the Monsters , they are set to chase pacman or escape
from it.
Monster_draw()
{
Here, the pacman is drawn using the glutSolidSphere () function.
Board_draw()
Its done in 2 steps to avoid complication in depth. Depending on the x-y coordinates , the board is
rendered Using different walls.
Using the random f( ) , the color of the pebbles is changed To give it a flicker effect.
10 / 40
Render_scene()
Here , the collision detection for pacman , the conditions for Normal & super pills consumption, with
monster movements Are covered.
Create_list()
Display lists. Based on the position, the appropriate list are called.
}
Syntax: glPushMatrix( );
glPopMatrix( );
Description:
Pushes the current transformation matrix onto the matrix stack. The glPushMatrix() function saves the
current coordinate system to the stack and glPopMatrix() restores the prior coordinate system.
Ø Solid Sphere
Syntax:
12 / 40
13 Parameters:
Description:
Renders a sphere centered at the modeling coordinates origin of the specified radius. The
sphere is subdivided aroundthe Z axis into slices and along the Z axis into stacks.
Specifies one of 256 possible key codes. You can use left- and right-distinguishing constants to specify
certain keys.
Description:
The GetAsyncKeyState function determines whether a key is up or down at the time the function is
called, and whether the key was pressed after a previous call to GetAsyncKeyState.
Return Value:
SHORT
Ø Post Redisplay :
Syntax: