Top Banner
VISVESVARAYA TECHNOLOGICAL UNIVERSITY BELGAUM A Project report on A Train Submitted in partial fulfillment for the award of the degree in Bachelor of Engineering In COMPUTER SCIENCE & ENGINEERING By Ranjeet Singh 1NC11CS069 Under the guidance of Mrs. Manjhusa Ms Prabha Naik Assistant Professors CSE Department.
43

6th Sem Project on Heli Dept. Report

Apr 19, 2017

Download

Documents

RanjeetSingh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 6th Sem Project on Heli Dept. Report

VISVESVARAYA TECHNOLOGICAL UNIVERSITYBELGAUM

A Project report on

A TrainSubmitted in partial fulfillment for the award of the degree in

Bachelor of EngineeringIn

COMPUTER SCIENCE & ENGINEERING

By

Ranjeet Singh 1NC11CS069

Under the guidance ofMrs. ManjhusaMs Prabha Naik

Assistant ProfessorsCSE Department.

COLLEGE OF ENGINEERING AND TECHNOLOGYVENKATAGIRI KOTE, DEVANAHALLI, BENGALURU – 562110

Page 2: 6th Sem Project on Heli Dept. Report

Department of Computer Science Engineering

COLLEGE OF ENGINEERINGAND TECHNOLOGY

CERTICIFICATE

This is to certify that the project work entitled “A Train” is carried out by Mr. Ranjeet

Singh, USN 1NC11CS069 a are the bonafied students of Nagarjuna College of Engineering

and Technology in partial fulfillment for the award of Bachelor of Engineering in VI semester

Computer Science & Engineering of Visvesvaraya Technological University, Belgaum during

the year 2014.

Name & Signature of the Guide Name & Signature of the HOD

Mrs Manjhusa Dr. Shantakumar B.Patil

External ExaminerName of the External Examiners Signature with Date:-

1.

2.

1 | P a g e

Page 3: 6th Sem Project on Heli Dept. Report

ACKNOWLEDGEMENT

We would like to take this opportunity to thank all the people who have helped us to successfully

complete this mini project.

I am very thankful to the principal, Dr. S. G. Gopalakrishna, NCET, Bangalore, for being kind

enough to provide me an opportunity to work on a project in this institution.

First and foremost we would like to thank Dr. Shantakumar B. Patil, HOD of computer

Science Department for providing excellent lab facilities and for his in valuable advice that

helped us in completing our project on time.

We would also like to acknowledge the effort put in by our lecturer Mrs. Manjhusa,Ms

Prabha Naik in helping us understand the relevant concepts related to assemblers and for

providing guidance whenever necessary.

We are also highly indebted to the lab administrator who acceded to our requests whenever we

required lab facilities to work on our project as well as all our friends who helped us in testing

and debugging our project.

Ranjeet Singh (1NC11CS069)

2 | P a g e

Page 4: 6th Sem Project on Heli Dept. Report

ABSTRACT

Creating a Train in Computer graphics is not that much hard but logical. we are going to see an OpenGL Projects on trains. Our objective is to implement cg projects for running train. Here we implementthe following things - 1.Train - the bogies and the engine2. Train Tracks3. Sky 4. Mouse/keyboard for motionOur next aim would be to give motion to the train. As we are going to implement a simple train so our track will be a straight not in zigzag manner.Design and ImplementationFor developing the train - it's bogies and engine we have defined a simple function. In this simple OpenGL projects we are coding this function so we can make any no trains, by just calling it.Software Requirements:

An MS-DOS based operating system like Windows 98, Windows 2000 or

Windows XP the platform required to develop the 2D and 2D graphics

applications.

A Visual C/C++ compiler is required for compiling the source code to make the

executable file which can then be directly executed.

A built in graphics library like glut and glut32, and header file like glut.h and also

dynamic link libraries like glut and glut32 are required for creating the 2D layout.

Hardware Requirements:

The hardware requirements are very minimal and the software can run on most of the machines.

Processor - Intel 486/Pentium processor or above.

Processor Speed - 500 MHz or above

RAM - 64MB or above Storage Space - 2 MB or above

Monitor resolution - A color monitor with a minimum resolution of 640*480

Table of Contents

3 | P a g e

Page 5: 6th Sem Project on Heli Dept. Report

Certificate Acknowledgement

AbstractChapter 1 Introduction……………………………………

1.1-About OpenGl…………………………………... 1.1-Train Rendering in OpenGl ………………. Chapter 2 – System Analysis……………………………...

2.1 -Scope of the Project…………………………… 2.2- Aim of the Project………………………………

Chapter 3 -Requirement Specifications …………………... 3.1- Software Requirement………………………….

Chapter 4 – Design Phase…………………………………. 4.1- Introduction………………………………… 4.2- Model Description …………………………

Chapter 5-Code……………………………………………. 5.1- Animations.cpp……………………………….. 5.2- Cloud.cpp………………………………………… 5.3-Ground.cpp ……………………………………….. 5.4-Train.cpp ……………………………………. 5.5- Main.cpp…………………………………………..

SnapShots …………………………………………………. Conclusion………………………………………………… Bibliography ………………………………………………

1.INTRODUCTION

4 | P a g e

Page 6: 6th Sem Project on Heli Dept. Report

The dominant characteristic of this new millennium is how computer and communication

technologies have become dominant forces in our life. Activities as wide –ranging as

filmmaking, publishing, banking, and education continue to undergo revolutionary changes as

these technologies alter the ways in which we conduct our daily activities. The combination of

computers, networks, and the complex visual systems, through computer graphics, has led to

new ways of displaying information, seeing virtual worlds and communicating with people and

machines.

Computer graphics is concerned with all aspects of producing pictures or images using a

computer. The field began humbly almost 50 years ago, with a display of few lines on a cathode-

ray-tube; now, we can create images by computer that are indistinguishable from photographs of

real objects. We routinely train pilots with simulated airplanes, generating graphical displays of a

virtual environment of real time. Feature –length movies made entirely by computer have been

successful, both critically and financially. Massive multiplayer games can involve tens of

thousands of concurrent participants.

GLUT:

It is a complete API written by Mark Kilgard, which lets us create windows and handle the

messages. It exists for several platforms that mean that a program, which uses GLUT, can be

compiled on many platforms without any changes in the code.

ADDITIONAL LIBRARIES

There are two libraries that we have that came with OpenGL:

5 | P a g e

Page 7: 6th Sem Project on Heli Dept. Report

1: glu:It is a set of utility functions. They are easy way of doing things that is tedious with raw

OpenGL

2: glx:It allows you to open up X window and link it up with OpenGL so that it will draw to that

window.

HOW OpenGL WORKS?

To be hardware independent OpenGL provides its own data types. They all begin with

“GL”. Example: GLfloat, Glint.

There are also many symbolic constants that all begin with “GL_”Example:

GL_POINTS,GL_POLYGON.

Finally commands have prefix “gl”. Example: glVertex3f.

There is a utility library called “GLU”. Here the prefixes are”GLU_”,”glu”. GLUT

commands begin with “glut”. It is the same for every library

OpenGL is a widely accepted standard for developing graphics applications. Fortunately,

OpenGL is easy to learn and it possesses most of the characteristics of other graphics systems.

Graphics API’s, such as OpenGL, developed as a way to provide application programmers with

access to hardware features that were being provided by latest graphics hardware.

1.1 APPLICATIONS OF COMPUTER GRAPHICS

The development of computer graphics has been driven both by the needs of the user

community and by advances in hardware and software. The applications of computer graphics

are many and varied; we can divide them into four major areas:

1. Display of information

2. Design

3. Simulation and animation

4. User interfaces

1.1.1. DISPLAY OF INFORMATION

6 | P a g e

Page 8: 6th Sem Project on Heli Dept. Report

Medical imaging posses interesting and important data analysis problems. Modern

imaging technologies such as computed tomography (CT), magnetic resonance imaging (MRI),

ultrasound and positron emission tomography (PET)-generate 2D data that must be subjected to

algorithmic manipulation to provide useful information.

The field of scientific visualization provides graphical tools that help the researchers

interpret the fast quantity of data that they generate.

1.1.2. DESIGN

Professions such as engineering and architectures are concerned with design. Starting with a set

of specifications, engineers and architects seek a cost effective and esthetic solution that satisfies

the specifications.

Design is an interactive process. Design problem are either over determined such that

they posses no solution that satisfies all the criteria, much less an optimal solution, or

underdetermined, such that they have multiple solutions that satisfy the design criteria.

1.1.3. SIMULATION AND ANIMATION

Graphic system evolved to be capable of generating sophisticated images in real time,

engineers and researchers began to use them as simulators. One of the most important uses has

been in the training of pilots. The use of special PLSI chips has led to a generation of arcade,

games as sophisticated as flight simulators.

The simulator can be used for designing the robot, planning its path, and simulating its

behavior in complex environment. The success of flight simulators led to the use of computer

graphics for animation in the TV, motion picture and advertising industries. Entire animated

7 | P a g e

Page 9: 6th Sem Project on Heli Dept. Report

movies can now be made by computers at a cost less than that of movies made with tradition

hand animation techniques

The graphic technology for games, both in the form of the graphics processing units that

are on graphics cards in personal computers and in game boxes such as the Xbox and the play

stations, is being used for simulation rather than expensive specialized hardware.

1.1.4. USER INTERFACES

Our interaction with computers has become dominated by a visual paradigm that includes

windows, icons, menus and a pointing device such as a mouse. From users perspective, winding

system such as the X window system, Microsoft windows, and the Macintosh Os x defer only in

derails.

2. INTRODUCTION TO OpenGL

What is OpenGL?

Graphics rendering API.

8 | P a g e

Page 10: 6th Sem Project on Heli Dept. Report

High-quality color images composed of geometric primitives.

Operating system independent.

OpenGL is an application programmer’s interface (API) that allows

programmers to write programs that access graphics hardware.

OpenGL provides a set of commands to render a three dimensional scene. That means

you provide the data in an OpenGL-useable form and OpenGL will show this data on the screen

(render it). It is developed by many companies and it is free to use. You can develop OpenGL-

applications without licensing.

OpenGL bases on the state variables. There are many values, for example the color, that

remain after being specified. That means, you can specify a color once and draw several

polygons, lines or whatever with this color then. There are no classes like in DirectX. However,

it is logically structured. Before we come to the commands themselves, here is another thing:

To be hardware independent, OpenGL provides its own data types. They all begin with

"GL". For example GLfloat, GLint and so on. There are also many symbolic constants, they all

begin with "GL_", like GL_POINTS, GL_POLYGON. Finally the commands have the prefix

"gl" like h. There is a utility library called GLU, here the prefixes are "GLU_" and "glu". GLUT

commands begin with "glut", it is the same for every library. You want to know which libraries

coexist with the ones called before. There are libraries for every system, Windows has the wgl*-

Functions, UNIX systems glx* and so on.

A very important thing is to know, that there are two important matrices, which affect the

transformation from the 2D-world to the 2d-screen: The projection matrix and the modelview

matrix. The projection matrix contains information, how a vertex – let's say a "point" in space –

shall be mapped to the screen. This contains, whether the projection shall be isometric or from a

perspective, how wide the field of view is and so on. Into the other matrix you put information,

how the objects are moved, where the viewer is and so on.

2.1 The OpenGL pipeline:

9 | P a g e

Page 11: 6th Sem Project on Heli Dept. Report

Fig 1.0 The OpenGL rendering pipeline.

Commands may either be accumulated in display lists, or processed immediately through

the pipeline. Display lists allow for greater optimization and command reuse, but not all

commands can be put in display lists.

The first stage in the pipeline is the evaluator. This stage effectively takes any polynomial

evaluator commands and evaluates them into their corresponding vertex and attributes

commands.

The second stage is the per-vertex operations, including transformations, lighting,

primitive assembly, clipping, projection, and viewport mapping.

The third stage is rasterization. This stage produces fragments, which are series of frame

buffer addresses and values, from the viewport-mapped primitives as well as bitmaps and pixel

rectangles.

The fourth stage is the per-fragment operations. Before fragments go to the frame buffer,

they may be subjected to a series of conditional tests and modifications, such as blending or z-

buffering.

10 | P a g e

Page 12: 6th Sem Project on Heli Dept. Report

2.2 Vertices and Primitives

Most objects use Begin/End primitives. Each Begin/End primitive contains a series of

vertex data, and may optionally contain normals, texture coordinates, colors, edge flags, and

material properties.

There are ten primitive types, as follows:

Points individual points

Linespairs of vertices interpreted as individual line

segments

Polygon boundary of a simple, convex polygon

Triangles triples of vertices interpreted as triangles

Quadsquadruples of vertices interpreted as four-sided

polygons

11 | P a g e

Page 13: 6th Sem Project on Heli Dept. Report

Line Strip series of connected line segments

Line Loopsame as above, with a segment added between last

and first vertices

Triangle Strip linked strip of triangles

Triangle Fan linked fan of triangles

Quad Strip linked strip of quadrilaterals

2. PROGRAM DEFINITION

What is the difference between transparent, translucent, and blended primitives?

A transparent physical material shows objects behind it as unobscured and doesn't reflect

light off its surface. Clear glass is a nearly transparent material. Although glass allows most light

12 | P a g e

Page 14: 6th Sem Project on Heli Dept. Report

to pass through unobscured, in reality it also reflects some light. A perfectly transparent material

is completely invisible.

A translucent physical material shows objects behind it, but those objects are obscured by the

translucent material. In addition, a translucent material reflects some of the light that hits it,

making the material visible. Physical examples of translucent materials include sheer cloth, thin

plastic, and smoked glass.

Transparent and translucent are often used synonymously. Materials that are neither

transparent nor translucent are opaque.

Blending is OpenGL's mechanism for combining color already in the frame buffer with

the color of the incoming primitive. The result of this combination is then stored back in the

frame buffer. Blending is frequently used to simulate translucent physical materials. One

example is rendering the smoked glass windshield of a car. The driver and interior are still

visible, but they are obscured by the dark color of the smoked glass.

How can I achieve a transparent effect?

glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

After blending is enabled, as shown above, the incoming primitive color is blended with

the color already stored in the frame buffer. glBlendFunc() controls how this blending occurs.

The typical use described above modifies the incoming color by its associated alpha value and

modifies the destination color by one minus the incoming alpha value. The sum of these two

colors is then written back into the framebuffer.

The primitive’s opacity is specified using glColor4*(). RGB specifies the color, and the

alpha parameter specifies the opacity.

13 | P a g e

Page 15: 6th Sem Project on Heli Dept. Report

When using depth buffering in an application, you need to be careful about the order in

which you render primitives. Fully opaque primitives need to be rendered first, followed by

partially opaque primitives in back-to-front order. If you don't render primitives in this order, the

primitives, which would otherwise be visible through a partially opaque primitive, might lose the

depth test entirely.

How can I create screen door transparency?

This is accomplished by specifying a polygon stipple pattern with glPolygonStipple() and

by rendering the transparent primitive with polygon stippling enabled

(glEnable(GL_POLYGON_STIPPLE)). The number of bits set in the stipple pattern determine

the amount of translucency and opacity; setting more bits result in a more opaque object, and

setting fewer bits results in a more translucent object. Screendoor transparency is sometimes

preferable to blending, becuase it's order independent (primitives don't need to be rendered in

back-to-front order).

How can I render glass with OpenGL?

This question is difficult to answer, because what looks like glass to one person might not

to another. What follows is a general algorithm to get you started.

First render all opaque objects in your scene. Disable lighting, enable blending, and

render your glass geometry with a small alpha value. This should result in a faint rendering of

your object in the frame buffer. (Note: You may need to sort your glass geometry, so it's

rendered in back to front Z order.)

Now, you need to add the specular highlight. Set your ambient and diffuse material colors

to black, and your specular material and light colors to white. Enable lighting. Set

glDepthFunc(GL_EQUAL), then render your glass object a second time.

14 | P a g e

Page 16: 6th Sem Project on Heli Dept. Report

Do I need to render my primitives from back to front for correct rendering of translucent

primitives to occur?

If your hardware supports destination alpha, you can experiment with different

glBlendFunc() settings that use destination alpha. However, this won't solve all the problems

with depth buffered translucent surfaces. The only sure way to achieve visually correct results is

to sort and render your primitives from back to front.

I want to use blending but cannot get destination alpha to work. Can I blend or create a

transparency effect without destination alpha?

Many OpenGL devices don't support destination alpha. In particular, the OpenGL 1.1

software rendering libraries from Microsoft don't support it. The OpenGL specification doesn't

require it.

If you have a system that supports destination alpha, using it is a simple matter of asking

for it when you create your window. For example, pass GLUT_ALPHA to

glutInitDisplayMode(), then set up a blending function that uses destination alpha, such as:

glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);

Often this question is asked under the mistaken assumption that destination alpha is

required to do blending. It's not. You can use blending in many ways to obtain a transparency

effect that uses source alpha instead of destination alpha. The fact that you might be on a

platform without destination alpha shouldn't prevent you from obtaining a transparency effect.

See the OpenGL Programming Guide chapter 6 for ways to use blending to achieve

transparency.

If I draw a translucent primitive and draw another primitive behind it, I expect the second

primitive to show through the first, but it's not there?

15 | P a g e

Page 17: 6th Sem Project on Heli Dept. Report

a.Is depth buffering enabled?

If you're drawing a polygon that's behind another polygon, and depth test is enabled, then

the new polygon will typically lose the depth test, and no blending will occur. On the other hand,

if you've disabled depth test, the new polygon will be blended with the existing polygon,

regardless of whether it's behind or in front of it.

b.How can I make part of my texture maps transparent or translucent?

It depends on the effect you're trying to achieve.

If you want blending to occur after the texture has been applied, then use the OpenGL

blending feature. Try this:

glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE);

You might want to use the alpha values that result from texture mapping in the blend

function. If so, (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is always a good function

to start with.

However, if you want blending to occur when the primitive is texture mapped (i.e., you

want parts of the texture map to allow the underlying color of the primitive to show through),

then don't use OpenGL blending. Instead, you'd use glTexEnv(), and set the texture environment

mode to GL_BLEND. In this case, you'd want to leave the texture environment color to its

default value of (0,0,0)

1.1 – Train Rendering in OpenGl:

A virtual train along with view in 2D showing the intial rest position of the

.The entire scenery is constructed based on different OpenGl

16 | P a g e

Page 18: 6th Sem Project on Heli Dept. Report

functions along with other parameters.The construction basically consists of components

used such as ,we have constructed two metres..Clouds have also been constructed over the sky

for adding a good theme.Now the main purpose to serve is provided by the train which can be

driven over different directions along with various functions which I will be mentioning

later.Basically a set of functions along with main function served the purpose of developing

the abstract.

Uses: mouse interactions have been used to interact with the

Implementation.

A few to list out would be trustworthy for both users as well as me so that the points

May be crystal clear to the viewers.

2.SYSTEM ANALYSIS

2.1 Scope of the Project:

As per the concern being given to the scope we would definately say that this project will

give a rough idea to the students who are basically wondering of how the major games related

to train are being developed.The sourcecode used in this project is an outline view of the

scenery being constructed over which the games are implemented.The background plays a very

vital role along with the graphics used in the games.This project will just give a flashback

of background construction along with objects used in the games.Basically at the end I would

give a full stop to the scope by saying that the primary and main scope of the project is “A

doorstep for beginners of today to transform into Gamers of tomorrow”

17 | P a g e

Page 19: 6th Sem Project on Heli Dept. Report

2.2 Aim of the Project:

The primary aim of this project is to demonstrate the the motion of a train in different directions

as per the source code being used as well as presenting with mouse interaction to show various

textures and effects of the entire building over which the train is being driven.

3. REQUIREMENT SPECIFICATIO N

4.1 Software Requirements:

An MS-DOS based operating system like Windows 98, Windows 2000 or

Windows XP the platform required to develop the 2D and 2D graphics

applications.

A Visual C/C++ compiler is required for compiling the source code to make the

executable file which can then be directly executed.

A built in graphics library like glut and glut32, and header file like glut.h and also

dynamic link libraries like glut and glut32 are required for creating the 2D layout.

4.2 Hardware Requirements:

The hardware requirements are very minimal and the software can run on most of the machines.

Processor - Intel 486/Pentium processor or above.

18 | P a g e

Page 20: 6th Sem Project on Heli Dept. Report

Processor Speed - 500 MHz or above

RAM - 64MB or above Storage Space - 2 MB or above

Monitor resolution - A color monitor with a minimum resolution of 640*480

4.DESIGN PHASE

4.1 Introduction

This project is basically being constructed keeping in view the construction and simulationof a

train over a 2D animated building as told earlier.Basically the project undertaken by us has gone

through a variety of functions and headers along with a number of source codes.Now let me sort

out a few functions along with headers.Here I would basically brief out a few explanation of the

contents.

4.2 Modular Description

The major functions that are used in the creation of the program are as follows:

1. void init(void)

19 | P a g e

Page 21: 6th Sem Project on Heli Dept. Report

Let's start by looking at init(). It creates a display list for the torus and initializes the viewing

matrices and other rendering state.It also creates the starting window of the programme.

2: glutPostRedisplay()

Then glutPostRedisplay() is called, which will cause glutMainLoop() to call display() and

render the torus after other events have been processed. When the `i' key is

pressed, keyboard() restores the initial modelview matrix and returns the torus to its original

location.

3:display()

The display() function is very simple: It clears the window and then calls glCallList() to

execute the commands in the display list. If we hadn't used display lists, display() would have to

reissue the commands to draw the torus each time it was called.

A display list contains only OpenGL commands. In Example 1-7, only

the glBegin(), glVertex(), and glEnd() calls are stored in the display list. The parameters for the

calls are evaluated, and their values are copied into the display list when it is created. All the

trigonometry to create the torus is done only once, which should increase rendering performance.

However, the values in the display list can't be changed later. And once a command has been

stored in a list it is not possible to remove it. Neither can you add any new commands to the list

after it has been defined. You can delete the entire display list and create a new one, but you can't

edit it.

Note: Display lists also work well with GLU commands, since those operations are ultimately

broken down into low-level OpenGL commands, which can easily be stored in display lists. Use

of display lists with GLU is particularly important for optimizing performance of GLU

tessellators and NURBS.

We have different functions that makes use to create the fountain with simulated water, they

are as follows…

20 | P a g e

Page 22: 6th Sem Project on Heli Dept. Report

1:Cloud.cpp

This function is mainly used for the construction of the cloud which isfloating over the sky.The

function implementation may be stated as follows.

//dynamic object- Single cloud

#include <time.h>

// Material of cloud

materialStruct cloudShader = {{0.9f, 0.9f, 0.9f, 1.0f},

{0.9f, 0.9f, 0.9f, 0.7f},

{0.0f, 0.0f, 0.0f, 1.0f},

GLfloat x = 0.0;GLfloat y =0.0; GLfloat z = 0.0; GLfloat a = 0.0;

2:Ground.cpp

The function to add textured building to ground.

// Material of ground

materialStruct groundShader = {{0.0f, 0.0f, 0.0f, 1.0f},

{0.7f, 0.5f, 0.5f, 1.0f},

{0.7f, 0.7f, 0.7f, 1.0f},

{50.0f}};

21 | P a g e

Page 23: 6th Sem Project on Heli Dept. Report

3:Train.cpp

void TRAINS(int x1,int y1,int a,int b){ int i=0;

glBegin(GL_QUADS);glColor3f(0,0.0,1.0); //ENGINEglVertex2f(x1,y1); //lengh of engine=60;height of

engine=30;glColor3f(0,0.0,1.0);glVertex2f(x1+60,y1);glColor3f(1.0,0.0,0.0);glVertex2f(x1+60,y1-30);glColor3f(0,0.0,0.0);glVertex2f(x1,y1-30);glEnd();

while(i<3){ glBegin(GL_QUADS); //BOGIES

glColor3f(1.0,0.0,0.0); //For right train a=795,b=510glVertex2f(a,b);glColor3f(1.0,0.0,0.0);glVertex2f(a+60,b);glColor3f(1.0,0.0,0.0);glVertex2f(a+60,b-20);glColor3f(1.0,0.0,0.0);glVertex2f(a,b-20);glEnd();a+=65;i++;

}

}

4:Interface.cpp

An interface describes the behavior or capabilities of a C++ class without committing to a

particular implementation of that class.

The C++ interfaces are implemented using abstract classes and these abstract classes should not

be confused with data abstraction which is a concept of keeping implementation detail separate

from associated data.

A class is made abstract by declaring at least one of its functions as pure virtualfunction. A pure

virtual function is specified by placing "= 0" in its declaration as follows:

22 | P a g e

Page 24: 6th Sem Project on Heli Dept. Report

class Box

{

public:

// pure virtaul function

virtual double getVolume() = 0;

private:

double length; // Length of a box

double breadth; // Breadth of a box

double height; // Height of a box

};

The purpose of an abstract class (often referred to as an ABC) is to provide an appropriate base

class from which other classes can inherit. Abstract classes cannot be used to instantiate objects

and serves only as an interface. Attempting to instantiate an object of an abstract class causes a

compilation error.

Thus, if a subclass of an ABC needs to be instantiated, it has to implement each of the virtual

functions, which means that it supports the interface declared by the ABC. Failure to override a

pure virtual function in a derived class, then attempting to instantiate objects of that class, is a

compilation error.

Classes that can be used to instantiate objects are called concrete classes.

23 | P a g e

Page 25: 6th Sem Project on Heli Dept. Report

Abstract Class Example:

Consider the following example where parent class provides an interface to the base class to

implement a function called getArea():

#include <iostream>

using namespace std;

// Base class

class Shape

{

public:

// pure virtual function providing interface framework.

virtual int getArea() = 0;

void setWidth(int w)

{

width = w;

}

void setHeight(int h)

{

height = h;

}

protected:

int width;

24 | P a g e

Page 26: 6th Sem Project on Heli Dept. Report

5:Main.cpp

As all of us know the main contains all the functions stated earlier along with other parameters

useful to construct and implement the project.

4. CODE

#include<stdio.h>#include<stdlib.h>#include<GL/glut.h>#include <math.h>#include <time.h>#include <windows.h>#define M_PI 3.14

int c=0,d=500,g=380,h=970,i=540,j=970,k=380,l=965,m=540,n=970;GLfloat x=0.0,y=0.0;int z=0,a;int train1,basic;

//matrix

void sky(){

glBegin(GL_POLYGON);glColor3f(0,1,1);glVertex2f(0,730);glVertex2f(999,730);glVertex2f(999,999);glVertex2f(0,999);

25 | P a g e

Page 27: 6th Sem Project on Heli Dept. Report

glEnd();

}

void sleep(unsigned int mseconds){

clock_t goal = mseconds + clock(); while (goal > clock());}

void TRAINS(int x1,int y1,int a,int b){ int i=0;

glBegin(GL_QUADS);glColor3f(0,0.0,1.0); //ENGINEglVertex2f(x1,y1); //lengh of

engine=60;height of engine=30;glColor3f(0,0.0,1.0);glVertex2f(x1+60,y1);glColor3f(1.0,0.0,0.0);glVertex2f(x1+60,y1-30);glColor3f(0,0.0,0.0);glVertex2f(x1,y1-30);glEnd();

while(i<3){ glBegin(GL_QUADS); //BOGIES

glColor3f(1.0,0.0,0.0); //For right train a=795,b=510

glVertex2f(a,b);glColor3f(1.0,0.0,0.0);glVertex2f(a+60,b);glColor3f(1.0,0.0,0.0);glVertex2f(a+60,b-20);glColor3f(1.0,0.0,0.0);glVertex2f(a,b-20);glEnd();a+=65;i++;

}

}

26 | P a g e

Page 28: 6th Sem Project on Heli Dept. Report

void TRACKS(){

sky();/** Track **/glBegin(GL_LINES);

glColor3f(0.0,0.0,0.0);glVertex2f(0,500);glVertex2f(1000,500);glVertex2f(0,499);glVertex2f(1000,499);

glVertex2f(0,485);glVertex2f(1000,485);glVertex2f(0,486);glVertex2f(1000,486);while(c!=1000){

glVertex2f(c,d);glVertex2f(c,d-15);c+=10;

}glEnd();

}

void myinit(){ glClearColor(0.0,0.5,0.0,0.0); //background color

gluOrtho2D(0,999,0,999);glPointSize(2.0);glLineWidth(2.0);

basic = glGenLists(1);glNewList(basic, GL_COMPILE);TRACKS();

glEndList();

train1 = glGenLists(1);glNewList(train1, GL_COMPILE);TRAINS(730,520,795,510);

glEndList();}

27 | P a g e

Page 29: 6th Sem Project on Heli Dept. Report

void draw(void){

glClear(GL_COLOR_BUFFER_BIT);glPushMatrix();

glPushMatrix();glCallList(basic);

glPopMatrix();

glPushMatrix();glTranslatef(x,y,0.0);glCallList(train1);

glFlush();glPopMatrix();

if(z<198){ a+=5;

x=x-5.0;sleep(100);z++;

}

glPopMatrix();glutPostRedisplay();glFlush();

}void mouse(int button,int state,int x,int y){

switch(button){case GLUT_LEFT_BUTTON:

if(state==GLUT_DOWN)glutDisplayFunc(draw);

break;

case GLUT_RIGHT_BUTTON:if(state==GLUT_DOWN)

sleep(1000);break;

}}void main(){ glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowPosition(0,0);glutInitWindowSize(1200,700);

28 | P a g e

Page 30: 6th Sem Project on Heli Dept. Report

glutCreateWindow("Running Trains");glutMouseFunc(mouse);glutDisplayFunc(draw);myinit();

glutMainLoop ();}

Snapshot

29 | P a g e

Page 31: 6th Sem Project on Heli Dept. Report

30 | P a g e

Page 32: 6th Sem Project on Heli Dept. Report

7. CONCLUSION:-

The above project prepared on the topic “ Train ov “is successful and hopefully demonstrating

its working with the help of both mouse as well as keys interaction.The OpenGl source code

along with headers and othermain code helped us to prepare the project as per the

requirement.In future this conceptwill garnish and will act as a plus point in implementing a

game related to train.

31 | P a g e

Page 33: 6th Sem Project on Heli Dept. Report

8. Bibliography

Interactive Computer Graphics.

A Top-Down Approach using OpenGL- Edward Angel

http://en.wikipedia.org/wiki/OpenGL

http://www.google.co.in/

http://www.opengl.org/

32 | P a g e