Simulation of A Lift
Simulation of A Lift
BELAGAVI- 590018
“SIMULATION OF A LIFT”
Submitted by
MEGHA T.R 4RA18CS400
YASHASWINI.S 4RA18CS405
CERTIFICATE
Certified that the Mini project work entitled “STIMULATION OF A LIFT” is carried out by
Ms.MEGHA T.R [4RA18CS400] and Ms. YASHASWINI S [4RA18CS405] respectively, a
bonafide student of RAJEEV INSTITUTE OF TECHNOLOGY, Hassan in partial
fulfillment for the subject COMPUTER GRAPHICS AND VISUALIZATION in
COMPUTER SCIENCE AND ENGINEERING of Visvesvaraya Technological University,
Belagavi during the year 2019-2020. The Mini project report has been approved as it satisfies
the academic requirements in respect of mini project work prescribed for the said degree .
2.
ACKNOWLEDGEMENT
The satisfaction and euphoria that accompany the successful of any task would be incomplete
without the mention of the people who made it possible, whose constant guidance and
encouragement crowned our efforts with success.
We would like to profoundly thank our Management of RIT & our President Dr.Rajeev for
providing such a healthy environment.
We would like to express our sincere thanks to our principal Dr.A.N Ramakrishna, Rajeev
Institute of Technology for his encouragement.
We wish to express our gratitude to Dr.H.N Prakash, Head of the Department of CSE for
providing a good working environment and for his constant support and encouragement.
We would also like to thank all our staffs of Computer Science and Engineering department
who have directly or indirectly helped us in the successful completion of this project and also
we would like to thank our parents.
MEGHA T.R
YASHASWINI S
i
ABSTRACT
Computer Graphics is an interactive method of pictorial synthesis of real or imaginary objects
from their computer-based models. Another closely related term is the “image processing”
which is the analysis of scene or the reconstruction of the models of 2D or 3D from their
pictures. These are used in everyday life, be it a reply in a cricket match, advanced graphics
in movies or the daily weather report display on TV.
This application gives a detailed description about the implementation of the
“SIMULATION OF A LIFT “through an OpenGL program.The aim of the project is to
demonstrate Simulation of a lift. We demonstrate how a person can move to various floors of
a building using a lift having some interaction using mouse and keyboard. By pressing left
mouse button the door of the lift opens & the person enters into the lift on pressing the key
‘e’ ,the person moves to the first floor on pressing the middle mouse button, the person exits
the first floor on pressing the key ‘f’, the person moves to the second floor on pressing the
right mouse button, the person exits the second floor on pressing the key ‘s’, the person can
exit back to the ground floor on pressing the key ‘E’.
ii
CONTENTS
Acknowledgement i
Abstract ii
1 INTRODUCTION 1
1.1Introduction to open GL 2
1.2 Support Libraries 2
2 LITERATURE SURVEY 3
2.1 Open gl programming guide-The redbook 3
2.2 OpenGL Resources 4
4 SOFTWARE DESIGN 6
4.1 High level design 6
4.2 Algorithm 7
5 IMPLEMENTATION 8
5.1 Pseudo Code 8
5.2 Source Code 11
6 SCREENSHOTS 32
BIBILOGRAPHY 35
SIMULATION OF A LIFT
Chapter 1
INTRODUCTION
Computer graphics is concerned with all aspects of producing pictures or images using
a computer.
Here we use a particular graphics software system, OpenGL; which has become a widely
accepted standard for developing graphics applications.
The various applications of computer graphics include:
Display of information
Design
Simulation and animation
User interface
As a software interface for the graphics hardware, OpenGL’s main purpose is render two
and three dimensional objects into a frame buffer. These objects are described as sequences of
vertices (which define geometric objects) or pixels (which define images).OpenGL performs
several processing steps on this data to convert it to pixels of form the final desired images in the
frame buffer.
Features of OpenGL:
The main features of OpenGL are
It provides 3D geometric objects such as lines, polygons, triangles, meshes, spheres,
cubes, curved surfaces.
It provides 3D modeling transformations and viewing functions to create views of 3D
scenes using the idea of virtual camera.
It supports high quality rendering of scenes, including hidden surface removal, multiple
light sources, material types, transparency etc.
It provides display lists for creating graphics caches and hierarchical models.
It supports manipulation of images as pixels, enabling frame-buffer effects such as
anti-aliasing, motion blur, depth of field and soft shadows.
Chapter 2
LITERATURE SURVEY
A literature review or narrative review is a type of review article. A literature review is
a scholarly paper, which includes the current knowledge including substantive findings, as well
as theoretical and methodological contributions to a particular topic. Literature reviews
are secondary sources, and do not report new or original experimental work. Most often
associated with academic-oriented literature, such reviews are found in academic journals, and
are not to be confused with book reviews that may also appear in the same publication. Literature
reviews are a basis for research in nearly every academic field.[1] A narrow-scope literature
review may be included as part of a peer-reviewed journal article presenting new research,
serving to situate the current study within the body of the relevant literature and to provide
context for the reader. In such a case, the review usually precedes the methodology and results
sections of the work.
Chapter 3
REQUIREMENTS & SPECIFICATION
3.1 Software requirements
An MS-DOS based operating system like Windows 98, Windows 2000 or Windows XP
is the platform required to develop the 2D and 3D graphics applications.
A Visual C/C++ compiler is required for compiling the source code to make the
executable file which can then be directly executed.
A built in graphics library like glut and glut32, and header file like glut.h and also
dynamic link libraries like glut and glut32 are required for creating the 3D layout.
Chapter 4
SOFTWARE DESIGN
4.1 High level design
4.2 Algorithm
Step 1: Start
Step 2: [Create and Initialize the output window]
glutCreateWindow( ) function is called.
Step 3: [Output window consisting of initial setup of a building with 2 floors and having
a lift is displayed.]
The display( ) function is called.
Step 4: [Keyboard is used to interact with the user]
If "e" button is pressed then
glutKeyboardFunc( ) function gets called
then
man will enter the lift at the ground floor
Chapter 5
IMPLEMENTATION
5.1 Pseudo Code:
Important open gl functions used in our program:
1: Pseudo code to fill face:
glColor3ub(255,191,128);
glPushMatrix();
glTranslatef(270, 105, 0);
glutSolidTorus(7, 7, 100, 90);
glPopMatrix();
The above pseudo code is used to fill the face of the person.
The present colors are set to red, green and blue using glcolor3ub() function.
The solid torus is rendered using glutSolidTorus(7, 7, 100, 90); function;
3: To draw eyes
glBegin(GL_POLYGON);
glVertex2i(263,111);
glVertex2i(265,111);
glVertex2i(265,109);
glVertex2i(263,109);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(275,111);
glVertex2i(277,111);
glVertex2i(277,109);
glVertex2i(275,109);
glEnd();
glVertex2i(GLint x ,Glint y) functions are used in order to properly draw polygon
which is constructed using appropriate x and y co-ordinates to form a polygon at
the right place which resembles the eyes of the man.
In all the above function calls we see that polygon is constructed for x and y
co-ordinates sent as parameters to glVertex2i() function.
Similarly even shirts, pants, hands, buttons are also created by using glVertex2i()
functions.
4: To enter the ground floor
if(offset==0)
{
if(flag1==1||flag1==2||flag1==3)
{
glPushMatrix();
glTranslated(40,5,0);
scaleman();
glPopMatrix();
If the flag1 value is 1 or if flag1 is 2 or 3 then the person enters into the lift at the ground floor.
Now again translate function is called .again the man is scaled inside the lift using scaleman()
function.
5: To exit first floor
else if(offset==1)
{
glPushMatrix();
glTranslated(270,205,0);
glScaled(1.0,0.8,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
if the offset value is 1 then the man is in first floor and using above pseudo code the man can exit
first floor.
6: To Exit Second Floor
glPushMatrix();
glTranslated(270,300,0);
glScaled(1.0,0.7,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
if the offset value is other than 0 or 1 then the man is in second floor and using above pseudo
code the man can exit second floor.
7: To Control Movement of Man In and Out of lift
void keys(unsigned char key,int x,int y)
{
if(key=='e')
flag1=1;
if(key=='f')
flag1=2;
if(key=='s')
flag1=3;
if(key=='E')
flag1=4;
glFlush();
}
If the key pressesd is ‘e’ then flag1 is set to 1 and the man can enter into the lift.
If the key pressesd is ‘f’ then flag1 is set to 2 and the man can come out of lift in 1 st floor.
If the key pressesd is ‘s’ then flag1 is set to 3 and the man can come out of lift in second
floor.
If the key pressesd is ‘E’ then flag1 is set to 4 and the man can exit from the lift.
{
glColor3ub(0,0,0);
glPushMatrix();
glTranslatef(270,105,0);
glutSolidTorus(1,15,100,90);
glPopMatrix();
//fill face
glColor3ub(255,191,128);
glPushMatrix();
glTranslatef(270,105,0);
glutSolidTorus(7,7,100,90);
glPopMatrix();
//draw nose eyebrow
glColor3ub(0,0,0);
glBegin(GL_LINES);
glVertex2i(270,107);
glVertex2i(270,100);
glVertex2i(261,113);
glVertex2i(267,113);
glVertex2i(273,113);
glVertex2i(279,113);
glEnd();
// eyes
glBegin(GL_POLYGON);
glVertex2i(263,111);
glVertex2i(265,111);
glVertex2i(265,109);
glVertex2i(263,109);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(275,111);
glVertex2i(277,111);
glVertex2i(277,109);
glVertex2i(275,109);
glEnd();
// mouth
glBegin(GL_POLYGON);
glVertex2i(266,97);
glVertex2i(270,95);
glVertex2i(274,97);
glVertex2i(270,95);
glEnd();
//shirt
glBegin(GL_POLYGON);
glColor3ub(55,50,70);
glVertex2i(259,90);
glVertex2i(281,90);
glVertex2i(296,79);
glVertex2i(291,71);
glVertex2i(286,75);
glVertex2i(286,55);
glVertex2i(254,55);
glVertex2i(254,75);
glVertex2i(249,70);
glVertex2i(244,79);
glEnd();
//hands
glBegin(GL_POLYGON);
glColor3ub(255,191,128);
glVertex2i(295,78);
glVertex2i(305,63);
glVertex2i(297,64);
glVertex2i(292,72);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(305,63);
glVertex2i(286,48);
glVertex2i(286,55);
glVertex2i(297,64);
glEnd();
//hands2
glBegin(GL_POLYGON);
glVertex2i(245,78);
glVertex2i(235,63);
glVertex2i(243,64);
glVertex2i(248,72);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(235,63);
glVertex2i(254,48);
glVertex2i(254,55);
glVertex2i(243,64);
glEnd();
// belt
glBegin(GL_POLYGON);
glColor3ub(100,120,130);
glVertex2i(286,55);
glVertex2i(254,55);
glVertex2i(254,50);
glVertex2i(286,50);
glEnd();
// collar
glBegin(GL_POLYGON);
glColor3ub(200,140,110);
glVertex2i(259,90);
glVertex2i(281,90);
glVertex2i(276,80);
glVertex2i(264,80);
glEnd();
glBegin(GL_TRIANGLES);
glColor3ub(20,140,110);
glVertex2i(270,87);
glVertex2i(275,80);
glVertex2i(265,80);
glEnd();
// buttons
glColor3ub(0,0,0);
glPushMatrix();
glTranslatef(270,75,0);
glutSolidTorus(1,1,100,90);
glPopMatrix();
glPushMatrix();
glTranslatef(270,68,0);
glutSolidTorus(1,1,100,90);
glPopMatrix();
glPushMatrix();
glTranslatef(270,61,0);
glutSolidTorus(1,1,100,90);
glPopMatrix();
// pant
glBegin(GL_POLYGON);
glColor3ub(10,10,10);
glVertex2i(285,50);
glVertex2i(254,50);
glVertex2i(250,15);
glVertex2i(260,15);
glVertex2i(263,48);
glVertex2i(280,15);
glVertex2i(290,15);
glEnd();
}
glVertex3iv(vertices[d]);
glEnd();
}
glBegin(GL_POLYGON);//2nd door
glVertex3iv(d[4]);
glVertex3iv(d[5]);
glVertex3iv(d[6]);
glVertex3iv(d[7]);
glEnd();
}
//to draw opened lift door
void liftdoor(int k)
{
GLint
d[][3]={{290,55+off[k],0},{290,130+off[k],0},{309,130+off[k],0},{309,55+off[k],0},{310,55+
off[k],0},{310,130+off[k],0},{330,130+off[k],0},{330,55+off[k],0}};
glColor3f(0.0,0.25,0.25);
glPushMatrix();
glTranslatef(290.0,55.0,0.0);
glScaled(0.2,1.0,0.0);
glTranslatef(-290.0,-55.0,0.0);
glBegin(GL_POLYGON);
glVertex3iv(d[0]);
glVertex3iv(d[1]);
glVertex3iv(d[2]);
glVertex3iv(d[3]);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(330.0,55.0,0.0);
glScaled(0.2,1.0,0.0);
glTranslatef(-330.0,-55.0,0.0);
glBegin(GL_POLYGON);
glVertex3iv(d[4]);
glVertex3iv(d[5]);
glVertex3iv(d[6]);
glVertex3iv(d[7]);
glEnd();
glPopMatrix();
glutPostRedisplay();
}
}
else if(offset==1)//to exit first floor
{
glPushMatrix();
glTranslated(270,205,0);
glScaled(1.0,0.8,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
else //to exit 2nd floor
{
glPushMatrix();
glTranslated(270,300,0);
glScaled(1.0,0.7,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
glutPostRedisplay();
}
//keyboard function
void keys(unsigned char key,int x,int y)
{
if(key=='e')//enter
flag1=1;
if(key=='f')//exit 1st floor
flag1=2;
if(key=='s')//exit 2nd floor
flag1=3;
if(key=='E')//exit
flag1=4;
glFlush();
}
//mouse function
void mouse(int btn,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)//ground floor
{
flag=1;
liftdoor(0);
}
if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)//first floor
{
flag=2;
liftdoor(1);
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)//second floor
{
flag=3;
liftdoor(2);
}
glFlush();
}
0},{143,80+off[i],0},{143,100+off[i],0},{133,80+off[i],0},{143,120+off[i],0},{133,120+off[i],0
}};//curtains
GLint
door[][3]={{160,55+off[i],0},{160,140+off[i],0},{220,140+off[i],0},{220,55+off[i],0},{170,70
+off[i],0},{205,70+off[i],0}};//door
GLint
wind[][3]={{83,80+off[i],0},{83,120+off[i],0},{143,120+off[i],0},{143,80+off[i],0},{100,80+o
ff[i],0},{100,120+off[i],0}};//window
GLint
shut[][3]={{160,55+off[i],0},{160,140+off[i],0},{170,125+off[i],0},{170,65+off[i],0},{205,65+
off[i],0},{205,125+off[i],0},{220,140+off[i],0},{220,55+off[i],0}};//door shutters
//door
glColor3f(0.79,0.90,0.0);
//modified
drawface(door[0],door[1],door[2],door[3]);
glColor3f(0.84,0.84,0.74);
drawface(door[0],door[4],door[5],door[3]);
glColor3f(0.25,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex3iv(door[0]);
glVertex3iv(door[1]);
glVertex3iv(door[2]);
glVertex3iv(door[3]);
glEnd();
//door shutters
glBegin(GL_POLYGON);
glVertex3iv(shut[0]);
glVertex3iv(shut[1]);
glVertex3iv(shut[2]);
glVertex3iv(shut[3]);
glEnd();
glBegin(GL_POLYGON);
glVertex3iv(shut[4]);
glVertex3iv(shut[5]);
glVertex3iv(shut[6]);
glVertex3iv(shut[7]);
glEnd();
//windows
glColor3f(0.79,0.90,0.0);
//glColor3f(0.95,0.9,0.9);
drawface(wind[4],wind[5],wind[2],wind[3]);
drawface(wind[0],wind[1],wind[5],wind[4]);
glColor3f(0.82,0.6,1.0);
//modified
//glColor3f(0.64,0.64,0.54);
//curtains
glBegin(GL_POLYGON);
glVertex3iv(cur[1]);
glVertex3iv(cur[2]);
glVertex3iv(cur[3]);
glEnd();
glBegin(GL_POLYGON);
glVertex3iv(cur[0]);
glVertex3iv(cur[1]);
glVertex3iv(cur[4]);
glEnd();
glBegin(GL_POLYGON);
glVertex3iv(cur[5]);
glVertex3iv(cur[6]);
glVertex3iv(cur[7]);
glEnd();
glBegin(GL_POLYGON);
glVertex3iv(cur[6]);
glVertex3iv(cur[8]);
glVertex3iv(cur[9]);
glEnd();
for(k=0;k<3;k++)//window separaters
{
for(j=0;j<3;j++)
{
int s[]={0,20,40};
glColor3f(0.25,0.0,0.0);
glPointSize(5.0);
glBegin(GL_LINE_LOOP);
glVertex3i(83+s[j],80+off[k],0);
glVertex3i(83+s[j],120+off[k],0);
glVertex3i(103+s[j],120+off[k],0);
glVertex3i(103+s[j],80+off[k],0);
glEnd();
}
}
}
}
[k],0},{100,170+off[k],0},{400,170+off[k],0},{400,70+off[k],0}};//wall
GLint
c[][3]={{50,154+off[k],0},{50,170+off[k],0},{375,170+off[k],0},{375,154+off[k],0},{85,175+
off[k],0},{85,190+off[k],0},{410,190+off[k],0},{410,175+off[k],0}};//grills
GLint
l[][3]={{285,55+off[k],0},{335,55+off[k],0},{335,155+off[k],0},{285,155+off[k],0}};//lift
back-ground
GLint
bg[][3]={{290,55+off[k],0},{290,130+off[k],0},{330,130+off[k],0},{330,55+off[k],0},{300,65
+off[k],0},{300,130+off[k],0},{320,130+off[k],0},{320,65+off[k],0}};//lift door back-ground
glColor3f(0.0,0.5,0.5);
drawface(w[0],w[4],w[7],w[3]);
drawface(w[5],w[4],w[7],w[6]);
drawface(w[1],w[5],w[4],w[0]);
glColor3f(0.0,0.4,0.4);
drawface(w[2],w[6],w[7],w[3]);
glColor3f(0.0,0.5,0.5);
drawface(w[0],w[1],w[2],w[3]);
glColor3f(0.6,0.6,0.6);
drawface(w[1],w[5],w[6],w[2]);
drawface(c[0],c[4],c[7],c[3]);
glColor3f(0.29,0.29,0.0);
drawface(c[5],c[4],c[7],c[6]);
drawface(c[1],c[5],c[4],c[0]);
glColor3f(0.5,0.0,0.5);
drawface(l[0],l[1],l[2],l[3]);
glColor3f(0.3,0.3,0.3);
drawface(bg[0],bg[1],bg[5],bg[4]);
glColor3f(0.42,0.42,0.42);
drawface(bg[5],bg[4],bg[7],bg[6]);
glColor3f(0.5,0.5,0.5);
drawface(bg[6],bg[7],bg[3],bg[2]);
glColor3f(0.6,0.6,0.6);
drawface(bg[0],bg[4],bg[7],bg[3]);
}
ground();
}
polygon(12,13,14,15);
polygon(16,17,18,19);
polygon(15,14,18,19);
polygon(13,14,18,17);
polygon(20,21,22,23);
polygon(24,25,26,27);
polygon(20,21,25,24);
polygon(21,22,26,25);
}
void init(void)
{
glClearColor(0.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
glEnd();
}
entry(0);
}
else if(flag1==2||flag1==3)
entry(0);
else if(flag1==4)//when 'E' is pressed
{
entry(0);
lift(0);
}
else
{
glPushMatrix();
glTranslated(270,105,0);
scaleman();
glPopMatrix();
}
lift(1);
lift(2);
}
else if(flag==2)//executed when the middle mouse button is clicked
{
liftdoor(1);
if(flag1==2)//when 'f' is pressed
{
entry(1);
lift(1);
}
else
{
glPushMatrix();
glTranslated(310,205,0);
glScaled(1.0,0.8,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
lift(0);
lift(2);
}
else if(flag==3)//executed when the right mouse button is clicked
{
liftdoor(2);
if(flag1==3)//when 's' is pressed
{
entry(2);
lift(2);
}
else
{
glPushMatrix();
glTranslated(310,300,0);
glScaled(1.0,0.7,0);
glTranslated(-270,-105,0);
scaleman();
glPopMatrix();
}
lift(0);
lift(1);
}
else//when no mouse interaction
{
lift(0);
lift(1);
lift(2);
}
if(flag1==0)//when no keyboard interaction
scaleman();
grill();
glFlush();
}
//main method
void main(int argc,char**argv)
{
printf("Click left mouse button to open the lift\n");
printf("Press 'e' to enter the lift\n");
printf("Click middle mouse button to go to the first floor\n");
printf("Press 'f' to exit at first floor\n");
printf("Click right mouse button to go to the second floor\n");
printf("Press 's' to exit at second floor\n");
printf("Press 'E' to exit at ground floor\n");
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(500,500);
glutCreateWindow("THE ELEVATOR");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keys);
glutMainLoop();
}
Chapter 6
SCREENSHOTS
When we press the key ‘e’, the person enters into the lift at ground floor.
BIBLIOGRAPHY
[1] Computer Graphics Using OpenGL – F.S. Hill, Jr. 2nd Edition.
[2] Computer Graphics - OpenGL Version – Donald Hearn and Pauline Baker, 2 nd
Edition.
[3] OpenGL –A primer by Edward Angel, 3rd Edition.
[4] http://www.opengl.org/
[5] http://www.codecolony.de/opengl
[6] http://www.wikipedia.org/opengl