Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Flying Ball

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 25

Visvesvaraya Technological University,

Belgavi, Karnataka-590 014

Project report on

FLYING BALL
Submitted in partial fulfillment of the requirement for the award of the degree of
Bachelor of Engineering
In
Computer Science & Engineering
Submitted by
NOOR AFSHAN
(1GC13CS030)
Under the guidance of
DEEPAK N.A
HOD (Dept. of CSE)

Department of Computer Science & Engineering


Ghousia College of Engineering
Ramanagaram –571511
KARNATAKA
GHOUSIA COLLEGE OF ENGINEERING
RAMANAGARAM-562159

CERTIFICAT
E

This is to certify that Ms. NOOR AFSHAN have satisfactorily


completed the mini project on FLYING BALL that has been
approved as it satisfies the academic requirement in view of
the project work prescribed for partial completion of the 6 th
semester B.E. degree in Computer Science course awarded by
the Visvesvaraya Technological University, Belgavi in the
year 2015-2016.

Signature of the Signature of the


Head of Department Examiner
ACKNOWLEDGEMENT

We consider it a privilege to whole heartedly express our gratitude and respect to each and
every one who guided and helped us in the successful completion of this project.

We are very thankful to the Principal Dr. Mohamedd Haneef, for being kind enough to
provide us an opportunity to work on a project in this institution.

We are also thankful to Deepak N.A HOD, Department of Computer Science and
Engineering, for his co-operation and encouragement at all moments of our approach.

We would greatly mention the enthusiastic influence provided by, Project Guide, for his ideas
and co-operation showed on us during our venture and making this project a great success.

We would also like to thank our parents and well-wishers as well as our dear classmates for
their guidance and their kind co-operation.

Finally, it is a pleasure and happiness to the friendly co-operation showed by all the staff
members of computer science department, GCE.

NOOR AFSHAN (1GC13CS030)


ABSTRACT

This Project is on “Flying Ball” in Computer Graphics using OpenGL Functions.

This Project shows a Fling Ball which involves 3 components in this project - Ball, 4
bladed fan and the big net covering them. The big net is like funnel and is beautifully rise
from the bottom to top covering both the ball and the fan. The fan is in the middle which
mean to give air so ball can fly at the top. There is option to stop running the fan. As the fan
stops the ball also stop spinning in the air.

This Project makes use of OpenGL for the entire coding purpose. The OpenGL
Utility Toolkit is a Programming Interface. The Toolkit supports much functionality like
callback event driven processing, sophisticated input devices etc.
TABLE OF CONTENTS

Chapter Name No
1. Introduction…..……………………………………………… 1-3
1.1: Computer Graphics
1.2: OpenGL Interface
1.3: About the project

2. System specification ….……………………………………… 4


2.1 : Hardware Requirements
2.2 : Software Requirements

3. Implementation……………………………………………….. 5-10
3.1: Source code

4. Snapshots……………………………………………………... 11-16

5. Conclusion and future enhancement............... 17

6. References....................................................... 18

7. Appendix.......................................................... 19-20
Chapter 1
INTRODUCTION

This report contains implementation of Student Marks Evaluator using a set of


OpenGL functions.This project generates graphs. It takes the marks as the input from the user
through the keyboard and produces the output in the form of graphs. We are mainly using
keyboard and mouse as interface to view the different types of graph.The graphs and the texts
are drawn by using GLUT functions. This project has been developed using Microsoft
Visual Studio 2010 with OpenGL API.

1.1 About Computer Graphics:


Graphics provides one of the most natural means of communicating within a
computer, since our highly developed 2D and 3D pattern-recognition abilities allow us to
perceive and process pictorial data rapidly and effectively. 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.
Computer graphics started with the display of data on hardcopy plotters and
cathode ray tube screens soon after the introduction of computers themselves. It has grown to
include the creation, storage, and manipulation of models and images of objects. These
models come from a diverse and expanding set of fields, and include physical, mathematical,
engineering, architectural, and even conceptual structures, natural phenomena, and so on.
Computer graphics today is largely interactive. The user controls the contents, structure, and
appearance of the objects and of their displayed images by using input devices, such as
keyboard, mouse, or touch-screen. Due to close relationships between the input devices and
the display, the handling of such devices is included in the study of computer graphics. The
advantages of the interactive graphics are many in number. In many design, implementation,
and construction processes today, the information pictures can give is virtually indispensable.
1.2 About OpenGL:
OpenGL is an application program interface (API) offering various functions to
implement primitives, models and images. This offers functions to create and manipulate
render lighting, coloring, viewing the models. OpenGL offers different coordinate system
and frames. OpenGL offers translation, rotation and scaling of objects.
Most of our applications will be designed to access OpenGL directly through
functions in three libraries. They are, Main GL: Library has names that begin with the letter
gl and are stored in a library usually referred to as GL. OpenGL Utility Library (GLU):
This library uses only GL functions but contains code for creating common objects and
simplifying viewing.OpenGL Utility Toolkit (GLUT): This provides the minimum
functionality that should be accepted in any modern windowing system.

1.3 About the project

Features of the Flying Ball Project


1. There are 3 components involved in this project - Ball, 4 bladed fan and the
big net covering them.
2. The big net is like funnel and is beautifully rise from the bottom to top
covering both the ball and the fan.
3. The fan is in the middle which mean to give air so ball can fly at the top.
There is option to stop running the fan. As the fan stops the ball also stop spinning in the air.
4. We have added the 4 different background for the front screen and more can
added easily.

USER INTERFACE:
Keyboard Interactions:
Key Action
1 Default Front Screen
2 Front Screen - White
3 Front Screen - Brown
4 Front Screen - Green
b Flying Ball
B Stop Flying Ball
Q/q Exit Project
Mouse Interaction:
Right Click and Choose from the menu -
1. Flying ball - Take to the page with ball flying in air
2. Quit - Exit from the project
Chapter 2

SYSTEM SPECIFICATION

2.1 Hardware Requirements


There are no rigorous restrictions on the machine configuration. The model should be
capable of working on all machines capable of supporting recent versions of Microsoft Visual
Studio.
 Processor: Intel® Pentium 4 CPU
 Hard disk Capacity: 80 GB
 RAM: 1 GB
 CPU Speed: 2.9 GHz
 Keyboard: Standard QWERTY serial
 Mouse: Standard serial mouse
 Cache memory: 256 KB
 Processor Speed: 800 MHz
 CD-ROM: Speed 48x and above

2.2 Software Requirements


1. Operating System: WINDOWS
2. Compiler Used: C/C++
3. Microsoft Visual Studio 2010 with OpenGL API and Its Library Functions.
Chapter 3
IMPLEMENTATION

In this project we are implementing a flying ball that contains The fan in the middle
which mean to give air so ball can fly at the top. There is option to stop running the fan. As
the fan stops the ball also stop spinning in the air with the use of open GL functions.

The implementation stage of this model involves the following phases.


 Implementation of OpenGL built in functions.
 User defined function Implementation.

3.1 Source code:

#include <windows.h>
#include<string.h>
#include<stdarg.h>
#include<stdio.h>
#include <GL/glut.h>
static double x=0.0;
void stroke_output(GLfloat x, GLfloat y, char *format,...)
{

va_list args;
char buffer[200], *p;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glPushMatrix();
glTranslatef(-2.5, y, 0);
glScaled(0.003, 0.005, 0.005);
for (p = buffer; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix(); }
//changing backgroun color
void d4()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,1.0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
stroke_output(-2.0, 1.7, "Wel Come");
stroke_output(-2.0, 0.9, "To");
stroke_output(-2.0, 0.0, "Project Created");
stroke_output(-2.0, -0.9, "By");
stroke_output(-2.0, -1.8, "NOOR AFSHAN");
glFlush();
glutSwapBuffers();
}
void d5()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0,1.0,1.0,1.0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
stroke_output(-2.0, 1.7, "Wel Come");
stroke_output(-2.0, 0.9, "To");
stroke_output(-2.0, 0.0, "Project Created");
stroke_output(-2.0, -0.9, "By");
stroke_output(-2.0, -1.8, "NOOR AFSHAN");
glFlush();
glutSwapBuffers();
}
void d6()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.7,0.3,.2,1.0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
stroke_output(-2.0, 1.7, "Wel Come");
stroke_output(-2.0, 0.9, "To");
stroke_output(-2.0, 0.0, "Project Created");
stroke_output(-2.0, -0.9, "By");
stroke_output(-2.0, -1.8, "NOOR AFSHAN");
glFlush();
glutSwapBuffers();
}
void d7()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.5,0.7,0.3,1.0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
stroke_output(-2.0, 1.7, "Wel Come");
stroke_output(-2.0, 0.9, "To");
stroke_output(-2.0, 0.0, "Project Created");
stroke_output(-2.0, -0.9, "By");
stroke_output(-2.0, -1.8, "NOOR AFSHAN");
glFlush();
glutSwapBuffers();
}
void flying(double ang)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,-.5f,-13.0f);
glRotatef(115,1.0f,0.0f,0.0f);
//fan
glPushMatrix();
glRotatef(ang,0.0f,0.0f,1.0f);
glScaled(2.9,0.2,0.1);
glTranslatef(0.0,0.0,16.0);
glRotatef(ang,0.0f,0.0f,1.0f);
glutSolidSphere(0.7,20,60);
glPopMatrix();
//2nd blade
glPushMatrix();
glRotatef(ang,0.0f,0.0f,1.0f);
glScaled(0.2,2.9,0.1);
glTranslatef(0.0,0.0,16.0);
glRotatef(ang,0.0f,0.0f,1.0f);
glutSolidSphere(0.7,20,60);
glPopMatrix();
glPushMatrix();
glutWireCone(4,3,80,120);
glPopMatrix();
glPushMatrix();
glRotated(ang,0.0,1.0,0.0);
glTranslatef(0.05,-3.0,0.0);
glRotated(ang,0.0,1.0,0.0);
glutSolidSphere(0.3,20,60);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void fly()
{
x += 5.30;
flying(x);
}
void nofly()
{
flying(0);
}
void doInit()
{
/* Background and foreground color */
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(.0,1.0,1.0);
glViewport(0,0,640,480);
/* Select the projection matrix and reset it then
setup our view perspective */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);
/* Select the modelview matrix, which we alter with rotatef() */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void doDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
stroke_output(-2.0, 1.7, "Wel Come");
stroke_output(-2.0, 0.9, "To");
stroke_output(-2.0, 0.0, "Project Created");
stroke_output(-2.0, -0.9, "By");
stroke_output(-2.0, -1.8, "NOOR AFSHAN");
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
/*GLfloat lightIntensity[]={3.7f,0.7f,0.7f,1.0f};
OrangeGLfloat light_position[]={2.0f,5.0f,3.0f,1.0f};*/
/*light source properties*/
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position[]={2.0f,0.0f,0.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
GLfloat light_position2[]={0.0f,0.0f,8.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position2);
GLfloat light_position3[]={0.0f,5.0f,2.0f,0.5f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
glFlush();
glutSwapBuffers();
}
void menu(int id)
{
switch(id)
{
case 1:glutIdleFunc(fly);
break;
case 2:exit(0);
break;
}
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void mykey(unsigned char key,int x,int y)
{
if(key=='q'||key=='Q')
{
exit(0);
}
if(key=='1')
{
glutIdleFunc(d4);
}
if(key=='2')
{

glutIdleFunc(d5);
}
if(key=='3')
{
glutIdleFunc(d6);
}
if(key=='4')
{
glutIdleFunc(d7);
}
if(key=='b')
{
glutIdleFunc(fly);
}
if(key=='B')
{
glutIdleFunc(nofly);
} }
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Flying ball");
glutDisplayFunc(doDisplay);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("Flying ball",1);
glutAddMenuEntry("Exit",2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
return 0;
}
Chapter 4
SNAPSHOTS

Fig 4.1: shows the welcome screen


Fig 4.2: shows the movement of ball
Fig 4.3: shows the change in colour of welcome screen
Fig 4.4:shows the movement of ball
Fig 4.5 and 4.6: shows the change in colour of welcome
screen and movement of ball
Chapter 5

CONCLUSION AND FUTURE ENHANCEMENTS

Well I like to say you can turn this as a game play. Add a timer which will start the
game, so on clock tick to 0 player start accelerating the fan in air. For every minute 10 key
press to accelerate allowed to player. As ball fall down player finished the game. Calculate
the score with the time the ball remain in air. The interfaces are mouse and keyboard driven
and the user can select a function by clicking on an option representing that function or by
pressing keys in the keyboard. I finally conclude that this graphics package satisfies all
requirements and provides good entertainment

The future versions of this project may be developed in a 3-D platform for a much
better user interface, by providing lighting effects for each fan blade, backgrounder area, ball
and Zooming in and zooming out effects. Additional Menus could also be provided.

.
REFERENCES

[1] URL:-http://www.opengl.com
[2] Interactive Computer Graphics A Top-Down Approach with OpenGL,5th Edition,
Edward Angel ,Addison-Wesley,2008
[3] Computer Graphics Using OpenGL.2nd Edition, F.S.Hill,Jr ,Pearson Education,2001
APPENDIX
OPENGL FUNCTIONS USED:

 glutMainLoop():

Cause the program to enter an event processing loop. It should be the last statement in main.

 glutBitmapCharacter(GLUT_ BITMAP_HELVETICA_18,c):

It is used to stroke and create the bitmap characters at a raster position.

 glRaster3f():

The character which is present at raster position on the display is measured in pixels and can
be altered by using this function.

 glutMouseFunc(mouse);

GLUTs mouse interface provides a lot of options for adding mouse interactivy, namely
detecting clicks and mouse motion. As in the keyboard version, GLUT provides a way for
you to register the function that will be responsible for processing events generated by mouse
Clicks

The name of this function is glutMouseFunc, and it is commonly called in the initialization
phase of the application .the syntax is as follows:
Void glutMouseFunc(void(*func)(int button,int state,int x,int y));

 glutKeyboardFunc(key);

This OpenGL will teach you how to add keyboard interaction to your opengl application
through the use of glut and glut's keyboard calls. Now glut has many different keyboard
calls,
 But anyway, all you have to edit after that is the 'main' function. Just add the
line:
glutKeyboardFunc (keyboard);
where 'keyboard' is the name of your keyboard function.
glVertex3f():A vertex is a position in plane.

 glutInitWindowPosition() and   glutInitWindowSize() :


 set the initial window position and size respectively.
 Usage:
void glutInitWindowSize(int width, int height);
void glutInitWindowPosition(int x, int y);

 glutCreateWindow():
 creates a top-level window.
 Usage:
glutCreateWindow(char *name);

 glutDisplayFunc():
 sets the display callback for the current window.
 Usage
void glutDisplayFunc(void (*func)(void));
 Parameter
func : The new display callback function
 Description
glutDisplayFunc sets the display callback for the current window.

You might also like