100% found this document useful (1 vote)
587 views40 pages

Simulation of A Lift

This document describes a mini project report on simulating a lift. The project was submitted by two students, Megha T.R. and Yashaswini S., to Visvesvaraya Technological University in partial fulfillment of their computer graphics and visualization course. The project was guided by Renuka Chalavadi of the Computer Science department at Rajeev Institute of Technology in Hassan. The project involved simulating the movement of a person between floors of a building using a lift, with interactions using mouse and keyboard buttons.

Uploaded by

Nandita Iyer
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
100% found this document useful (1 vote)
587 views40 pages

Simulation of A Lift

This document describes a mini project report on simulating a lift. The project was submitted by two students, Megha T.R. and Yashaswini S., to Visvesvaraya Technological University in partial fulfillment of their computer graphics and visualization course. The project was guided by Renuka Chalavadi of the Computer Science department at Rajeev Institute of Technology in Hassan. The project involved simulating the movement of a person between floors of a building using a lift, with interactions using mouse and keyboard buttons.

Uploaded by

Nandita Iyer
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/ 40

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELAGAVI- 590018

A mini Project Report on

“SIMULATION OF A LIFT”

Submitted by
MEGHA T.R 4RA18CS400
YASHASWINI.S 4RA18CS405

To the Visvesvaraya Technological University during the academic year 2018-2019


in partial fulfillment for the subject

COMPUTER GRAPHICS AND VISUALIZATION


(VI SEMESTER)
in
COMPUTER SCIENCE AND ENGINEERING

Under the Guidance of


Ms. Renuka Chalavadi
Assistant Professor,
Department of Computer Science & Engineering
Rajeev Institute of Technology
Hassan.

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


RAJEEV INSTITUTE OF TECHNOLOGY
HASSAN-573201
2019-2020
RAJEEV INSTITUTE OF TECHNOLOGY,
HASSAN
(Approved by AICTE, New Delhi and Affiliated to VTU, Belagavi.)
Plot # 1-D, Growth Center, Industrial Area, B-M Bypass Road, Hassan-573201
Ph: (08172)-243180/80/84 Fax: (08172)-243183

Department of Computer Science &Engineering

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 .

Ms RENUKA CHALAVADI Dr. H.N PRAKASH Dr. A.N RAMAKRISHNA


Assistant Professor Head of the Department Principal
Dept. of Computer Science Computer Science & RIT, HASSAN
& Engineering Engineering, RIT, HASSAN
RIT, HASSAN

Name of the examiners Signature with date


1.

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.

It gives us great pleasure to express our gratitude to Ms.Renuka Chalavadi Assistant


Professor, Department of CSE for her expert guidance, initiative and encouragement that led
us to complete this project.

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

Sl.no Chapter names Page- no

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

3 REQUIREMENTS AND SPECIFICATION 5


3.1 Software requirements 5
3.2 Hardware requirements 5

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

CONCLUSION AND FUTURE SCOPE 34

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.

1.1 Introduction to OpenGL


OpenGL provides a set of commands to render a three dimensional scene. That means
you provide the data in an OpenGL-useable form and OpenGL will show this data on the screen
(render it).It is developed by many companies and it is free to use. You can develop
OpenGL-applications without licensing.
OpenGL is a hardware and system-independent interface. An OpenGL application will
work on every platform, as long as there is an installed implementation. Because it is system
independent, there are no functions to create windows etc., but there are helper functions for each
platforms. A very useful thing is GLUT.

Dept of CSE, RIT, Hassan 2019-2020 Page 1


SIMULATION OF A LIFT

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.

1.2 Support Libraries:


 OpenGL provides a powerful but primitive set of rendering command, and all higher
level drawing must be done in terms of these commands. There are several libraries that
allow you to simplify your programming tasks, including the following:
 GL provides lower level functions for drawing points, lines and polygons. All GL
function name starts with “gl”.
 OpenGL Utility Library (GLU) contains several routines that use lower level OpenGL
commands to perform such tasks as setting up matrices for specific viewing orientations
and projections and rendering surfaces.
 OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by
Mark Kilgard, to hide the complexities of differing window APIs.

Dept of CSE, RIT, Hassan 2019-2020 Page 2


SIMULATION OF A LIFT

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.

2.1 The OpenGL Programming Guide –The Redbook


 The OpenGL Programming Guide 5th Edition. The Official Guide to
Learning OpenGL Version 2.1
The OpenGL Programming Guide, Fifth Edition, provides definitive and comprehensive
information on OpenGL Utility Library. The previous edition covered OpenGL through Version
1.3 and 1.4. This fifth edition of the best-selling “red-book” description the latest features of
OpenGL Version 1.5 and 2.0, including the introduction of the OpenGL Shading language. You
will find clear explanation of OpenGL functionality and many basic computer graphics
techniques, such as building and rendering 3D models; interactively viewing texture mapping,
antialiasing, fog and atmosphere effects, NURBS, image processing, and more.

Dept of CSE, RIT, Hassan 2019-2020 Page 3


SIMULATION OF A LIFT

2.2 OpenGL Resources


 Pervisim offers consulting and software development for visualization
leveraging OpenGL
Pervisim is a new software development firm located in carry, NC that specializes in 3D
visualization application. Recently completed and revived project include mash up visualization
that create terrain visualization in 3D pdf and molecular modelling using OpenGL .

 VSFL-Very Simple Font Library


Text rendering is very useful to display information on top of 3D world. VSFL aims at providing
users with the ability to render bitmapped text in an OpenGL application using the core profile.
With immediate mode gone in core OpenGL version, so are the vast majority of font libs that
worked with OpenGL. Immediate mode was terribly slow, a code was very extensive. Vertex
Buffer are clearly the way to go. This lib uses VAOs and vertex buffer to render text.
The basic functions like glColor3f (…); glRotatef (...), glTranslatef (...) etc that are most
commonly used in the code are taken from the prescribed VTU Text book “INTERACTIVE
COMPUTER GRAPHICS” 5th edition by Edward Angel.
The lab programs in the syllabus also serve as a basic template for creating a project. The usage
of colours and specifications are taken from the various programs that were taught in the lab.
The VTU prescribed text book serves as a huge database of functions and they are used in the
project.

Dept of CSE, RIT, Hassan 2019-2020 Page 4


SIMULATION OF A LIFT

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.

3.2 Hardware requirements


The hardware requirements are very minimal and the software can run on most of the
machines.
 Processor - Intel Pentium processor or above.
 Processor Speed – 3 GHz or above.
 RAM – 2GB or above.
 Monitor resolution - A color monitor with a minimum resolution of 640*480
 HDD – 40 GB or above
 Mouse
 Keyboard

Dept of CSE, RIT, Hassan 2019-2020 Page 5


SIMULATION OF A LIFT

Chapter 4
SOFTWARE DESIGN
4.1 High level design

Fig 4.1 Block diagram of simulation of lift

Dept of CSE, RIT, Hassan 2019-2020 Page 6


SIMULATION OF A LIFT

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

Step 5: If Left mouse button is pressed


glutMouseFunc( ) function gets called
then man will move to the First Floor

step 6 : If right mouse button is pressed


glutMouseFunc( ) function gets called
then man will move to the second Floor

step 7: If ‘s’ button is pressed


glutKeyboardFuncFunc( ) function gets called
then man will exit the first Floor
Step 8: Stop.

Dept of CSE, RIT, Hassan 2019-2020 Page 7


SIMULATION OF A LIFT

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;

2: To draw the nose and 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();
 glVertex2i(GLint x, Glint y) functions are used in order to properly draw lines
using appropriate x and y co-ordinates to form the nose and eyes of the man.
 In all the above function calls we see that lines are specified for x and y
co-ordinates sent as parameters to glVertex2i() function.

Dept of CSE, RIT, Hassan 2019-2020 Page 8


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 9


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 10


SIMULATION OF A LIFT

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.

5.2 SOURCE CODE


#include<stdio.h>
#include<GL/glut.h>
typedef int point[3];
GLint
vertices[][3]={{40,40,0},{40,50,0},{400,50,0},{400,40,0},{90,75,0},{90,65,0},{430,75,0},{430
,65,0},{0,0,0},{0,70,0},{499,70,0},{499,0,0},{137,0,0},{137,5,0},{142,5,0},{142,0,0},{175,30,
0},{175,32,0},{177,32,0},{177,30,0},{272,0,0},{272,5,0},{277,5,0},{277,0,0},{237,30,0},{237
,32,0},{239,32,0},{239,30,0}};//points for the base,lawn & compound
GLfloat
color[][3]={{0.8,0.8,0.8},{0.8,0.8,0.8},{0.0,0.0,0.0},{0.8,0.8,0.8},{0.1,0.1,0.1},{0.1,0.1,0.1},{0.
0,0.0,0.0},{0.0,0.0,0.0},{0.0,1.0,0.0},{0.0,1.0,0.0},{0.0,1.0,0.0},{0.0,1.0,0.0},{1.0,0.5,0.0},{0.9,
0.8,0.0},{1.0,0.5,0.0},{0.9,0.8,0.0},{1.0,0.8,0.0},{0.9,0.8,0.0},{0.9,0.8,0.0},{0.5,0.0,0.0},{1.0,0.
5,0.0},{0.9,0.8,0.0},{1.0,0.5,0.0},{0.9,0.8,0.0},{1.0,0.8,0.0},{0.9,0.8,0.0},{0.9,0.8,0.0},{0.5,0.0,
0.0}};
int off[3]={0,100,200};//offset for each floor
int flag=0;//set when mouse clicked
int flag1=0;//set when a key is pressed
void man()

Dept of CSE, RIT, Hassan 2019-2020 Page 11


SIMULATION OF A 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);

Dept of CSE, RIT, Hassan 2019-2020 Page 12


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 13


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 14


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 15


SIMULATION OF A LIFT

glVertex2i(254,50);
glVertex2i(250,15);
glVertex2i(260,15);
glVertex2i(263,48);
glVertex2i(280,15);
glVertex2i(290,15);
glEnd();
}

//Function to scale the man


void scaleman()
{
glPushMatrix();
glTranslated(270,105,0);
glScaled(0.3,0.6,0);
glTranslated(-270,-105,0);
man();
glPopMatrix();
}

//To draw the compound,lawn & base


void polygon(int a,int b,int c,int d)
{
glBegin(GL_POLYGON);
glColor3fv(color[a]);
glVertex3iv(vertices[a]);
glColor3fv(color[b]);
glVertex3iv(vertices[b]);
glColor3fv(color[c]);
glVertex3iv(vertices[c]);
glColor3fv(color[d]);

Dept of CSE, RIT, Hassan 2019-2020 Page 16


SIMULATION OF A LIFT

glVertex3iv(vertices[d]);
glEnd();
}

//draw each wall of the building


void drawface(point a,point b,point c,point d)
{
glBegin(GL_POLYGON);
glVertex3iv(a);
glVertex3iv(b);
glVertex3iv(c);
glVertex3iv(d);
glEnd();
}

//function to draw closed lift doors


void lift(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);
glBegin(GL_POLYGON);//1st door
glVertex3iv(d[0]);
glVertex3iv(d[1]);
glVertex3iv(d[2]);
glVertex3iv(d[3]);
glEnd();

glBegin(GL_POLYGON);//2nd door
glVertex3iv(d[4]);

Dept of CSE, RIT, Hassan 2019-2020 Page 17


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 18


SIMULATION OF A LIFT

glVertex3iv(d[7]);
glEnd();
glPopMatrix();
glutPostRedisplay();
}

//moves man in & out of the lift


void entry(int offset)
{
if(offset==0)//ground floor
{
if(flag1==1||flag1==2||flag1==3)//to enter
{
glPushMatrix();
glTranslated(40,5,0);
scaleman();
glPopMatrix();
}
if(flag1==4)//to exit
{
glPushMatrix();
glTranslated(-40,-5,0);
scaleman();
glPopMatrix();
}

}
else if(offset==1)//to exit first floor
{
glPushMatrix();
glTranslated(270,205,0);

Dept of CSE, RIT, Hassan 2019-2020 Page 19


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 20


SIMULATION OF A LIFT

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

//draws door, window & curtains


void ground()
{
int I,j,k;
for(i=0;i<3;i++)
{
GLint
cur[][3]={{83,80+off[i],0},{83,100+off[i],0},{83,120+off[i],0},{93,120+off[i],0},{93,80+off[i],

Dept of CSE, RIT, Hassan 2019-2020 Page 21


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 22


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 23


SIMULATION OF A LIFT

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

//draws building with lift


void building()
{
for(int k=0;k<3;k++)
{
GLint
w[][3]={{75,55+off[k],0},{75,155+off[k],0},{375,155+off[k],0},{375,55+off[k],0},{100,70+off

Dept of CSE, RIT, Hassan 2019-2020 Page 24


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 25


SIMULATION OF A LIFT

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

//to draw the railings


void grill()
{
for(int i=0;i<3;i++)//grill
{
GLint
c[][3]={{50,154+off[i],0},{50,170+off[i],0},{375,170+off[i],0},{375,154+off[i],0},{85,175+off
[i],0},{85,190+off[i],0},{410,190+off[i],0},{410,175+off[i],0}};
glColor3f(0.5,0.5,0.0);
drawface(c[0],c[1],c[2],c[3]);
glColor3f(0.3,0.3,0.0);
drawface(c[2],c[6],c[7],c[3]);
}
}

//draws base, compound


void bottom()
{
polygon(0,5,7,3);
polygon(4,5,7,6);
polygon(0,1,4,5);
polygon(2,3,7,6);
polygon(0,1,2,3);
polygon(1,4,6,2);

Dept of CSE, RIT, Hassan 2019-2020 Page 26


SIMULATION OF A LIFT

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

//draws white stripes on the road


void roadStrips(int r)
{
int roff[]={0,15};
float
rstrip[][3]={{204.5,5.0+roff[r],0.0},{209.5,5.0+roff[r],0.0},{208.0,15.0+roff[r],0.0},{206.0,15.0
+roff[r],0.0}};
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3fv(rstrip[0]);
glVertex3fv(rstrip[1]);
glVertex3fv(rstrip[2]);
glVertex3fv(rstrip[3]);

Dept of CSE, RIT, Hassan 2019-2020 Page 27


SIMULATION OF A LIFT

glEnd();
}

//displays the building, lift


void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
polygon(8,9,10,11);//lawn
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex3f(15.0,30.0,0.0);
glVertex3f(75.0,65.0,0.0);
glVertex3f(455.0,65.0,0.0);
glVertex3f(420,30.0,0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(142.0,0.0,0.0);
glVertex3f(177.0,30.0,0.0);
glVertex3f(237.0,30.0,0.0);
glVertex3f(272.0,0.0,0.0);
glEnd();
roadStrips(0);
roadStrips(1);
bottom();
building();

if(flag==1)//executed when the left mouse button is clicked


{
liftdoor(0);
if(flag1==1)//when 'e' is pressed
{

Dept of CSE, RIT, Hassan 2019-2020 Page 28


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 29


SIMULATION OF A LIFT

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
{

Dept of CSE, RIT, Hassan 2019-2020 Page 30


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 31


SIMULATION OF A LIFT

Chapter 6

SCREENSHOTS

Fig 6.1: Opening of a lift door at ground level.


When we press the left mouse button the door of the lift present at the ground floor opens as
shown in the above snapshot.

Fig 6.2: Person moved into the lift at ground floor.

When we press the key ‘e’, the person enters into the lift at ground floor.

Dept of CSE, RIT, Hassan 2019-2020 Page 32


SIMULATION OF A LIFT

Fig 6.3: Person moved to second floor.


When we press the right mouse button the person at the ground floor gets elevated to the second
floor.

Fig 6.4: Person moved outside the lift at second floor.


When we press the key ‘s’ the person comes out of the lift at second floor.

Dept of CSE, RIT, Hassan 2019-2020 Page 33


SIMULATION OF A LIFT

CONCLUSION & FUTURE SCOPE


We started with modest aim with no prior experience in any programming projects as
this, but ended up in learning many things, fine tuning the programming skills and getting into
the real world of software development with an exposure to corporate environment.
This project was a demonstration to show that OpenGL can be used to implement graphics
which can be applied in various fields such advertising industries to endorse company’s products
animation studios to make animated films,cartoons;gaming industries by displaying use of
high-end graphics in designing games ;in engineering,architecture,medical fields by creating
real-like models for better understanding,clarity and bringing out fresh,new ideas to enhance
them.
Checking and verification of all possible types of the functions are taken care. Care was
taken to avoid bugs. Bugs may be reported to creator as the need may be. So, we conclude on
note that we are looking to develop more such projects with an appetite to learn more in
computer graphics.

Dept of CSE, RIT, Hassan 2019-2020 Page 34


SIMULATION OF A LIFT

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

Dept of CSE, RIT, Hassan 2019-2020 Page 35

You might also like