Professional Documents
Culture Documents
CG Final Project
CG Final Project
For the requirement of 6th Semester B.E in Computer Science & Engineering
For the award of degree of
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE AND ENGINEERING
Submitted by
VAMSHA ATTAVAR(1KT20CS090)
VAISHNAVI P GAVADE(1KT20CS089)
CERTIFICATE
Certified that the mini project work prescribed in 18CSMP68 entitled “ TRAFFIC SIGNAL
SIMULATOR” carried out by VAMSHA ATTAVAR(1KT20CS090), VAISHNAVI P GAVADE
(1KT20CS089), bonafide students of Sri Krishna Institute of Technology, Bengaluru in partial
fulfilment of the award of Bachelor of Engineering in Computer Science and Engineering of the
Visvesvaraya Technological University, Belagavi during the year 2021-22. It is certified that all
corrections /suggestions indicated for Internal Assessment have been incorporated in the report deposited
in the departmental library. The mini-project report has been approved as it satisfies the academic
requirements with respect to project work prescribed for the said Degree.
EXTERNAL
1. ………………………… ………………………
2. ………………………… ………………………
ACKNOWLEDGEMENT
We consider special privilege to express a few words of gratitude and respect to all those
who have guided and inspired us in completing the Mini Project report. The success of the
Mini Project depends largely on the encouragement and guidance of many other. We take this
opportunity to express our gratitude our gratitude to the people who have been instrument in
successful completion of the Mini Project.
We would like to profoundly thank the Management of Sri Krishna Institute of Technology
[SKIT] for providing such a working environment for successful completion of the Mini Project.
We express our sincere thanks to Dr. Mahesha K, Principal of Sri Krishna Institute of
technology, for his courteous comments and valuable suggestions, which enabled the
successful completion of the Mini Project.
We express our gratitude to Dr. Shantharam Nayak, Head of the Department of Computer
Science and Engineering, for his constant support, kind guidance and encouragement.
VAMSHA ATTAVAR(1KT20CS090)
VAISHNAVI P GAVADE(1KT20CS089)
i
ABSTRACT
The Graphics package is aimed at supporting the requirements of the Computer Graphics using
OpenGL functions. The project has been implemented under the Windows environment using
the Microsoft Visual C++ platform, OpenGL and associated functionalities of GLUT (Graphics
Library Utility Toolkit).
Main aim of this Mini Project is to illustrate the concepts and usage of pre-built functions in
OpenGL. Simulation of a traffic signal is being done using computer graphics. The car built
using cubes can be moved using arrow keys and based on traffic signal light the user can obey
the traffic rules. If the car hits other car then accident scene is shown. We have used input
devices like mouse and key board to interact with program .
ii
TABLE OF CONTENTS PAGE NO
1. INTRODUCTION
2. REQUIREMENTS SPECIFICATION
3. SYSTEM DEFINITION
4. IMPLEMENTATION
6. SNAPSHOTS 24
BIBILOGRAPHY 27
V
(
v
TRAFFIC SIGNAL
CHAPTER 1
INTRODUCTION
Input
Output
Processor Frame buffer
Device device
Memory
Mouse
GLU
GL
OpenGL Frame Buffer
OpenGL Application
Applicatio Program
n program
GLUT Xlib, Xtk
GLX
Display
list
Rasterization Per-fragment operation
CHAPTER 2
REQUIREMENTS SPECIFICATION
CHAPTER 3
SYSTEM DEFINITION
➢ glutCreateWindow() : this opens the OPENGL window and displays the title at top of
the window
➢ glTranslatef() : used to translate or move the rotation centre from one point to another
in three dimensions
The project starts its execution from the main() function, which in turn calls a function called
display_about() . This function shows an overview of the information about the software. On the screen
mouse and keyboard inputs can be used to execute all the features of this system. The various functions that
can be called from this screen are: display_nuclear_power_plant(), display_operations(), reactions(). Once
any of the above are executed the display_about() is called back or we can quit the window.
CHAPTER 4
IMPLEMENTATION
#include<stdio.h>
#include<gl/glut.h>
void bus();
void road();
void signal();
void car();
void car2();
void bus2();
void mydisplay();
void display();
void frontsreen();
void drawstring();
void setFont();
void myMouse();
void update();
void control();
void helpscreen();
GLint a = 300, b = -300, flag = 0, traffic_regulator = 1, control_keyl, control_keyr;
GLfloat red = 0, blue = 1, green = .3;
GLfloat p = 0, q = 0, r = 0;
//
void* currentfont;
void frontscreen(void)
Pag
Dept of CSE, 2022-
TRAFFIC SIGNAL
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glClearColor(0.5, 1.5, 1.1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0, 0);
drawstring(450.0, 700.0, 0.0, "vtu");
glColor3f(0.7, 0, 1);
drawstring(330, 650, 0.0, "DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING");
glColor3f(1, 0.5, 0);
drawstring(530, 600, 0.0, "A MINI PROJECT ON");
glColor3f(1, 0, 0);
drawstring(360, 500, 0.0, "GRAPHICAL REPRESENTATION OF TRAFFIC SIGNALS");
glColor3f(1, 0.5, 0);
drawstring(200, 400, 0.0, "SUBMITTED BY:");
glColor3f(0, 0, 0);
drawstring(100, 300, 0.0, "VAMSHA ATTAVAR");
glColor3f(0, 0, 0);
drawstring(100, 240, 0.0, "1KT20CS090");
glColor3f(1, 0.5, 0);
{
switch (key)
{
case 13:
if (flag == 1)
{
flag = 2;
mydisplay();
}
if (flag == 0) //Ascii of 'enter' key is 13
{
flag = 1; mydisplay();
}
//wheel 1
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(-0.45,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();
//wheel 2
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(0.35,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();
//footer cube
glPushMatrix();
glTranslatef(-0.2,0,0);
glScaled(1.5,1,.7);
glColor3f(0,0,1);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
}
glutSolidCube(1);
glPopMatrix();
//wheel 1
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(-0.45,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();
//wheel 2
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(0.35,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();
//footer cube
glPushMatrix();
glTranslatef(-0.2,0,0);
glScaled(1.5,1,.7);
glColor3f(0,0,1);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
}
for(int tx=0;tx<=4;tx++)
{
if(tempx[tx]>=1.8 && tempx[tx]<=3 && green){
}else if(tx==0)
{ x[tx]+=0.0
7;
}
else if(tempx[tx]<=tempx[tx-1]+2)
{
}
else x[tx]
+=0.07;
cars(tempx[tx],3.5);
}
// Condition for vertical car
crash for(int ty1=0;ty1<=4;ty1+
+)
{
glScaled(0.2,0.2,0.2);
glutSolidSphere(0.35,30,30);
glPopMatrix();
//green signal
glPushMatrix();
if(green)
glColor3f(0,1,0);
else
glColor3f(0,0,0);
glTranslatef(0.65,2.5,0.9);
glScaled(0.2,0.2,0.2);
glutSolidSphere(0.35,30,30);
glPopMatrix();
//red signal
glPushMatrix();
if(red)
glColor3f(0,1,0);
else
glColor3f(0,0,0);
glTranslatef(-0.6,0.8,0.7);
glScaled(0.2,0.5,0.5);
glutSolidSphere(0.25,30,30);
glPopMatrix
//green signal
glPushMatrix();
if(green)
glColor3f(1,0,0);
else
glColor3f(0,0,0);
glTranslatef(-0.6,0.8,1);
glScaled(0.2,0.5,0.5);
glutSolidSphere(0.25,30,30);
glPopMatrix();
//Garden trees
glPushMatrix();
glTranslatef(2.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();
glPushMatrix();
glTranslatef(1.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();
glPushMatrix();
glTranslatef(0.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();
glPushMatrix();
glTranslatef(2.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();
glPushMatrix();
glTranslatef(1.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix
glPushMatrix();
glTranslatef(0.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void
i()
{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0,0.5,0.5,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,1,-1.0,"Submitted By");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-2,0,-1.0,"Student 1");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-2,-1,-1.0,"Student 2");
glEnable(GL_COLOR_MATERIAL);glFlush();
glutSwapBuffers();
void c()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.5,0.0,0.5,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-1,-1.0,"Press a/A -> LEFT");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-2,-1.0,"Press d/D -> RIGHT");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-3,-1.0,"Press s/S -> DOWN");
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
}
void gameOver(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,1,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1,0,-1.0,"Accident");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1,-1,-1.0,"Press r -> Reset");
glFlush();
glutSwapBuffers();
}
void p()
{
//automate signals
if(s1<=10){
if(s1<5){
red=true;
green=false;
s1+=0.006;
}
if(s1>5){
red=false;
green=true;
s1+=0.006;
}
if(s1>=9.5){
s1=0;
}
}
if(crash)
{
gameOver();
}
else{
//if(!stop)
//x+=0.07;
trafic(x[0]);
void P()
{
//x += .07;
trafic(x[0]);
}
void doInit()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glEnable( GL_COLOR_MATERIAL );
glDepthFunc(GL_LEQUAL);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,1,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2,0,-1.0,"A Mini Project on 'TRAFFIC SIGNALS'");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2,-1,-1.0," Press 'I/i' For Students Information");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glVertex2f(5.45, 2.15);
glVertex2f(5.4, 1.9);
glVertex2f(5.35, 1.8);
glVertex2f(5.2, 1.6);
glVertex2f(5.0, 1.5);
glVertex2f(4.9, 1.4);
glVertex2f(4.7, 1.3);
glVertex2f(4.6, 1.27);
glVertex2f(4.4, 1.25);
glVertex2f(4.0, 1.25);
glVertex2f(3.9, 1.3);
glVertex2f(3.75, 1.35);
glVertex2f(3.6, 1.4);
glVertex2f(3.45, 1.55);
glVertex2f(3.3, 1.7);
glVertex2f(3.2, 1.8);
glVertex2f(3.1, 2.2);
glEnd()
glBegin(GL_POLYGON); //drawing front
tyre glVertex2f(17.0, 2.5);
2
TRAFFIC SIGNAL
glVertex2f(17.3, 3.35);
glVertex2f(17.4, 3.4);
glVertex2f(17.5, 3.45);
glVertex2f(17.6, 3.55);
glVertex2f(17.7, 3.6);
glVertex2f(17.8, 3.63);
glVertex2f(18.0, 3.65);
glVertex2f(18.2, 3.7);
glVertex2f(18.4, 3.7);
glVertex2f(18.6, 3.65);
glVertex2f(18.8, 3.55);
glVertex2f(19.0, 3.45);
glVertex2f(19.1, 3.4);
glVertex2f(19.2, 3.25);
glVertex2f(19.3, 3.2);
glVertex2f(19.4, 3.0);
glVertex2f(19.5, 2.5);
glVertex2f(19.45, 2.15);
glVertex2f(19.4, 1.9);
glVertex2f(19.35, 1.8);
glVertex2f(19.2, 1.6);
glVertex2f(19.0, 1.5);
glVertex2f(18.9, 1.4);
glVertex2f(18.7, 1.3);
glVertex2f(18.6, 1.27);
glVertex2f(18.4, 1.25);
glVertex2f(18.0, 1.25);
glVertex2f(17.9, 1.3);
glVertex2f(17.75, 1.35);
glVertex2f(17.6, 1.4);
glVertex2f(17.45, 1.55);
glVertex2f(17.3, 1.7);
glVertex2f(17.2, 1.8);
glVertex2f(17.1, 2.2);
glEnd();
glPopMatrix();
}
glBegin(GL_LINES); //connecting outer line
glVertex2d(7.0, 5.0);
glVertex2d(15.0, 5.0);
glEnd();
2
TRAFFIC SIGNAL
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 1346.0, 0.0, 728.0);
}
glutDisplayFunc(mydisplay);
glutKeyboardFunc(myKeyboard);
glutMouseFunc(myMouse);
myinit();
glutMainLoop();
}
CHAPTER 5
TESTING AND RESULTS
Testing is the process of evaluating a system or its component(s) with the intent to find whether it
satisfies the specified requirements or not. Testing is executing a system in order to identify any
gaps, errors, or missing requirements in contrary to the actual requirements
3. System Testing
This is concerned with finding errors that result from unanticipated interaction between Sub-
system interface problems.
4. Acceptance Testing
The system is tested with data supplied by the system customer rather than simulated test data.
CHAPTER 6
SNAPSHOTS
CONCLUSION
Traffic Signal Simulator is designed and implemented using graphics software called OpenGL
which has become widely accepted standard for developing graphic application. Using OpenGL
functions user can create geometric objects and can use translation, rotation and scaling with respect to
the co-ordinate system. The development of the Traffic Signal Simulator has given a good exposure to
OpenGL by which I have learnt some of the techniques. This mini project on <Traffic Signal
Simulator= using OpenGL is a reliable graphics package that provides the user to easily understand
the working of the nuclear power plant.
The user-friendly interface allows the user to interact with it very effectively. So, I conclude on note
that this project has given me a great exposure to the OpenGL and computer graphics. This is very
reliable graphics package supporting various primitive objects like polygon, line loops, etc. Also, color
selection, menu, keyboard and mouse-based interface are included. Transformations like translation,
rotation, scaling is also provided.
BIBLIOGRAPHY
References
[1].Donald Hearn & Pauline Baker: Computer Graphics with OpenGL Version,3rd / 4th Edition,
Pearson Education,2011
[2].Edward Angel: Interactive Computer Graphics- A Top Down approach with OpenGL, 5th edition.
Pearson Education,2008
[3].James D Foley, Andries Van Dam, Steven K Feiner, John F Huges Computer graphics
[4].with OpenGL: pearson education
[5].M M Raiker, Computer Graphics using OpenGL, Filip learning/Elsevier
[6].Kelvin Sung, Peter Shirley, Steven Baer : Interactive Computer Graphics, concepts andapplications,
Cengage Learning
[7].www.opengl.org
[8].www.vtupro.blogspot.in
[9].www.opengl.start4all.com