Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

CHAPTER - 1
OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992 and is widely used in CAD,
INTRODUCTION 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.
COMPUTER GRAPHICS:
OpenGL provides a powerful but primitive set of rendering command, and all higher-level
Computer graphics is concerned with all aspects of producing pictures or images using drawing must be done in terms of these commands. There are several libraries that allow you to
computer. The field began humble almost 50 years ago, with the display of few lines on the cathode simplify your programming tasks, including the following:
ray tube (CRT) now, we can create images using computer that are indistinguishable from
photographs from the real objects.  OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL
Today computers and computer-generated images touch many aspects of our daily life. commands to perform such tasks as setting up matrices for specific viewing orientations
Computer imagery is found on television, in newspapers, in weather reports, and during surgical and projections and rendering surfaces.
procedures. A well-constructed graph can present complex statistics in a form that is and other
presentation material. A range of tools and facilities are available to enable users to visualize their  OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by Mark
data, and computer graphics are used in many disciplines Kilgard, to hide the complexities of differing window APIs. Rather than using a different
Graphics is created using computers and generally, the representation and manipulation of library for each system we use available library called openly utility toolkit. It is used as
pictorial data by computer .the development of computer graphics has made computers easier to #include <glut.h>.
interact and better for understanding and interpreting many types of data. The phrase “computer
graphics” was coined in 1960 by William Fetter, a graphic designer for Boeing.
The graphics in openly provides a wide variety of built-in functions. The computer graphics
remains one of the most exciting and growing computer fields. It has become a common element
in user interface. Major applications of computer graphics are in Computational Biology,
Computational physics, Computer Aided Designing, Computer simulation, Digital art, Education,
Graphic Design, Video gaming, Virtual reality and Web designing….etc. 1.1 Aim:
Show a walk-in simulation through the campus of college. The campus is visualized in a
3D perspective view with keyboard and mouse inputs for navigating through the campus

OpenGL (Open Graphics Library):


1.2 Overview:
OpenGL has become a widely accepted standard for developing graphics application. OpenGL is
The design and implementation of any graphical package needs knowledge of both
easy to learn, and it possesses most of the characteristics of other popular graphic system. It is top- computer graphics and a language that aids in the coding one of the interesting sections in graphics

down approach. OpenGL is a standard specification defining a cross-language, Cross-platform is transformation of objects. This projects involves the demonstration of some of the
transformation.A project using OpenGL to show a walk-in simulation through the campus of
API for writing applications that produce 2D and 3D computer graphics. The interface consists of
college.A project implemented using c and OpenGL in VisualStudio,aims at simulating the
over 250 different function calls which can be used to draw complex three dimensional scenes campus of the college. The campus portrayed is a sample of how the real campus looks however

from simple primitives.

DEPARTMENT OF CS & E, MITT -2018-19 1 DEPARTMENT OF CS & E, MITT -2018-19 2


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

details such as paint color and building dimensions couldn’t be accounted for.With help of textures Step 4: [Keyboard is used to interact with the user]
I have the football field . If „
“Mouse left” is pressed
Then
Input keys for the application: Drag left rotate & view towards left
If „
f-Move forward
“Mouse right” is pressed
b-Move backward Then

u-Move vertically up Drag right rotate & view towards right


If,,
d-Move vertically down
”w” key is pressed
Mouse left click and drag right-Rotate view towards right Then
glutKeyboardFunc() function gets called
Mouse left click and drag left-Rotate view towards left
it moves forwards,
If,,
”s” key is pressed

1.3 Outcome: Then


glutKeyboardFunc() function gets called
It can be used to travel the whole campus,we can easily find out the department blocks.
it moves Backwards,

CHAPTER – 2 If,,
”u” key is pressed
DESIGN AND IMPLEMENTATION Then
2.1 ALGORITHM glutKeyboardFunc() function gets called

Step 1: Start it moves upwards,


If,,
Step 2: [Create and Initialize the output window]
”j” key is pressed
glutCreateWindow ( ) function is called.
Then
glutKeyboardFunc() function gets called
Step 3: [Output window consisting of initial setup of bus is displayed]
it moves downwards,
The display( ) function is called.
Step5 : end

DEPARTMENT OF CS & E, MITT -2018-19 3 DEPARTMENT OF CS & E, MITT -2018-19 4


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top): Defines
2.3 OPENGL WITH DESCRIPTION a two-dimensional viewing rectangle in the plane.
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
void glutCreateWindow(char *title) : Creates a window on the display. The string title can be
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 used to label the window. The return value provides a reference to the window that can be used
contains code for creating common objects and simplifying viewing. All functions in GLU can be when there are multiple windows.
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. void glutInitDisplaymode(unsigned int mode) :Requests a display with the properties in mode.
This project makes extensive use of translations, rotations and scaling for creating Provides The value of mode is determined by the logical OR of options including the color
the description of the following functions. model(GLUT_RGB<GLUT_INDEX) and buffering (GLUT_SINGLE<GLUT_DOUBLE).
void glScalef(TYPE sx, TYPE sy, TYPE sz): Alters the current matrix by a scaling of (sx, sy,
sz). TYPE here is GLfloat. void glutInitWindowSize(int width,int heights) :Specifies the initial height and width of the
Here in the above considered example we use scaling to minimize the length of the curve at each window in pixels.
iteration. For this curve we use the scale factor to be 3 units because we substitute a line by 4 lines
in each iteration void glutInitWindowPosition(int x,int y) :Specifies the initial position of the top-left corner of
the window in pixels.
void glRotatef(TYPE angle, TYPE dx, TYPE dy, TYPE dz): Aalters the current matrix by a
rotation of angle degrees about the axis(dx, dy, dz). TYPE here is GLfloat. void glViewport(int x,int y,GLsizei width,GLsizei height): Specifies a width * height viewport
For a Koch curve we rotate by 60° about the z-axis. in pixels whose lower-left corner is at (x,y) measured from he origin of the window.

void glTranslatef(TYPE x, TYPE y, TYPE z): Alters the current matrix by a displacement of void glutMainLoop(): Cause the program to enter an event –processing loop.it should be the
(x, y, z). TYPE here is GLfloat. statement in main.
We need to translate to display the new position of the line from the old position and also to go
out to the beginning of the next side while drawing. void glutPostRedisplay() :Requests that the display callback be executed after the current
callback returns.
void glLoadIdentity(): Sets the current transformation matrix to an identity matrix.

void glPushMatrix(): Pushes to the matrix stack corresponding to the current matrix mode.

void glPopMatrix(): Pops from the matrix stack corresponding to the current matrix mode.

DEPARTMENT OF CS & E, MITT -2018-19 5 DEPARTMENT OF CS & E, MITT -2018-19 6


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

2.4 SOURCE CODE: glVertex3f(0,2,0);


glVertex3f(9,0,0);
glVertex3f(10,0,0);
glVertex3f(10,2,0);
//#include <Windows.h> glVertex3f(9,2,0);
#include<stdio.h> glEnd();
#include<math.h> glColor3f(0.690,0.878,0.901);
#include <cstdio> glBegin(GL_QUADS);
#include <cstdlib> glVertex3f(0,2,0);
#include <cstring> glVertex3f(10,2,0);
#include<errno.h> glVertex3f(10,4,0);
//#include<GL\GL.h> glVertex3f(0,4,0);
//#include<GL\GLU.h> glEnd();
#include<GL/glut.h> }
float y = 1, x = -30, z = 100; // initially 5 units south of GLuint loadBMP_custom(const char * imagepath)
origin {
float deltaMove = 0.0; // initially camera doesn't move // Open the file
// Camera direction FILE * file = fopen(imagepath,"rb");
float lx = 0.0, lz = -1; // camera points initially along y-axis if (!file)
//float angle = 0.0; // angle of rotation for the camera {
direction printf("Image could not be opened\n");
//float deltaAngle = 0.0; // additional angle change when printf("Error %d \n", errno);
dragging return 0;
float angle = 0.0; // angle of rotation for the camera direction }
float deltaAngle = 0.0; // additional angle change when dragging if ( fread(header, 1, 54, file)!=54 )
// Mouse drag control { // If not 54 bytes read : problem
int isDragging = 0; // true when dragging printf("Not a correct BMP file\n");
int xDragStart = 0; // records the x-coordinate when dragging return false;
starts }
int move=0; if ( header[0]!='B' || header[1]!='M' )
int vertmove=0; {
unsigned char header[54]; // Each BMP file begins by a 54- printf("Not a correct BMP file\n");
bytes header return 0;
unsigned int dataPos; // Position in the file where }
the actual data begins dataPos = *(int*)&(header[0x0A]);
unsigned int width, height; imageSize = *(int*)&(header[0x22]);
unsigned int imageSize; // = width*height*3 width = *(int*)&(header[0x12]);
unsigned char * data=NULL; // Actual RGB data height = *(int*)&(header[0x16]);
void draw_board() // Some BMP files are misformatted, guess missing information
{ if (imageSize==0)
glColor3f(0.177,0.564,1); imageSize=width*height*3; // 3 : one byte for each Red,
glBegin(GL_QUADS); Green and Blue component
glVertex3f(0,0,0); if (dataPos==0)
glVertex3f(1,0,0); dataPos=54; // The BMP header is done that way
glVertex3f(1,2,0); // Create a buffer

DEPARTMENT OF CS & E, MITT -2018-19 7 DEPARTMENT OF CS & E, MITT -2018-19 8


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

data = new unsigned char [imageSize]; glEnable(GL_TEXTURE_2D);


// Read the actual data from the file into the buffer GLuint textureID;
fread(data,1,imageSize,file); glGenTextures(1, &textureID);
//Everything is in memory now, the file can be closed glBindTexture(GL_TEXTURE_2D, textureID);
fclose(file); // Set the texture wrapping parameters
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
void draw_map() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
{ // Set texture filtering parameters
GLuint Texture = loadBMP_custom("field.bmp"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
glEnable(GL_TEXTURE_2D); GL_LINEAR);
GLuint textureID; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
glGenTextures(1, &textureID); GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, textureID); // Load image, create texture and generate mipmaps
// Set the texture wrapping parameters glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); GL_RGB, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glColor3f(1.0f,1.0f,1.0f);
GL_LINEAR); glBegin(GL_QUADS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, .0f, 0.0f);
GL_LINEAR); glTexCoord2f(1.0f, 0.0f); glVertex3f(4.0f, 0.0f,
// Load image, create texture and generate mipmaps 0.0f);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, glTexCoord2f(1.0f, 1.0f); glVertex3f( 4.0f, 5.0f,
GL_RGB, GL_UNSIGNED_BYTE, data); 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 5.0f,
glColor3f(1.0f,1.0f,1.0f); 0.0f);
glBegin(GL_QUADS); glEnd();
glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.0f, -3.0f, glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture when done,
20.0f); so we won't accidentily mess up our texture.
glTexCoord2f(10.0f, 0.0f); glVertex3f(30.0f, -3.0f, delete []data;
20.0f); glDeleteTextures(1, &textureID);
glTexCoord2f(10.0f, 10.0f); glVertex3f( 30.0f, -3.0f, glDisable(GL_TEXTURE_2D);
-20.0f); }
glTexCoord2f(0.0f, 10.0f); glVertex3f( -15.0f, -3.0f, void restrict() //restrict movement within boundaries
-20.0f); {
glEnd(); if(x>100) x=100;
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture when done, else if(x<-100) x=-100;
so we won't accidentily mess up our texture. if(y>60) y=60;
delete []data; else if(y<0.5) y=0.5;
glDeleteTextures(1, &textureID); if(z>100) z=100;
glDisable(GL_TEXTURE_2D); else if(z<-100) z=-100;
} }
void draw_idol() void mech_court() //badminton court
{ {
GLuint Texture = loadBMP_custom("Vishnu.bmp"); int k;

DEPARTMENT OF CS & E, MITT -2018-19 9 DEPARTMENT OF CS & E, MITT -2018-19 10


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,0.1,20); glVertex3f(k,0,0.1);
glColor3f(0.5,0.5,0.5); glVertex3f(k,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,4,0.1);
glVertex3f(0,0,0); glVertex3f(k-2,0,0.1);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-40); }
glVertex3f(0,0,-40); glPopMatrix();
glEnd(); glPushMatrix();
glColor3f(0,0,0); glTranslatef(-65,0.1,15);
for(k=2;k<18;k+=4) glColor3f(0,0,1);
{ glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0.2,0);
glVertex3f(k,0,-0.1); glVertex3f(10,0.2,0);
glVertex3f(k,4,-0.1); glVertex3f(10,0.2,-30);
glVertex3f(k+2,4,-0.1); glVertex3f(0,0.2,-30);
glVertex3f(k+2,0,-0.1); glEnd();
glEnd(); glColor3f(1,1,1);
} glBegin(GL_LINE_LOOP);
for(k=-2;k>-38;k-=6) glVertex3f(1,0.3,-1);
{ glVertex3f(9,0.3,-1);
glBegin(GL_QUADS); glVertex3f(9,0.3,-13);
glVertex3f(0.1,0,k); glVertex3f(1,0.3,-13);
glVertex3f(0.1,4,k); glEnd();
glVertex3f(0.1,4,k-2); glBegin(GL_LINE_LOOP);
glVertex3f(0.1,0,k-2); glVertex3f(1,0.3,-15);
glEnd(); glVertex3f(9,0.3,-15);
} glVertex3f(9,0.3,-29);
glPopMatrix(); glVertex3f(1,0.3,-29);
glPushMatrix(); glEnd();
glTranslatef(-50,0.1,20); glPopMatrix();
for(k=-2;k>-38;k-=6) glPushMatrix();
{ glTranslatef(-65,0,8);
glBegin(GL_QUADS); glColor3f(1,1,1);
glVertex3f(-0.1,0,k); for(float i=0;i<0.8;i+=0.2)
glVertex3f(-0.1,4,k); for(float j=0;j<9.8;j+=0.2)
glVertex3f(-0.1,4,k-2); {
glVertex3f(-0.1,0,k-2); glBegin(GL_LINE_LOOP);
glEnd(); glVertex3f(j,i,0);
} glVertex3f(j+0.2,i,0);
glPopMatrix(); glVertex3f(j+0.2,i+0.2,0);
glPushMatrix(); glVertex3f(j,i+0.2,0);
glTranslatef(-50,0.1,-20); glEnd();
for(k=-2;k>-18;k-=4) }
{ glPopMatrix();

DEPARTMENT OF CS & E, MITT -2018-19 11 DEPARTMENT OF CS & E, MITT -2018-19 12


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-65,0,-8); glVertex3f(0,0,0);
glColor3f(1,1,1); glVertex3f(0,0,-40);
for(float i=0;i<0.8;i+=0.2) glVertex3f(-4,0,-40);
for(float j=0;j<9.8;j+=0.2) glVertex3f(-4,0,0);
{ glEnd();
glBegin(GL_LINE_LOOP); glColor3f(1,0.972,0.862);
glVertex3f(j,i,0); glBegin(GL_QUADS);
glVertex3f(j+0.2,i,0); glVertex3f(-4,0,-4);
glVertex3f(j+0.2,i+0.2,0); glVertex3f(-4,0,-36);
glVertex3f(j,i+0.2,0); glVertex3f(-4,2,-36);
glEnd(); glVertex3f(-4,2,-4);
} glEnd();
glPopMatrix(); glColor3f(0,0,0);
for(int i=0;i<15;i+=5) for(k=-2;k>-38;k-=6)
{ {
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,6+i,20); glVertex3f(-0.1,0,k);
glColor3f(1,0.894,0.709); glVertex3f(-0.1,4,k);
glBegin(GL_QUADS); glVertex3f(-0.1,4,k-2);
glVertex3f(0,0,0); glVertex3f(-0.1,0,k-2);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-4); }
glVertex3f(0,0,-4); glTranslatef(0,0,-40);
glEnd(); glColor3f(1,0.894,0.709);
glColor3f(1,0.972,0.862); glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0,0);
glVertex3f(4,0,-4); glVertex3f(-20,0,0);
glVertex3f(16,0,-4); glVertex3f(-20,0,4);
glVertex3f(16,2,-4); glVertex3f(0,0,4);
glVertex3f(4,2,-4); glEnd();
glEnd(); glColor3f(1,0.972,0.862);
glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=2;k<18;k+=4) glVertex3f(-4,0,4);
{ glVertex3f(-16,0,4);
glBegin(GL_QUADS); glVertex3f(-16,2,4);
glVertex3f(k,0,-0.1); glVertex3f(-4,2,4);
glVertex3f(k,4,-0.1); glEnd();
glVertex3f(k+2,4,-0.1); glColor3f(0,0,0);
glVertex3f(k+2,0,-0.1); for(k=-2;k>-18;k-=4)
glEnd(); {
} glBegin(GL_QUADS);
glPushMatrix(); glVertex3f(k,0,0.1);
glTranslatef(20,0,0); glVertex3f(k,4,0.1);
glColor3f(1,0.894,0.709); glVertex3f(k-2,4,0.1);

DEPARTMENT OF CS & E, MITT -2018-19 13 DEPARTMENT OF CS & E, MITT -2018-19 14


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glVertex3f(k-2,0,0.1); glBegin(GL_QUADS);
glEnd(); glVertex3f(k,0,-0.1);
} glVertex3f(k,4,-0.1);
glPopMatrix(); glVertex3f(k+2,4,-0.1);
glColor3f(1,0.894,0.709); glVertex3f(k+2,0,-0.1);
glBegin(GL_QUADS); glEnd();
glVertex3f(0,0,0); }
glVertex3f(0,0,-40); for(k=-2;k>-38;k-=6)
glVertex3f(4,0,-40); {
glVertex3f(4,0,0); glBegin(GL_QUADS);
glEnd(); glVertex3f(0.1,0,k);
glColor3f(1,0.972,0.862); glVertex3f(0.1,4,k);
glBegin(GL_QUADS); glVertex3f(0.1,4,k-2);
glVertex3f(4,0,-4); glVertex3f(0.1,0,k-2);
glVertex3f(4,0,-36); glEnd();
glVertex3f(4,2,-36); }
glVertex3f(4,2,-4); glPopMatrix();
glEnd(); glPushMatrix();
glColor3f(0,0,0); glTranslatef(-50,0.1,-30);
for(k=-2;k>-38;k-=6) for(k=-2;k>-38;k-=6)
{ {
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f(0.1,0,k); glVertex3f(-0.1,0,k);
glVertex3f(0.1,4,k); glVertex3f(-0.1,4,k);
glVertex3f(0.1,4,k-2); glVertex3f(-0.1,4,k-2);
glVertex3f(0.1,0,k-2); glVertex3f(-0.1,0,k-2);
glEnd(); glEnd();
} }
glPopMatrix(); glPopMatrix();
} glPushMatrix();
} glTranslatef(-50,0.1,-70);
void disp_mba() //mba block interiors for(k=-2;k>-18;k-=4)
{int k; {
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,0.1,-30); glVertex3f(k,0,0.1);
glColor3f(0.5,0.5,0.5); glVertex3f(k,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,4,0.1);
glVertex3f(0,0,0); glVertex3f(k-2,0,0.1);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-40); }
glVertex3f(0,0,-40); glPopMatrix();
glEnd(); for(int i=0;i<15;i+=5)
glColor3f(0,0,0); {
for(k=2;k<18;k+=4) glPushMatrix();
{ glTranslatef(-70,6+i,-30);

DEPARTMENT OF CS & E, MITT -2018-19 15 DEPARTMENT OF CS & E, MITT -2018-19 16


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glColor3f(1,0.894,0.709); glVertex3f(-0.1,4,k);
glBegin(GL_QUADS); glVertex3f(-0.1,4,k-2);
glVertex3f(0,0,0); glVertex3f(-0.1,0,k-2);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-4); }
glVertex3f(0,0,-4); glTranslatef(0,0,-40);
glEnd(); glColor3f(1,0.894,0.709);
glColor3f(1,0.972,0.862); glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0,0);
glVertex3f(4,0,-4); glVertex3f(-20,0,0);
glVertex3f(16,0,-4); glVertex3f(-20,0,4);
glVertex3f(16,2,-4); glVertex3f(0,0,4);
glVertex3f(4,2,-4); glEnd();
glEnd(); glColor3f(1,0.972,0.862);
glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=2;k<18;k+=4) glVertex3f(-4,0,4);
{ glVertex3f(-16,0,4);
glBegin(GL_QUADS); glVertex3f(-16,2,4);
glVertex3f(k,0,-0.1); glVertex3f(-4,2,4);
glVertex3f(k,4,-0.1); glEnd();
glVertex3f(k+2,4,-0.1); glColor3f(0,0,0);
glVertex3f(k+2,0,-0.1); for(k=-2;k>-18;k-=4)
glEnd(); {
} glBegin(GL_QUADS);
glPushMatrix(); glVertex3f(k,0,0.1);
glTranslatef(20,0,0); glVertex3f(k,4,0.1);
glColor3f(1,0.894,0.709); glVertex3f(k-2,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,0,0.1);
glVertex3f(0,0,0); glEnd();
glVertex3f(0,0,-40); }
glVertex3f(-4,0,-40); glPopMatrix();
glVertex3f(-4,0,0); glColor3f(1,0.894,0.709);
glEnd(); glBegin(GL_QUADS);
glColor3f(1,0.972,0.862); glVertex3f(0,0,0);
glBegin(GL_QUADS); glVertex3f(0,0,-40);
glVertex3f(-4,0,-4); glVertex3f(4,0,-40);
glVertex3f(-4,0,-36); glVertex3f(4,0,0);
glVertex3f(-4,2,-36); glEnd();
glVertex3f(-4,2,-4); glColor3f(1,0.972,0.862);
glEnd(); glBegin(GL_QUADS);
glColor3f(0,0,0); glVertex3f(4,0,-4);
for(k=-2;k>-38;k-=6) glVertex3f(4,0,-36);
{ glVertex3f(4,2,-36);
glBegin(GL_QUADS); glVertex3f(4,2,-4);
glVertex3f(-0.1,0,k); glEnd();

DEPARTMENT OF CS & E, MITT -2018-19 17 DEPARTMENT OF CS & E, MITT -2018-19 18


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=-2;k>-38;k-=6) glVertex3f(stair[0][0]-x,stair[0][1]-
{ y,stair[0][2]+z);
glBegin(GL_QUADS); glVertex3f(stair[1][0]+x,stair[1][1]-
glVertex3f(0.1,0,k); y,stair[1][2]+z);
glVertex3f(0.1,4,k); glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
glVertex3f(0.1,4,k-2); z);
glVertex3f(0.1,0,k-2); glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
glEnd(); z);
} glEnd();
glPopMatrix(); glColor3f(0.933,0.913,0.8);
} glBegin(GL_QUADS);
glVertex3f(stair[0][0]-x,stair[0][1]-
} y,stair[0][2]+z);
class temple //construction of temple glVertex3f(stair[0][0]-x,stair[0][1]-1-
{ y,stair[0][2]+z);
float stair[4][3]; glVertex3f(stair[1][0]+x,stair[1][1]-1-
float room[8][3]; y,stair[1][2]+z);
float ceil[6][3]; glVertex3f(stair[1][0]+x,stair[1][1]-
public: y,stair[1][2]+z);
temple()
{ glVertex3f(stair[1][0]+x,stair[1][1]-
stair[0][0]=0;stair[0][1]=0;stair[0][2]=0; y,stair[1][2]+z);
stair[1][0]=12;stair[1][1]=0;stair[1][2]=0; glVertex3f(stair[1][0]+x,stair[1][1]-1-
stair[2][0]=12;stair[2][1]=0;stair[2][2]=-12; y,stair[1][2]+z);
stair[3][0]=0;stair[3][1]=0;stair[3][2]=-12; glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-
z);
room[0][0]=0;room[0][1]=0;room[0][2]=0; glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
room[1][0]=0;room[1][1]=6;room[1][2]=0; z);
room[2][0]=0;room[2][1]=6;room[2][2]=-7;
room[3][0]=0;room[3][1]=0;room[3][2]=-7; glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
room[4][0]=7;room[4][1]=0;room[4][2]=-7; z);
room[5][0]=7;room[5][1]=6;room[5][2]=-7; glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
room[6][0]=7;room[6][1]=6;room[6][2]=0; z);
room[7][0]=7;room[7][1]=0;room[7][2]=0; glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]-
ceil[0][0]=0;ceil[0][1]=6;ceil[0][2]=4; z);
ceil[1][0]=3.5;ceil[1][1]=9;ceil[1][2]=4; glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-
ceil[2][0]=7;ceil[2][1]=6;ceil[2][2]=4; z);
ceil[3][0]=7;ceil[3][1]=6;ceil[3][2]=-9;
ceil[4][0]=3.5;ceil[4][1]=9;ceil[4][2]=-9; glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
ceil[5][0]=0;ceil[5][1]=6;ceil[5][2]=-9; z);
} glVertex3f(stair[0][0]-x,stair[0][1]-
void disp_stair(int x, int y, int z) y,stair[0][2]+z);
{ glVertex3f(stair[0][0]-x,stair[0][1]-1-
glColor3f(1,0.960,0.933); y,stair[0][2]+z);

DEPARTMENT OF CS & E, MITT -2018-19 19 DEPARTMENT OF CS & E, MITT -2018-19 20


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]- glColor3f(0.933,0.866,0.509);
z); glBegin(GL_POLYGON);
glEnd(); glVertex3fv(ceil[2]);
} glVertex3fv(ceil[1]);
void disp_room() glVertex3fv(ceil[4]);
{ glVertex3fv(ceil[3]);
glColor3f(0.803,0.803,0.756); glEnd();
glBegin(GL_QUADS); glBegin(GL_POLYGON);
glVertex3fv(room[0]); glVertex3fv(ceil[0]);
glVertex3fv(room[1]); glVertex3fv(ceil[1]);
glVertex3fv(room[2]); glVertex3fv(ceil[4]);
glVertex3fv(room[3]); glVertex3fv(ceil[5]);
glVertex3fv(room[3]); glEnd();
glVertex3fv(room[2]); }
glVertex3fv(room[5]); void draw_pil()
glVertex3fv(room[4]); {
glVertex3fv(room[4]); GLUquadricObj *quadratic;
glVertex3fv(room[5]); quadratic = gluNewQuadric();
glVertex3fv(room[6]); glPushMatrix();
glVertex3fv(room[7]); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glVertex3fv(room[1]); glColor3f(0.933,0.866,0.509);
glVertex3fv(room[2]); gluCylinder(quadratic,0.5,0.5,6.0f,32,32);
glVertex3fv(room[5]); glPopMatrix();
glVertex3fv(room[6]); }
glVertex3fv(room[0]); void draw_mesh()
glVertex3f(room[0][0]+1,room[0][1],room[0][2]); {
glVertex3f(room[1][0]+1,room[1][1],room[1][2]); glColor3f(1,0.843,0);
glVertex3fv(room[1]); for(float i=0;i<0.9;i+=0.2)
glVertex3fv(room[7]); for(float j=0;j<6;j+=0.2)
glVertex3f(room[7][0]-1,room[7][1],room[7][2]); {
glVertex3f(room[6][0]-1,room[6][1],room[6][2]); glBegin(GL_LINE_LOOP);
glVertex3fv(room[6]); glVertex3f(i,j,0);
glEnd(); glVertex3f(i+0.2,j,0);
} glVertex3f(i+0.2,j+0.2,0);
void disp_ceil() glVertex3f(i,j+0.2,0);
{ glEnd();
glColor3f(1,0.843,0); }
glBegin(GL_TRIANGLES); }
glVertex3fv(ceil[2]); void disp_temple()
glVertex3fv(ceil[1]); {
glVertex3fv(ceil[0]); disp_stair(0,0,0);
glVertex3fv(ceil[3]); glPushMatrix();
glVertex3fv(ceil[4]); disp_stair(2,1,2);
glVertex3fv(ceil[5]); disp_stair(4,2,4);
glEnd();

DEPARTMENT OF CS & E, MITT -2018-19 21 DEPARTMENT OF CS & E, MITT -2018-19 22


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glPopMatrix(); glVertex3fv(structure[0]);
glPushMatrix(); glVertex3fv(structure[1]);
glTranslatef(4,0,-9); glVertex3fv(structure[2]);
glRotatef(-90,0,1,0); glVertex3fv(structure[3]);
disp_room(); glEnd();
disp_ceil(); glBegin(GL_QUADS);
glPushMatrix(); glVertex3fv(structure[0]);
glTranslatef(0.4,0,2.5); glVertex3fv(structure[4]);
draw_pil(); glVertex3fv(structure[7]);
glTranslatef(6.2,0,0); glVertex3fv(structure[3]);
draw_pil(); glEnd();
glPopMatrix(); glBegin(GL_QUADS);
glPushMatrix(); glVertex3fv(structure[4]);
glTranslatef(1.5,0,-3); glVertex3fv(structure[5]);
draw_idol(); glVertex3fv(structure[6]);
glPopMatrix(); glVertex3fv(structure[7]);
glPushMatrix(); glEnd();
glTranslatef(1,0,0); glBegin(GL_QUADS);
draw_mesh(); glVertex3fv(structure[1]);
glTranslatef(4,0,0); glVertex3fv(structure[2]);
draw_mesh(); glVertex3fv(structure[6]);
glPopMatrix(); glVertex3fv(structure[5]);
glPopMatrix(); glEnd();
}
}temp; if(structure[1][0]>(-1*structure[4][2]))
class building //construction of the block buildings {
{ for(float i=10; i<structure[2][1]; i+=10)
float structure[8][3]; {
public: glPushMatrix();
building(float a, float b, float c) glTranslatef(0,i,0);
{ for(float j=5; j<structure[1][0]; j+=15)
structure[0][0]=0;structure[0][1]=0;structure[0][2]=0; {
structure[1][0]=a;structure[1][1]=0;structure[1][2]=0; glColor3f(0,0,0);
structure[2][0]=a;structure[2][1]=b;structure[2][2]=0; glBegin(GL_POLYGON);
structure[3][0]=0;structure[3][1]=b;structure[3][2]=0; glVertex3f(j,0,0.1);
structure[4][0]=0;structure[4][1]=0;structure[4][2]=c; glVertex3f(j+5,0,0.1);
structure[5][0]=a;structure[5][1]=0;structure[5][2]=c; glVertex3f(j+5,5,0.1);
structure[6][0]=a;structure[6][1]=b;structure[6][2]=c; glVertex3f(j,5,0.1);
structure[7][0]=0;structure[7][1]=b;structure[7][2]=c; glEnd();
} glBegin(GL_POLYGON);
void disp_build(char text[15],char side='/0') glVertex3f(j,0,structure[4][2]-0.1);
{ glVertex3f(j+5,0,structure[4][2]-0.1);
float door[3]; glVertex3f(j+5,5,structure[4][2]-0.1);
glColor3f(1,0.980,0.980); glVertex3f(j,5,structure[4][2]-0.1);
glBegin(GL_QUADS); glEnd();

DEPARTMENT OF CS & E, MITT -2018-19 23 DEPARTMENT OF CS & E, MITT -2018-19 24


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

} glTranslatef(0,i,0);
for(float j=0;j<structure[1][0];j+=15) for(float j=-5; j>structure[4][2]; j-=15)
{ {
glColor3f(1,0,0); glColor3f(0,0,0);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f(j,-10,0.1); glVertex3f(-0.1,0,j);
glVertex3f(j+2,-10,0.1); glVertex3f(-0.1,0,j-5);
glVertex3f(j+2,10,0.1); glVertex3f(-0.1,5,j-5);
glVertex3f(j,10,0.1); glVertex3f(-0.1,5,j);
glEnd(); glEnd();
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f(j,-10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,0,j);
glVertex3f(j+2,-10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,0,j-5);
glVertex3f(j+2,10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,5,j-5);
glVertex3f(j,10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,5,j);
glEnd(); glEnd();
} }
glPopMatrix(); for(float j=0;j>structure[4][2];j-=15)
} {
glColor3f(0,0,0); glColor3f(1,0,0);
door[0]=(structure[1][0]/2); glBegin(GL_POLYGON);
glBegin(GL_POLYGON); glVertex3f(-0.1,-10,j);
glVertex3f(door[0]-4,0,0.2); glVertex3f(-0.1,-10,j-2);
glVertex3f(door[0]+4,0,0.2); glVertex3f(-0.1,10,j-2);
glVertex3f(door[0]+4,7,0.2); glVertex3f(-0.1,10,j);
glVertex3f(door[0]-4,7,0.2); glEnd();
glEnd(); glBegin(GL_POLYGON);
glPushMatrix(); glVertex3f(structure[1][0]+0.1,-10,j);
glTranslatef(10,0,3); glVertex3f(structure[1][0]+0.1,-10,j-2);
draw_board(); glVertex3f(structure[1][0]+0.1,10,j-2);
glPushMatrix(); glVertex3f(structure[1][0]+0.1,10,j);
glTranslatef(1,2,0.1); glEnd();
glScalef(.01, .01, .01); }
glLineWidth(2); glPopMatrix();
glColor3f(0,0,0); }
for (int c=0; text[c] != 0; ++c) door[2]=(structure[4][2]/2);
glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); door[0]=structure[1][0];
glPopMatrix(); glColor3f(0,0,0);
glPopMatrix(); if(side=='r')
} {
else glBegin(GL_POLYGON);
{ glVertex3f(door[0]+0.2,0,door[2]-4);
for(float i=10; i<structure[2][1]; i+=10) glVertex3f(door[0]+0.2,0,door[2]+4);
{ glVertex3f(door[0]+0.2,7,door[2]+4);
glPushMatrix(); glVertex3f(door[0]+0.2,7,door[2]-4);

DEPARTMENT OF CS & E, MITT -2018-19 25 DEPARTMENT OF CS & E, MITT -2018-19 26


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glEnd(); glBegin(GL_LINES);
glPushMatrix();
glTranslatef(door[0]+3,0,-2); glVertex3f(structure[0][0],i,structure[0][2]+0.1);
glRotatef(90,0,1,0);
draw_board(); glVertex3f(structure[1][0],i,structure[0][2]+0.1);
glPushMatrix(); glVertex3f(structure[0][0]-
glTranslatef(1,2,0.1); 0.1,i,structure[0][2]);
glScalef(.01, .01, .01); glVertex3f(structure[0][0]-
glLineWidth(2); 0.1,i,structure[4][2]);
glColor3f(0,0,0); glVertex3f(structure[4][0],i,structure[4][2]-
for (int c=0; text[c] != 0; ++c) 0.1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, glVertex3f(structure[5][0],i,structure[4][2]-
text[c]); 0.1);
glPopMatrix();
glPopMatrix(); glVertex3f(structure[5][0]+0.1,i,structure[5][2]);
}
else if(side=='l') glVertex3f(structure[1][0]+0.1,i,structure[1][2]);
{ glEnd();
glBegin(GL_POLYGON); }
glVertex3f(-0.2,0,door[2]-4); glPopMatrix();
glVertex3f(-0.2,0,door[2]+4); }
glVertex3f(-0.2,7,door[2]+4); };
glVertex3f(-0.2,7,door[2]-4); building canteen(20,30,-30);
glEnd(); building mech(20,40,-40);
glPushMatrix(); building mba(20,40,-40);
glTranslatef(-3,0,-10); building admin(40,30,-20);
glRotatef(-90,0,1,0); building ec(40,30,-30);
draw_board(); building cs(30,40,-40);
glPushMatrix(); void loop(float x,float y,float z) //the basket loop of
glTranslatef(1,2,0.1); the basketball post
glScalef(.01, .01, .01); {
glLineWidth(2); float xx,zz,d;
glColor3f(0,0,0); glColor3f(1,0,0);
for (int c=0; text[c] != 0; ++c) glPointSize(2);
glutStrokeCharacter(GLUT_STROKE_ROMAN, glBegin(GL_POINTS);
text[c]); for(int i=0;i<360;i++)
glPopMatrix(); {
glPopMatrix(); d=i*(180/3.14);
} xx=cos(d)+x;
} zz=sin(d)+z;
glPushMatrix(); glVertex3f(xx,y,zz);
glTranslatef(0,10,0); }
glColor3f(0,0,1); glEnd();
for(int i=0;i<structure[2][1]-5;i+=5) }
{

DEPARTMENT OF CS & E, MITT -2018-19 27 DEPARTMENT OF CS & E, MITT -2018-19 28


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

class bball //construction of basketball glPopMatrix();


court glPushMatrix();
{ glTranslatef(15,0,-20);
float bordr[4][3]; loop(0,5,1);
float bskt[8][3]; glPushMatrix();
public: glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
bball() glColor3f(0.698,0.133,0.133);
{ gluCylinder(quadratic1,0.1,0.1,5.0f,32,32);
bordr[0][0]=0;bordr[0][1]=0;bordr[0][2]=0; glPopMatrix();
bordr[1][0]=20;bordr[1][1]=0;bordr[1][2]=0; glPopMatrix();
bordr[2][0]=20;bordr[2][1]=0;bordr[2][2]=-20; glColor3f(0.745,0.745,0.745);
bordr[3][0]=0;bordr[3][1]=0;bordr[3][2]=-20; glBegin(GL_QUADS);
bskt[0][0]=14;bskt[0][1]=4.5;bskt[0][2]=-0.1; for(int i=0;i<8;i++)
bskt[1][0]=16;bskt[1][1]=4.5;bskt[1][2]=-0.1; glVertex3fv(bskt[i]);
bskt[2][0]=16;bskt[2][1]=6.5;bskt[2][2]=-0.1; glEnd();
bskt[3][0]=14;bskt[3][1]=6.5;bskt[3][2]=-0.1; glPopMatrix();
bskt[4][0]=14,bskt[4][1]=4.5;bskt[4][2]=-19.9; }
bskt[5][0]=16;bskt[5][1]=4.5;bskt[5][2]=-19.9; };
bskt[6][0]=16;bskt[6][1]=6.5;bskt[6][2]=-19.9; bball crt1;
bskt[7][0]=14;bskt[7][1]=6.5;bskt[7][2]=-19.9; class ground //construction of the football field
} {
void disp_court() float bordr[4][3];
{ public:
glPushMatrix(); ground()
glTranslatef(0,0.1,0); {
glColor3f(0.745,0.745,0.745); bordr[0][0]=0;bordr[0][1]=-2;bordr[0][2]=0;
glBegin(GL_QUADS); bordr[1][0]=40;bordr[1][1]=-2;bordr[1][2]=0;
glVertex3fv(bordr[0]); bordr[2][0]=40;bordr[2][1]=-2;bordr[2][2]=-40;
glVertex3fv(bordr[1]); bordr[3][0]=0;bordr[3][1]=-2;bordr[3][2]=-40;
glVertex3fv(bordr[2]); }
glVertex3fv(bordr[3]); void ground_disp()
glEnd(); {
glColor3f(1,0.270,0); float t=6;
GLUquadricObj *quadratic; for(int i=0;i<3;i++,t-=2)
quadratic = gluNewQuadric(); {
GLUquadricObj *quadratic1; glPushMatrix();
quadratic1 = gluNewQuadric(); glTranslatef(0,i,0);
glPushMatrix(); glColor3f(0.803,0.701,0.545);
glTranslatef(15,0,0); glBegin(GL_POLYGON);
loop(0,5,-1); glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]);
glPushMatrix(); glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]-
glColor3f(0.698,0.133,0.133); t);
gluCylinder(quadratic,0.1,0.1,5.0f,32,32); glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]-
glPopMatrix(); t);

DEPARTMENT OF CS & E, MITT -2018-19 29 DEPARTMENT OF CS & E, MITT -2018-19 30


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glEnd();
glColor3f(0.545,0.474,0.368); glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]+t);
glBegin(GL_POLYGON); glVertex3f(bordr[3][0],bordr[3][1]-
glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]- 1,bordr[3][2]+t);
t); glVertex3f(bordr[2][0],bordr[2][1]-
glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]- 1,bordr[2][2]+t);
t); glEnd();
glVertex3f(bordr[1][0],bordr[1][1]-1,bordr[1][2]- glColor3f(0.803,0.701,0.545);
t); glBegin(GL_POLYGON);
glVertex3f(bordr[0][0],bordr[0][1]-1,bordr[0][2]- glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]);
t); glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]);
glEnd();
glColor3f(0.803,0.701,0.545); glVertex3f(bordr[0][0]+t,bordr[0][1],bordr[0][2]);
glBegin(GL_POLYGON);
glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]); glVertex3f(bordr[3][0]+t,bordr[3][1],bordr[3][2]);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]); glEnd();
glVertex3f(bordr[2][0]- glColor3f(0.545,0.474,0.368);
t,bordr[2][1],bordr[2][2]); glBegin(GL_POLYGON);
glVertex3f(bordr[1][0]- glVertex3f(bordr[0][0]+t,bordr[0][1],bordr[0][2]);
t,bordr[1][1],bordr[1][2]);
glEnd(); glVertex3f(bordr[3][0]+t,bordr[3][1],bordr[3][2]);
glColor3f(0.545,0.474,0.368); glVertex3f(bordr[3][0]+t,bordr[3][1]-
glBegin(GL_POLYGON); 1,bordr[3][2]);
glVertex3f(bordr[1][0]- glVertex3f(bordr[0][0]+t,bordr[0][1]-
t,bordr[1][1],bordr[1][2]); 1,bordr[0][2]);
glVertex3f(bordr[2][0]- glEnd();
t,bordr[2][1],bordr[2][2]); glPopMatrix();
glVertex3f(bordr[2][0]-t,bordr[2][1]- }
1,bordr[2][2]); glPushMatrix();
glVertex3f(bordr[1][0]-t,bordr[1][1]- glTranslatef(16.5,-3,-7);
1,bordr[1][2]); glColor3f(0.827,0.827,0.827);
glEnd(); glLineWidth(10);
glColor3f(0.803,0.701,0.545); glBegin(GL_LINE_LOOP);
glBegin(GL_POLYGON); glVertex3f(0,0,0);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]); glVertex3f(0,2,0);
glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]); glVertex3f(4,2,0);
glVertex3f(4,0,0);
glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]+t); glEnd();
glPopMatrix();
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]+t); glPushMatrix();
glEnd(); glTranslatef(16.5,-3,-33);
glColor3f(0.545,0.474,0.368); glColor3f(0.827,0.827,0.827);
glBegin(GL_POLYGON); glLineWidth(10);
glBegin(GL_LINE_LOOP);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]+t); glVertex3f(0,0,0);

DEPARTMENT OF CS & E, MITT -2018-19 31 DEPARTMENT OF CS & E, MITT -2018-19 32


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glVertex3f(0,2,0); glBegin(GL_QUADS);
glVertex3f(4,2,0); glVertex3f(-20,0.1,75);
glVertex3f(4,0,0); glVertex3f(40,0.1,75);
glEnd(); glVertex3f(40,0.1,80);
glPopMatrix(); glVertex3f(-20,0.1,80);
} glEnd();
}fball; glBegin(GL_QUADS);
void changeSize(int w, int h) glVertex3f(35,0.1,75);
{ glVertex3f(35,0.1,-70);
float ratio = ((float) w) / ((float) h); // window aspect glVertex3f(40,0.1,-70);
ratio glVertex3f(40,0.1,75);
glMatrixMode(GL_PROJECTION); // projection matrix is active glEnd();
glLoadIdentity(); // reset the projection }
gluPerspective(45.0, ratio, 0.1, 100.0); // perspective void trees() //draw a tree
transformation {
glMatrixMode(GL_MODELVIEW); // return to modelview mode GLUquadricObj *quadratic;
glViewport(0, 0, w, h); // set viewport (drawing area) to GLUquadricObj *quadratic1;
entire window quadratic1 = gluNewQuadric();
} quadratic = gluNewQuadric();
void update(void) glPushMatrix();
{ glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
if (deltaMove) { // update camera position glColor3f(0.721,0.525,0.043);
x += deltaMove*lx * 0.38; gluCylinder(quadratic,1,1,10.0f,32,32);
z += deltaMove*lz * 0.38; glPopMatrix();
} glTranslatef(0,2,0);
if(vertmove==1) y+=0.1; glPushMatrix();
if(vertmove==-1) y-=0.1; float k=0;
restrict(); for(int i=0,j=0;i<3;i++,j+=0.5,k+=0.15)
glutPostRedisplay(); // redisplay everything {
} glTranslatef(0,1.8,0);
void disp_roads() //display the roads in the campus glColor3f(0.133+k,0.545+k,0.133-k);
{ glPushMatrix();
glColor3f(0.411,0.411,0.411); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); gluCylinder(quadratic1,4-j,0,4.0f,32,32);
glVertex3f(-40,0.1,90); glPopMatrix();
glVertex3f(-40,0.1,-70); }
glVertex3f(-20,0.1,-70); glPopMatrix();
glVertex3f(-20,0.1,90); }
glEnd(); void draw_arch(char text[5]) //draw the arch
glBegin(GL_QUADS); {
glVertex3f(-20,0.1,55); glColor3f(0,0,1);
glVertex3f(90,0.1,55); glPushMatrix();
glVertex3f(90,0.1,60); glTranslatef(0,3.5,0);
glVertex3f(-20,0.1,60); glScalef(4,7,2);
glEnd(); glutSolidCube(1);

DEPARTMENT OF CS & E, MITT -2018-19 33 DEPARTMENT OF CS & E, MITT -2018-19 34


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glPopMatrix(); glVertex3f(25,0,-20);
glPushMatrix(); glVertex3f(100,0,-20);
glTranslatef(16,3.5,0); glVertex3f(100,0,20);
glScalef(4,7,2); glVertex3f(25,0,20);
glutSolidCube(1); glEnd();
glPopMatrix(); draw_map();
glPushMatrix(); disp_roads();
glTranslatef(8,9,0); for(int i=-10;i<40;i+=10)
glScalef(20,4,2); {
glutSolidCube(1); glPushMatrix();
glPopMatrix(); glTranslatef(i,0,67);
glPushMatrix(); trees();
glTranslatef(5,8,1.1); glPopMatrix();
glScalef(.02, .02, .02); }
glLineWidth(4.5); for(int i=45;i<90;i+=10)
glColor3f(1,1,1); {
for (int c=0; text[c] != 0; ++c) glPushMatrix();
glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); glTranslatef(i,0,65);
glPopMatrix(); trees();
} glPopMatrix();
void display() glPushMatrix();
{ glTranslatef(i,0,75);
glClearColor(0.7,0.7,1,0); trees();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPopMatrix();
glEnable(GL_DEPTH_TEST); }
glLoadIdentity(); for(int i=-10;i<35;i+=10)
gluLookAt( {
x, y, z, glPushMatrix();
x+lx, y, z+lz, glTranslatef(i,0,25);
0.0, 1.0, 0.0); trees();
printf("\nz=%f\tx=%f\n",z,x); glPopMatrix();
glColor3f(0,1,0); }
glBegin(GL_QUADS); glPushMatrix();
glVertex3f(-100,0,100); glTranslatef(-38,0,90);
glVertex3f(100,0,100); draw_arch("RNSIT");
glVertex3f(100,0,20); glPopMatrix();
glVertex3f(-100,0,20); glPushMatrix();
glVertex3f(-100,0,20); glTranslatef(-70,0,80);
glVertex3f(-15,0,20); canteen.disp_build("CANTEEN",'r');
glVertex3f(-15,0,-100); glPopMatrix();
glVertex3f(-100,0,-100); glPushMatrix();
glVertex3f(-15,0,-100); glTranslatef(-65,0,45);
glVertex3f(100,0,-100); crt1.disp_court();
glVertex3f(100,0,-20); glPopMatrix();
glVertex3f(-15,0,-20); glPushMatrix();

DEPARTMENT OF CS & E, MITT -2018-19 35 DEPARTMENT OF CS & E, MITT -2018-19 36


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glTranslatef(-70,0,20); case 's' : deltaMove = 0.0; glutIdleFunc(NULL);break;


mech.disp_build("MECH BLOCK",'r'); case 'u' : vertmove=0;glutIdleFunc(NULL);break;
glPopMatrix(); case 'j' : vertmove=0;glutIdleFunc(NULL);break;
mech_court(); }
glPushMatrix(); }
glTranslatef(-70,0,-30); void mouseMove(int x, int y)
mba.disp_build("MBA BLOCK",'r'); {
glPopMatrix(); if (isDragging) { // only when dragging
disp_mba(); // update the change in angle
glPushMatrix(); deltaAngle = (x - xDragStart) * -0.005;
glTranslatef(-10,0,50); // camera's direction is set to angle + deltaAngle
admin.disp_build("ADMIN BLOCK"); lx = sin(angle + deltaAngle);
glPopMatrix(); lz = -cos(angle + deltaAngle);
glPushMatrix(); glutIdleFunc(update);
glTranslatef(-15,0,20); }
fball.ground_disp(); }
glPopMatrix(); void mouseButton(int button, int state, int x, int y)
glPushMatrix(); {
glTranslatef(50,0,50); if (button == GLUT_LEFT_BUTTON) {
ec.disp_build("EC BLOCK"); if (state == GLUT_DOWN) {
glPopMatrix(); isDragging = 1;
glPushMatrix(); xDragStart = x;
glTranslatef(50,0,0); }
cs.disp_build("CS BLOCK",'l'); else { /* (state = GLUT_UP) */
glPopMatrix(); angle += deltaAngle; // update camera turning angle
glPushMatrix(); isDragging = 0; // no longer dragging
glTranslatef(-6,3,-30); glutIdleFunc(NULL);
temp.disp_temple();
glPopMatrix(); }
glutSwapBuffers(); }
glFlush(); }
} int main()
void pressKey(unsigned char key, int xx, int yy) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
{ glutInitWindowSize(500,500);
switch (key) { glutInitWindowPosition(40,40);
case 'w' : deltaMove = 1.0;glutIdleFunc(update); break; glutCreateWindow("HOUSE");
case 's' : deltaMove = -1.0;glutIdleFunc(update); break; glutReshapeFunc(changeSize); // window reshape callback
case 'u' : vertmove=1;glutIdleFunc(update);break; glutDisplayFunc(display);
case 'j' : vertmove=-1;glutIdleFunc(update);break;
} glutIgnoreKeyRepeat(1);
} glutKeyboardFunc(pressKey);
void releaseKey(unsigned char key, int x, int y) glutKeyboardUpFunc(releaseKey);
{ glutMouseFunc(mouseButton); // process mouse button
switch (key) { push/release
case 'w' : deltaMove = 0.0; glutIdleFunc(NULL);break; glutMotionFunc(mouseMove); // process mouse dragging motion

DEPARTMENT OF CS & E, MITT -2018-19 37 DEPARTMENT OF CS & E, MITT -2018-19 38


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

glutMainLoop();
}

Fig 1
CHAPTER – 3
RESULT ANALYSIS

3.1 SNAPSHOTS:

DEPARTMENT OF CS & E, MITT -2018-19 39 DEPARTMENT OF CS & E, MITT -2018-19 40


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

Fig3

Fig 2

Fig4

DEPARTMENT OF CS & E, MITT -2018-19 41 DEPARTMENT OF CS & E, MITT -2018-19 42


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

Fig5 Fig7

Fig6
Fig8

DEPARTMENT OF CS & E, MITT -2018-19 43 DEPARTMENT OF CS & E, MITT -2018-19 44


CAMPUS TRAVERSE Computer graphic & visulalization CAMPUS TRAVERSE Computer graphic & visulalization

3.2 DISCUSSION:  The Successful Completion of the project “campus traverse” using some of the OpenGL

Fig 1: API’s has been done.

Fig 1 of snapshot shows the user can see the collage with the help of camera function  This is developed to watch the animation as per the instruction given by the user to know
the working of a college campus.
Fig 2:

Fig 2 of snapshot shows the admin block.


4.2 FUTURE ENHANCEMENT:
Fig 3:
1. The college campus can be shown with help camera function.
Fig 3 of snapshot shows the cse department & football ground.
2. This project can be modified and a lot by adding other objects like classrooms grounds
Fig 4:
library,swimming pool,etc.
Fig 4 of snapshot shows the ece department.
3. Simulation of college can be done.
Fig 5:

Fig 5 of snapshot shows the mechanical department.

Fig 6:
4.3 REFERENCES:
Fig 6 of snapshot shows the civil department.
1. Edward Angel, Interactive Computer Graphics, 5th edition, Addison-Wesley, 2009.
Fig 7:

Fig 7 of snapshot shows the canteen. 2. F.S Hill, JR., Stephen.M.Kelley, Computer Graphics Using OpenGL, 3rd edition, Pearson
Education, 2009.
Fig 8: 3. Donald Hearn & Pauline Baker: Computer Graphics-OpenGL Version,3rd Edition, Pearson
Education,2011.
Fig 8 of snapshot shows the basketball ground.

CHAPTER – 4
CONCLUSION AND FUTURE WORK
4.1 CONCLUSION:
 The final conclusion is that by using the appropriate graphical packages called OpenGL.

DEPARTMENT OF CS & E, MITT -2018-19 45 DEPARTMENT OF CS & E, MITT -2018-19 46

You might also like