Вы находитесь на странице: 1из 35

Gear system

INTRODUCTION
1.1 INTRODUCTION TO COMPUTER GRAPHICS
Computer Graphics is one of the most effective and commonly used methods to communicate the processed information to the user. It displays the information in the form of graphical objects such as pictures, charts, graphs and diagram instead of simple text. Graphics often combine text, illustration, and color. Graphic design may consist of the deliberate selection, creation, or arrangement of typography alone, as in a brochure, flier, poster, web site, or book without any other element. Clarity or effective communication may be the objective, association with other cultural elements may be sought, or merely, the creation of a distinctive style.

Graphics can be functional or artistic. The latter can be a recorded version, such as a photograph, or an interpretation by a scientist to highlight essential features, or an artist, in which case the distinction with imaginary graphics may become blurred. Computer Graphics today is largely interactive. The user controls the contents, structure, and appearance of objects and their displayed images by using input devices, such as a keyboard, mouse, or touch-sensitive panel on the screen. Computer graphics concerns with the pictorial synthesis of real or imaginary objects from their computer based models, where as the related field of image processing treats the converse process, the analysis of scenes, or the reconstruction of models of 2D or 3D objects from their pictures. A broad classification of major subfields in Computer Graphics might be: 1. Geometry: Studies ways to represent and process surfaces. 2. Animation: Studies ways to represent and manipulate motion. 3. Rendering: Studies algorithms to reproduce light transport. 4. Imaging: Studies image acquisition or image editing. Computer graphics: Computer graphics is concerned with all aspects of producing pictures and images using a computer.
Dept. of CSE, SCE Page 1

Gear system

Translation: Translation is an operation that displaces points by a fixed size in a given direction. Rotation: Three features of transformation extended to other rotations 1. There is one point in the origin that is unchanged by the rotation called fixed point. 2. Two dimensional plane is a part of three dimensional space, we can reinterpret this rotation in three dimension. 3. Rotation in the two dimensional plane z=0 is equivalent to a three dimensional rotation about the z-axis. Scaling: Scaling is a non rigid body transformation, by which, we can make an object bigger or smaller.

1.2 AREAS OF APPLICATION OF COMPUTER GRAPHICS


User interfaces and Process control Cartography Office automation and Desktop publishing Plotting of graphs and charts Computer aided Drafting and designs Simulation and Animation

1.3 INTRODUCTION TO OpenGL ABOUT OpenGL


OpenGL has become a widely accepted standard for developing graphics application. Most of our applications will be designed to access OpenGL directly through functions in three libraries. Functions in main GL library have names that begin with the letters gl and are stored in a library usually referred to as GL.

Dept. of CSE, SCE

Page 2

Gear system

The second is the OpenGL Utility Library (GLU). This library uses only GL functions but contains code for creating common objects and simplifying viewing. All functions in GLU can be created from the core GL library. The GLU library is available in all OpenGL implementations; functions in the GLU library begin with the letters glu. The third is called the OpenGL Utility Toolkit (GLUT), which provides the minimum functionality that should be expected in any modern windowing system.

GLU

OpenGL Application program

GL Xlib, Xtk GLUT

Frame buffer

GLX

Fig 1.1: Library organization of OpenGL

Dept. of CSE, SCE

Page 3

Gear system

GRAPHICS FUNCTIONS

Function calls Application programs Graphics system

Outputs Ip/op devices

Data

Input

Fig 1.2: Graphics system as a black box.

Our basic model of a graphics package is a black box, a term that engineers use to denote a system whose properties are described only by its inputs and outputs. We describe an API through the functions in its library. Some of the functions are: The primitive functions define the low-level objects or atomic entities that our system can display. Attribute functions allow us to perform operations ranging from choosing the color with which we display a line segment, to picking a pattern with which to fill the inside of a polygon, to selecting a typeface for the titles of a graph. Transformation function allows carrying out transformations of objects, such as rotation, translation, and scaling. A set of input functions allow us to deal with the diverse forms of input that characterize modern graphics systems. The control functions enable us to communicate with the window systems, to initialize our programs, and to deal with any errors that take place during the execution of programs.

Dept. of CSE, SCE

Page 4

Gear system

REQUIREMENT SPECIFICATION

Software Requirements

Platform used: Windows XP& Above


Tool used: Microsoft (Visual C++ 10.0) with OpenGL Libraries Language: C++

Hardware Requirements
This package has been developed on: Pentium 4 40 GB hard disk 256 MB RAM VGA Color Monitor Basic Graphic Card

However it has been designed to work on systems with minimal resources

Dept. of CSE, SCE

Page 5

Gear system

DESIGN
FLOWDIAGRAM:Start

Main

Initialize OPENGL Callback functions

Callback functions

Right Click Button

List of menus

Help Pause/Play Toggle direction View along axis Toggle Lighting About Exit

Events

End

Dept. of CSE, SCE

Page 6

Gear system

IMPLEMENTATION
In this application we have used some of the built in functions and library functions defined in glut header files.

Description of <GL/glut.h>header file


The header file <GL/glut.h> includes the standard commands that help us in executing the OpenGL codes. It supports inbuilt functions. It also includesgl.h&glu.h header files. Below listed are some of the standard commands that are included in this project.

Built in Functions in glut.h: void glutInit ( int argc, char **argv)


It initializes GLUT. Any command line arguments from main are passed in and can be used by the application.

void glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH)
It requests a display with the properties in mode. It specifies RGB color model, a depth buffer for hidden-surface removal, and double buffer.

void glutInitWindowSize(int width,int height)


It specifies the initial height and width of the window in pixels.

void glutInitCreateWindow(char * string)


It creates a window with an opengl context. String can be used to label the window. It returns a unique identifier for the new window, that can be used when there are multiple windows.

void glutReshapeFunc(void *f(int width,int height)) It registers the reshape callback function f. It indicates what actions should be
taken when window is resized. The callback function returns the height and width of the new window in pixels.

void glutDisplayFunc(void (*func)(void)) It registers the display callback function func that is executed when the window
needs to be redrawn. We should put all the routines we need to redraw the scene in the display callback function.

void glutKeyboardFunc(void *f(unsigned char key, int x,int y))

Dept. of CSE, SCE

Page 7

Gear system

It registers the keyboard callback function f. The callback function returns the ASCII code of key pressed and the position of the mouse relative to top-left corner of the window.

void glutSpecialFunc(void *f(int key,int x,int y))


It registers the special key callback function f. The callback function returns the ASCII code of special key pressed(all four arrows, page up & down, Home, Insert, End Keys etc.) and the position of the mouse relative to top-left corner of the window.

void glutCreateMenu(void (*f)( int value))


It returns an identifier for a top-level menu and register the callback function f that returns an integer value corresponding to the menus entry selected.

void glutAddMenuEntry(char *name, int value)


It adds an entry with the string name displayed to the current menu, value is returned to the menu callback when the entry is selected.

void glutAddSubMenu(char *name, int value)


It adds an submenu entry with the string name displayed to the current menu, value is returned to the menu callback when the submenu was created.

void glutAttachMenu(int button)


It attaches the current menu to the specified mouse button.

void glutIdleFunc(void (*func)(void)) It registers the display callback function func that is executed whenever there are
no other events to be handled.

void glutMainLoop(*) It cause the program to enter an event-processing loop.It should be the last stamen
in main.

void glutSwapBuffers( )
Swaps the front and back buffers. The front buffer is always the one displayed,whereas the back buffer is the one into which we draw.

void glutPostRedisplay( )
It requests that the display callback be executed after the current call back returns.

void glutBitmapCharacter(void *font, int character)


It renders the character with ASCII code char at the current raster position using the raster font given by font.Fonts include GLUT_BITMAP_HELVETICA_12.
Dept. of CSE, SCE Page 8

Gear system

Built in Functions in gl.h: void glEnable(GLenum feature)


It enables an OpenGL feature like GL_LIGHT0, GL_DEPTH_TEST etc. GL_TEXTURE_2D, GL_LIGHTING,

void glDisable(GLenum feature)


It disablesanOpenGLfeature,like GL_TEXTURE_2D, GL_LIGHT0, GL_DEPTH_TEST etc. GL_LIGHTING,

void glBegin (GLenum mode)


It initiates a new primitive of typr mode and starts the collection of vertices. Values of mode include GL_QUADS,GL_LINES,GL_POLYGON.

void glEnd (void)


It terminates the list of vertices.

void glColor[34][b i f d ubui ]v(TYPE *color)


It sets the present RGB (or RGBA) colors. Valid types are byte (b), int (i), float (f), double (d), unsigned byte (ub), unsigned short (us), unsigned int (ui). The maximum & minimum values of the floating-point types are 1.0 and 0.0, respectively.

void glVertex[234][s i f d]v(TYPE *coordinates)


It specifies the position of a vertex in 2, 3, or 4 dimensions. The coordinates can be specified as short(s), int (i), float (f) or double (d).If the v is present, the argument is a pointer to an array containing the coordinates.

void glRasterPos[234][sifd]v(GLfloat x, GLfloat y)


It specifies the raster position. The parameters are the same as for glvertex.

void glMaterial[if]v GLfloat*params)

(GLenum

face,

GLenumpname,const
for face

It sets parameter pname (GL_FRONT,GL_BACK,GL_FRONT_AND_BACK) It sets scalar and vector parameter pname for light source light.

void glLight[if]v (GLenum light, GLenumpname, constGLfloat *params) void glLineWidth (GLfloat width)
It sets the width of the line attribute in pixels.
Dept. of CSE, SCE Page 9

Gear system

void glPointSize (GLfloat width)


It sets the point size attribute in pixels.

void glPushMatrix() & void glPopMatrix( )


It pushes to and pops from the matrix stack corresponding to the current matrix mode.

void glRotate[fd](TYPE angle,TYPE dx, TYPEdy, TYPEdz)


It alters the current matrix by a rotation of angle degrees about the axis(dx,dy,dz). TYPE is either GLfloat or GLdouble.

void glTranslate[fd] (TYPE x, TYPE y, TYPE z)


It alters the current matrix by a displacement of (x,y,z). TYPE is either GLfloat or GLdouble.

void glScale[fd](TYPE angle,TYPE dx, TYPEdy, TYPEdz)


It alters the current matrix by a scaling of (dx,dy,dz). TYPE is either GLfloat or GLdouble.

void glShadeModel (GLenum mode) It specifies the mode (GL_SMOOTH or GL_FLAT).


void glViewport(intx,inty,GLsizei width, GLsizei height) It specifies a widthheight viewport in pixels whose lower-left corner is at (x,y) measured from the origin of the window.

void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
It sets the present RGBA clear color used when clearing the color buffer.variablesof GLclampf are floating point numbers b/w 0.0 and 1.0.

void glClear (GLbitfield mask)


It clears the pixels.

void glClearDepth (GLclampd depth)


It sets the depth buffer. void glDepthFunc (GLenumfunc) It selects the type of depth test to do.

void glHint (GLenum target, GLenum mode)


Dept. of CSE, SCE Page 10

Gear system

It performs the nice perspective calculation.

void glMatrixMode (GLenum mode)


It specifies which matrix will be affected by subsequent transformation,mode GL_MODELVIEW,GL_PROJECTION or GL_TEXTURE.

void glLoadIdentity (void)


It sets the current transformation matrix to an 4 X 4 Identitymatrix.

void glNewList() void glRect[sifd](GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
It specifies a two dimension axis aligned rectangle by the x,y coordinates of the diagonally opposite vertices in the standard data types. Void glCallList()

Built in Functions in glu.h: void gluPerspective ( GLdoublefovy, GLdoublezNear, GLdoublezFar)

GLdouble

aspect,

It defines a perspective viewing volume using the y direction field of view fov measured in degrees, the aspect ratio of the front clipping plane, and the near and far distances.

Description of <Windows.h>header file


Here this header file <Windows.h> includes the standard commands that help us in showing message box in our project.

intMessageBox(HWND hWnd, LPCWSTR lpText,LPCWSTRlpCaption,UINT uType)


It returns the message box id. lpText refers contents of the message box. lpCaption refers the title of the message box. uType refers the type of icon aswellas type of button.

User Defined Functions: void main(int argc, char *argv[ ]): The program starts its execution from this
function, and this function calls all the user defined and graphical functions.

Dept. of CSE, SCE

Page 11

Gear system

static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat

width,GLint teeth, GLfloat tooth_depth) : To build the spur gear wheels.

void front_screen() :To draw the front screen.

static void idle(void) : To compute the angle of rotation of the three gears. static void display(void) : To display the final output. static void key(unsigned char k, int x, int y): This function is used to provide all the keyboard functionalities to the user and the appropriate response to each keystroke is rendered appropriately. static void special(int k, int x, int y) : This function is used to specify all the functions associated with the special keys. void menu(int item):This function is used to perform menu options. void demo_gear(): This function is used to make the demo gears.

Dept. of CSE, SCE

Page 12

Gear system

SOURCE CODE
/* gears.c */ #include <math.h> #include <stdlib.h> #include<GL/glut.h> # include<Windows.h> int pause=1,direction=0,start=0,light=0; #define M_PI 3.14159265 /** It will draw a Spur gear wheel. Input: inner_radius - radius of hole at center outer_radius - radius at center of teeth width - width of gear teeth - number of teeth tooth_depth - depth of tooth **/ static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,GLint teeth, GLfloat tooth_depth) { GLint i; GLfloat r0, r1, r2; GLfloat angle, da; GLfloat u, v, len; r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0; r2 = outer_radius + tooth_depth / 2.0; da = 2.0 * M_PI / teeth / 4.0; glNormal3f(0.0, 0.0, 1.0); /* draw front face */ glBegin(GL_QUAD_STRIP);
Dept. of CSE, SCE Page 13

Gear system

for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } glEnd(); /* draw front sides of teeth */ glBegin(GL_QUADS); da = 2.0 * M_PI / teeth / 4.0; for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } glEnd(); glNormal3f(0.0, 0.0, -1.0); /* draw back face */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); } glEnd(); /* draw back sides of teeth */ glBegin(GL_QUADS); da = 2.0 * M_PI / teeth / 4.0; for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
Dept. of CSE, SCE Page 14

Gear system

glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); } glEnd(); /* draw outward faces of teeth */ glBegin(GL_QUAD_STRIP); for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); u = r2 * cos(angle + da) - r1 * cos(angle); v = r2 * sin(angle + da) - r1 * sin(angle); len = sqrt(u * u + v * v); u /= len; v /= len; glNormal3f(v, -u, 0.0); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); glNormal3f(cos(angle), sin(angle), 0.0); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); glNormal3f(v, -u, 0.0); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glNormal3f(cos(angle), sin(angle), 0.0); } glVertex3f(r1 , 0, width * 0.5); glVertex3f(r1, 0, -width * 0.5); glEnd(); glShadeModel(GL_SMOOTH); /* draw inside radius cylinder */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glNormal3f(-cos(angle), -sin(angle), 0.0);
Dept. of CSE, SCE Page 15

Gear system

glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); } glEnd(); } void Display_on_screen(char *string) { while(*string) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *string++); } void Display_on(char *string) { while(*string) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *string++); } void end_screen() { glColor3f(1.0, 0.5, 0.5); glRasterPos3f(-6.0,0.0,-5.0); Display_on("THANK YOU !"); glColor3f(1, 1, 1); glRasterPos3f(-3.5,-1.4,-5.0); Display_on_screen("Press ESC to exit"); glColor3f(1, 1, 1); glRasterPos2f(10.0,15.0); Display_on_screen("<<<< ENTER"); glBegin(GL_LINE_LOOP); glColor3f(0.0,0.75,0.75); glVertex3f(-6.0,-0.5,-5.0); glVertex3f(6.0,-0.5,-5.0); glEnd(); } void front_screen() { glColor3f(.1, 0.2, 1); glLineWidth(2.0); glBegin(GL_LINE_LOOP); glVertex2f(-10.0,6.0); glVertex2f(10.0,6.0); glVertex2f(10.0,-4.0); glVertex2f(-10.0,-4.0); glEnd();
Dept. of CSE, SCE Page 16

Gear system

glColor3f(.13, 0.25, 1); glRasterPos2f(-3.5,4.0); Display_on_screen("CREATED BY :-"); glRasterPos2f(-7.0,1.0); Display_on_screen("SANDEEP KUMAR 1SG08CS060"); glRasterPos2f(-7.0,0.0); Display_on_screen(" SANJAY KUMAR 1SG08CS064"); glRasterPos2f(-9.0,-2.0); Display_on_screen("OPENGL PROJECT ON :-"); glRasterPos2f(2.0,-2.0); Display_on_screen("GEAR SYSTEM"); //prints top message glColor3f(1.0,0.0,1.0); glRasterPos2f(-5.0,-6.2); Display_on_screen("Press ENTER to continue :"); // Prints bottom message glColor3f(.7, 0.7, 0.9); glRasterPos2f(-15.0,-15.0); Display_on_screen("@Copyright under ISO 2011 "); glRasterPos2f(-15.0,-16.0); Display_on_screen(" All rights reserved by SCE. "); }

static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLint gear1, gear2, gear3; static GLfloat angle = 0.0; static GLuint limit; static GLuint count = 1; static void idle(void) { if(direction==0) { angle += 20.0; if(angle>360.0) angle=0.0; } else { angle-=20.0; if(angle<-360.0) angle=0.0;
Dept. of CSE, SCE Page 17

Gear system

} glutPostRedisplay(); } int ang; void demo_spin() { ang-=5.0; glutPostRedisplay(); } void demo_gear() { GLint i; GLfloat r0, r1, r2; GLfloat angle, da; GLfloat inner_radius=0.5; GLfloat outer_radius=2.0; GLfloat width=0; GLint teeth=15; GLfloat tooth_depth=0.7; r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0; r2 = outer_radius + tooth_depth / 2.0; da = 2.0 * M_PI / teeth / 4.0; glNormal3f(0.0, 0.0, 1.0); /* draw front face */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } glEnd(); /* draw front sides of teeth */ glBegin(GL_QUADS); da = 2.0 * M_PI / teeth / 4.0;
Dept. of CSE, SCE Page 18

Gear system

for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } glEnd(); glNormal3f(0.0, 0.0, -1.0);

} static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(start==0) { front_screen(); glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(7.0,-7.0,-5.0); glRotatef(ang,0.0,0.0,1.0); demo_gear(); glutIdleFunc(demo_spin); glPopMatrix(); } else if(start==1) { glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(-9.0,0.0,-5.0); glRotatef(ang,0.0,0.0,1.0); demo_gear(); glPopMatrix(); glPushMatrix(); glColor3f(0.0,0.5,0.8); glTranslatef(9.0,0.0,-5.0); glRotatef(-ang,0.0,0.0,1.0); demo_gear(); glPopMatrix();

Dept. of CSE, SCE

Page 19

Gear system

glutIdleFunc(demo_spin); end_screen(); } else { if(light) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); glPushMatrix(); glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_rotz, 0.0, 0.0, 1.0); glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(angle, 0.0, 0.0, 1.0); glCallList(gear1); glPopMatrix(); glPushMatrix(); glTranslatef(5.0, -2.0, 0.0); glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); glCallList(gear2); glPopMatrix(); glPushMatrix(); glTranslatef(-8.4, 4.2, 0.0); glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); glCallList(gear3); glPopMatrix(); glPopMatrix(); if(pause) glutIdleFunc(idle); else glutIdleFunc(NULL); } glutSwapBuffers(); } void main_menu(int); /* change view angle, exit upon ESC */ /* ARGSUSED1 */
Dept. of CSE, SCE Page 20

Gear system

static void key(unsigned char k, int x, int y) { switch (k) { case 'P': case 'p':main_menu(3); break; case 'd': case 'D':main_menu(4); break; case 'l': case 'L':main_menu(5); break; case 13: start=4; break; case 27:/* Escape */ exit(0); break; } glutPostRedisplay(); } /* change view angle */ static void special(int k, int x, int y) { switch (k) { case GLUT_KEY_RIGHT: view_roty += 5.0; break; case GLUT_KEY_LEFT: view_roty -= 5.0; break; case GLUT_KEY_DOWN: view_rotx -= 5.0; break; case GLUT_KEY_UP: view_rotx += 5.0; break; case GLUT_KEY_PAGE_UP: view_rotz += 5.0; break; case GLUT_KEY_PAGE_DOWN:
Dept. of CSE, SCE Page 21

Gear system

view_rotz -= 5.0; break; default: return; } glutPostRedisplay(); } /* new window size or exposure */ static void reshape(int width, int height) { glViewport(0,0,width,height); float aspect_ratio = (float)width/ (float)height; glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix gluPerspective(45.0f, aspect_ratio, 0.1, 90.0); // Calculate The Aspect Ratio Of The Window glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); glTranslatef(0.0, 0.0, -40.0); } static void init(void) { static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0}; static GLfloat red[4] = {0.8, 0.1, 0.0, 0.70}; static GLfloat green[4] = {0.0, 0.8, 0.2, .70}; static GLfloat blue[4] = {0.2, 0.2, 1.0, .70}; glShadeModel(GL_SMOOTH); // Set Smooth Shading glClearColor(0.0, 0.0, 0.2, 0.0); // BackGround Color glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

glEnable(GL_DEPTH_TEST);

/* make the gears */


Dept. of CSE, SCE Page 22

Gear system

gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glColor3fv(red); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0, 6.0, 2.0,20,0.7); glEndList(); gear2 = glGenLists(1); glNewList(gear2, GL_COMPILE); glColor3fv(green); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); gear(0.5, 2.0, 2.0, 10, 0.7); glEndList(); gear3 = glGenLists(1); glNewList(gear3, GL_COMPILE); glColor3fv(blue); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); gear(1.3, 2.0, 1.5, 10, 0.7); glEndList(); glEnable(GL_NORMALIZE); } void main_menu(int index) { int msgboxId; switch(index) { case 1:msgboxId=MessageBox(NULL,(LPCWSTR)L"Gear Syatem Program\tVersion: 1.0.0\nAuthor:Sandeep & Sanjay\nFor Suggestion,Queries and Comments,\n Mail to sanjay_kumar_2009@yahoo.in", (LPCWSTR)L"About Gear Syatem",MB_ICONINFORMATION | MB_OK); break; case 2:glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); start=1; break; case 3:if(pause) pause=0; else pause=1; break;
Dept. of CSE, SCE Page 23

Gear system

case 4: pause=1; if(direction) direction=0; else direction=1; break; case 5: glEnable(GL_LIGHT0); if(light) light=0; else light=1; break; } glutPostRedisplay(); } void main_menu_1(int index) { switch (index) { case 1: view_roty += 5.0; break; case 2: view_roty -= 5.0; break; case 3: view_rotx -= 5.0; break; case 4: view_rotx += 5.0; break; case 5: view_rotz += 5.0; break; case 6: view_rotz -= 5.0; break; } glutPostRedisplay(); } void main(int argc, char *argv[]) { int glut_menu[2]; glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
Dept. of CSE, SCE Page 24

Gear system

glutInitWindowSize(500,500); glutCreateWindow("Gears"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutSpecialFunc(special); glut_menu[1] = glutCreateMenu(main_menu_1); glutAddMenuEntry("+y axis : up arrow", 1); glutAddMenuEntry("-y axis: down arrow", 2); glutAddMenuEntry("-x axis : left arrow", 3); glutAddMenuEntry("+x axis : right arrow", 4); glutAddMenuEntry("+z axis : pg up", 5); glutAddMenuEntry("-z axis : pg down", 6); glut_menu[0] = glutCreateMenu(NULL); glutAddSubMenu("View along", glut_menu[1]); glutCreateMenu(main_menu); glutAddMenuEntry("Pause/Play (p)", 3); glutAddMenuEntry("Toggle Direction (d)", 4); glutAddMenuEntry("Toggle Lighting (l)", 5); glutAddMenuEntry("About",1); glutAddSubMenu("Help ?", glut_menu[0]); glutAddMenuEntry("Exit",2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); }

Dept. of CSE, SCE

Page 25

Gear system

SNAPSHOTS

Output: First Screen

Output: Three rotating Spur Gears


Dept. of CSE, SCE Page 26

Gear system

Output: Rotating Spur gears with light effect

Output: Rotating Spur gears without light effect

Dept. of CSE, SCE

Page 27

Gear system

Output: Showing the About Message Box

Output: Showing the Help Menu


Dept. of CSE, SCE Page 28

Gear system

Output: Exit Screen

Dept. of CSE, SCE

Page 29

Gear system

TESTING What is Testing?


Testing in general means validation and verification. It shows that the system conforms to its specifications and system meets all expectation of the user. It involves 5 different kind of testing.

7. TEST CASES
7.1 TEST CASE FOR MENU OPTION Sl Test case No. Description
1.

Expected Result

Actual Result Remarks


Menu with Pause/Play Toggle Direction Toggle Light Help for View along Pass

Right click the Menu with mouse button on the display Pause/Play Toggle Direction screen Toggle Light Help for View along About Exit Click on Pause/Play The entire gear system should stop rotating and when clicked again it should start rotating. The gears should start rotating in the opposite direction.

2.

The spur gears are paused and when clicked again they start rotating.

Pass

3.

Click on Toggle Direction

The gears start rotating in the opposite direction.

Pass

4.

Click on Toggle Light

The Light source The Light source is must be switched switched on or off on and off using using this button. this button.

Pass

Dept. of CSE, SCE

Page 30

Gear system

5.

Click on About

Should give Gives information information about the about the project. project.

Pass

6.

Click on Help View Along

The direction to be The direction to change changed for view the view is specified. along it, must be specified. The output window The output should exit. exits. window

Pass

7.

Click on Exit

Pass

7.2 TEST CASE FOR KEYBOARD OPTION SL No.


1.

Test case Description


Press key enter on the initial display screen

Expected Result

Actual Result Remarks


Pass

The main output The main screen screen must on which the appear. output is seen appears.

2.

Press key L or l

The light source The Light source must turn ON turns ON and and OFF. OFF. The entire gear The entire gear system must system pauses pause and play. and plays on alternate press. The direction of The direction of rotation of all the rotation of the gears must gears changes.

Pass

3.

Press key P or p

Pass

4.

Press D or d key

Pass

Dept. of CSE, SCE

Page 31

Gear system

change.

5.

Press UP and DOWN key

TO rotate the entire view of the system along positive and negative Y axis.

The entire view is rotated along the positive and negative y axis.

Pass

6.

Press RIGHT and LEFT key

The entire view The entire view must rotate in the rotates along the positive and desired axis. negative X axis. The entire view must rotate in the positive and negative Z axis. The entire view rotates in the positive and negative Z axis.

Pass

7.

Press PAGE UP and PAGE DOWN key

Pass

Dept. of CSE, SCE

Page 32

Gear system

CONCLUSION
We had a great experience in the course of designing this package, which made us discover and learn many things as, pertaining to the topic of OpenGL programming. We have tried to our best potential to incorporate all the basic level requirements of a normal graphics package for Windows operating system.

This is very reliable graphics package supporting various primitive objects like quadrilateral, line, point, line loop etc. Also menu based interfaces are included. Transformation like translation, rotations& scaling are also provided. It also includes basic texture effect, lighting effect as per our concern.

Owing to certain constraints we could not incorporate all the tasks that a graphics package should perform. However it meets the basic requirements of user successfully. Since its user friendly it enables the user to interact effectively and easily.

This package has been implemented using optimized algorithms and thus is fast. Special attention has been provided to the keyboard and mouse interfaces, menus and submenus that make its use comfortable. I hope this package proves to be flexible in all respects to one and all.

Dept. of CSE, SCE

Page 33

Gear system

FUTURE ENHANCEMENT
This project has been designed using C++, which works on the Windows platform. The project can be designed using other languages and better graphical interfaces. The following features can be incorporated

To provide a more realistic look to the arrangement. More color options according to the users choice and texture can also be introduced To show the various fields where the spur gears find their application like in watches, automobiles etc. We will provide button interface to make more user interactive.

Dept. of CSE, SCE

Page 34

Gear system

BIBLIOGRAPHY
BOOKS
1) Edward Angel, Education,2005 Interactive Computer Graphics,5th edition, Pearson

2) Jackie L. Neider, Mark Warhol, Tom R. Davies, OpenGL Red Book, 2nd Revised Edition,2005 3) Donald D Hearn and M. Pauline Baker, Computer Graphics with OpenGL,3rd edition. 4) F.S.Hill and Stephen M.Kelly, Computer Graphics using OpenGl ,3rd edition

WEBSITES: 1) http://www.opengl.org
2) http://www.wikipedia.com
3) http://basic4gl.wikispaces.com 4) http://www.geometer.org/gear

Dept. of CSE, SCE

Page 35