Airplane Game Management System Project Report
Airplane Game Management System Project Report
net/publication/383399489
CITATIONS READS
0 24
1 author:
Kamal Acharya
Tribhuvan University
248 PUBLICATIONS 4,437 CITATIONS
SEE PROFILE
All content following this page was uploaded by Kamal Acharya on 25 August 2024.
Date: 2024/01/23
ABSTRACT
Graphics provides one of the most natural means of communicating with a
computer, since our highly developed 2D and 3D pattern recognition
allow us to perceive and process pictorialdata rapidly and efficiently.
Interactive computer graphics is the most important means of producing the
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 such as survey results.
6 Future Enhancement 37
Bibliography 39
1.2 OpenGL supports two classes of primitives:
1.5 Introduction to OpenGL API 1 Geometric primitives
OpenGL’s structure is similar to that of most 2 Image or raster primitives
Geometric primitive are specified in the problem domain and include
modern API’s any effort that you put into learning OpenGL will points, line segments, polygons, curves, and surfaces. Raster primitives
carry over to other software systems. OpenGL is easy to learn are those which are displayed using array of pixels, it is difficult to
manipulate raster primitive objects.
compared with other API’s, it support two and three dimensional
programs that we develop. OpenGL provides the programmer with OpenGL provide various viewing function that helps us to develop
various views of single object, and the way in which it appears on
an interface to graphics hardware. It is a powerful, low- level screen. OpenGL default view is the orthographic projection. OpenGL
rendering and modeling software library, available on all major also provide various transformation functions with the help of these
functions user can render its object at the desired location on the screen.
platforms, with wide hardware support. In OpenGL we obtain viewing and modeling functionality through a
small set of transformation functions. We can even rotate the object
Most of our applications will be designed to access along desired locations and with the desired angle on the screen.
OpenGL directly through functions in three libraries they are as
follows: 1.3 OpenGL
1. GLU
OpenGL provides a set of commands to render a three dimensional
2. GL scene. That means you provide the data in an OpenGL-useable form
and OpenGL will show this data on the screen (render it). It is
3. GLUT
developed by many companies and it is free to use.
The main GL libraries usually have function that
OpenGL is a hardware- and system-independent interface. An
begins with the letters gl. The OpenGL Utility Library (GLU) uses OpenGL-application will work on every platform, as long as there is an
gl functions but contains code for creating common objects and installed implementation. Because it is system independent, there are no
functions to create windows etc., but there are helper functions for each
simplifying viewing. To interface with the window system and to platform. A very useful thing is GLUT.
get input from external devices into our programs we need at least
one more library. For each major window system there is a system- 1.4 GLUT
specific library that provides the glue between the window system GLUT is a complete API written by Mark Kilgard which lets you create
windows and handle the messages. It exists for several platforms, that means
and OpenGL that library is OpenGL Utility Toolkit (GLUT).
that a program which uses GLUT can be compiled on many platforms without
(or at least with very few) changes in the code.
CHAPTER 2 REQUIREMENTS ANALYSIS
1.6 OpenGL architecture
OpenGL is a collection of several hundred functions providing access to all the 2.1 RESOURCE REQUIREMENTS
features offered by your graphics hardware. Internally, it acts as a state
machine--a collection of states that tells OpenGL what to do. Using the API, The requirement analysis phase of the project can be classified into:
you can set various aspects of the state machine, including such things as the Software Requirements
current color, lighting, blending, and so on. When rendering, everything drawn Hardware Requirements
is affected by the current settings of the state machine. It's important to be
aware of what the various states are, and the effect they have, because it's not SOFTWARE REQUIREMENTS:
uncommon to have unexpected results due to having one or more states set
incorrectly. At the core of OpenGL is the rendering pipeline as shown in
Figure. Input Requirement Standard Input Device :Keyboard, Mouse. Output
Requirement Standard Output Device : Color Monitor(60Hz) Software
Requirement Programming Language :C
Compiler Used : Visual C++ 2006/2008/2010/2012 Operating System :
Windows
HARDWARE REQUIREMENTS:
The hardware requirements are very minimal and the software can run on most
of the machines.
Fig 1.3 The OpenGL rendering pipeline
1. Main processor : Pentium 4
2. Processor Speed : 1000 MHz or More
1.1 How does OpenGL work? 3. RAM Size : 64 MB DDR or More
OpenGL bases on the state variables. There are many values, for example the 4. Keyboard : Standard QWERTY serial or PS/2 keyboard
color, that remain after being specified. There are no classes like in DirectX. 5. Mouse : Standard serial or PS/2 mouse
However, it is logically structured. 6. Compatibility : AT/T compatible
OpenGL provides its own data types. They all begin with "GL". For example- 7. Cache memory : 512 KB
GLfloat, GLint and so on. There are also many symbolic constants; they all
begin with "GL_", like GL_POINTS, GL_POLYGON.
3.1 Translation Functions
1. glTranslate
CHAPTER 3 OPENGL FUNCTIONS The glTranslated and glTranslatef functions multiply the current matrix by
the translation matrix.
3.3 Basic Functions
Void glTranslate(x, y, z) ;
1. glPushMatrix, glPopMatrix Function
Parameters
The glPushMatrix and glPopMatrix functions push and pop the current
x, y, z : The x, y, and z coordinates of a translation vector.
matrix stack. SYNTAX: void glPushMatrix();
void glPopMatrix(void); PARAMETERS: This function has no
2. glRotate
parameters.
The glRotated and glRotatef functions multiply the current matrix by a rotation
2. glColor3f Function
matrix. Void glRotate(Glfloat angle,Glfloat x,Glfloat y,Glfloat z);
Sets the current color.
Parameters
SYNTAX: void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
angle : The angle of rotation, in degrees. X: The x coordinate of a vector.
Y: The y coordinate of a vector. Z: The z coordinate of a vector.
3. glBegin, glEnd Function
The glBegin and glEnd functions delimit the vertices of a primitive or a
group of like primitives. SYNTAX: void glBegin, glEnd (GLenum
mode);
PARAMETERS: mode
The primitive or primitives that will be created from vertices presented
between glBegin and the subsequent glEnd. The following are accepted
symbolic constants and their meanings: GL_LINES: Treats each pair of Fig 3.2 Vertex Transformation
vertices as an independent line segment. Vertices 2n - 1 and 2n define
line n. N/2 lines are drawn. 3.2 Functions Used To Display
GL_LINE_STRIP: Draws a connected group of 1. glClear Function
line segments from the first vertex to the last. The glClear function clears buffers to preset values.
Vertices n and n+1 define line n. N - 1 lines are drawn. SYNTAX: glClear(GLbitfield mask); PARAMETERS: mask
GL_LINE_LOOP: Draws a connected group of line segments from the Bitwise OR operators of masks that indicate the buffers to be cleared. The four
first vertex to the last, then back to the first. Vertices n and n + 1 define masks are as follows.
line n. The last line, however, is defined by vertices N and N lines are
drawn. Value Meaning
GL_TRIANGLES: Treats each triplet of vertices as an independent GL_COLOR_BUFFER_BIT The buffers currently enabled for
triangle. Vertices 3n -2, 3n - 1, and 3n define triangle n. N/3 triangle are color writing. GL_DEPTH_BUFFER_BIT The depth buffer.
drawn. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
GL_QUADS: Treats each group of four vertices as an independent
quadrilateral. Vertices 4n - 3, 4n - 2, 4n - 1, and 4n defined quadrilateral 2. glMatrixMode Function
n. N/4 quadrilaterals are drawn. The glMatrixMode function specifies which matrix is the current matrix.
SYNTAX: void glMatrixMode(GLenum mode);
PARAMETERS: mode
The matrix stack that is the target for subsequent matrix operations. The mode
parameter can assume one of three values:
matrix stack. glMatrixMode(GL_MODELVIEW);
mode
Value Meaning Display mode, normally the bitwise OR-ing of GLUT display mode bit masks. See
GL_MODELVIEW Applies subsequent matrix operations to the values below:
modelview GLUT_RGB: An alias for GLUT_RGBA.
matrix stack.
GLUT_DOUBLE: Bit mask to select a double buffered window. This overrides
glMatrixMode(GL_MODELVIEW); GLUT_SINGLE if it is also specified.
3. glLoadIdentity Function GLUT_DEPTH: Bit mask to select a window with a depth buffer.
The glLoadIdentity function replaces the current matrix with the identity
matrix. SYNTAX: void glLoadIdentity(void);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
4. glutSwapBuffers
glutSwapBuffers swaps the buffers of the current window if double 2. glutInitWindowPosition, glutInitWindowSize Functions
buffered. SYNTAX: void glutSwapBuffers(void); glutInitWindowPosition and glutInitWindowSize set the initial window position
glutSwapBuffers(); and size
5. glOrtho . respectively.
SYNTAX: void glutInitWindowSize(int width, int height); void
This function defines orthographic viewing volume with all parameters
glutInitWindowPosition(int x, int y);
measured from the centre of projection.
multiply the current matrix by a perspective matrix. PARAMETERS:
SYNTAX: void glOrtho( GLdouble left, GLdouble right,
width
GLdouble bottom, GLdouble top, GLdouble near,
Width in pixels.
GLdouble far)
height
3.4 Functions Used To Reshape Height in pixels.
1. glutDisplayFunc Function x
glutDisplayFunc sets the display callback for the current window. Window X location in pixels.
SYNTAX: void glutDisplayFunc(void (*func)(void)); y
PARAMETERS: Window Y location in pixels.
func glutInitWindowSize(300,300);
The new display callback function.
glutDisplayFunc(display); 1. glutMainLoop Function
glutMainLoop enters the GLUT event processing loop. SYNTAX: void
3.5 Main Functions glutMainLoop(void);
3. glutInitDisplayMode Function glutMainLoop(); glutStrokeCharacter
glutInitDisplayMode sets the initial display mode. SYNTAX: void
glutInitDisplayMode(unsigned int mode); PARAMETERS:
It renders the character with ASCII code char at the current raster position using CHAPTER 4 IMPLEMENTATION
the stoke font. SYNTAX: Void glutStrokeCharacter(void* font, int char)
PARAMETERS: Tools Used:
Font: GLUT_STROKE_MONO_ROMAN & GLUT_STROKE_ROMAN. OpenGL is an application program interface that is used to define 2D and 3D
3.6 Text Displaying Functions computer graphics. This cross-platform API is generally considered to set the
standard in the computer industry when it comes to this type of interaction
1. GlRasterPos with 2D computer graphics and has also become the usual tool for use with 3D
glRasterPos specify the raster position for pixel operations. graphics as well. Short for Open Graphics Library, OpenGL eliminated the
need for programmers to rewrite the graphics section of an operating system
Parameters each time a business would upgrade to a new version of the system.
x,y, z, w
The basic function of OpenGL is to issue a specific collection of executable or
Specify the x, y, z, and w object coordinates (if present) for the raster position. commands to the operating system. In doing so, the program works with the
2. glutBitmapCharacter existing graphics hardware that resides on the hard drive or other specified
source. Each command in the set is designed to engage a certain drawing
action, or launch a specific special effect associated with the graphics.
glutBitmapCharacter renders a bitmap character using OpenGL. Syntax: void
glutBitmapCharacter(void *font, int character); The available fonts are: 4.1 Implementation of User Defined Functions
GLUT_BITMAP_8_BY_13 GLUT_BITMAP_9_BY_15
GLUT_BITMAP_TIMES_ROMAN_10 GLUT_BITMAP_TIMES_ROMAN_24 User Defined Functions
The project contains several main user defined functions performing the
3.7 Interactive Functions essential tasks for implementing the game. They include:
boundHit( ) : Checks if the plane exceeds the boundary. bool
glutKeyboardfunc FUNCTION boundHit()
Registers the keyboard callback function func. The callback function returns the {
ASCII code of the key pressed and the position of the mouse. if(plane_mvmt+50>=100||plane_mvmt+50 <=18) return true;
SYNTAX: void glutKeyboardFunc (void (*func) (unsigned char key, int x, int else
y)); return false;
}
BuildingBlock( ) : Constructing the building. void buildingBlock()
{
b.block_x=50.0; srand(time(0)); b.no_floors = rand()%3+4; buildColor = rand()%3;
void glClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a):
b.block_y=b.no_floors*10 +15; b.state=true;
s.state=false;
Sets the present RGBA clear color used when clearing the color buffer.
}
Variables of GLclampf are floating-point numbers between 0.0 and 1.0.
buildingHit( ) : Checking if the airplane has crashed into the building. bool int glutCeateWindow(char *title):
buildingHit()
{ Creates a window on the display. The string title can be used to label the
if (((int)b.block_x<=8 &&(int)b.block_x>=-7 && ((int)plane_mvmt+50)- window. The return value provides a reference to the window that can be
b.block_y<=3)) return true; used where there are multiple windows.
else if (((int)b.block_x<=10 &&(int)b.block_x>=-5 && void glutInitWindowSize(int width, int height):
((int)plane_mvmt+50)- b.block_y<=0))
return true; Specifies the initial height and width of the window in pixels.
else if(((int)b.block_x<=6 &&(int)b.block_x>=-3 &&
((int)plane_mvmt+47)- b.block_y<=0)) return true; void glutInitWindowPosition(int x, int y) :
else if(((int)b.block_x<=4 &&(int)b.block_x>=-4 &&
((int)plane_mvmt+47)- b.block_y<=3)) Specifies the initial position of the top-left corner of the window in pixels.
}
} void glutInitDisplayMode(unsigned int mode):
Built in Functions:
Request a display with the properties in mode. The value of mode is
void glBegin(glEnum mode): determined by the logical OR of operation including the color model
(GLUT_RGB, GLUT_INDEX) and buffering (GLUT_SINGLE,
Initiates a new primitive of type mode and starts the collection of vertices. Values GLUT_DOUBLE).
of mode include GL_POINTS, GL_LINES and GL_POLYGON. void glFlush( ):
void glEnd( ):
Forces any buffered any OpenGL commands to execute.
Terminates a list of vertices.
void glutInit (intargc, char **argv):
void glColor3f[ i f d ] (TYPE r, TYPE g, TYPE b):
Initializes GLUT. The arguments from main are passed in and can be used
Sets the present RGB colors. Valid types are int( i ), float ( f ) and double ( d ). by the application.
The maximum and minimum values of the floating-point types are 1.0 and 0.0,
respectively.
void glutMainLoop( ): void glViewport(intx,inty,GLsizeiwidth,GLsizei height):
Cause the program to enter an event processing loop. It should be the last statement Specifies a width*height viewport in pixel whose lower left corner is at
in main. (x,y) measured from the origin of the window.
void glutBitmapCharacter(void *font, int char):
void glutDisplayFunc(void (*func) (void)):
Renders the character with ASCII code char at the current raster
Registers the display function func that is executed when the window needs to be position using the raster font given by font. Fonts include
redrawn. GLUT_BITMAP_TIMES_ROMAN_10 and
GLUT_BITMAP_TIMES_ROMAN_24 etc. The raster position is
void glutBitmapCharacter(void *font, int char): incremented by the width of the character.
Renders the character with ASCII code char at the current raster position using the
raster font given by font. Fonts include GLUT_BITMAP_TIMES_ROMAN_10
and GLUT_BITMAP_TIMES_ROMAN_24 etc. The raster position is incremented
by the width of the character.
void glClear(GL_COLOR_BUFFER_BIT):
void glutpostRedisplay():
Registers the display function that is executed when the window needs to be
redrawn.
void LoadIdentity():
4. Exit – Exits from the screen. Fig 5.4 Game over Screen
When the plane collides with the cloud/building, the game ends and the
game over screen appears. This screen shows the distance travelled by
the plane (in meters) and the levels completed.
By clicking on the Restart button, it goes back to the start screen and
you can choose among the four options.