88% found this document useful (8 votes)
6K views

Free Flying Ball Computer Graphics Project Report

This document provides details about a project called "Flying Ball" that illustrates concepts of static pressure in OpenGL. It includes an abstract, specifications for the required software and hardware, an introduction to OpenGL concepts used in the project, descriptions of the implementation and user interaction, and sample source code for rendering 3D objects like a table fan and ceiling fan. The goal of the project is to create an interactive 3D environment using OpenGL where the user can turn objects on and off using keyboard inputs.

Uploaded by

prerna panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
88% found this document useful (8 votes)
6K views

Free Flying Ball Computer Graphics Project Report

This document provides details about a project called "Flying Ball" that illustrates concepts of static pressure in OpenGL. It includes an abstract, specifications for the required software and hardware, an introduction to OpenGL concepts used in the project, descriptions of the implementation and user interaction, and sample source code for rendering 3D objects like a table fan and ceiling fan. The goal of the project is to create an interactive 3D environment using OpenGL where the user can turn objects on and off using keyboard inputs.

Uploaded by

prerna panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Flying Ball

Contents

SL.NO particulars PAGE.NO


1 Abstract 2
2 System Specifications 3
3 Introduction to openGL 4
5 Implementation 7
6 Interaction 9
7 Source Code 10
8 Output 29
9 Conclusion 31
10 Bibliography 32

1 Dept. of Computer Science & Engineering.


Flying Ball

Abstract

Main aim of this is to illustrate the concepts of Static Pressure.

This project uses the ​GLUT pre-built models sub-API​ in openGL.

We have used input devices like mouse and key board to interact with
program.

We have added menu which makes the program more interactive​.

This project illustrates the concept of static pressure in OpenGL.

2 Dept. of Computer Science & Engineering.


Flying Ball

System specifications

SOFTWARE REQUIREMENTS​ :
▪ MICROSOFT VISUAL C++

▪ OPENGL

OPERATING SYSTEM​ :

▪ WINDOWS XP,VISTA

HARDWARE REQUIREMENT​ :

▪ GRAPHICS SYSTEM,
▪ Pentium P4 with 256 of Ram(Min)

3 Dept. of Computer Science & Engineering.


Flying Ball

Introduction to openGL

As a software interface for graphics hardware, OpenGL's main purpose is to


render two- and three-dimensional objects into a frame buffer.
These objects are described as sequences of vertices or pixels.
OpenGL performs several processing steps on this data to convert it to pixels to
form the final desired image in the frame buffer.

OpenGL Fundamentals
This section explains some of the concepts inherent in OpenGL.

Primitives and Commands


OpenGL draws primitives—points, line segments, or polygons—subject to several
selectable modes.
You can control modes independently of each other; that is, setting one mode
doesn't affect whether other modes are set .Primitives are specified, modes are
set, and other OpenGL operations are described by issuing commands in the form
of function calls.
Primitives are defined by a group of one or more vertices. A vertex defines a
point, an endpoint of a line, or a corner of a polygon where two edges meet. Data
is associated with a vertex, and each vertex and its associated data are processed
independently, in order, and in the same way. The type of clipping depends on
which primitive the group of vertices represents.
Commands are always processed in the order in which they are received,

4 Dept. of Computer Science & Engineering.


Flying Ball

although there may be an indeterminate delay before a command takes effect.


This means that each primitive is drawn completely before any subsequent
command takes effect. It also means that state-querying commands return data
that's consistent with complete execution of all previously issued OpenGL
commands.

Basic OpenGL Operation


The figure shown below gives an abstract, high-level block diagram of how
OpenGL processes data. In the diagram, commands enter from the left and
proceed through what can be thought of as a processing pipeline. Some
commands specify geometric objects to be drawn, and others control how the
objects are handled during the various processing stages.
Figure . OpenGL Block Diagram

As shown by the first block in the diagram, rather than having all commands
proceed immediately through the pipeline, you can choose to accumulate some
of them in a display list for processing at a later time.

5 Dept. of Computer Science & Engineering.


Flying Ball

Rasterization produces a series of frame buffer addresses and associated values


using a two-dimensional description of a point, line segment, or polygon.
Each fragment so produced is fed into the last stage,
per-fragment operations, which performs the final operations on the data before
it's stored as pixels in the frame buffer. These operations include conditional
updates to the frame buffer based on incoming and previously stored z-value s
(for z-buffering) and blending of incoming pixel colors with stored colors, as well
as masking and other logical operations on pixel values.
All elements of OpenGL state, including the contents of the texture memory and
even of the frame buffer, can be obtained by an OpenGL application.

6 Dept. of Computer Science & Engineering.


Flying Ball

Implementation

This program is implemented using various openGL functions which are

shown below.

​Various functions used in this program.

glutInit() : interaction between the windowing system and OPENGL is


initiated

glutInitDisplayMode() : used when double buffering is required and depth


information is required

glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window

glutInitWindowSize() : specifies the size of the window

glutInitWindowPosition() : specifies the position of the window in screen


co-ordinates

glutKeyboardFunc() : handles normal ascii symbols

7 Dept. of Computer Science & Engineering.


Flying Ball

glutSpecialFunc() : handles special keyboard keys

glutReshapeFunc() : sets up the callback function for reshaping the window

glutIdleFunc() : this handles the processing of the background

glutDisplayFunc() : this handles redrawing of the window

glutMainLoop() : this starts the main loop, it never returns

glViewport() : used to set up the viewport

glVertex3fv() : used to set up the points or vertices in three dimensions

glColor3fv() : used to render color to faces

glFlush() : used to flush the pipeline

glutPostRedisplay() : used to trigger an automatic redrawal of the object

glMatrixMode() : used to set up the required mode of the matrix

glLoadIdentity() : used to load or initialize to the identity matrix

8 Dept. of Computer Science & Engineering.


Flying Ball

glTranslatef() : used to translate or move the rotation centre from one


point to another in three dimensions

glRotatef() : used to rotate an object through a specified rotation angle

Interaction with program

.Both mouse and keyboard are used to interact with the program.

C,c are used to turn on and off the ceiling fan.

F,f are used to turn on and off the table fan.

B,b are used to turn on and off the flying ball.

Right mouse button can be used to get a menu.

9 Dept. of Computer Science & Engineering.


Flying Ball

Source Code

/*An Interactive Program to create 3d objects*/

#include <windows.h>

#include<string.h>

#include<stdarg.h>

#include<stdio.h>

#include <glut.h>

static double x=0.0;

static double inc=0.0;

void

stroke_output(GLfloat x, GLfloat y, char *format,...)

10 Dept. of Computer Science & Engineering.


Flying Ball

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

// Table Fan

void fan(double ang)

{ glClearColor(0.8,0.8,0.8,0.0);

11 Dept. of Computer Science & Engineering.


Flying Ball

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glTranslatef(0.0f,0.0f,-13.0f);

glRotatef(180,0.0f,1.0f,0.0f);

//fan Blades

glPushMatrix();

glRotatef(ang,0.0f,0.0f,1.0f);

glScaled(0.9,0.2,0.1);

glTranslatef(0.0,0.0,0.0);

glRotatef(ang,0.0f,0.0f,1.0f);

glutSolidSphere(0.7,20,60);

glPopMatrix();

glScaled(0.8,0.04,0.8);

glTranslatef(0.0,-40.2,0.0);

glutSolidCube(6.0);

glPopMatrix();

12 Dept. of Computer Science & Engineering.


Flying Ball

// leg 1

glPushMatrix();

glScaled(0.04,0.4,0.04);

glTranslatef(0.0,-40.2,0.0);

glutSolidCube(6.0);

glPopMatrix();

//fan cover

glPushMatrix();

glScaled(0.8,1.0,0.2);

glTranslatef(0.0,0.0,0.0);

glutWireSphere(0.9,20,60);

glPopMatrix();

glPushMatrix();

glScaled(0.8,0.18,0.8);

13 Dept. of Computer Science & Engineering.


Flying Ball

glTranslatef(0.0,-7.2,0.0);

glutSolidCube(0.7);

glPopMatrix();

//Fan motor

glPushMatrix();

glScaled(0.35,0.4,0.5);

glTranslatef(0.0,0.0,0.5);

glutSolidSphere(0.5,20,60);

glPopMatrix();

//

glFlush();

glutSwapBuffers();

// Ceiling Fan

14 Dept. of Computer Science & Engineering.


Flying Ball

void cfan(double rang)

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glClearColor(0.5,0.5,0.5,0.0);

glLoadIdentity();

glTranslatef(0.0f,0.0f,-13.0f);

glPushMatrix();

glTranslatef(-2.0f,0.0f,0.0f);

glRotatef(rang,0.0f,1.0f,0.0f);

glScaled(0.7,0.7,0.7);

glPushMatrix();

glTranslated(0.0,1.5,0.0);

glScaled(0.1,0.8,0.1);

glutSolidSphere(1.0,20,60);

glPopMatrix();

glPushMatrix();

glTranslated(0.0,0.9,0.0);

15 Dept. of Computer Science & Engineering.


Flying Ball

glScaled(0.6,0.3,0.6);

glutSolidSphere(1.0,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();

glTranslatef(0.0,inc,0.0);

glPushMatrix();

glRotated(ang,0.0,1.0,0.0);

16 Dept. of Computer Science & Engineering.


Flying Ball

glTranslatef(0.05,2.0,0.0);

glutSolidSphere(0.3,20,60);

glPopMatrix();

glPopMatrix();

glFlush();

glutSwapBuffers();

void f()

x += 9.0;

fan(x);

//stop the fan

void F()

x = 0.0;

fan(x);

17 Dept. of Computer Science & Engineering.


Flying Ball

void c()

x += 10.9;

cfan(x);

void C()

x+=0.0;

cfan(x);

void fly1()

if (inc<=-4){

x+=5.30;

cfan(x);

18 Dept. of Computer Science & Engineering.


Flying Ball

else

inc-=0.01;

x += 5.30;

cfan(x);

void StopFly1()

if(inc>=0){

cfan(0);

else if(x>=0)

{x+=0.3;

inc+=.01;

cfan(x);

19 Dept. of Computer Science & Engineering.


Flying Ball

}else{

cfan(0);

void fly()

if (inc<=-4){

x+=5.30;

flying(x,inc);

else

inc-=0.01;

x += 5.30;

flying(x,inc);

void StopFly()

20 Dept. of Computer Science & Engineering.


Flying Ball

if(inc>=0){

flying(0,0); }

else if(x>=0)

{x+=0.3;

inc+=.01;

flying(x,inc);

}else{

flying(0,0);

void doInit()

21 Dept. of Computer Science & Engineering.


Flying Ball

/* Background and foreground color */

glClearColor(0.8,0.0,0.8,0.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);

22 Dept. of Computer Science & Engineering.


Flying Ball

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, "Demonstration of Static Pressure ");

glPushMatrix();

glScaled(0.7,0.7,0.7);

stroke_output(-2.0, 0.9, "b --> Apply Pressure");

stroke_output(-2.0, 0.0, "B --> Stop ");

stroke_output(-2.0, -0.9, "f | F --> Start/Stop Table Fan");

stroke_output(-2.0, -1.8, "c | C --> Start/Stop Ceiling Fan");

glPopMatrix();

GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};

GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};

23 Dept. of Computer Science & Engineering.


Flying Ball

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);

/*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();

24 Dept. of Computer Science & Engineering.


Flying Ball

void menu(int id)

switch(id)

case 1:glutIdleFunc(f);

break;

case 2:glutIdleFunc(F);

break;

case 3:glutIdleFunc(c);

break;

case 4:glutIdleFunc(C);

break;

case 5:glutIdleFunc(fly);

break;

case 6:exit(0);

break;

25 Dept. of Computer Science & Engineering.


Flying Ball

glFlush();

glutSwapBuffers();

glutPostRedisplay();

void mykey(unsigned char key,int x,int y)

if(key=='f')

glutIdleFunc(f);

if(key=='F')

glutIdleFunc(F);

if(key=='q'||key=='Q')

26 Dept. of Computer Science & Engineering.


Flying Ball

exit(0);

if(key=='C')

glutIdleFunc(StopFly1);

if(key=='c')

glutIdleFunc(fly1);

if(key=='b')

glutIdleFunc(fly);

if(key=='B')

glutIdleFunc(StopFly);

27 Dept. of Computer Science & Engineering.


Flying Ball

int main(int argc, char *argv[])

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(640,480);

glutInitWindowPosition(0,0);

glutCreateWindow("Basic Structures Orientation");

glutDisplayFunc(doDisplay);

glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glShadeModel(GL_SMOOTH);

glEnable(GL_DEPTH_TEST);

glEnable(GL_NORMALIZE);

glutKeyboardFunc(mykey);

28 Dept. of Computer Science & Engineering.


Flying Ball

glutCreateMenu(menu);

glutAddMenuEntry("Start Fan 'f'",1);

glutAddMenuEntry("Stop Fan 'F'",2);

glutAddMenuEntry("Start Ceiling Fan 'c'",3);

glutAddMenuEntry("Stop Ceiling Fan 'C'",4);

glutAddMenuEntry("Flying Ball 'b'",5);

glutAddMenuEntry("Exit 'q'",6);

glutAttachMenu(GLUT_LEFT_BUTTON);

doInit();

glutMainLoop();

return 0;

29 Dept. of Computer Science & Engineering.


Flying Ball

OUTPUT OF THE PROGRAM

30 Dept. of Computer Science & Engineering.


Flying Ball

31 Dept. of Computer Science & Engineering.


Flying Ball

32 Dept. of Computer Science & Engineering.


Flying Ball

Conclusions

The project “ Flying ball” is based on concepts of Static pressure.

This program illustrates the concept of static pressure using various functions.

Finally we conclude that this program clearly illustrate the static pressure in
OpenGL and has been completed successfully and is ready to be demonstrated.

33 Dept. of Computer Science & Engineering.


Flying Ball

Bibliography

WE HAVE OBTAINED INFORMATION FROM MANY RESOURCES TO DESIGN AND


IMPLEMENT OUR PROJECT SUCCESSIVELY. WE HAVE ACQUIRED MOST OF THE
KNOWLEDGE FROM RELATED WEBSITES. THE FOLLOWING ARE SOME OF THE
RESOURCES​ :

TEXT BOOKS :
INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH
-By Edward Angel.

COMPUTER GRAPHICS,PRINCIPLES & PRACTICES

​- Foley van dam

- Feiner hughes

WEB REFERENCES:
http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson3.php
http://google.com
http://opengl.org

34 Dept. of Computer Science & Engineering.


Flying Ball

35 Dept. of Computer Science & Engineering.

You might also like