CG Project Report
CG Project Report
(18CLS67) ON
“SPACE SHOOTER”
Submitted in partial fulfilment of the requirements for the award of the
degree of
Bachelor of Engineering
In
Computer Science and Engineering
By
T.XXXX 4BP19CS0XX
XXXXXX 4BP18CS0XX
XXXXXX 4BP18CS0XX
CERTIFICATE
This is to certify that the mini project work entitled “Space Shooter” carried out by
T.XXXX (4BP19CS0XX),XXXXXX (4BP18CS0XX) and XXXX (4BP18CS0XX)
in partial fulfilments of the requirements of Computer Graphics Laboratory with
Mini Project (18CSL67) prescribed by the Visvesvaraya Technological University,
Belagavi for the VI Semester B.E(Computer Science and Engineering) Degree
course during the academic year of 2021-2022.
We, XXXX , XXXXX, XXXXX hereby declare that the report presented in this computer
graphics project entitled “Space Shooter” is an authentic collection of information that has
been carried out independently in our 6th semester Computer Science and Engineering at
Bearys Institute of Technology, Mangalore under the guidance of Prof. M.
XXXXXX (4BP19CS0XX)
XXXXXX (4BP18CS0XX)
XXXXXX (4BP18CS0XX)
ACKNOWLEDGEMENT
The sense of contentment and elation that accompanies the successful completion of this
task would give incomplete without mentioning the names of the people who have helped
in accomplishment of this work.
We express our sincere thanks and deep sense of gratitude to our Prof. M Head of the
Computer Science Engineering Department, BIT Mangalore, for his valuable support and
advise.
We express our deep sense of gratitude to our guide Prof. M for his valuable support and
guidance.
We extend our sincere thanks to all staffs of BIT and to all our friends and parents for the
help and support.
XXXXXX (4BP19CS061)
XXXXXX (4BP18CS034)
XXXXXXX (4BP18CS032)
6th Sem
ABSTRACT
The project is two player shooting game, where there will be two spaceship
representing two players and objective is to destroy opponent’s ship first.
Here we are using mouse for selecting option from menu and keyboard for
moving the spaceship and shooting beams.
TABLE OF CONTENTS
CHAPTER 3 DESIGN 05
CHAPTER 4 IMPLEMENTATION 06
4.1 In-Built OpenGL Functions 06
4.2 Standard Header and Library Functions 10
4.3 User-Defined Functions 11
4.4 Algorithm to Shoot at aTarget 13
CHAPTER 5 RESULTS 14
5.1 Screenshots 14
CONCLUSION 17
REFERENCES 18
I
LIST OF FIGURES
II
Space Shooter 2021-22
CHAPTER 1
INTRODUCTION
Computer Graphics in today’s world is one of the most widely used powerful and interesting
features of the computer which gives us the power to handle the graphical data very
efficiently and also process them rapidly and effectively Computer graphics started with a
display of data on hard copy plotters and cathode ray tube screens soon after the
introduction of computers themselves. The development of computer graphics has been
driven both by the needs of the user community and by advances in hardware and software.
Computer graphics today is largely interactive. The user controls the contents, structures and
appearances of the object and of their displayed images by using input devices, such as
keyboard, mouse or touch-screen. Due to the close relationships between the input devices
and the display, the handling of such devices is included in the study of computer graphics.
Texturing combines the two types of primitives together. There are several APIs related to
OpenGL:
In the project, we use a particular graphics software system, OpenGL. The applications are
designed to access OpenGL directly through functions in three libraries. The first is the GL
library in which the function name begins with gl. The second is the OpenGL utility library
(GLU) which uses only GL functions but contains code for creating common objects and
simplify viewing and these functions that begin with glu. To interface with the windows
system and to get input from the external devices into our programs we use the third library,
the OpenGL Utility Toolkit (GLUT) whose functions are prefixed as glut.
OpenGL has a wide variety of functions in GL, GLU, GLUT, and GLE. GLUT uses a
callback mechanism to do its event processing. Callbacks simplify event processing for the
application developer. Given below are some of the functions used in this project:
The OpenGL API calls are designed to accept almost any basic data type, which is reflected
in the calls name. Knowing how the calls are structured makes it easy to determine which
call should be used for a particular data format and size. For instance, vertices from most
commercial models are stored as three component floating point vectors.
As such, the appropriate OpenGL command to use is glVertex3fv (co-ordinates). For
glVertex*() calls Selective Repeat ARQ which don’t specify all the coordinates i.e.,
glvertex2f (), OpenGL will take default z=0.0
CHAPTER 2
SYSTEM REQUIREMENT
The package is designed such that users with a computer having minimum configuration
can also use it, which does not require complex graphics packages.
The package requires simple in-built functions found in the header file along with a few
users defined functions.
CHAPTER 3
DESIGN
The project “Star Wars” is designed in C++ language using some standard header and
library functions. When we run the program, a window appears then you press “Enter” it
will take you to a Menu.
W - UP
S - DOWN
A - LEFT
D - RIGHT
C - to shoot, Use 'w' and 's' to change direction.
I - UP
K - DOWN
J - LEFT
L - RIGHT
M - to shoot, Use 'I' and 'K' to change direction.
CHAPTER 4
IMPLEMENTATION
4.1.1 Initialize
4.1.2 WindowPosition
4.1.3 CreateWindow
4.1.4 DisplayFunc
Code: glutDisplayFunc(display);
4.1.5 ReshapeFunc
Code: glutReshapeFunc(myReshape);
4.1.6 KeyboardFunc
Code: glutKeyboardFunc(keys);
4.1.7 glutBitmapCharacter
4.1.8 MouseFunc
Code: glutMouseFunc(mouse);
4.1.9 LineWidth
Code: glLineWidth(5);
4.1.10 Scale
This Function is used to multiply the current matrix by a general scaling matrix.
4.1.11 SwapBuffers
This Function swaps the buffers of the current window if double buffered.
Code: glutSwapBuffers();
4.1.12 Colour
4.1.13 Vertex
Code: glVertex3f(1,.8,-1);
4.1.14 PostRedisplay
Code: glutPostRedisplay();
Code: glMatrixMode();
Code: glLoadIdentity();
4.1.17 Viewport
4.1.18 Modelview
Code: glMatrixMode(GL_MODELVIEW);
4.1.19 MainLoop
This function call causes the program to enter an event processing loop. It should be the
last statement in main.
4.1.20 ClearColor
This function call sets the present RGBA clear color used when clearing the color
buffer.
4.1.21 DisplayMode
This function call requests a display with the properties that are specified in mode.
4.1.22 WindowSize
This function call specifies the initial height and width of window in pixels.
4.1.23 ClearColor
Code: glFlush();
4.2.1 stdio.h
This header file is used for standard input and output and stream manipulation function.
4.2.2 stdlib.h
4.2.3 GL/gl.h
4.2.4 GL/glu.h
4.2.5 GL/glut.h
4.2.6 math.h
4.3.1 Alien
void DrawSpaceshipDoom()
void DrawSteeringWheel()
4.3.3 Laser
4.3.4 Menu
void introScreen()
void startScreenDisplay()
void instructionsScreenDisplay()
void gameScreenDisplay()
This function defined to find out if the laser intersects with spaceship.
void checkLaserContact(int x, int y, bool dir[], int xp, int yp, bool player1)
4.3.6 Display
This function defined to display the result which is invoked by built-in function
glutDisplayFunc() in main.
void display(void)
4.3.7 Mouse
This function defined to perform mouse button interaction which is invoked by built-in
function glutMouseFunc() in main.
4.3.8 Keyboard
This function defined to perform character keys of keyboard interaction which is invoked by
built-in function glutKeyboardFunc(keys) in main.
This function defined to perform all the key operation during the movement and shooting of
the spaceship.
void keyOperations()
4.3.10 Reshape
This function defined to reshape result for changing screen size which is invoked by built-in
function glutReshapeFunc(display) in main.
4.3.11 PassiveMotionFunc
This function sets passive motion callbacks respectively for the current window. The passive
motion callback for a window is called when the mouse moves within the window while no
mouse buttons are pressed.
Let the target be at the position A and moving with velocity VA, and the shooter be
stationary at the position B and can fire bullets with speed s. Let the shooter fire at time 0.
The bullet hits at time t such that |A − B + t VA| = t s. This is a straightforward quadratic
equation in t, which you should be easily able to solve (or determine that there is no
solution).
CHAPTER 5
RESULTS
5.1 Screenshots
5.1.1 Execution
5.2.2 Menu
CONCLUSION
The wonderful experience developing this project. By working on the project, we gained
hands- on experience of using the OpenGL software using which we experimented this
project. We have made use of hardware devices such as mouse and keyboard driven
interface, thus to reduce the complexity and make it user friendly.
The project helped in understanding the working of computer graphics using OpenGL and
various concepts, functions and methodologies for the development of a graphics packages.
The proposed project will serve its purpose without any hassles.
REFERENCES
[2].Computer Graphics Using OpenGL – F.S. Hill, Jr. 2nd Edition, Pearson 1.
Education,2001.
[3].Computer Graphics – James D Foley, Andres Van Dam, Steven K Feigner, John F
Hughes, Addison-Wesley 1997.
[4].Computer Graphics - OpenGL Version – Donald Hearn and Pauline Baker, 2nd
Edition, Pearson Education.
[5]. www.geeksforgeeks.org
[6]. www.stackoverflow.com