Flying Ball
Flying Ball
Flying Ball
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)
CERTIFICAT
E
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.
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
3. Implementation……………………………………………….. 5-10
3.1: Source code
4. Snapshots……………………………………………………... 11-16
6. References....................................................... 18
7. Appendix.......................................................... 19-20
Chapter 1
INTRODUCTION
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
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.
#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
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):
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.
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.