You are on page 1of 35

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
Mr! Manjh"a
M #ra$ha Nai%
Assistant Professors
CSE Department.
COLLEGE O& ENGINEERING AN' TECHNOLOGY
E!"A#A$I%I "&#E' DEA!A(A))I' BE!$A)U%U * +,-../
Departent of Cop!ter Science Engineering
COLLEGE O& ENGINEERING
AN' TECHNOLOGY
CERTICI&ICATE
#his is to certify that the pro0ect wor1 entitled (A Train) is carried out by Mr! Ranjeet
Singh* US! 1NC11CS069 a are the bonafied students of Nagarj"na C+,,ege +- Engineering
an. Te/hn+,+g0 in partial fulfillment for the award of Ba/he,+r +- Engineering in VI semester
Computer Science 2 Engineering of is3es3araya #echnological Uni3ersity' Belgaum during
the year 1012.
Na3e 4 Signat"re +- the G"i.e Na3e 4 Signat"re +- the HO'
Mr" Manjh!"a Dr# Shanta$!ar B#Patil

E4ternal E4aminer
!ame of the E4ternal E4aminers Signature with Date56
..
- 7 P a g e
-.
AC5NO6LE'GEMENT
8e would li1e to ta1e this opportunity to than1 all the people who ha3e helped us to successfully
complete this mini pro0ect.
I am 3ery than1ful to the principal' 'r! S! G! G+7a,a%rihna' !CE#' Bangalore' for being 1ind
enough to pro3ide me an opportunity to wor1 on a pro0ect in this institution.
9irst and foremost we would li1e to than1 'r! Shanta%"3ar B! #ati,' (&D of computer
Science Department for pro3iding e4cellent lab facilities and for his in 3aluable ad3ice that
helped us in completing our pro0ect on time.
8e would also li1e to ac1nowledge the effort put in by our lecturer Mr! Manjh"a*M
#ra$ha Nai% in helping us understand the rele3ant concepts related to assemblers and for
pro3iding guidance whene3er necessary.
8e are also highly indebted to the lab administrator who acceded to our re:uests whene3er we
re:uired lab facilities to wor1 on our pro0ect as well as all our friends who helped us in testing
and debugging our pro0ect.
; 7 P a g e
Ranjeet Singh 81NC11CS0699

ABSTRACT
Creating a #rain in Computer graphics is not that much hard but logical. we are going to see an
&pen$) Pro0ects on trains. &ur ob0ecti3e is to implement cg pro0ects for running train. (ere we
implementthe following things 6
..#rain 6 the bogies and the engine
-. #rain #rac1s
;. S1y
<. =ouse>1eyboard for motion
&ur ne4t aim would be to gi3e motion to the train. As we are going to implement a simple train
so our trac1 will be a straight not in ?ig?ag manner.
'eign an. I37,e3entati+n
9or de3eloping the train 6 it@s bogies and engine we ha3e defined a simple function. In this
simple &pen$) pro0ects we are coding this function so we can ma1e any no trains' by 0ust
calling it.
S+-t:are Re;"ire3ent<
A An =S6D&S based operating system li1e 8indows BC' 8indows -/// or
8indows DP the platform re:uired to de3elop the -D and -D graphics
applications.
A A isual C>CEE compiler is re:uired for compiling the source code to ma1e the
e4ecutable file which can then be directly e4ecuted.
A A built in graphics library li1e glut and glut;-' and header file li1e glut.h and also
dynamic lin1 libraries li1e glut and glut;- are re:uired for creating the -D layout.
Har.:are Re;"ire3ent<
#he hardware re:uirements are 3ery minimal and the software can run on most of the machines.
AProcessor 6 Intel <C,>Pentium processor or abo3e.
AProcessor Speed 6 +// =(? or abo3e
< 7 P a g e
A%A= 6 ,<=B or abo3e Storage Space 6 - =B or abo3e
A=onitor resolution 6 A color monitor with a minimum resolution of ,</F<C/
Ta$,e +- C+ntent
Certi-i/ate
A/%n+:,e.ge3ent
A$tra/t
Cha7ter 1 Intr+."/ti+n==============
1!1>About &pen$l=============!!!
...6#rain %endering in &pen$l GGGGGG.
Cha7ter 1 * S0te3 Ana,0i===========!!!
1!1 >Scope of the Pro0ectGGGGGGGGGGG
1!1> Aim of the Pro0ectGGGGGGGGGGGG
Cha7ter ? >%e:uirement Specifications =======!!!
?!1> S+-t:are Re;"ire3ent==========!
Cha7ter 2 * Design PhaseGGGGGGGGGGGGG.
<..6 IntroductionGGGGGGGGGGGGG
<.-6 =odel Description GGGGGGGGGG
Cha7ter @6CodeGGGGGGGGGGGGGGGGG.
+..6 Animations.cppGGGGGGGGGGGG..
+.-6 Cloud.cppGGGGGGGGGGGGGGGG
+.;6$round.cpp GGGGGGGGGGGGGGG..
+.<6#rain.cpp GGGGGGGGGGGGGG.
+.+6 =ain.cppGGGGGGGGGGGGGGGG..
Sna7Sh+t ===================!
C+n/,"i+n===================
Bi$,i+gra7h0 GGGGGGGGGGGGGGGGGG
+ 7 P a g e
1!INTRO'UCTION
#he dominant characteristic of this new millennium is how computer and communication
technologies ha3e become dominant forces in our life. Acti3ities as wide *ranging as
filmma1ing' publishing' ban1ing' and education continue to undergo re3olutionary changes as
these technologies alter the ways in which we conduct our daily acti3ities. #he combination of
computers' networ1s' and the comple4 3isual systems' through computer graphics' has led to
new ways of displaying information' seeing 3irtual worlds and communicating with people and
machines.
Computer graphics is concerned with all aspects of producing pictures or images using a
computer. #he field began humbly almost +/ years ago' with a display of few lines on a cathode6
ray6tubeH now' we can create images by computer that are indistinguishable from photographs of
real ob0ects. 8e routinely train pilots with simulated airplanes' generating graphical displays of a
3irtual en3ironment of real time. 9eature *length mo3ies made entirely by computer ha3e been
successful' both critically and financially. =assi3e multiplayer games can in3ol3e tens of
thousands of concurrent participants.
GLUT<
, 7 P a g e
It is a complete API written by =ar1 "ilgard' which lets us create windows and handle the
messages. It e4ists for se3eral platforms that mean that a program' which uses $)U#' can be
compiled on many platforms without any changes in the code.
A''ITIONAL LIBRARIES
#here are two libraries that we ha3e that came with &pen$)5
.5 glu5It is a set of utility functions. #hey are easy way of doing things that is tedious with raw
&pen$)
-5 gl45It allows you to open up D window and lin1 it up with &pen$) so that it will draw to that
window.
HO6 O7enGL 6OR5SA
#o be hardware independent &pen$) pro3ides its own data types. #hey all begin with
I$)J. E4ample5 $)float' $lint.
#here are also many symbolic constants that all begin with I$)KJE4ample5
$)KP&I!#S'$)KP&)L$&!.
9inally commands ha3e prefi4 IglJ. E4ample5 glerte4;f.
#here is a utility library called I$)UJ. (ere the prefi4es areJ$)UKJ'JgluJ. $)U#
commands begin with IglutJ. It is the same for e3ery library
&pen$) is a widely accepted standard for de3eloping graphics applications. 9ortunately'
&pen$) is easy to learn and it possesses most of the characteristics of other graphics systems.
$raphics APIMs' such as &pen$)' de3eloped as a way to pro3ide application programmers with
access to hardware features that were being pro3ided by latest graphics hardware.
N 7 P a g e
1!1 A##LICATIONS O& COM#UTER GRA#HICS
#he de3elopment of computer graphics has been dri3en both by the needs of the user
community and by ad3ances in hardware and software. #he applications of computer graphics
are many and 3ariedH we can di3ide them into four ma0or areas5
.. Display of information
-. Design
;. Simulation and animation
<. User interfaces
1!1!1! 'IS#LAY O& IN&ORMATION
=edical imaging posses interesting and important data analysis problems. =odern
imaging technologies such as computed tomography OC#P' magnetic resonance imaging O=%IP'
ultrasound and positron emission tomography OPE#P6generate -D data that must be sub0ected to
algorithmic manipulation to pro3ide useful information.
#he field of scientific 3isuali?ation pro3ides graphical tools that help the researchers
interpret the fast :uantity of data that they generate.
1!1!1! 'ESIGN
Professions such as engineering and architectures are concerned with design. Starting with a set
of specifications' engineers and architects see1 a cost effecti3e and esthetic solution that satisfies
the specifications.
Design is an interacti3e process. Design problem are either o3er determined such that
they posses no solution that satisfies all the criteria' much less an optimal solution' or
underdetermined' such that they ha3e multiple solutions that satisfy the design criteria.
C 7 P a g e
1!1!?! SIMULATION AN' ANIMATION
$raphic system e3ol3ed to be capable of generating sophisticated images in real time'
engineers and researchers began to use them as simulators. &ne of the most important uses has
been in the training of pilots. #he use of special P)SI chips has led to a generation of arcade'
games as sophisticated as flight simulators.
#he simulator can be used for designing the robot' planning its path' and simulating its
beha3ior in comple4 en3ironment. #he success of flight simulators led to the use of computer
graphics for animation in the #' motion picture and ad3ertising industries. Entire animated
mo3ies can now be made by computers at a cost less than that of mo3ies made with tradition
hand animation techni:ues
#he graphic technology for games' both in the form of the graphics processing units that
are on graphics cards in personal computers and in game bo4es such as the Dbo4 and the play
stations' is being used for simulation rather than e4pensi3e speciali?ed hardware.
1!1!2! USER INTER&ACES
&ur interaction with computers has become dominated by a 3isual paradigm that includes
windows' icons' menus and a pointing de3ice such as a mouse. 9rom users perspecti3e' winding
system such as the D window system' =icrosoft windows' and the =acintosh &s 4 defer only in
derails.
B 7 P a g e
1! INTRO'UCTION TO O7enGL
6hat i O7enGLA
$raphics rendering API.
(igh6:uality color images composed of geometric primiti3es.
&perating system independent.
&pen$) is an application programmerMs interface OAPIP that allows
programmers to write programs that access graphics hardware.
&pen$) pro3ides a set of commands to render a three dimensional scene. #hat means
you pro3ide the data in an &pen$)6useable form and &pen$) will show this data on the screen
Orender itP. It is de3eloped by many companies and it is free to use. Lou can de3elop &pen$)6
applications without licensing.
&pen$) bases on the state 3ariables. #here are many 3alues' for e4ample the color' that
remain after being specified. #hat means' you can specify a color once and draw se3eral
./ 7 P a g e
polygons' lines or whate3er with this color then. #here are no classes li1e in DirectD. (owe3er'
it is logically structured. Before we come to the commands themsel3es' here is another thing5
#o be hardware independent' &pen$) pro3ides its own data types. #hey all begin with
Q$)Q. 9or e4ample $)float' $)int and so on. #here are also many symbolic constants' they all
begin with Q$)KQ' li1e $)KP&I!#S' $)KP&)L$&!. 9inally the commands ha3e the prefi4
QglQ li1e h. #here is a utility library called $)U' here the prefi4es are Q$)UKQ and QgluQ. $)U#
commands begin with QglutQ' it is the same for e3ery library. Lou want to 1now which libraries
coe4ist with the ones called before. #here are libraries for e3ery system' 8indows has the wglF6
9unctions' U!ID systems gl4F and so on.
A 3ery important thing is to 1now' that there are two important matrices' which affect the
transformation from the -D6world to the -d6screen5 #he pro0ection matri4 and the model3iew
matri4. #he pro0ection matri4 contains information' how a 3erte4 * let@s say a QpointQ in space *
shall be mapped to the screen. #his contains' whether the pro0ection shall be isometric or from a
perspecti3e' how wide the field of 3iew is and so on. Into the other matri4 you put information'
how the ob0ects are mo3ed' where the 3iewer is and so on.
1!1 The O7enGL 7i7e,ine<
.. 7 P a g e
9ig ../ #he &pen$) rendering pipeline.
Commands may either be accumulated in display lists' or processed immediately through
the pipeline. Display lists allow for greater optimi?ation and command reuse' but not all
commands can be put in display lists.
#he first stage in the pipeline is the e3aluator. #his stage effecti3ely ta1es any polynomial
e3aluator commands and e3aluates them into their corresponding 3erte4 and attributes
commands.
#he second stage is the per63erte4 operations' including transformations' lighting'
primiti3e assembly' clipping' pro0ection' and 3iewport mapping.
#he third stage is rasteri?ation. #his stage produces fragments' which are series of frame
buffer addresses and 3alues' from the 3iewport6mapped primiti3es as well as bitmaps and pi4el
rectangles.
.- 7 P a g e
#he fourth stage is the per6fragment operations. Before fragments go to the frame buffer'
they may be sub0ected to a series of conditional tests and modifications' such as blending or ?6
buffering.
1!1 Verti/e an. #ri3itiBe
=ost ob0ects use Begin>End primiti3es. Each Begin>End primiti3e contains a series of
3erte4 data' and may optionally contain normals' te4ture coordinates' colors' edge flags' and
material properties.
#here are ten primiti3e types' as follows5
Points indi3idual points
)ines
pairs of 3ertices interpreted as indi3idual line
segments
Polygon boundary of a simple' con3e4 polygon
#riangles triples of 3ertices interpreted as triangles
.; 7 P a g e
Ruads
:uadruples of 3ertices interpreted as four6sided
polygons
)ine Strip series of connected line segments
)ine )oop
same as abo3e' with a segment added between last
and first 3ertices
#riangle Strip lin1ed strip of triangles
#riangle 9an lin1ed fan of triangles
Ruad Strip lin1ed strip of :uadrilaterals
.< 7 P a g e
1! #ROGRAM 'E&INITION
6hat i the .i--eren/e $et:een tran7arent* tran,"/ent* an. $,en.e. 7ri3itiBeA
A transparent physical material shows ob0ects behind it as unobscured and doesn@t reflect
light off its surface. Clear glass is a nearly transparent material. Although glass allows most light
to pass through unobscured' in reality it also reflects some light. A perfectly transparent material
is completely in3isible.
A translucent physical material shows ob0ects behind it' but those ob0ects are obscured by the
translucent material. In addition' a translucent material reflects some of the light that hits it'
ma1ing the material 3isible. Physical e4amples of translucent materials include sheer cloth' thin
plastic' and smo1ed glass.
#ransparent and translucent are often used synonymously. =aterials that are neither
transparent nor translucent are opa:ue.
Blending is &pen$)@s mechanism for combining color already in the frame buffer with
the color of the incoming primiti3e. #he result of this combination is then stored bac1 in the
frame buffer. Blending is fre:uently used to simulate translucent physical materials. &ne
e4ample is rendering the smo1ed glass windshield of a car. #he dri3er and interior are still
3isible' but they are obscured by the dar1 color of the smo1ed glass.
H+: /an I a/hieBe a tran7arent e--e/tA
glEnable O$)KB)E!DPH glBlend9unc O$)KS%CKA)P(A' $)K&!EK=I!USKS%CKA)P(APH
After blending is enabled' as shown abo3e' the incoming primiti3e color is blended with
the color already stored in the frame buffer. glBlend9uncOP controls how this blending occurs.
#he typical use described abo3e modifies the incoming color by its associated alpha 3alue and
.+ 7 P a g e
modifies the destination color by one minus the incoming alpha 3alue. #he sum of these two
colors is then written bac1 into the framebuffer.
#he primiti3eMs opacity is specified using glColor<FOP. %$B specifies the color' and the
alpha parameter specifies the opacity.
8hen using depth buffering in an application' you need to be careful about the order in
which you render primiti3es. 9ully opa:ue primiti3es need to be rendered first' followed by
partially opa:ue primiti3es in bac16to6front order. If you don@t render primiti3es in this order' the
primiti3es' which would otherwise be 3isible through a partially opa:ue primiti3e' might lose the
depth test entirely.
H+: /an I /reate /reen .++r tran7aren/0A
#his is accomplished by specifying a polygon stipple pattern with glPolygonStippleOP and
by rendering the transparent primiti3e with polygon stippling enabled
OglEnableO$)KP&)L$&!KS#IPP)EPP. #he number of bits set in the stipple pattern determine
the amount of translucency and opacityH setting more bits result in a more opa:ue ob0ect' and
setting fewer bits results in a more translucent ob0ect. Screendoor transparency is sometimes
preferable to blending' becuase it@s order independent Oprimiti3es don@t need to be rendered in
bac16to6front orderP.
H+: /an I ren.er g,a :ith O7enGLA
#his :uestion is difficult to answer' because what loo1s li1e glass to one person might not
to another. 8hat follows is a general algorithm to get you started.
9irst render all opa:ue ob0ects in your scene. Disable lighting' enable blending' and
render your glass geometry with a small alpha 3alue. #his should result in a faint rendering of
., 7 P a g e
your ob0ect in the frame buffer. O!ote5 Lou may need to sort your glass geometry' so it@s
rendered in bac1 to front S order.P
!ow' you need to add the specular highlight. Set your ambient and diffuse material colors
to blac1' and your specular material and light colors to white. Enable lighting. Set
glDepth9uncO$)KERUA)P' then render your glass ob0ect a second time.
'+ I nee. t+ ren.er 30 7ri3itiBe -r+3 $a/% t+ -r+nt -+r /+rre/t ren.ering +- tran,"/ent
7ri3itiBe t+ +//"rA
If your hardware supports destination alpha' you can e4periment with different
glBlend9uncOP settings that use destination alpha. (owe3er' this won@t sol3e all the problems
with depth buffered translucent surfaces. #he only sure way to achie3e 3isually correct results is
to sort and render your primiti3es from bac1 to front.
I :ant t+ "e $,en.ing $"t /ann+t get .etinati+n a,7ha t+ :+r%! Can I $,en. +r /reate a
tran7aren/0 e--e/t :ith+"t .etinati+n a,7haA
=any &pen$) de3ices don@t support destination alpha. In particular' the &pen$) ...
software rendering libraries from =icrosoft don@t support it. #he &pen$) specification doesn@t
re:uire it.
If you ha3e a system that supports destination alpha' using it is a simple matter of as1ing
for it when you create your window. 9or e4ample' pass $)U#KA)P(A to
glutInitDisplay=odeOP' then set up a blending function that uses destination alpha' such as5
glBlend9uncO$)K&!EK=I!USKDS#KA)P(A'$)KDS#KA)P(APH
.N 7 P a g e
&ften this :uestion is as1ed under the mista1en assumption that destination alpha is
re:uired to do blending. It@s not. Lou can use blending in many ways to obtain a transparency
effect that uses source alpha instead of destination alpha. #he fact that you might be on a
platform without destination alpha shouldn@t pre3ent you from obtaining a transparency effect.
See the &pen$) Programming $uide chapter , for ways to use blending to achie3e
transparency.
I- I .ra: a tran,"/ent 7ri3itiBe an. .ra: an+ther 7ri3itiBe $ehin. it* I eC7e/t the e/+n.
7ri3itiBe t+ h+: thr+"gh the -irt* $"t itD n+t thereA
a!I .e7th $"--ering ena$,e.A
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. &n the other hand'
if you@3e disabled depth test' the new polygon will be blended with the e4isting polygon'
regardless of whether it@s behind or in front of it.
$!H+: /an I 3a%e 7art +- 30 teCt"re 3a7 tran7arent +r tran,"/entA
It depends on the effect you@re trying to achie3e.
If you want blending to occur after the te4ture has been applied' then use the &pen$)
blending feature. #ry this5
glEnable O$)KB)E!DPH glBlend9unc O$)K&!E' $)K&!EPH
Lou might want to use the alpha 3alues that result from te4ture mapping in the blend
function. If so' O$)KS%CKA)P(A'$)K&!EK=I!USKS%CKA)P(AP is always a good function
to start with.
.C 7 P a g e
(owe3er' if you want blending to occur when the primiti3e is te4ture mapped Oi.e.' you
want parts of the te4ture map to allow the underlying color of the primiti3e to show throughP'
then don@t use &pen$) blending. Instead' you@d use gl#e4En3OP' and set the te4ture en3ironment
mode to $)KB)E!D. In this case' you@d want to lea3e the te4ture en3ironment color to its
default 3alue of O/'/'/P
1!1 E Train Ren.ering in O7enG,<
A 3irtual train along with 3iew in -D showing the intial rest position of the
.#he entire scenery is constructed based on different &pen$l
functions along with other parameters.#he construction basically consists of components
used such as 'we ha3e constructed two metres..Clouds ha3e also been constructed o3er the s1y
for adding a good theme.!ow the main purpose to ser3e is pro3ided by the train which can be
dri3en o3er different directions along with 3arious functions which I will be mentioning
later.Basically a set of functions along with main function ser3ed the purpose of de3eloping
the abstract.
Ue< mouse interactions ha3e 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
=ay be crystal clear to the 3iewers.
1!SYSTEM ANALYSIS
.B 7 P a g e
1!1 S/+7e +- the #r+je/t<
As per the concern being gi3en to the scope we would definately say that this pro0ect will
gi3e a rough idea to the students who are basically wondering of how the ma0or games related
to train are being de3eloped.#he sourcecode used in this pro0ect is an outline 3iew of the
scenery being constructed o3er which the games are implemented.#he bac1ground plays a 3ery
3ital role along with the graphics used in the games.#his pro0ect will 0ust gi3e a flashbac1
of bac1ground construction along with ob0ects used in the games.Basically at the end I would
gi3e a full stop to the scope by saying that the primary and main scope of the pro0ect is A
doorstep for beginners of today to transform into Gamers of tomorrow
1!1 Ai3 +- the #r+je/t<
#he primary aim of this pro0ect 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 3arious
te4tures and effects of the entire building o3er which the train is being dri3en.
?! REFUIREMENT S#ECI&ICATIO !
-/ 7 P a g e
2!1 S+-t:are Re;"ire3ent<
A An =S6D&S based operating system li1e 8indows BC' 8indows -/// or
8indows DP the platform re:uired to de3elop the -D and -D graphics
applications.
A A isual C>CEE compiler is re:uired for compiling the source code to ma1e the
e4ecutable file which can then be directly e4ecuted.
A A built in graphics library li1e glut and glut;-' and header file li1e glut.h and also
dynamic lin1 libraries li1e glut and glut;- are re:uired for creating the -D layout.
2!1 Har.:are Re;"ire3ent<
#he hardware re:uirements are 3ery minimal and the software can run on most of the machines.
AProcessor 6 Intel <C,>Pentium processor or abo3e.
AProcessor Speed 6 +// =(? or abo3e
A%A= 6 ,<=B or abo3e Storage Space 6 - =B or abo3e
A=onitor resolution 6 A color monitor with a minimum resolution of ,</F<C/
2!'ESIGN #HASE
-. 7 P a g e
2!1 Intr+."/ti+n
#his pro0ect is basically being constructed 1eeping in 3iew the construction and simulationof a
train o3er a -D animated building as told earlier.Basically the pro0ect underta1en by us has gone
through a 3ariety of functions and headers along with a number of source codes.!ow let me sort
out a few functions along with headers.(ere I would basically brief out a few e4planation of the
contents.
2!1 M+.",ar 'e/ri7ti+n
#he ma0or functions that are used in the creation of the program are as follows5
1! B+i. init8B+i.9
)et@s start by loo1ing at initOP. It creates a display list for the torus and initiali?es the 3iewing
matrices and other rendering state.It also creates the starting window of the programme.
1< g,"t#+tRe.i7,a089
#hen glutPost%edisplayOP is called' which will cause glut=ain)oopOP to call displayOP and
render the torus after other e3ents ha3e been processed. 8hen the Ti@ 1ey is
pressed' 1eyboardOP restores the initial model3iew matri4 and returns the torus to its original
location.
?<.i7,a089
#he displayOP function is 3ery simple5 It clears the window and then calls glCall)istOP to
e4ecute the commands in the display list. If we hadn@t used display lists' displayOP would ha3e to
reissue the commands to draw the torus each time it was called.
-- 7 P a g e
A display list contains only &pen$) commands. In E4ample .6N' only
the g,Begin89' g,VerteC89' and g,En.89 calls are stored in the display list. #he parameters for the
calls are evaluated' and their 3alues 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.
(owe3er' the 3alues in the display list can@t be changed later. And once a command has been
stored in a list it is not possible to remo3e it. !either can you add any new commands to the list
after it has been defined. Lou can delete the entire display list and create a new one' but you can@t
edit it.
N+te< Display lists also wor1 well with $)U commands' since those operations are ultimately
bro1en down into low6le3el &pen$) commands' which can easily be stored in display lists. Use
of display lists with $)U is particularly important for optimi?ing performance of $)U
tessellators and !U%BS.
8e ha3e different functions that ma1es use to create the fountain with simulated water' they
are as followsG
1<C,+".!/77
#his function is mainly used for the construction of the cloud which isfloating o3er the s1y.#he
function implementation may be stated as follows.
>>dynamic ob0ect6 Single cloud
Uinclude Vtime.hW
>> =aterial of cloud
-; 7 P a g e
materialStruct cloudShader X YY/.Bf' /.Bf' /.Bf' ../fZ'
Y/.Bf' /.Bf' /.Bf' /.NfZ'
Y/./f' /./f' /./f' ../fZ'
$)float 4 X /./H$)float y X/./H $)float ? X /./H $)float a X /./H

1<Gr+"n.!/77
#he function to add te4tured building to ground.
>> =aterial of ground
materialStruct groundShader X YY/./f' /./f' /./f' ../fZ'
Y/.Nf' /.+f' /.+f' ../fZ'
Y/.Nf' /.Nf' /.Nf' ../fZ'
Y+/./fZZH
?<Train!/77
void TRAINS(int x1,int y1,int a,int b)
{ int i=0;
glBegin(GL!"A#S);
gl$olo%&'(0,0(0,1(0); ))*NGIN*
gl+e%tex,'(x1,y1); ))leng- o' engine=.0;-eig-t o'
engine=&0;
gl$olo%&'(0,0(0,1(0);
gl+e%tex,'(x1/.0,y1);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(x1/.0,y10&0);
gl$olo%&'(0,0(0,0(0);
gl+e%tex,'(x1,y10&0);
gl*nd();
1-ile(i2&)
-< 7 P a g e
{ glBegin(GL!"A#S); ))B3GI*S
gl$olo%&'(1(0,0(0,0(0); ))4o% %ig-t t%ain a=567,b=710
gl+e%tex,'(a,b);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a/.0,b);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a/.0,b0,0);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a,b0,0);
gl*nd();
a/=.7;
i//;
8
8
2<Inter-a/e!/77
An interface describes the beha3ior or capabilities of a CEE class without committing to a
particular implementation of that class.
#he CEE interfaces are implemented using a$tra/t /,ae and these abstract classes should not
be confused with data abstraction which is a concept of 1eeping implementation detail separate
from associated data.
A class is made abstract by declaring at least one of its functions as 7"re Birt"a,function. A pure
3irtual function is specified by placing QX /Q in its declaration as follows5
class Bo4
Y
-+ 7 P a g e
public5
>> pure 3irtaul function
3irtual double getolumeOP X /H
pri3ate5
double lengthH >> )ength of a bo4
double breadthH >> Breadth of a bo4
double heightH >> (eight of a bo4
ZH
#he purpose of an a$tra/t /,a Ooften referred to as an ABCP is to pro3ide an appropriate base
class from which other classes can inherit. Abstract classes cannot be used to instantiate ob0ects
and ser3es only as an inter-a/e. Attempting to instantiate an ob0ect of an abstract class causes a
compilation error.
#hus' if a subclass of an ABC needs to be instantiated' it has to implement each of the 3irtual
functions' which means that it supports the interface declared by the ABC. 9ailure to o3erride a
pure 3irtual function in a deri3ed class' then attempting to instantiate ob0ects of that class' is a
compilation error.
Classes that can be used to instantiate ob0ects are called /+n/rete /,ae.
-, 7 P a g e
Abstract Class E4ample5
Consider the following e4ample where parent class pro3ides an interface to the base class to
implement a function called getArea895
Uinclude ViostreamW

using namespace stdH

>> Base class
class Shape
Y
public5
>> pure 3irtual function pro3iding interface framewor1.
3irtual int getAreaOP X /H
3oid set8idthOint wP
Y
width X wH
Z
3oid set(eightOint hP
Y
height X hH
Z
protected5
int widthH
-N 7 P a g e
@<Main!/77
As all of us 1now the main contains all the functions stated earlier along with other parameters
useful to construct and implement the pro0ect.
2! CO'E
9in:l;de2<tdio(-=
9in:l;de2<tdlib(-=
9in:l;de2GL)gl;t(-=
9in:l;de 2>at-(-=
9in:l;de 2ti>e(-=
9in:l;de 21indo1<(-=
9de'ine ?@I &(1A
int :=0,d=700,g=&B0,-=650,i=7A0,C=650,D=&B0,l=6.7,>=7A0,n=650;
GL'loat x=0(0,y=0(0;
int E=0,a;
int t%ain1,ba<i:;
))>at%ix
void <Dy()
{
glBegin(GL@3LFG3N);
gl$olo%&'(0,1,1);
gl+e%tex,'(0,5&0);
gl+e%tex,'(666,5&0);
gl+e%tex,'(666,666);
gl+e%tex,'(0,666);
gl*nd();
8
void <leeG(;n<igned int ><e:ond<)
{
-C 7 P a g e
:lo:Dt goal = ><e:ond< / :lo:D();
1-ile (goal = :lo:D());
8
void TRAINS(int x1,int y1,int a,int b)
{ int i=0;
glBegin(GL!"A#S);
gl$olo%&'(0,0(0,1(0); ))*NGIN*
gl+e%tex,'(x1,y1); ))leng- o'
engine=.0;-eig-t o' engine=&0;
gl$olo%&'(0,0(0,1(0);
gl+e%tex,'(x1/.0,y1);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(x1/.0,y10&0);
gl$olo%&'(0,0(0,0(0);
gl+e%tex,'(x1,y10&0);
gl*nd();
1-ile(i2&)
{ glBegin(GL!"A#S); ))B3GI*S
gl$olo%&'(1(0,0(0,0(0); ))4o% %ig-t t%ain
a=567,b=710
gl+e%tex,'(a,b);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a/.0,b);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a/.0,b0,0);
gl$olo%&'(1(0,0(0,0(0);
gl+e%tex,'(a,b0,0);
gl*nd();
a/=.7;
i//;
8
8
void TRA$HS()
{
<Dy();
-B 7 P a g e
)II T%a:D II)
glBegin(GLLIN*S);
gl$olo%&'(0(0,0(0,0(0);
gl+e%tex,'(0,700);
gl+e%tex,'(1000,700);
gl+e%tex,'(0,A66);
gl+e%tex,'(1000,A66);
gl+e%tex,'(0,AB7);
gl+e%tex,'(1000,AB7);
gl+e%tex,'(0,AB.);
gl+e%tex,'(1000,AB.);
1-ile(:J=1000)
{
gl+e%tex,'(:,d);
gl+e%tex,'(:,d017);
:/=10;
8
gl*nd();
8
void >yinit()
{ gl$lea%$olo%(0(0,0(7,0(0,0(0); ))ba:Dg%o;nd :olo%
gl;3%t-o,#(0,666,0,666);
gl@ointSiEe(,(0);
glLineKidt-(,(0);
ba<i: = glGenLi<t<(1);
glNe1Li<t(ba<i:, GL$3?@IL*);
TRA$HS();
gl*ndLi<t();
t%ain1 = glGenLi<t<(1);
glNe1Li<t(t%ain1, GL$3?@IL*);
TRAINS(5&0,7,0,567,710);
gl*ndLi<t();
8
void d%a1(void)
{
;/ 7 P a g e
gl$lea%(GL$3L3RB"44*RBIT);
gl@;<-?at%ix();
gl@;<-?at%ix();
gl$allLi<t(ba<i:);
gl@oG?at%ix();
gl@;<-?at%ix();
glT%an<late'(x,y,0(0);
gl$allLi<t(t%ain1);
gl4l;<-();
gl@oG?at%ix();
i'(E216B)
{ a/=7;
x=x07(0;
<leeG(100);
E//;
8
gl@oG?at%ix();
gl;t@o<tRedi<Glay();
gl4l;<-();
8
void >o;<e(int b;tton,int <tate,int x,int y)
{
<1it:-(b;tton)
{
:a<e GL"TL*4TB"TT3NL
i'(<tate==GL"T#3KN)
gl;t#i<Glay4;n:(d%a1);
b%eaD;
:a<e GL"TRIGMTB"TT3NL
i'(<tate==GL"T#3KN)
<leeG(1000);
b%eaD;
8
8
void >ain()
{ gl;tInit#i<Glay?ode(GL"TSINGL*NGL"TRGB);
gl;tInitKindo1@o<ition(0,0);
gl;tInitKindo1SiEe(1,00,500);
;. 7 P a g e
gl;t$%eateKindo1(OR;nning T%ain<O);
gl;t?o;<e4;n:(>o;<e);
gl;t#i<Glay4;n:(d%a1);
>yinit();
gl;t?ainLooG ();
8
Snap"hot
;- 7 P a g e
;; 7 P a g e
G! CONCLUSION<>
#he abo3e pro0ect prepared on the topic % Train o& %is successful and hopefully demonstrating
its wor1ing with the help of both mouse as well as 1eys interaction.#he &pen$l source code
along with headers and othermain code helped us to prepare the pro0ect as per the
re:uirement.In future this conceptwill garnish and will act as a plus point in implementing a
game related to train.



;< 7 P a g e
H! Bi$,i+gra7h0
Interacti3e Computer $raphics.
A #op6Down Approach using &pen$)6 Edward Angel
http5>>en.wi1ipedia.org>wi1i>&pen$)
http5>>www.google.co.in>
http5>>www.opengl.org>
;+ 7 P a g e

You might also like