0% found this document useful (0 votes)
147 views38 pages

CG

This document discusses the design and implementation of a 2D bascule bridge simulation using OpenGL. It provides an algorithm for the simulation in 58 steps and a flowchart showing the overall process. The algorithm initializes the window and display, creates menus to select options, and displays the bridge, boat, cars, and poles, allowing the user to change elements like the boat color. OpenGL is described as an open standard for 3D graphics that provides functions for drawing primitives and complex scenes across languages and platforms.

Uploaded by

bindhu
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
0% found this document useful (0 votes)
147 views38 pages

CG

This document discusses the design and implementation of a 2D bascule bridge simulation using OpenGL. It provides an algorithm for the simulation in 58 steps and a flowchart showing the overall process. The algorithm initializes the window and display, creates menus to select options, and displays the bridge, boat, cars, and poles, allowing the user to change elements like the boat color. OpenGL is described as an open standard for 3D graphics that provides functions for drawing primitives and complex scenes across languages and platforms.

Uploaded by

bindhu
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/ 38

2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

CHAPTER - 1

INTRODUCTION

An OpenGL is a software API(Application Programming Interface) consisting of


many functions that allow us to do graphics hardware and has a high quality color images
composed of 3D geometric objects and images primitives. OpenGL is window and
operating system independent. An OpenGL is a platform independent, need some way to
integrate OpenGL into each windowing system. To integrate it into various window
system, additional libraries are used to modify the native window into an OpenGL
capable window. Every window system has its own unique library and functions to do.
OpenGL also includes a utility library, GLU to simplify common task such as rendering
quadric surfaces, curves. OpenGL has two types that it can render Geometric primitives
and Image primitives. Geometric primitives are lines, points and polygons. Image
primitives are bitmaps and graphic images.

To simplify programming and window system dependence, we’ll be using the


GLUT. GLUT is a simple tool kit for making a simple OpenGL applications, which
simplify the Process of working with events in the window system and animation. Most
of the window-based programs are event driven. GLUT uses a callback mechanism to do
its event processing.

1.1 Aim of the project

Computers have become a powerful media for the rapid and economical
production of pictures. There is virtually no area in which graphical display cannot be
used for some advantage. Graphics provide a so natural means of communicating with a
computer that they have become widespread. The fields in which computer graphics find
their uses are many here we have tried to incorporate and present the working
environment of a Lift Over Bridge which is also known as Bascule bridge in 2D.

The bascule bridge works with a counterweight that balances the span while the
upward swing provides clearance for boat traffic. Here we have created a scene consisting
of the bascule bridge which operates to allow a boat to pass under it while a bus waits for

Department of CS&E, MITT 2018-19 Page 1


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
the leaf of the bridge to swing back into its position and then passes along the bridge after
the boat has sailed across.

1.2 Overview of the project

In this project we have created a bascule bridge which opens when the ship
needs to pass and closes after the ship moves. Here we have created a scenario, when the
bridge opens the buses moving on the bridge will be stopped and then after the bridge is
closed the movement of the bus will be continued. The passage of ship and bus and the
lift of bridge makes this project more attractive.

1.3 Outcome of the project

We have attempted to design and implement “2D Bascule Bridge Simulation”.


OpenGL supports enormous flexibility in the design and the use of OpenGL graphics
programs. It is the graphical representation of the 2D bascule bridge and its working. The
presence of many built-in classes methods take care of much functionality and reduce the job
of coding as well as make the implementation simpler. Bascule bridge show the real life
graphical implementation of how a bascule bridge works when a ship comes or goes. It also
shows how the buses wait when the bridge is lifted .

Department of CS&E, MITT 2018-19 Page 2


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

CH APTER – 2

DESIGN AND IMPLEMENTATION

Design and implementation is the fourth phase of the project cycle, subsequent to
value chain selection, value chain analysis and designing the competitiveness strategy.
Implementation is the carrying out, execution, or any design, idea, model, specification,
standard or policy for doing something. As such implementation is the action that must
follow any preliminary thinking in order for something to actually happen. While is it
useful to separate these phases for the purpose of discussion, in practice many of the
techniques and skills used in the selection, analysis and strategy development are
continually applied during implementation. Further, while these stages of project cycle
are sequential, they are not linear: it is essential that analysis continuous during the
implementation phase, in order to guide modifications to the competitiveness strategy in
response to changes in the market, the enabling environment or the chain itself.

Department of CS&E, MITT 2018-19 Page 3


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

2.1 Algorithm

Step 1: Start

Step 2: print the keyboard options

Step 3: Initialize the viewing window

Step 4: Initialize the display mode

Step 5: Initialize window size

Step 6: Initialize window position

Step 7: Display the sub menu

Step 8: If submenu entry is 1 goto step 10

Step 9: If submenu entry is 2 goto step 11

//sub menu

Step 10: Assign choice==1

Step 11: return

Step 12: Assign choice==2

Step 13: return

Step 14: Display the main menu

Step 15: if main menu entry is 1 goto step 19

Step 16: if main menu entry is 2 goto step 21

Step 17: if main menu entry is 3 goto step 23

Step 18: if main menu entry is 4 goto step 57

//main menu

Step 19: create the bridge stripes in downside up

Step 20: return

Step 21: create the bridge stripes in upside down

Department of CS&E, MITT 2018-19 Page 4


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
Step 22: return

Step 23: Pause the animation

Step 24: return

Step 25: Enter the keyboard option for changing boat color

Step 26:If key==’r’||’R’ then goto step 34

Step 26:If key==’g’||’G’ then goto step 34

Step 26:If key==’b’||’B’ then goto step 34

Step 26:If key==’c’||’C’ then goto step 34

Step 26:If key==’m’||’M’ then goto step 34

Step 26:If key==’w’||’W’ then goto step 34

Step 26:If key==’y’||’Y’ then goto step 34

Step 33: To display car, pole, vehicles goto step 48

Step 34: Display boat in red color

Step 35: return

Step 36: Display boat in green color

Step 37: return

Step 38: Display boat in blue color

Step 39: return

Step 40: Display boat in cyan color

Step 41: return

Step 42: Display boat in magenta color

Step 43: return

Step 44: Display boat in white color

Step 45: return

Department of CS&E, MITT 2018-19 Page 5


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
Step 46: Display boat in yellow color

Step 47: return

Step 48: If choice==1 then

Step 49: else goto step 52

Step 50: Create sea in day mode

Step 51: Create bridge,boat,car and poles

Step 52: return

Step 53: If choice==2 then

Step 54: else goto step 7

Step 55: Create sea in night mode

Step 56: Create bridge,boat,car and poles

Step 57: return

Step 58: End

Department of CS&E, MITT 2018-19 Page 6


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

2.2 Flowchart

start

Print the keyboard options

glutInit(&argC,argV)

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)

glutInitWindowSize(2000,1600)

GlutInitWindowPosition(0,0)

glutCreateWindow(“Bridge Simulation”)

glutCreateSubMenu()

glutCreateMainMenu()

glutKeyboardFunc()

glutDisplayFunc()

MyInit()

glClearColor(1,1,0,1)

glMainLoop()

End

Department of CS&E, MITT 2018-19 Page 7


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

2.3 OPENGL WITH DESCRIPTION

Most of our application will be designed to access OpenGL directly


through functions in three libraries. Functions in the main GL (or OpenGL in windows)
library have names that begin with the letters gl and are stored in a library usually referred
to as GL (or OpenGL in windows). 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 but application programmers prefer not to write the code repeatedly. The GLU
library is available in all OpenGL implementations; functions in the GLU library begin
with letters glu.

OpenGL (Open Graphics Library):

OpenGL has become a widely accepted standard for developing graphics


application. OpenGL is easy to learn, and it possesses most of the characteristics of other
popular graphic system. It is top-down approach. OpenGL is a standard specification
defining a cross-language, Cross-platform API for writing applications that produce 2D
and 3D computer graphics. The interface consists of different function calls which can be
used to draw complex three dimensional scenes from simple primitives.

OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992 and is widely used
in CAD, virtual reality, scientific visualization, information visualization and flight
simulation. It is also used in video games, where it competes with direct 3D on Microsoft
Windows platforms.

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:

 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, used to
hide the complexities of differing window APIs. Rather than using a different

Department of CS&E, MITT 2018-19 Page 8


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
library for each system we use available library called openly utility toolkit. It is
used as #include <glut.h>

This project makes extensive use of translations, rotations and scaling for creating
provides the description of the following functions.

Sl No OpenGL API’s Used OpenGL API’s Used

1 void glBegin(glEnum mode); Initiates a new primitive of type mode and


starts the collection of vertices. Values of
mode include GL_POINTS, GL_LINES and
GL_POLYGON.

2 void glEnd( ); It terminates a list of vertices.

3 void glColor3f[ i f d ] (TYPE Sets the present RGB colors. Valid types are
r, TYPE g, TYPE b); int ( i ), float ( f ) and double ( d ). The
maximum and minimum values of the
floating-point types are 1.0 and 0.0,
respectively.

4 int glutCreateWindow(char Creates a window on the display. The string


*title); title can be used to label the window. The
return value provides a reference to the
window that can be used where there are
multiple windows.

5 void glutInitWindowSize(int Specifies the initial height and width of the


width, int height); window in pixels.

6 void Specifies the initial position of the top-left


glutInitWindowPosition(int x, corner of the window in pixels.
int y);

7 void Request a display with the properties in mode.


glutInitDisplayMode(unsigned The value of mode is determined by the
int mode); logical OR of operation including the color
model (GLUT_RGB, GLUT_INDEX) and
buffering (GLUT_SINGLE,

Department of CS&E, MITT 2018-19 Page 9


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

GLUT_DOUBLE);

8 void glFlush( ); Forces any buffered any OpenGL commands


to execute.

9 void glutInit (int argc, char Initializes GLUT. The arguments from main
**argv); are passed in and can be used by the
application.

10 void glClearColor(GLclampf Sets the present RGBA clear color used when
r,GLclampf g,GLclampf clearing the color buffer. Variables of
b,GLclampf a); GLclampf are floating-point numbers between
0.0 and 1.0.

11 void glutMainLoop( ); Cause the program to enter an event


processing loop. It should be the last
statement in main.

12 void glutDisplayFunc(void Registers the display function func that is


(*func) (void)); executed when the window needs to be
redrawn.

13 gluOrtho2D(GLdouble left, Defines a two-dimensional viewing rectangle


GLdouble right, GLdouble in the plane Z=0;
bottom, GLdouble top);

14 void Renders the character with ASCII code char at


glutBitmapCharacter(void the current raster position using the raster font
*font, int char); given by font. Fonts include
GLUT_BITMAP_TIMES_ROMAN_10 and
GLUT_BITMAP_TIMES_ROMAN_8_Y_13.
The raster position is incremented by the
width of the character.

15 void glClear(GL_COLOR_ To make the screen solid and white.


BUFFER_BIT);

16 void MouseFunc(myMouse); It is used for the implementation of mouse


interface. Passing the control to void
myMouse(int button,int state,int x,int y);

Department of CS&E, MITT 2018-19 Page 10


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

17 17 void KeyboardFunc(key); It is used for the implementation of keyboard


interface.

18 void glLoadMatrix[fd](TYPE Loads the 16 element array of TYPE GLfloat


*m); or GLdouble as a current matrix.

Department of CS&E, MITT 2018-19 Page 11


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

CHAPTER – 3

RESULT ANALYSIS

3.1 Snapshots

Fig3.1 Day mode of bascule bridge scenario

Fig3.2 Night mode of bascule bridge scenario

Department of CS&E, MITT 2018-19 Page 12


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

Fig3.3 Downside up movement of the ship

Fig3.4 Opening of the bascule bridge and the bus stops

Department of CS&E, MITT 2018-19 Page 13


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

Fig3.5 Ship passing the bascule bridge

Fig3.6 Bascule Bridge closes after the ship passes

Department of CS&E, MITT 2018-19 Page 14


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

Fig3.7 Movement of the bus after the bridge closes

Fig3.8 Upside down movement of the ship

Department of CS&E, MITT 2018-19 Page 15


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

Fig3.9 Bascule Bridge closes after the ship passes

3.2 Discussion

1. The bascule bridge scenario is associated with day mode and night mode along with the
water under the bridge and the movement of bus.

2. The bascule bridge scenario is associated with night mode along with the water under
the bridge and the movement of bus.

3. When the ship starts moving from downside up the bascule bridge starts opening.

4. When the ship comes near the bascule bridge and when the bridge starts opening the
movement of bus over the bridge is stopped.

5. When the ship passes under the bascule bridge the bridge completely opens.

6. After the ship passes the bridge the bridge starts closing.

7. Movement of the bus is continued when the when the bridge is completely closed.

8. Bridge also opens when the ship comes from upside down way.

9. Bridge closes after the ship passes in the upside down way.
Department of CS&E, MITT 2018-19 Page 16
2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

CHAPTER – 4

CONCLUSION AND FUTURE WORK

The 2D bascule bridge simulation has been drawn and displayed using the computer
graphics how it works in general. The demo is made more interactive with a keyboard and
mouse interaction module in the program.

Even though demo designed is enriched with many options, it is a two dimensional
demo, in future it can be redesigned with 3D animation and sound effects. This project
can be modified with a lot of features like design of the bridge, ship and the movement of
the ship. Sounds of sea, boat, bus and bridge movement can be incorporated. Support for
different types of vehicles. Support for transparency of the layer and originality.

Department of CS&E, MITT 2018-19 Page 17


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory

APPENDIX

Source code
#include<windows.h>
#include<stdio.h>
#include<GL/glut.h>
float y=0,ang=0,i=0,k=0,n=0;
float a=900,b=880,c=900,d=900,p,q=0,s;
float g=0; // car translate indicator
float m=.80,j=.50,o=.15;
int choice,ch;
void sea1()
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glColor3f(0.0,0.50,1.0);
glVertex2f(0.0,0.0);
glVertex2f(2000.0,0.0);
glVertex2f(2000.0,1600.0);
glVertex2f(0.0,1600.0);
glEnd();
glPushMatrix();
glTranslatef(0,q,0);
glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
for(p=0;p<20000;p=p+100)
for(s=0;s<20000;s=s+100)
glVertex2f(100.0+s,100.0+p);
glVertex2f(200.0+s,100.0+p);
glEnd();
glPopMatrix();

Department of CS&E, MITT 2018-19 Page 18


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
}
void sea2()
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.20);
glVertex2f(0.0,0.0);
glVertex2f(2000.0,0.0);
glVertex2f(2000.0,1600.0);
glVertex2f(0.0,1600.0);
glEnd();
glPushMatrix();
glTranslatef(0,q,0);
glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
for(p=0;p<20000;p=p+100)
for(s=0;s<20000;s=s+100)
glVertex2f(100.0+s,100.0+p);
glVertex2f(200.0+s,100.0+p);
glEnd();
glPopMatrix();
}
void bridge()
{
glBegin(GL_POLYGON);
glColor3f(0.40,0.40,0.40);
glVertex2f(0.0,900.0);
glVertex2f(500.0,900.0);
glVertex2f(500.0,1200.0); //bridge top 1
glVertex2f(0.0,1200.0);
glEnd();

Department of CS&E, MITT 2018-19 Page 19


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(100.0,1030.0);
glVertex2f(200.0,1030.0);
glVertex2f(200.0,1040.0); //strip1
glVertex2f(100.0,1040.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(300.0,1030.0);
glVertex2f(400.0,1030.0);
glVertex2f(400.0,1040.0); //strip2
glVertex2f(300.0,1040.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,.0);
glVertex2f(0.0,1170.0);
glVertex2f(500.0,1170.0);
glVertex2f(500.0,1175.0); //yellow strip1
glVertex2f(0.0,1175.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,0.0);
glVertex2f(0.0,920.0);
glVertex2f(500.0,920.0);
glVertex2f(500.0,930.0); //yellow strip2
glVertex2f(0.0,930.0);
glEnd();
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(0.46,0.46,0.46);

Department of CS&E, MITT 2018-19 Page 20


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(500.0,900.0);
glVertex2f(900.0-k,900.0+n);
glVertex2f(900.0-k,1200.0+n);
glVertex2f(500.0,1200.0);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(20.0,1400.0);
glVertex2f(900.0-k,900.0+n); //pole thread
front
glVertex2f(0.0,1400.0);
glVertex2f(900.0-k,880.0+n);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(30.0,1550.0);
glVertex2f(900.0-k,1200.0+n); //pole thread back
glVertex2f(50.0,1550.0);
glVertex2f(900.0-k,1203.0+n);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(500.0,880.0);
glVertex2f(900.0-k,880.0+n); //base1
glVertex2f(900.0-k,900.0+n);
glVertex2f(500.0,900.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.46,0.46,0.46);
glVertex2f(900.0+k,900.0+n)
glVertex2f(1300.0,900.0);

Department of CS&E, MITT 2018-19 Page 21


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(1300.0,1200.0);
glVertex2f(900.0+k,1200.0+n);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(900.0+k,880.0+n);
glVertex2f(1300.0,880.0); // base 2
glVertex2f(1300.0,900.0);
glVertex2f(900.0+k,900.0+n);
glEnd();
glPopMatrix();
printf("i== %f\t k==%f\n",i,k);
glBegin(GL_POLYGON);
glColor3f(0.40,0.40,0.40);
glVertex2f(1300.0,900.0);
glVertex2f(2000.0,900.0);
glVertex2f(2000.0,1200.0);
glVertex2f(1300.0,1200.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,0.0);
glVertex2f(1300.0,1170.0);
glVertex2f(2000.0,1170.0);
glVertex2f(2000.0,1175.0); //yellow strip3
glVertex2f(1300.0,1175.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,0.0);
glVertex2f(1300.0,920.0);
glVertex2f(2000.0,920.0);
glVertex2f(2000.0,930.0); // yellow strip4

Department of CS&E, MITT 2018-19 Page 22


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(1300.0,930.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(1400.0,1030.0);
glVertex2f(1500.0,1030.0);
glVertex2f(1500.0,1040.0); //strip3
glVertex2f(1400.0,1040.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(1600.0,1030.0);
glVertex2f(1700.0,1030.0);
glVertex2f(1700.0,1040.0); //strip4
glVertex2f(1600.0,1040.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(1800.0,1030.0);
glVertex2f(1900.0,1030.0);
glVertex2f(1900.0,1040.0); //strip5
glVertex2f(1800.0,1040.0);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(1725.0,1550.0);
glVertex2f(900.0+k,1200.0+n); //rite pole
thread
glVertex2f(1745.0,1550.0);
glVertex2f(900.0+k,1200.0+n);
glEnd();

Department of CS&E, MITT 2018-19 Page 23


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glBegin(GL_POLYGON);
glColor3f(0.25,0.25,0.25);
glVertex2f(200.0,800.0); //6 point polygon 1
glVertex2f(200.0,700.0);
glVertex2f(300.0,700.0);
glVertex2f(300.0,800.0);
glVertex2f(350.0,880.0);
glVertex2f(150.0,880.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(0.0,880.0);
glVertex2f(500.0,880.0); //base3
glVertex2f(500.0,900.0);
glVertex2f(0.0,900.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); //base4
glVertex2f(1300.0,880.0);
glVertex2f(2000.0,880.0);
glVertex2f(2000.0,900.0);
glVertex2f(1300.0,900.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.25,0.25,0.25);
glVertex2f(1500.0,800.0);
glVertex2f(1500.0,700.0);
glVertex2f(1600.0,700.0); //6 point polygon2
glVertex2f(1600.0,800.0);
glVertex2f(1650.0,880.0);
glVertex2f(1450.0,880.0);

Department of CS&E, MITT 2018-19 Page 24


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glEnd();
}
void boat()
{
glPushMatrix();
glTranslatef(0,y,0);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(m,j,o);
glVertex2f(900.0,700.0);
glVertex2f(800.0,620.0);
glVertex2f(750.0,500.0);
glVertex2f(750.0,200.0); //ship
glVertex2f(900.0,50.0);
glVertex2f(1050.0,200.0);
glVertex2f(1050.0,500.0);
glVertex2f(1000.0,620.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0); // ship back 1
glVertex2f(750.0,200.0);
glVertex2f(900.0,0.0);
glVertex2f(900.0,50.0);
glVertex2f(751.0,200.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.1,0.1,0.1);
glVertex2f(901.0,0.0); //ship back 2
glVertex2f(1050.0,200.0);
// glVertex2f(1051.0,200.0);
glVertex2f(901.0,50.0);

Department of CS&E, MITT 2018-19 Page 25


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(900.0,700.0);
glVertex2f(820.0,600.0); //boat grill
glVertex2f(820.0,600.0);
glVertex2f(800.0,620.0);
glVertex2f(820.0,600.0);
glVertex2f(770.0,500.0);
glVertex2f(770.0,500.0);
glVertex2f(750.0,500.0);
glVertex2f(770.0,500.0);
glVertex2f(770.0,200.0);
glVertex2f(770.0,200.0);
glVertex2f(750.0,200.0);
glVertex2f(770.0,200.0);
glVertex2f(900.0,70.0);
glVertex2f(900.0,70.0);
glVertex2f(900.0,50.0);
glVertex2f(900.0,70.0);
glVertex2f(1030.0,200.0);
glVertex2f(1030.0,200.0);
glVertex2f(1050.0,200.0);
glVertex2f(1030.0,200.0);
glVertex2f(1030.0,500.0);
glVertex2f(1030.0,500.0);
glVertex2f(1050.0,500.0);
glVertex2f(1030.0,500.0);
glVertex2f(980.0,620.0);
glVertex2f(980.0,620.0);
glVertex2f(1000.0,620.0);

Department of CS&E, MITT 2018-19 Page 26


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(980.0,620.0);
glVertex2f(900.0,700.0);
glVertex2f(770.0,350.0);
glVertex2f(750.0,350.0);
glVertex2f(770.0,450.0);
glVertex2f(750.0,450.0);
glVertex2f(770.0,250.0);
glVertex2f(750.0,250.0);
glVertex2f(1030.0,250.0);
glVertex2f(1050.0,250.0);
glVertex2f(1030.0,350.0);
glVertex2f(1050.0,350.0);
glVertex2f(1030.0,450.0);
glVertex2f(1050.0,450.0);
glVertex2f(840.0,130.0);
glVertex2f(820.0,110.0);
glVertex2f(975.0,110);
glVertex2f(955.0,125.0);
glEnd();
// printf("g==%d\n",g);
glBegin(GL_POLYGON);
glColor3f(0.10,0.10,0.);
glVertex2f(850.0,400.0); //boat inside
polygon
glVertex2f(950.0,400.0);
glVertex2f(950.0,500.0);
glVertex2f(850.0,500.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(850.0,400.0);//table on ship1

Department of CS&E, MITT 2018-19 Page 27


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(850.0,350.0);
glVertex2f(860.0,350.0);
glVertex2f(860.0,400.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(920.0,400.0);//2
glVertex2f(930.0,380.0);
glVertex2f(930.0,380.0);
glVertex2f(920.0,400.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(950.0,400.0);//3
glVertex2f(950.0,350.0);
glVertex2f(940.0,350.0);
glVertex2f(940.0,400.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex2f(860.0,400.0);
glVertex2f(860.0,380.0);
glVertex2f(870.0,380.0);//4
glVertex2f(870.0,400.0);
glEnd();
glPopMatrix();
glPopMatrix();
}
void car()
{
glPushMatrix();

Department of CS&E, MITT 2018-19 Page 28


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glTranslatef(g,0,0);
glBegin(GL_POLYGON); // car
glColor3f(1.0,0.0,0.0);
glVertex2f(1800.0,1050.0);
glVertex2f(1950.0,1050.0);
glVertex2f(1950.0,1150.0);
glVertex2f(1800.0,1150.0);
glEnd();
glBegin(GL_POLYGON); // car
glColor3f(0.0,0.0,0.0);
glVertex2f(1770.0,1030.0);
glVertex2f(1800.0,1050.0);
glVertex2f(1800.0,1150.0);
glVertex2f(1770.0,1130.0);
glEnd();
glBegin(GL_POLYGON); // car
glColor3f(0.0,0.0,0.0);
glVertex2f(1770.0,1030.0);
glVertex2f(1930.0,1030.0);
glVertex2f(1950.0,1050.0);
glVertex2f(1800.0,1050.0);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(1820.0,1080.0);
glVertex2f(1920.0,1080.0);
glVertex2f(1920.0,1080.0);
glVertex2f(1920.0,1110.0);
glVertex2f(1920.0,1110.0); //carrier
glVertex2f(1820.0,1110.0);
glVertex2f(1820.0,1110.0);

Department of CS&E, MITT 2018-19 Page 29


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(1820.0,1080.0);
glVertex2f(1840.0,1080.0);
glVertex2f(1840.0,1110.0);
glVertex2f(1860.0,1080.0);
glVertex2f(1860.0,1110.0);
glVertex2f(1880.0,1080.0);
glVertex2f(1880.0,1110.0);
glVertex2f(1900.0,1080.0);
glVertex2f(1900.0,1110.0);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(1780.0,1035.0); //head lamp
glVertex2f(1780.0,1045.0);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(1780.0,1125.0); //head lamp
glVertex2f(1780.0,1135.0);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(1790.0,1055.0); //horn grill
glVertex2f(1790.0,1125.0);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(1800.0,1040.0); //side window
glVertex2f(1928.0,1040.0);
glEnd();
glPopMatrix();

Department of CS&E, MITT 2018-19 Page 30


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
}
void poles()
{
glBegin(GL_POLYGON); // left pole
behind
glColor3f(0.0,0.0,0.0);
glVertex2f(30.0,1200.0);
glVertex2f(50.0,1200.0);
glVertex2f(50.0,1550.0);
glVertex2f(30.0,1550.0);
glEnd();
glBegin(GL_POLYGON); // right pole
behind
glColor3f(0.0,0.0,0.0);
glVertex2f(1725.0,1200.0);
glVertex2f(1745.0,1200.0);
glVertex2f(1745.0,1550.0);
glVertex2f(1725.0,1550.0);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(1750.0,1400.0);
glVertex2f(900.0+k,900.0+n); //right pole
thread front
glVertex2f(1770.0,1400.0);
glVertex2f(900.0+k,880.0+n);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(20.0,1400.0);
glVertex2f(900.0-k,900.0+n); //pole thread
front
glVertex2f(0.0,1400.0);

Department of CS&E, MITT 2018-19 Page 31


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
glVertex2f(900.0-k,880.0+n);
glEnd();
glBegin(GL_POLYGON); // left pole
front
glColor3f(0.0,0.0,0.0);
glVertex2f(0.0,900.0);
glVertex2f(20.0,900.0);
glVertex2f(20.0,1400.0);
glVertex2f(0.0,1400.0);
glEnd();
glBegin(GL_POLYGON); // right pole
front
glColor3f(0.0,0.0,0.0);
glVertex2f(1750.0,900.0);
glVertex2f(1770.0,900.0);
glVertex2f(1770.0,1400.0);
glVertex2f(1750.0,1400.0);
glEnd();
}
void display(void)
{
if(choice==1)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
sea1();
bridge();
boat();
car();
poles();
// car2();
glFlush();
}

Department of CS&E, MITT 2018-19 Page 32


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
if(choice==2)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
sea2();
bridge();
boat();
car();
poles();
// car2();
glFlush();
}
glutSwapBuffers();
}
void animate1()
{
q=q-.5;
y=y+0.2;
i+=0.2;
if((i>=135) && (i<=439))
{ k=k+0.1;
n=n+0.1;
}
if(i>=1200 && !(k<=0 && n<=0))
{
k=k-0.1;
n=n-0.1;
}
if(k<=0)
g-=0.5;
if(g<=-2100)
{

Department of CS&E, MITT 2018-19 Page 33


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
q=0;
g=0;
i=0;
k=0;
n=0;
s=0;
i=0;
y=0;
}
glutPostRedisplay();
}
void animate2()
{
q=q-.5;
y=y-0.2;
i+=0.2;
if((i>=135) && (i<=439))
{ k=k+0.1;
n=n+0.1;
}
if(i>=1200 && !(k<=0 && n<=0))
{
k=k-0.1;
n=n-0.1;
}
if(k<=0)
g-=0.5;
if(g<=-2100)
{
q=0;
g=0;

Department of CS&E, MITT 2018-19 Page 34


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
i=0;
k=0;
n=0;
s=0;
i=0;
y=1600;
}
glutPostRedisplay();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,1.0,1.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,2000.0,0.0,1600.0);
}
void main_menu(int ch)
{
switch(ch)
{
case 1: g=0;
i=0;
k=0;
n=0;
s=0;
i=0;
y=0;
glutIdleFunc(animate1);
break;

Department of CS&E, MITT 2018-19 Page 35


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
case 2: g=0;
i=0;
k=0;
n=0;
s=0;
i=0;
y=1600;
glutIdleFunc(animate2);
break;
case 3: glutIdleFunc(NULL);
break;
case 4:exit(0);
}
glutPostRedisplay();
}
void sub_menu(int id)
{
if(id==1)
{
choice=1;
}
if(id==2)
{
choice=2;
}
glutPostRedisplay();
}
void keyboard( unsigned char key, int x, int y )
{
switch( key )
{

Department of CS&E, MITT 2018-19 Page 36


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
case 'r':m=1.0,j=0.0,o=0.0;
glutPostRedisplay();
break;
case 'g':m=0.0,j=1.0,o=0.0;
glutPostRedisplay();
break;
case 'b':m=.80,j=.50,o=0.15;
glutPostRedisplay();
break;
case 'w':m=1.0,j=1.0,o=1.0;
glutPostRedisplay();
break;
case 'm':m=1.0,j=.0,o=1.0;
glutPostRedisplay();
break;
case 'c':m=.0,j=1.0,o=1.0;
glutPostRedisplay();
break;
case 'y':m=.75,j=0.75,o=.75;
glutPostRedisplay();
break;
}
}
int main(int argc,char **argv)
{
int id;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(2000,1600);
glutInitWindowPosition(0,0);
glutCreateWindow("BRIDGE SIMULATION");

Department of CS&E, MITT 2018-19 Page 37


2D Bascule Bridge Simulation Computer Graphics & Visualization Laboratory
id=glutCreateMenu(sub_menu);
glutAddMenuEntry("Day",1);
glutAddMenuEntry("Night",2);
glutCreateMenu(main_menu);
glutAddSubMenu("MODES",id);
glutAddMenuEntry("Downside Up Animation",1);
glutAddMenuEntry("Upside Down Animation",2);

glutAddMenuEntry("Stop Animation",3);
glutAddMenuEntry("Quit",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutKeyboardFunc(keyboard);
printf("press 'r' to change the ship color to red\n");
printf("press 'g' to change the ship color to
green\n");
printf("press 'b' to change the ship color to
brown\n");
printf("press 'c' to change the ship color to cyan\n");
printf("press 'm' to change the ship color to
majenta\n");
printf("press 'w' to change the ship color to
white\n");
printf("press 'y' to change the ship color to light
grey\n");
glutDisplayFunc(display);
myinit();
glClearColor (1.0, 1.0, 0.0, 1.0);
glutMainLoop();
return 0;
}

Department of CS&E, MITT 2018-19 Page 38

You might also like