Sei sulla pagina 1di 57

Computer Graphics and Visualization 10CS65

VTU QUESTION PAPER SOLUTION


UNIT -1
INTRODUCTION
1. Briefly explain any t! appli"ati!n# !f "!$p%ter &rap'i"#. ()%ne *+1*, -.
Ans: Applications of computer graphics are:
Display f !nformation
Design
Simulation " Animation
#ser !nterfaces
*. Explain t'e "!n"ept !f pin'!le "a$era !f an i$a&in& #y#te$. Al#! /eri0e t'e
expre##i!n f!r an&le !f 0ie. ()%ne *+1*, 1.
Ans :
#se trigonometry to find pro$ection of point at
%&'y'z( xp= -x/z/d yp= -y/z/d zp= d
)hese are e*uations of simple perspecti+e
2. Di#"%## t'e &rap'i"# pipeline ar"'ite"t%re3 it' t'e 'elp !f a f%n"ti!nal #"'e$ati"
/ia&ra$. ()%ne *+1*, 1+.
Ans : Graphics ,ipeline :
,rocess o-$ects one at a time in the order they are generated -y the application
All steps can -e implemented in hard.are on the graphics card
Verte& ,rocessor
Dept/ of CS0' C0C ,age 1
Computer Graphics and Visualization 10CS65
1uch of the .or2 in the pipeline is in con+erting o-$ect representations from one coordinate
system to another
3 -$ect coordinates
3 Camera %eye( coordinates
3 Screen coordinates
0+ery change of coordinates is e*ui+alent to a matri& transformation
Verte& processor also computes +erte& colors
,rimiti+e Assem-ly
Vertices must -e collected into geometric o-$ects -efore clipping and rasterization can ta2e
place
3 4ine segments
3 ,olygons
3 Cur+es and surfaces
Clipping
5ust as a real camera cannot 6see7 the .hole .orld' the +irtual camera can only see part of the
.orld or o-$ect space
3 -$ects that are not .ithin this +olume are said to -e clipped out of the scene
8asterization :
!f an o-$ect is not clipped out' the appropriate pi&els in the frame -uffer must -e assigned colors
8asterizer produces a set of fragments for each o-$ect
9ragments are 6potential pi&els7
3 :a+e a location in frame -ufffer
3 Color and depth attri-utes
Verte& attri-utes are interpolated o+er o-$ects -y the rasterizer
9ragment ,rocessor:
Dept of CS0' C0C ,age ;
Computer Graphics and Visualization 10CS65
9ragments are processed to determine the color of the corresponding pi&el in the frame -uffer
Colors can -e determined -y te&ture mapping or interpolation of +erte& colors
9ragments may -e -loc2ed -y other fragments closer to the camera
-. 4it' a neat /ia&ra$3 explain t'e "!$p!nent# !f a &rap'i"# #y#te$. (De" *+11, 1.
An# 5 A Graphics system has 5 main elements :
!nput De+ices
,rocessor
1emory
9rame <uffer
utput De+ices
,i&els and the 9rame <uffer
A picture is produced as an array %raster( of picture elements %pi&els(/
)hese pi&els are collecti+ely stored in the 9rame <uffer/
,roperties of frame -uffer:
8esolution 3 num-er of pi&els in the frame -uffer
Depth or ,recision 3 num-er of -its used for each pi&el
0/g/: 1 -it deep frame -uffer allo.s ; colors
= -it deep frame -uffer allo.s ;56 colors/
A 9rame -uffer is implemented either .ith special types of memory chips or it can -e a part of
system memory/
Dept of CS0' C0C ,age >
Computer Graphics and Visualization 10CS65
!n simple systems the C,# does -oth normal and graphical processing/
Graphics processing ? )a2e specifications of graphical primiti+es from application program and
assign +alues to the pi&els in the frame -uffer !t is also 2no.n as 8asterization or scan
con+ersion/
6. 4it' a neat /ia&ra$3 explain t'e '%$an 0i#%al #y#te$. (De" *+11, 1.
An#5
8ods are used for : monochromatic' night +ision
Cones
Color sensiti+e
)hree types of cones
nly three +alues %the tristimulus +alues( are sent to the -rain
@eed only match these three +alues
3 @eed only three primary colors
6/ De#"ri7e t'e !r8in& !f an !%tp%t /e0i"e it' an exa$ple. ()%ly*+11, 6.
An# 5 )he most predominant type of display has -een the Cathode 8ay )u-e %C8)(/
Various parts of a C8):

0lectron Gun 3 emits electron -eam .hich stri2es the phosphor coating to emit light/
Dept of CS0' C0C ,age A
Computer Graphics and Visualization 10CS65
Deflection ,lates 3 controls the direction of -eam/ )he output of the computer is con+erted -y
digital?to?analog con+erters o +oltages across & " y deflection plates/
8efresh 8ate 3 !n order to +ie. a flic2er free image' the image on the screen has to -e
retraced -y the -eam at a high rate %modern systems operate at
=5:z( ; types of refresh:
@oninterlaced display: ,i&els are displayed ro. -y ro. at the refresh rate/
!nterlaced display: dd ro.s and e+en ro.s are refreshed alternately/
Dept of CS0' C0C ,age 5
Computer Graphics and Visualization 10CS65
UNIT -*
T9E OPEN:L
1. 4it' t'e 'elp !f a /ia&ra$3 /e#"ri7e t'e !pen :L interfa"e. ()%n*+1*, -.
An#5 penG4 pro+ides a po.erful -ut primiti+e set of rendering commands' and all higher?le+el
dra.ing must -e done in terms of these commands/
)he penG4 #tility 4i-rary %G4#( contains se+eral routines that use lo.er?le+el penG4
commands to perform such tas2s as setting up matrices for specific +ie.ing orientations and
pro$ections' performing polygon tessellation' and rendering surfaces/ )his li-rary is pro+ided
as part of e+ery penG4 implementation/
9or e+ery .indo. system' there is a li-rary that e&tends the functionality of that .indo.
system to support penG4 rendering/ 9or machines that use the B Cindo. System' the
penG4 0&tension to the B Cindo. System %G4B( is pro+ided as an ad$unct to penG4/
G4B routines use the prefi& &l;/ 9or 1icrosoft Cindo.s' the CG4 routines pro+ide the
Cindo.s to penG4 interface/
)he penG4 #tility )ool2it %G4#)( is a .indo. system?independent tool2it' .ritten -y
1ar2 Dilgard' to hide the comple&ities of differing .indo. system A,!s/
;/ 4rite explanat!ry n!te# !n5 i, R:B "!l!r $!/el< ii, in/exe/ "!l!r $!/el. ()%n*+1*, 1.
An#5 Colors are indices into ta-les of 8G< +alues
8e*uires less memory
3 indices usually = -its
3 not as important no.
1emory ine&pensi+e
Dept of CS0' C0C ,age 6
Computer Graphics and Visualization 10CS65
@eed more colors for shading
!n inde&ed mode' colors are stored as indices/ !f there are 2 indices then there can -e 2n?1 colors
that could -e got -y com-ining red' green and -lue/ )his yields a huge color palette as compared
to the normal 8G< mode/
2. 4rite an !pen :L re"%r#i0e pr!&ra$ f!r *D #ierpin#8i &a#8et it' rele0ant "!$$ent#.
()%n*+1*, 1+.
An#5 Einclude Fstdaf&/hF
Einclude GG4Hglut/hI
typedef float
pointJ>KL HM initial
tetrahedron MH
point +JK NOO0/0' 0/0' 1/0P'
O0/0' 1/0' ?1/0P' O?1/0'
?1/0' ?1/0P' O1/0' ?1/0'
?1/0PPL
static G4float thetaJK N O0/0'0/0'0/0PL
int nL
+oid triangle% point a' point -' point c(
HM display one triangle using a line loop for .ire frame MH
O
gl<egin%G4Q,4RG@(L
glVerte&>f+%a(L
glVerte&>f+%-(L
glVerte&>f+%c(L
Dept of CS0' C0C ,age S
Computer Graphics and Visualization 10CS65
gl0nd%(L
P
+oid di+ideQtriangle%point a' point -' point c' int m(
O
HM triangle su-di+ision using +erte& num-ers
righthand rule applied to create out.ard pointing faces MH
point +1' +;'
+>L int $L
if%mI0(
O
for%$N0L $G>L $TT( +1J$KN%aJ$KT-J$K(H;L
for%$N0L $G>L $TT( +;J$KN%aJ$KTcJ$K(H;L
for%$N0L $G>L $TT( +>J$KN%-J$KTcJ$K(H;L
di+ideQtriangle%a' +1' +;' m?1(L
di+ideQtriangle%c' +;' +>' m?1(L
di+ideQtriangle%-' +>' +1' m?1(L
P
HM dra. triangle at end of recursion MH
else%triangle%a'-'c((L
P
+oid tetrahedron% int m(
O
HM Apply triangle su-di+ision to faces of tetrahedron/Gi+e
a different color to each face of the tetrahedronMH
glColor>f%1/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J1K' +J;K' m(L
glColor>f%0/0'1/0'0/0(L
di+ideQtriangle%+J>K' +J;K' +J1K' m(L
glColor>f%0/0'0/0'1/0(L
di+ideQtriangle%+J0K' +J>K' +J1K' m(L
glColor>f%0/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J;K' +J>K' m(L
P
Dept of CS0' C0C ,age =
Computer Graphics and Visualization 10CS65
+oid display%+oid(
O
glClear%G4QC48Q<#9908Q<!) U
G4QD0,):Q<#9908Q<!)(L gl4oad!dentity%(L
tetrahedron%n(L
gl9lush%(L
P
+oid my8eshape%int .' int h(
O
glVie.port%0' 0' .' h(L
gl1atri&1ode%G4Q,850C)!@(L
gl4oad!dentity%(L
HM code to maintain the aspect
ratioMH HM Chen .idth -ecomes less
than height' ad$ust the -ottom'top parameters
to maintain the aspect ratioMH
if %. GN h(
glrtho%?;/0' ;/0' ?;/0 M %G4float( h H %G4float(
.' ;/0 M %G4float( h H %G4float( .' ?10/0' 10/0(L
HM Chen height -ecomes less
than .idth' ad$ust the left'right parameters to
maintain the aspect ratioMH
else
glrtho%?;/0 M %G4float( . H %G4float( h'
;/0 M %G4float( . H %G4float( h' ?;/0' ;/0'
?10/0' 10/0(L
gl1atri&1ode%G4Q1D04V!0C(L
glut,ost8edisplay%(L
P
+oid main%int argc' char MMarg+(
O
printf%Fenter the no of di+ision :
F(L scanf%FVdF'"n(L
glut!nit%"argc' arg+(L
glut!nitDisplay1ode%G4#)QS!@G40 U G4#)Q8G< U G4#)QD0,):(L
glut!nitCindo.Size%6A0' A=0(L
glutCreateCindo.%F>D Gas2etF(L
glut8eshape9unc%my8eshape(L
Dept of CS0' C0C ,age W
Computer Graphics and Visualization 10CS65
glutDisplay9unc%display(L
gl0na-le%G4QD0,):Q)0S)(L
glClearColor %1/0' 1/0' 1/0' 1/0(L
glut1ain4oop%(L
P
-. 4it' a neat /ia&ra$3 /i#"%## t'e "!l!r f!r$ati!n. Explain t'e a//iti0e an/ #%7tra"ti0e
"!l!r#3 in/exe/ "!l!r an/ "!l!r #!li/ "!n"ept. (De"*+11, 1*.
An#5
A +isi-le color can -e characterized -y the function C%X(
)ristimulus +alues 3 responses of the > types of cones to the colors/
> color theory 3 6!f ; colors produce the same tristimulus +alues' then they are +isually
indistinguisha-le/7
Additi+e color model 3 Adding together the primary colors to get the percie+ed colors/
0/g/ C8)/
Su-tracti+e color model 3 Colored pigments remo+e color components from light that is
stri2ing the surface/ :ere the primaries are the complimentary colors : cyan' magenta and
yello.
R:B "!l!r
0ach color component is stored separately in the frame
-uffer #sually = -its per component in -uffer
@ote in &lC!l!r2f the color +alues range from 0/0 %none( to 1/0 %all(' .hereas in
&lC!l!r2%7 the +alues range from 0 to ;55
)he color as set -y &lC!l!r -ecomes part of the state and .ill -e used until changed
Dept of CS0' C0C ,age 10
Computer Graphics and Visualization 10CS65
3 Colors and other attri-utes are not part of the o-$ect -ut are assigned .hen the
o-$ect is rendered
Ce can create conceptual vertex colors -y code such as
&lC!l!r
&lVertex
&lC!l!r
&lVertex
8G<A color system :

)his has A arguments 3 8G< and alpha


alpha 3 pacity/
glClearColor%1/0'1/0'1/0'1/0(
)his .ould render the .indo. .hite since all components are e*ual to 1/0' and is opa*ue
as alpha is also set to 1/0
In/exe/ "!l!r
Colors are indices into ta-les of 8G< +alues
8e*uires less memory
o indices usually = -its
o not as important no.
1emory ine&pensi+e
@eed more colors for shading
6. 4'at are "!ntr!l f%n"ti!n#= Explain it' exa$ple#. (De"*+11, >.
An#5 Cindo. 3 A rectangular area of our display/
1odern systems allo. many .indo.s to -e displayed on the screen %multi.indo.
en+ironment(/
Dept of CS0' C0C ,age 11
Computer Graphics and Visualization 10CS65
)he position of the .indo. is .ith reference to the origin/ )he origin %0' 0( is the top left
corner of the screen/
&l%tInit(,
allo.s application to get command line arguments and initializes system/)he function is
-asically used for initializing the glut li-rary and also to initiate a session .ith the .indo.s
system/ )he function does not ta2e any arguments and should -e the first function to -e
called .ithin the main program/
&l%InitDi#play.!/e(, re*uests properties for the .indo. %the rendering context(
8G< color? specified -y the argument G4#)Q8G</ !t specifies that a > color mode
needs to -e used/
Single -uffering 3 G4#)QS!@G40: specifies that the images are static and only a
single frame -uffer is re*uired to store the pi&els
G4#)QD#<40: specifies that the images are animations and t.o frame
-uffers'front and -ac2 are re*uired for rendering a smooth image/
,roperties logically 8ed
together &l%t4in/!Si?e in pi&els
&l%t4in/!P!#iti!n from top?left corner of display
&l%tCreate4in/! create .indo. .ith a particular title
1. 4rite a "!$plete !pen :L pr!&ra$ f!r "reatin& 2D #ierpin#8i &a#8et 7y #%7/i0i#i!n !f
a tetra'e/r!n. ()%ly*+11, 1+.
Ans: Einclude Fstdaf&/hF
Einclude GG4Hglut/hI
typedef float
pointJ>KL HM initial
tetrahedron MH
point +JK NOO0/0' 0/0' 1/0P'
O0/0' 1/0' ?1/0P' O?1/0'
?1/0' ?1/0P' O1/0' ?1/0'
?1/0PPL
static G4float thetaJK N O0/0'0/0'0/0PL
int nL
+oid triangle% point a' point -' point c(
Dept of CS0' C0C ,age 1;
Computer Graphics and Visualization 10CS65
HM display one triangle using a line loop for .ire frame MH
O
gl<egin%G4Q,4RG@(L
glVerte&>f+%a(L
glVerte&>f+%-(L
glVerte&>f+%c(L
gl0nd%(L
P
+oid di+ideQtriangle%point a' point -' point c' int m(
O
HM triangle su-di+ision using +erte& num-ers
righthand rule applied to create out.ard pointing faces MH
point +1' +;'
+>L int $L
if%mI0(
O
for%$N0L $G>L $TT( +1J$KN%aJ$KT-J$K(H;L
for%$N0L $G>L $TT( +;J$KN%aJ$KTcJ$K(H;L
for%$N0L $G>L $TT( +>J$KN%-J$KTcJ$K(H;L
di+ideQtriangle%a' +1' +;' m?1(L
di+ideQtriangle%c' +;' +>' m?1(L
di+ideQtriangle%-' +>' +1' m?1(L
P
HM dra. triangle at end of recursion MH
else%triangle%a'-'c((L
P
+oid tetrahedron% int m(
O
HM Apply triangle su-di+ision to faces of tetrahedron/Gi+e
a different color to each face of the tetrahedronMH
glColor>f%1/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J1K' +J;K' m(L
glColor>f%0/0'1/0'0/0(L
di+ideQtriangle%+J>K' +J;K' +J1K' m(L
Dept of CS0' C0C ,age 1>
Computer Graphics and Visualization 10CS65
glColor>f%0/0'0/0'1/0(L
di+ideQtriangle%+J0K' +J>K' +J1K' m(L
glColor>f%0/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J;K' +J>K' m(L
P
+oid display%+oid(
O
glClear%G4QC48Q<#9908Q<!) U G4QD0,):Q<#9908Q<!)(L
gl4oad!dentity%(L
tetrahedron%n(L
gl9lush%(L
P
+oid my8eshape%int .' int h(
O
glVie.port%0' 0' .' h(L
gl1atri&1ode%G4Q,850C)!@(L
gl4oad!dentity%(L
HM code to maintain the aspect
ratioMH HM Chen .idth -ecomes less
than height' ad$ust the -ottom'top parameters
to maintain the aspect ratioMH
if %. GN h(
glrtho%?;/0' ;/0' ?;/0 M %G4float( h H %G4float(
.' ;/0 M %G4float( h H %G4float( .' ?10/0' 10/0(L
HM Chen height -ecomes less
than .idth' ad$ust the left'right parameters to
maintain the aspect ratioMH
else
glrtho%?;/0 M %G4float( . H %G4float( h'
;/0 M %G4float( . H %G4float( h' ?;/0' ;/0'
?10/0' 10/0(L
gl1atri&1ode%G4Q1D04V!0C(L
glut,ost8edisplay%(L
P
+oid main%int argc' char MMarg+(
O
printf%Fenter the no of di+ision : F(L
Dept of CS0' C0C ,age 1A
Computer Graphics and Visualization 10CS65
scanf%FVdF'"n(L
glut!nit%"argc' arg+(L
glut!nitDisplay1ode%G4#)QS!@G40 U G4#)Q8G< U G4#)QD0,):(L
glut!nitCindo.Size%6A0' A=0(L
glutCreateCindo.%F>D Gas2etF(L
glut8eshape9unc%my8eshape(L
glutDisplay9unc%display(L
gl0na-le%G4QD0,):Q)0S)(L
glClearColor %1/0' 1/0' 1/0' 1/0(L
glut1ain4oop%(L
P
@. Cla##ify t'e $aA!r &r!%p# !f API f%n"ti!n# in !pen :L. Explain any f!%r !f t'e$.
()%ly*+11, 1.
Ans:
,rimiti+e functions: Defines lo. le+el o-$ects such as points' line segments' polygons
etc/
Attri-ute functions : Attri-utes determine the appearance of o-$ects
o Color %points' lines' polygons(
o Size and .idth %points' lines(
o ,olygon mode
Display as filled
Display edges
Display +ertices
Vie.ing functions: Allo.s us to specify +arious +ie.s -y descri-ing the cameraYs
position and orientation/
)ransformation functions: ,ro+ides user to carry out transformation of o-$ects li2e
rotation' scaling etc/
!nput functions : Allo.s us to deal .ith a di+erse set of input de+ices li2e 2ey-oard'
mouse etc
Control functions: 0na-les us to initialize our programs' helps in dealing .ith any errors
during e&ecution of the program/
Zuery functions: :elps *uery information a-out the properties of the particular
implementation/
Dept of CS0' C0C ,age 15
Computer Graphics and Visualization 10CS65
>. 4'at i# an attri7%te it' re#pe"t t! &rap'i"# #y#te$= Li#t attri7%te# f!r line# an/
p!ly&!n#. ()%ly*+11, -.
An#5 Attri-ute functions : Attri-utes determine the appearance of o-$ects
Color %points' lines' polygons(
Size and .idth %points' lines(
,olygon mode
Display as filled
Display edges
Display +ertices
,olygons : -$ect that has a -order that can -e descri-ed -y a line loop " also has a .ell defined
interior
B. Li#t !%t /ifferent !pen :L pri$iti0e#3 &i0in& exa$ple# f!r ea"'. ()an*+1+, 1+.
Ans: penG4 supports ; types of primiti+es:
Geometric primiti+es %+ertices' line segments/( 3 they pass through the geometric
pipeline
Dept of CS0' C0C ,age 16
Computer Graphics and Visualization 10CS65
8aster primiti+es %arrays of pi&els( 3 passes through a separate pipeline to the frame -uffer/
4ine segments
G4Q4!@0S
G4Q4!@0QS)8!,
G4Q4!@0Q4,
1+. Briefly explain t'e !rt'!&rap'i" 0iein& it' Open:L f%n"ti!n# f!r */ an/ 2/ 0iein&.
In/i"ate t'e #i&nifi"an"e !f pr!Ae"ti!n plane an/ 0iein& p!int in t'i#. ()an*+1+, 1+.
An#5 !n the default orthographic +ie.' points are pro$ected for.ard along the z a&is onto the
plane z=0
Tran#f!r$ati!n# an/ Viein&
)he pipeline architecture depends on multiplying together a num-er of transformation matrices to
achie+e the desired image of a primiti+e/
).o important matrices :
1odel?+ie.
,ro$ection
)he +alues of these matrices are part of the state of the system/
!n penG4' pro$ection is carried out -y a pro$ection matri& %transformation(
)here is only one set of transformation functions so .e must set the matri& mode
first &l.atrix.!/e (:LCPRO)ECTION,
)ransformation functions are incremental so .e start .ith an identity matri& and alter it .ith a
pro$ection matri& that gi+es the +ie. +olume
&lL!a/I/entity(,<
&lOrt'!(-1.+3 1.+3 -1.+3 1.+3 -1.+3 1.+,<
Dept of CS0' C0C ,age 1S
Computer Graphics and Visualization 10CS65
UNIT-2
INPUT AND INTERACTION
1. 4'at are t'e 0ari!%# "la##e# !f l!&i"al inp%t /e0i"e# t'at are #%pp!rte/ 7y !pen :L=
Explain t'e f%n"ti!nality !f ea"' !f t'e#e "la##e#. ()%n*+1*, >.
Ans : Consider the C and CTT code
3 CTT: "in DD x<
3 C: #"anf (EF/G3 Hx,<
Chat is the input de+ice[
3 CanYt tell from the code
3 Could -e 2ey-oard' file' output from another program
)he code pro+ides logical input
3 A num-er %an int( is returned to the program regardless of the physical de+ice
:rap'i"al L!&i"al De0i"e#
Graphical input is more +aried than input to standard programs .hich is usually num-ers'
characters' or -its
).o older A,!s %GDS' ,:!GS( defined si& types of logical input
3 L!"at!r: return a position/ ,lacing the mouse pointer at any location on the screen
.ould return the corresponding & and y coordinates of the location/ 1ouse acts as
a locator de+ice/
3 Pi"8: return !D of an o-$ect/ Chen there are se+eral graphical o-$ects on the screen
pic2ing one of them and that .ould occupy the entire screen/ )his is a pic2
operation/
Again the mouse can act as apic2 de+ice/
3 Iey7!ar/: return strings of characters/ )yping on the 2ey-oard .ould 2eep storing
the typed letters into a -uffer and on e+nets li2e pressing on enter 2ey' the entire
string .ould -e returned to the graphics system/Dey-oard itself is the de+ice for
this purpose/
3 Str!8e: return array of positions/ <asically used in paint applications .here .hen a
paint -rush is mo+ed across the editor a stro2e is generated/ All the locations
in+ol+ed in the stro2e are returned as an array/ 1ouse can act as a stro2e de+ice/
3 Val%at!r: return floating point num-er/
Dept of CS0' C0C ,age 1=
Computer Graphics and Visualization 10CS65
3 C'!i"e: return one of n items/ Chen there are se+eral items on the screen then
selecting one of them is the purpose of this de+ice/ !t could -e selected -y a
mouse clic2 .hich returns the id associated .ith a particular o-$ect/
*. Li#t t'e 0ari!%# feat%re# t'at a &!!/ intera"ti0e pr!&ra$ #'!%l/ in"l%/e. ()%n*+1*,
-.
An#5 Some of the good features of a interacti+e graphics program are:
#ser friendly G#!
:a+ing help menus
0asily understanda-le
,ro+iding smooth transitions of images/
Smooth >d animations -y using z -uffer/
2. 4rite an !pen :L pr!&ra$ t! /e$!n#trate t'e 'ierar"'i"al $ean#3 t! /ra a
re"tan&le an/ t! in"rea#e !r /e"rea#e t'e #i?e !f re"tan&le. ()%n*+1*, >.
An#5 )he open G4 program is as follo.s:
glutCreate1enu%demoQmenu(L
glutAdd1enu0ntry%6*uit7'1(L
glutAdd1enu0ntry%6increase s*uare size7';(L
glutAdd1enu0ntry%6decrease s*uare size7' >(L
GlutAttach1enu%G4#)Q8!G:)Q<#))@(L
)he call-ac2 function is:
+oid demoQmenu%int id(
O
s.itch%id(
O
case 1:
e&it%0(L -rea2L
case ;:
sizeN;MsizeL -rea2L
case >: if%sizeI1(
sizeNsizeH;L -rea2L
P
glut,ost8edisplay%(L
Dept of CS0' C0C ,age 1W
Computer Graphics and Visualization 10CS65
P
su-Qmenu N glutCreate1enu%sizeQmenu(L
glutAdd1enu0ntry%6increase s*uare size7' ;(L
glutAdd1enu0ntry%6Decrease s*uare size7'>(L
glutCreate1enu%topQmenu(L
glutAdd1enu0ntry%6Zuit7'1(L
glutAddSu-1enu%68esize7'su-Qmenu(L
glutAttach1enu%G4#)Q8!G:)Q<#))@(L
-. 4'i"' are t'e #ix "la##e# !f l!&i"al inp%t /e0i"e#= Explain. (De"*+11, 1.
Ans:
3 L!"at!r: return a position/ ,lacing the mouse pointer at any location on the screen
.ould return the corresponding & and y coordinates of the location/ 1ouse acts as
a locator de+ice/
3 Pi"8: return !D of an o-$ect/ Chen there are se+eral graphical o-$ects on the screen
pic2ing one of them and that .ould occupy the entire screen/ )his is a pic2
operation/
Again the mouse can act as apic2 de+ice/
3 Iey7!ar/: return strings of characters/ )yping on the 2ey-oard .ould 2eep storing
the typed letters into a -uffer and on e+nets li2e pressing on enter 2ey' the entire
string .ould -e returned to the graphics system/Dey-oard itself is the de+ice for
this purpose/
3 Str!8e: return array of positions/ <asically used in paint applications .here .hen a
paint -rush is mo+ed across the editor a stro2e is generated/ All the locations
in+ol+ed in the stro2e are returned as an array/ 1ouse can act as a stro2e de+ice/
3 Val%at!r: return floating point num-er/
3 C'!i"e: return one of n items/ Chen there are se+eral items on the screen then
selecting one of them is the purpose of this de+ice/ !t could -e selected -y a
mouse clic2 .hich returns the id associated .ith a particula o-$ect/
6. Di#"%## t'e reJ%e#t $!/e3 #a$ple $!/e an/ e0ent $!/e# it' t'e fi&%re# 'ere0er
reJ%ire/. (De"*+11, >.
Ans: 8e*uest 1ode:
)he measure of the de+ice is not returned to program until de+ice is triggered
Dept of CS0' C0C ,age ;0
Computer Graphics and Visualization 10CS65
Standard in nongraphical applications
)ypical of 2ey-oard input
o Can erase %-ac2space(' edit' correct until enter %return( 2ey %the trigger( is
depressed
Sa$ple .!/e5
As soon as the function call in the user program is encountered' the measure is returned/
@o trigger is needed
)he user must ha+e positioned the pointing de+ice -efore the function call' -ecause the
measure is e&tracted immediately from the -uffer/
<oth re*uest and sample mode are useful .here program guides the user/
E0ent .!/e5
1ost systems ha+e more than one input de+ice' each of .hich can -e triggered at an
ar-itrary time -y a user
0ach trigger generates an event .hose measure is put in an event queue .hich can -e
e&amined -y the user program
1. 4rite a pr!&ra$ t! /ra a r!tatin& #J%are. (De"*+11, 1.
Ans:
Dept of CS0' C0C ,age ;1
Computer Graphics and Visualization 10CS65
)he points &Ncos \' yNsin \ al.ays lies on a unit circle regardless of the +alue of \/
!n order to increase \ -y a fi&ed amount .hene+er nothing is happening' .e use the idle
function
Void idle%(
O
thetaT N;L
!f %theta IN>60/0( theta ? N >60/0L
glut,ost8edisplay%(L
P
!n order to turn the rotation feature on and off' .e can include a mouse function as
follo.s :
Void mouse%int -utton' int state' int &' int y(
O
if %-utton NN G4#)Q409)Q<#))@ "" state NN
G4#)QDC@( glut!dle9unc%idle(L
if %-utton NN G4#)Q1!DD40Q<#))@ "" state NN
G4#)QDC@( glut!dle9unc%@#44(L
P
@. S%pp!#e t'at t'e !pen:L in/! i# 6++ ; 6+ pixel# an/ t'e "lippin& in/! i# a
%nit #J%are it' t'e !ri&in at t'e l!er left "!rner. U#e #i$ple ;OR $!/e t! /ra
era#a7le line#. ()%l*+11, 1+.
An#5
+oid 1ouse1o+e%int &'int y(
O
if%94AG NN 0(O
B N &L
R N .inh ? yL
Bn N &L
Rn N .inh ? yL
94AG N 1L
P
Dept of CS0' C0C ,age ;;
Computer Graphics and Visualization 10CS65
else if%94AG NN 1(
O gl0na-le%G4QC48Q4G!CQ
,(L gl4ogicp%G4QB8(L
gl<egin%G4Q4!@0S(L
glVerte&;i%B'R(L
glVerte&;i%Bn'Rn(L
gl0nd%(L
gl9lush%(LHMld line erasedMH
gl<egin%G4Q4!@0S(L
glVerte&;i%B'R(L
glVerte&;i%&' .inh ? y(L
gl0nd%(L
gl9lush%(L
Bn N &L
Rn N .inh ? yL
P
P
>. 4'at i# t'e f%n"ti!nality !f /i#play li#t# in $!/elin&= Explain it' an exa$ple.
()%l*+11, 6.
An# 5 Display lists help in a+oiding redundant code -y storing the compiled code in a -uffer
and then re e&ecuting it again and again/
K!r e&5)he most efficient .ay of defining te&t is to define the font once' using a display list for
each char' and then store the font on the ser+er using these display lists
A function to dra. ASC!! characters
+oid ur9ont%char c(
O
s.itch%c(
O
case ]Y :
gl)ranslatef%0/5'0/5'0/0(L HM mo+e to the center MH
gl<egin%G4QZ#ADQS)8!,(
for %iN0LiG1;LiTT( HM 1; +ertices MH
O
angle N >/1A15WH6/0 M iL HM >0 degrees in radians MH
Dept of CS0' C0C ,age ;>
Computer Graphics and Visualization 10CS65
glVerte&;f%0/A M cos%angle(T0/5' 0/A M sin%angle(T0/5(
glVerte&;f%0/5 M cos%angle(T0/5' 0/5 M sin%angle(T0/5(
P
gl0nd%(L
-rea2L
P
P
B. Explain Pi"8in& !perati!n in !pen:L it' an exa$ple. ()%l*+11, 6.
An# 5 !dentify a user?defined o-$ect on the display
!n principle' it should -e simple -ecause the mouse gi+es the position and .e should -e
a-le to determine to .hich o-$ect%s( a position corresponds
,ractical difficulties
,ipeline architecture is feed for.ard' hard to go from screen -ac2 to
.orld Complicated -y screen -eing ;D' .orld is >D
:o. close do .e ha+e to come to o-$ect to say .e selected
it[ +oid mouse %int -utton' int state' int &' int y(
O
G4#int name<ufferJS!^0KL
G4int hitsL
G4int +ie.portJAKL
if %-utton NN G4#)Q409)Q<#))@ "" stateNN G4#)QDC@(
O
HM initialize the name stac2 MH
gl!nit@ames%(L
gl,ush@ame%0(L
glSelect<uffer%S!^0' name<uffer(l
HM set up +ie.ing for selection mode MH
glGet!nteger+%G4QV!0C,8)' +ie.port(L HHgets the current +ie.port
gl1atri&1ode%G4Q,850C)!@(L
HM sa+e original +ie.ing matri&
MH gl,ush1atri&%(L
gl4oad!dentity%(L
HM @ B @ pic2 area around cursor MH
glu,ic21atri&% %G4dou-le( &'%G4dou-le(%+ie.portJ>K?y('@'@'+ie.port(L
Dept of CS0' C0C ,age ;A
Computer Graphics and Visualization 10CS65
HM same clipping .indo. as in reshape call-ac2
MH glurtho;D%&min'&ma&'ymin'yma&(L
dra.Qo-$ects%G4QS040C)(L
gl1atri&1ode%G4Q,850C)!@(L
HM restore +ie.ing matri&
MH gl,op1atri&%(L
gl9lush%(L
HM return -ac2 to normal render mode MH
hits N gl8ender1ode%G4Q80@D08(L
HM process hits from selection mode renderingMH
process:its%hits' name<uff(L
HM normal render MH
glut,ost8edisplay%(L
P
P
+oid dra.Qo-$ects%G4enum mode(
O
if %mode NN G4QS040C)(
gl4oad@ame%1(L
glColor>f%1/0'0/0'0/0(
gl8ectf%?0/5'?0/5'1/0'1/0(L
if %mode NN G4QS040C)(
gl4oad@ame%;(L
glColor>f%0/0'0/0'1/0(
gl8ectf%?1/0'?1/0'0/5'0/5(L
P
+oid process:its%G4int hits' G4#int -ufferJK(
O
unsigned int i'$L
P
Dept of CS0' C0C ,age ;5
Computer Graphics and Visualization 10CS65
UNIT L -
:EO.ETRIC OB)ECTS AND TRANSKOR.ATIONS-1
1. Explain t'e "!$plete pr!"e/%re !f "!n0ertin& a !rl/ !7Ae"t fra$e int! "a$era !r eye
fra$e3 %#in& t'e $!/el 0ie $atrix. ()%n*+1*, 1+.
An#5 4!rl/ Spa"e
-$ect space for a particular o-$ect gi+es it no spatial relationship .ith respect to other o-$ects/
)he purpose of world space is to pro+ide some a-solute reference for all the o-$ects in your
scene/ :o. a .orld?space coordinate system is esta-lished is ar-itrary/ 9or e&ample' you may
decide that the origin of .orld space is the center of your room/ -$ects in the room are then
positioned relati+e to the center of the room and some notion of scale %!s a unit of distance a foot
or a meter[( and some notion of orientation %Does the positi+e y?a&is point FupF[ !s north in the
direction of the positi+e x?a&is[(/
T'e .!/elin& Tran#f!r$
)he .ay an o-$ect' specified in o-$ect space' is positioned .ithin .orld space is -y means of a
modeling transform/ 9or e&ample' you may need to rotate' translate' and scale the >D model of a
chair so that the chair is placed properly .ithin your room_s .orld?space coordinate system/ ).o
chairs in the same room may use the same >D chair model -ut ha+e different modeling
transforms' so that each chair e&ists at a distinct location in the room/
Rou can mathematically represent all the transforms in this chapter as a A&A matri&/ #sing the
properties of matrices' you can com-ine se+eral translations' rotations' scales' and pro$ections
into a single A&A matri& -y multiplying them together/ Chen you concatenate matrices in this
.ay' the com-ined matri& also represents the com-ination of the respecti+e transforms/ )his
turns out to -e +ery po.erful' as you .ill see/
!f you multiply the A&A matri& representing the modeling transform -y the o-$ect?space position
in homogeneous form %assuming a 1 for the w component if there is no e&plicit w component('
the result is the same position transformed into .orld space/ )his same matri& math principle
applies to all su-se*uent transforms discussed in this chapter/
Eye Spa"e
#ltimately' you .ant to loo2 at your scene from a particular +ie.point %the FeyeF(/ !n the
coordinate system 2no.n as eye space%or view space(' the eye is located at the origin of the
coordinate system/ 9ollo.ing the standard con+ention' you orient the scene so the eye is loo2ing
do.n one direction of the z?a&is/ )he FupF direction is typically the positi+e y direction/
Dept of CS0' C0C ,age ;6
Computer Graphics and Visualization 10CS65
0ye space' .hich is particularly useful for lighting' .ill -e discussed in Chapter 5/
T'e Vie Tran#f!r$
)he transform that con+erts .orld?space positions to eye?space positions is the view transform/
nce again' you e&press the +ie. transform .ith a A&A matri&/
)he typical +ie. transform com-ines a translation that mo+es the eye position in .orld space to
the origin of eye space and then rotates the eye appropriately/ <y doing this' the +ie. transform
defines the position and orientation of the +ie.point/
T'e .!/el0ie .atrix
1ost lighting and other shading computations in+ol+e *uantities such as positions and surface
normals/ !n general' these computations tend to -e more efficient .hen performed in either eye
space or o-$ect space/ Corld space is useful in your application for esta-lishing the o+erall
spatial relationships -et.een o-$ects in a scene' -ut it is not particularly efficient for lighting and
other shading computations/
9or this reason' .e typically com-ine the t.o matrices that represent the modeling and +ie.
transforms into a single matri& 2no.n as the modelview matrix/ Rou can com-ine the t.o
matrices -y simply multiplying the +ie. matri& -y the modeling matri&/
*. 4it' re#pe"t t! $!/elin& /i#"%## 0ertex array#. ()%n*+1*, 6.
An# 5
i( Verte& arrays pro+ide a method for encapsulating the information in data structure such that
.e can dra. polyhedral o-$ects .ith only fe. function calls/
)here are three steps in using +erte& arrays
%i( 0na-le the functionality of +erte& arrays
%ii( )ell openG4' location " format of the
array/ %iii( 8ender the o-$ect/
)he first t.o steps are called initialization part and the third step is called display call-ac2/
penG4 allo.s many different types of arraysL here .e are using t.o such arrays called color
and +erte& arrays/ )he arrays can -e ena-led as follo.s/
gl0na-leClientstate %G4QC48QA88AR(
gl0na-leClientstate %G4QV08)0BQA88AR(/
)he arrays are same as -efore/ @e&t' .e identify .here the arrays are as
follo.s/ glVerte&,ointer %>'G4Q94A)' 0' Vertices(L
glColor,ointer %>'G4Q94A)' 0' C48(L
2. Explain $!/elin& a "!l!r "%7e in /etail. (De"*+11, 1+.
Dept of CS0' C0C ,age ;S
Computer Graphics and Visualization 10CS65
An#5 Ce can use the +erte& list to define a color cu-e/ Ce can define a function *uad to dra.
*uadrilaterals polygons specified -y pointers into the +erte& list/ )he color cu-e specifies the si&
faces' ta2ing care to ma2e them all out.ard facing as follo.s/
G4floatVertices J=K J>K N OO?1/0' ?1/0' ?1/0P' O1/0' ?1/0' ?1/0P' O1/0' 1/0' ?1/0P' O?1/0' 1/0' ?1/0P O?
1/0' ?1/0' 1/0P' O1/0' ?1/0' 1/0P' O1/0' 1/0' 1/0P' O?1/0' 1/0' 1/0PP
G4float color J=K J>K N OO0/0' 0/0' 0/0P' O1/0' 0/0' 0/0P' O1/0' 1/0' 0/0P' O0/0' 1/0' 0/0P' O0/0' 0/0'
1/0P' O1/0' 0/0' 1/0P' O1/0' 1/0' 1/0P' O0/0' 1/0' 1/0PPL
+oid *uad %int a' int -' int c' int d(
O
gl<egin %G4QZ#ADS(L
glcolor>f+ %colorsJaK(L
glVerte&>f+%+erticesJaK(L
glcolor>f+%colorsJ-K(L
glVerte&>f+%+erticesJ-K(L
glcolor>f+%colorsJcK(L
glVerte&>f+ %+erticesJcK(L
glcolor>f+ %colorsJdK(L
glVerte&>f+%+erticesJdK(L
gl0nd%(L
P
Void colorcu-e %(
O *uad %0'>';'1(L *uad
%;'>'S'6(L *uad
%0' A'S'>(L *uad
%1' ;' 6' 5(L *uad
%A' 5' 6' S(L *uad
%0' 1' 5' A(L
-. Explain affine tran#f!r$ati!n#. (De"*+11, 1+.
An#5 An affine transformation is an important class of linear ;?D geometric transformations
.hich
maps +aria-les %e.g. pi&el intensity +alues located at position in an input image( into ne.
+aria-les %e.g. in an output image( -y applying a linear com-ination of translation'
rotation' scaling andHor shearing %i.e. non?uniform scaling in some directions( operations/
Dept of CS0' C0C ,age ;=
Computer Graphics and Visualization 10CS65
)he general affine transformation is commonly .ritten in homogeneous coordinates as sho.n
-elo.:
<y defining only the B matri&' this transformation can carry out pure translation:
,ure rotation uses the A matri& and is defined as %for positi+e angles -eing cloc2.ise rotations(:
:ere' .e are .or2ing in image coordinates' so the y a&is goes do.n.ard/ 8otation formula can
-e defined for .hen the y a&is goes up.ard/
Similarly' pure scaling is:
%@ote that se+eral different affine transformations are often com-ined to produce a resultant
transformation/ )he order in .hich the transformations occur is significant since a translation
follo.ed -y a rotation is not necessarily e*ui+alent to the con+erse/(
Since the general affine transformation is defined -y 6 constants' it is possi-le to define this
transformation -y specifying the ne. output image locations of any three input image
coordinate pairs/ %!n practice' many more points are measured and a least s*uares method
is used to find the -est fitting transform/(
6. In a '!$!&en!%# "!!r/inate #y#te$ &i0en t! fra$e# (0
13
0
*
3 0
2
3 P
+
, an/ (%
13
%
*
3 %
2
3 Q
+
,.
Let a an/ 7 7e t! 0e"t!r# /efine/ in t! fra$e# re#pe"ti0ely. Deri0e t'e expre##i!n
t'at repre#ent# 0e"t!r 7 inter$# !f a. ()%ly*+11, 1+.
An#5 @eed to 2no.
Dept of CS0' C0C ,age ;W
Computer Graphics and Visualization 10CS65
)he origin %or displacement +ector(
)he -asis +ectors ? )he direction and distance for T1 mo+ement along each a&is
)his definition is relati+e
)o plot a point
<egin at origin
)ra+el along the & -asis +ector JdirectionK scaled -y & coord' then along
the y -asis +ector scaled -y the y coord' then finally along the z -asis
+ector scaled -y the z coord/
Dept of CS0' C0C ,age >0
Computer Graphics and Visualization 10CS65
UNIT L 6
:EO.ETRIC OB)ECTS AND TRANSKOR.ATIONS-II
1. Define an/ repre#ent t'e f!ll!in& *-D tran#f!r$ati!n# in '!$!&en!%# "!!r/inate
#y#te$.
a. Tran#lati!n
7. R!tati!n
". S"alin&
/. Refle"ti!n ()%n*+1*, 1*.
Ans: Tran#lati!n
+oid gl)ranslateOfdP %)R,0 &' )R,0 y' )R,0 z(L
1ultiplies the current matri& -y a matri& that mo+es %translates( an o-$ect -y the gi+en
&' y' and z +alues
R!tati!n
+oid gl8otateOfdP%)R,0 angle' )R,0 &' )R,0 y' )R,0 z(L
1ultiplies the current matri& -y a matri& that rotates an o-$ect in a
countercloc2.ise direction a-out the ray from the origin through the point %&' y' z(/
)he angle parameter specifies the angle of rotation in degrees/
S"alin&
+oid glScaleOfdP %)R,0&' )R,0 y' )R,0z(L
1ultiplies the current matri& -y a matri& that stretches' shrin2s' or reflects an o-$ect along
the a&es/
Dept of CS0' C0C ,age >1
Computer Graphics and Visualization 10CS65
0*uations :
)ranslation: ,f N ) T ,
&
f
N &
o
T d&
y
f
N y
o
T dy
8otation: ,f N 8 ` ,
&
f
N &
o
M cos ? y
o
Msin
y
f
N &
o
M sin T y
o
Mcos

Scale: ,f N S ` ,
&
f
N s& M &
o
y
f
N sy M y
o
*. 4'at i# "!n"atenati!n tran#f!r$ati!n= Explain r!tati!n a7!%t a fixe/ p!int. ()%n*+1*,
>.
Ans: 8otate a house a-out the origin
8otate the house a-out one of its corners
translate so that a corner of the house is at the origin
rotate the house a-out the origin
translate so that the corner returns to its original position
Dept of CS0' C0C ,age >;
Computer Graphics and Visualization 10CS65
2. 4'at are J%aterni!n#= 4it' an exa$ple3 explain it# $at'e$ati"al repre#entati!n#.
(De"*+11, 1+.
Ans: A *uaternion is an element of a A dimensional +ector?space/ !t_s defined as . T &i T y$ T
z2 .here i' $ and 2 are imaginary num-ers/ Alternati+ely' a *uaternion is .hat you get .hen
you add a scalar and a >d +ector/ )he math -ehind *uaternions is only slightly harder than the
math -ehind +ectors/
void Camera::movex(float xmmod)
{
pos += rotation * Vector3(xmmod, 0.0f, 0.0f);

void Camera::move!(float !mmod)


{
pos.! "= !mmod;

void Camera::move#(float #mmod)


{
pos += rotation * Vector3(0.0f, 0.0f, "#mmod);

void Camera::rotatex(float xrmod)


{
$%aternion nrot(Vector3(&.0f, 0.0f, 0.0f), xrmod * '()V*+&,0);
rotation = rotation * nrot;

void Camera::rotate!(float !rmod)


{
$%aternion nrot(Vector3(0.0f, &.0f, 0.0f), !rmod * '()V*+&,0);
rotation = nrot * rotation;

void Camera::tic-(float seconds)


{
if (xrot .= 0.0f) rotatex(xrot * seconds * rotspeed);
if (!rot .= 0.0f) rotate!(!rot * seconds * rotspeed);
if (xmov .= 0.0f) movex(xmov * seconds * movespeed);
if (!mov .= 0.0f) move!(!mov * seconds * movespeed);
if (#mov .= 0.0f) move#(#mov * seconds * movespeed);

Dept of CS0' C0C ,age >>


Computer Graphics and Visualization 10CS65
-. Explain t'e 7a#i" tran#f!r$ati!n# in 2D an/ repre#ent t'e$ in $atrix f!r$. ()%n*+1+,
1+.
Ans: )ranslation:
Scaling:
8otation:
6. 4'at are t'e a/0anta&e# !f J%aterni!n= ()%n*+1+, *.
Ans: Zuaternions ha+e some ad+antages o+er other representations of rotations/
Zuaternions don_t suffer from gim-al loc2' unli2e 0uler angles/
)hey can -e represented as A num-ers' in contrast to the W num-ers of a rotations matri&/
)he con+ersion to and from a&isHangle representation is tri+ial/
Smooth interpolation -et.een t.o *uaternions is easy %in contrast to a&isHangle or
rotation matrices(/
After a lot of calculations on *uaternions and matrices' rounding errors accumulate' so
you ha+e to normalize *uaternions and orthogonalize a rotation matri&' -ut normalizing a
*uaternion is a lot less trou-lesome than orthogonalizing a matri&/
Similar to rotation matrices' you can $ust multiply ; *uaternions together to recei+e a
*uaternion that represents -oth rotations/
Dept of CS0' C0C ,age >A
Computer Graphics and Visualization 10CS65
UNIT -1
VIE4IN:
1. 4it' neat #8et"'e#3 explain t'e 0ari!%# type# !f 0ie# t'at are e$pl!ye/ in "!$p%ter
&rap'i"# #y#te$#. ()%n*+1*, 1+.
An#5
Per#pe"ti0e an/ parallel pr!Ae"ti!n# 5
,arallel +ie.ing is a limiting case of perspecti+e +ie.ing
,erspecti+e pro$ection has a C, .here all the pro$ector lines con+erge/
,arallel pro$ection has parallel pro$ectors/ :ere the +ie.er is assumed to -e present at
infinity/ So here .e ha+e a 6Direction of pro$ection %D,(7 instead of center of
pro$ection%C,(/
Dept of CS0' C0C ,age >5
Computer Graphics and Visualization 10CS65
Ort'!&rap'i" Pr!Ae"ti!n# 5
,ro$ectors are perpendicular to the pro$ection plane/ ,ro$ection
plane is 2ept parallel to one of the principal faces/
A +ie.er needs more than ; +ie.s to +isualize .hat an o-$ect loo2s li2e from its
multi+ie. orthographic pro$ection/
*. Briefly /i#"%## t'e f!ll!in& al!n& it' t'e f%n"ti!n# %#e/ f!r t'e p%rp!#e in !pen :L
i, Per#pe"ti0e pr!Ae"ti!n#
ii, Ort'!&!nal pr!Ae"ti!n# ()%n*+1*, 1+.
An#5 i, ,erspecti+e pro$ection has a C, .here all the pro$ector lines con+erge/
T'e f!ll!in& f%n"ti!n# 'a0e t! 7e %#e/ t! "reate per#pe"ti0e pr!Ae"ti!n#5
Dept of CS0' C0C ,age >6
Computer Graphics and Visualization 10CS65
gl1atri&1ode%G4Q,850C)!@(L
gl4oad!dentity%(L
glu,erspecti+e%f9V' fAspect ' f@ear,lane' f9ar,lane(L
Ort'!&!nal pr!Ae"ti!n#
,ro$ectors are perpendicular to the pro$ection plane/ ,ro$ection
plane is 2ept parallel to one of the principal faces/
A +ie.er needs more than ; +ie.s to +isualize .hat an o-$ect loo2s li2e from its multi+ie.
orthographic pro$ection/
+oid glrtho% G4dou-le left'
G4dou-le right'
G4dou-le -ottom'
G4dou-le top'
G4dou-le nearVal'
G4dou-le farVal(L
,arameters
left' right
Specify the coordinates for the left and right +ertical clipping planes/
-ottom' top
Specify the coordinates for the -ottom and top horizontal clipping planes/
nearVal' farVal
Specify the distances to the nearer and farther depth clipping planes/
)hese +alues are negati+e if the plane is to -e -ehind the +ie.er/
2. Explain t'e 0ari!%# type# !f ax!n!$etri" pr!Ae"ti!n#. (De"*+11, @.
Dept of CS0' C0C ,age >S
Computer Graphics and Visualization 10CS65
An#5 ,ro$ectors are orthogonal to the pro$ection plane ' -ut pro$ection plane can mo+e relati+e to
o-$ect/
Classification -y ho. many angles of a corner of a pro$ected cu-e are the same
none: trimetric
t.o: dimetric
three: isometric
-. 4'at i# "an!ni"al 0ie 0!l%$e= Explain t'e $appin& !f a &i0en 0ie 0!l%$e t! t'e
"an!ni"al f!r$. (De"*+11, @.
An#5 )he diagram sho.s the normalization process
9irst the +ie. +olume specified -y the glortho function is mapped to the canonical form
Canonical 9orm : default +ie. +olume centerd at the origin and ha+ing sides of length ;/
)his in+ol+es ; steps :
3 1o+e center to origin
)%?%leftTright(H;' ?%-ottomTtop(H;'%nearTfar(H;((
3 Scale to ha+e sides of length ;
S%;H%left?right(';H%top?-ottom(';H%near?far((
)he resultant matri& is a product of the a-o+e ; matrices i/e/ , N S) N
;
0 0
right left
right left right left
0
;
0
top ottom
top ottom top ottom
0 0
; far near
near far far near
0 0 0 1
Dept of CS0' C0C ,age >=
Computer Graphics and Visualization 10CS65
6. Deri0e eJ%ati!n# f!r per#pe"ti0e pr!Ae"ti!n an/ /e#"ri7e t'e #pe"ifi"ati!n# !f a
per#pe"ti0e "a$era 0ie in !pen :L. ()%n*+11, >.
An#.5 )he ne. coordinate system is specified -y a translation and
rotation .ith respect to the old coordinate system:
+aN 8 %+ ? +0( +0 is displacement
+ector 8 is rotation matri&
8 may -e decomposed into
> rotations a-out the
coordinate a&es:
By $%ltiplyin& t'e 2 $atri"e# Rx3 Ry an/ R?3 !ne &et#
K!r f!r$%la $anip%lati!n#3 !ne trie# t! a0!i/ t'e tri&!n!$etri" f%n"ti!n#
an/ ta8e#
@ote that the coefficients of 8 are constrained:
A rotation matri& is orthonormal: 8 8) N ! %unit matri&(
Dept of CS0' C0C ,age >W
Computer Graphics and Visualization 10CS65
UNIT L @
LI:9TIN: AND S9ADIN:
1. Explain p'!n& li&'tin& $!/el. In/i"ate t'e a/0anta&e# an/ /i#a/0anta&e#. ()%n*+1*,
1+.
An#5 ,hong de+eloped a simple model that can -e computed rapidly
!t considers three components
3 Diffuse
3 Specular
3 Am-ient
And #ses four +ectors
3 )o source represented -y the +ector l
3 )o +ie.er represented -y the +ector +
3 @ormal represented -y the +ector n
3 ,erfect reflector represented -y the +ector r
Ce need W coefficients to characterize the light source .ith am-ient' diffuse and specular
components/)he !llumination array for the i
th
light source is gi+en -y the matri&:
4ira 4iga 4i-a
4i N 4ird 4igd 4i-d
4irs 4igs 4i-s
)he intensity for each color source can -e computed -y adding the am-ient'specular and diffuse
components/

0/g/ 8ed intensity that .e see from source !:


!ir N 8ira4ira T 8ird4irdT 8irs4irs N !raT!rdT!rs
Since the necessary computations are same for each light
source' ! N !
a
T!
d
T!
s
*. 4'at are t'e /ifferent $et'!/# a0aila7le f!r #'a/in& a p!ly&!n= Briefly /i#"%## any *
!f t'e$. ()%n*+1*, 1+.
An#5 P!ly&!nal S'a/in&
Dept of CS0' C0C ,age A0
Computer Graphics and Visualization 10CS65
Klat #'a/in&
!n case of flat shading there are distinct -oundaries after color interpolation
> +ectors needed for shading are: l'n'+ /)he openG4 function to ena-le flat shading is :
glShade1odel%G4Q94A)(
9or a flat polygon'n is constant as the normal n is same at all points on the polygon/Also if .e
assume a distant +ie.er' the +ector 0 is constant and if .e consider a distant light source then the
+ector l is also a constant/:ere all the > +ectors are constant and therefore the shading
calculations needs to -e done only once for an entire polygon and each point on the polygon is
assigned the same shade/ )his techni*ue is 2no.n as 9lat shading/
Disad+antage : <ut if .e consider light sources and the +ie.er near the polygon' then flat
shading .ill sho. differences in shading and the human eye is +ery sensiti+e to slightest of such
differences due to the principle of 64ateral !nhi-ition7
S$!!t' an/ :!%ra%/ S'a/in&
Gouraud shading' also called intensity interpolation' pro+ides a .ay to display smooth?shaded
polygons -y defining the 8G< color components of each polygon +erte&/ !t operates -y first
interpolating the 8G< +alues -et.een the +ertical +ertices along each edge/ )his gi+es us the
8G< components for the left and right edges of each scan line %pi&el ro.(/ Ce then display each
ro. of pi&els -y horizontally interpolating the 8G< +alues -et.een that ro._s left and right
edges/ )his produces a remar2a-ly smooth?shaded polygon/ 9astgraph supports Gouraud shading
for direct color +irtual -uffers' -ut not for ;56?color +irtual -uffers/
2. 4rite a pr!&ra$ #e&$ent %#in& #tr%"t%re# t! repre#ent $e#'e# !f J%a/rilateral an/
#'a/e t'e$. (De"*+11, @.
An#5 Einclude Gstdli-/hI
Einclude GG4Hglut/hI
Edefine ma&& ;0
Edefine ma&y ;5
Edefine d& 15
Edefine dy 10
G4float &Jma&&KNO0/0P'yJma&yKNO0/0PL
G4float &0N50'y0N50L HH initial +alues for &' y
G4int i'$L
+oid init%(
Dept of CS0' C0C ,age A1
Computer Graphics and Visualization 10CS65
O
glClearColor%1/0'1/0'1/0'1/0(L
glColor>f%1/0'0/0'0/0(L
gl,ointSize%5/0(L
gl1atri&1ode%G4Q,850C)!@(L
gl4oad!dentity%(L
glurtho;D%0/0'AWW/0'0/0'AWW/0(L
glut,ost8edisplay%(L HH re*uest redisplay
P
+oid display%+oid(
O
HM clear .indo. MH
glClear%G4QC48Q<#9908Q<!)(L
glColor>f%0/0' 0/0' 1/0(L HH set color to -lue
HM dra. rectangles MH
for%iN0LiGma&&LiTT(
&JiKN&0TiMd&L HH compute &JiK
for%$N0L$Gma&yL$TT(
yJ$KNy0T$MdyL HH compute yJiK
glColor>f%0/0' 0/0' 1/0(L
for%iN0LiGma&&?1LiTT(
for%$N0L$Gma&y?1L$TT(
O
glColor>f%0/0' 0/0' 1/0(L
gl<egin%G4Q4!@0Q4,(
L
glVerte&;f%&JiK'yJ$K(L
glVerte&;f%&JiK'yJ$T1K(L
glVerte&;f%&JiT1K'yJ$T1K(L
glVerte&;f%&JiT1K'yJ$K(L
gl0nd%(L
gl9lush%(L
P
gl9lush%(L
P
+oid main%int argc' charMM arg+(
O
glut!nit%"argc' arg+(L HH penG4 initializations
Dept of CS0' C0C ,age A;
Computer Graphics and Visualization 10CS65
glut!nitDisplay1ode%G4#)QS!@G40 U G4#)Q8G<
glut!nitCindo.Size%500' A00(L HH create a 500&A00 .indo.
glut!nitCindo.,osition%0' 0(L HH ///in the upper left
glutCreateCindo.%F8ectangular 1eshF(L HH create the .indo.
glutDisplay9unc%display(L HH setup call-ac2s
init%(L
glut1ain4oop%(L HH start it running
P
-. De#"ri7e any t! type# !f li&'t #!%r"e#. ()%l*+11, -.
An#5 General light sources are difficult to .or2 .ith -ecause .e must integrate light coming
from all points on the source.
,oint source
1odel .ith position and color
Distant source N infinite distance a.ay %parallel(
Spotlight
8estrict light from ideal point source
Am-ient light
Same amount of light e+ery.here in scene
Can model contri-ution of many sources and reflecting surfaces
6. 9! i# appr!xi$ati!n !f a #p'ere /!ne 7y re"%r#i0e #%7/i0i#i!n= (De"*+11,
1+. An#5
Dept of CS0' C0C ,age A>
Computer Graphics and Visualization 10CS65
/* +ec%rsive s%0division of tetra1edron (C1apter 2). 31ree
displa! modes: 4ire frame, constant, and interpolative s1adin5 */
/*'ro5ram also ill%strates definin5 materials and li51t
so%rces in m!iit() */
/* mode 0 = 4ire frame, mode & = constant
s1adin5, mode 6 = interpolative s1adin5 */
/* 7pdated )cto0er &2, 6000, 0! Car! 8axer to convert (/) to C++. */
9incl%de :stdli0.1;
9incl%de :mat1.1;
9incl%de :iostream;
9incl%de :<8/5l%t.1;
t!pedef do%0le point=3>;
/* initial tetra1edron */
point v=>={{0.0, 0.0, &.0, {0.0, 0.?@6,0?, "0.33333,
{"0.,&2@?A, "0.@A&@0B, "0.333333, {0.,&2@?A, "0.@A&@0B,
" 0.333333;
static <8float t1eta=> = {0.0,0.0,0.0;
int n;
int mode;
void trian5le (point a, point 0, point
c); void normal (point p);
void divideCtrian5le (point a, point 0, point c, int
m); void tetra1edron (int m);
void displa! (void);
void m!+es1ape (int 4, int
1); void m!init ();
%sin5 namespace std;
void main(int ar5c, c1ar **ar5v)
{
co%t :: D*nter n%m0er of levels of rec%rsion:
D; cin ;; n;
5l%t(nit (Ear5c, ar5v);
5l%t(nitFispla!Gode (<873CF)7H8* I <873C+<H I
<873CF*'3J); 5l%t(nitKindo4Li#e (B00, B00);
5l%t(nitKindo4'osition (&00,
&00); 5l%tCreateKindo4
(DLp1ereD); m!init ();
5l%t+es1apeM%nc (m!+es1ape);
5l%tFispla!M%nc (displa!);
5l%tGain8oop ();

void trian5le (point a, point 0, point c)


/* displa! one trian5le %sin5 a line loop for 4ire frame, a sin5le
normal for constant s1adin5, or t1ree normals for interpolative s1adin5 */
Dept of CS0' C0C ,age AA
Computer Graphics and Visualization 10CS65
{
if (mode==0) 5lHe5in(<8C8(N*C8))');
else 5lHe5in(<8C')8O<)N);
if(mode==& II mode==6)
5lNormal3dv(a); 5lVertex3dv(a);
if(mode==6) 5lNormal3dv(0);
5lVertex3dv(0); if(mode==6)
5lNormal3dv(c);
5lVertex3dv(c);
5l*nd();

void normal (point p) /*


normali#e a vector */
{
do%0le d
=0.0; int i;
for(i=0; i:3; i++)
d+=p=i>*p=i>; d=sPrt(d);
if(d;0.0) for(i=0; i:3; i++) p=i>/=d;

void divideCtrian5le (point a, point 0, point c, int


m) /* trian5le s%0division %sin5 vertex n%m0ers
ri51t1and r%le applied to create o%t4ard pointin5 faces */
{
point v&, v6,
v3; int Q;
if(m;0)
{
for(Q=0; Q:3; Q++) v&=Q>=a=Q>
+0=Q>; normal(v&);
for(Q=0; Q:3; Q++) v6=Q>=a=Q>
+c=Q>; normal(v6);
for(Q=0; Q:3; Q++) v3=Q>=0=Q>
+c=Q>; normal(v3);
divideCtrian5le (a, v&, v6, m"&);
divideCtrian5le (c, v6, v3, m"&);
divideCtrian5le (0, v3, v&, m"&);
divideCtrian5le (v&, v3, v6, m"&);

else
trian5le (a,0,c); /* dra4 trian5le at end of rec%rsion */

void tetra1edron (int m)


/* Rppl! trian5le s%0division to faces of tetra1edron */
{
divideCtrian5le (v=0>, v=&>, v=6>, m);
divideCtrian5le (v=3>, v=6>, v=&>, m);
divideCtrian5le (v=0>, v=3>, v=&>, m);
divideCtrian5le (v=0>, v=6>, v=3>, m);

void displa! (void)


/* Fispla!s all t1ree modes, side 0! side */
{
Dept of CS0' C0C ,age A5
Computer Graphics and Visualization 10CS65
5lClear (<8CC)8)+CH7MM*+CH(3 I
<8CF*'3JCH7MM*+CH(3); 5l8oad(dentit! ();
mode=0;
tetra1edron
(n); mode=&;
5l3ranslated ("6.0, 0.0,
0.0); tetra1edron (n);
mode=6;
5l3ranslated (@.0, 0.0,
0.0); tetra1edron (n);
5l%tL4apH%ffers ();

void m!+es1ape (int 4, int 1)


{
5lVie4port (0, 0, 4, 1);
5lGatrixGode (<8C'+)S*C3()N);
5l8oad(dentit! ();
if (4 := 1)
5l)rt1o ("@.0, @.0, "@.0 * (<8float) 1 / (<8float) 4,
@.0 * (<8float) 1 / (<8float) 4, "&0.0, &0.0);
else
5l)rt1o ("@.0 * (<8float) 4 / (<8float) 1,
@.0 * (<8float) 4 / (<8float) 1, "@.0, @.0, "&0.0,
&0.0); 5lGatrixGode (<8CG)F*8V(*K);
5l%t'ost+edispla! ();

void m!init ()
{
<8float matCspec%lar=>={0.B, 0.0, 0.0,
&.0; <8float matCdiff%se=>={&.0, 0.0, 0.0,
&.0; <8float matCam0ient=>={&.0, 0.0, 0.0,
&.0; <8float matCs1ininess={&00.0;
<8float li51tCam0ient=>={0.0, 0.0, 0.0, &.0;
<8float li51tCdiff%se=>={&.0, &.0, &.0, &.0;
<8float li51tCspec%lar=>={&.0, &.0, &.0, &.0;
/* set %p am0ient, diff%se, and spec%lar components for li51t 0 */
5l8i51tfv (<8C8(<J30, <8CRGH(*N3, li51tCam0ient);
5l8i51tfv (<8C8(<J30, <8CF(MM7L*, li51tCdiff%se);
5l8i51tfv (<8C8(<J30, <8CL'*C78R+, li51tCspec%lar);
/* define material proerties for front face of all pol!5ons */
5lGaterialfv (<8CM+)N3, <8CL'*C78R+, matCspec%lar);
5lGaterialfv (<8CM+)N3, <8CRGH(*N3, matCam0ient);
5lGaterialfv (<8CM+)N3, <8CF(MM7L*, matCdiff%se);
5lGaterialf (<8CM+)N3, <8CLJ(N(N*LL,
matCs1ininess); 5l*na0le (<8CLG))3J); /*ena0le
smoot1 s1adin5 */ 5l*na0le (<8C8(<J3(N<); /* ena0le
li51tin5 */ 5l*na0le (<8C8(<J30); /* ena0le li51t 0
*/ 5l*na0le (<8CF*'3JC3*L3); /* ena0le # 0%ffer */
5lClearColor (&.0, &.0, &.0, &.0);
5lColor3f (0.0, 0.0, 0.0);

Dept of CS0' C0C ,age A6


Computer Graphics and Visualization 10CS65
UNIT ->
I.PLE.ENTATION
1. Di#"%## t'e Bre#en'a$M# ra#teri?ati!n al&!rit'$. 9! i# it a/0anta&e!%# 'en
"!$pare/ t! !t'er exi#tin& $et'!/#= De#"ri7e. ()%n*+1*, 1+.
An#5 Consider dra.ing a line on a raster grid .here .e restrict the allo.a-le slopes of the line to
the range /
!f .e further restrict the line?dra.ing routine so that it al.ays increments x as it plots' it -ecomes
clear that' ha+ing plotted a point at !x"y#' the routine has a se+erely limited range of options as to
.here it may put the next point on the line:
!t may plot the point !x$%"y#' or:
!t may plot the point !x$%"y$%#/
So' .or2ing in the first positive octant of the plane' line dra.ing -ecomes a matter of deciding
-et.een t.o possi-ilities at each step/
Ce can dra. a diagram of the situation .hich the plotting program finds itself in ha+ing plotted
!x"y#/
!n plotting !x"y# the line dra.ing routine .ill' in general' -e ma2ing a compromise -et.een .hat it
.ould li2e to dra. and .hat the resolution of the screen actually allo.s it to dra./ #sually the
plotted point !x"y# .ill -e in error' the actual' mathematical point on the line .ill not -e addressa-le
on the pi&el grid/ So .e associate an error' ' .ith each y ordinate' the real +alue of
y should -e / )his error .ill range from ?0/5 to $ust under T0/5/
Dept of CS0' C0C ,age AS
Computer Graphics and Visualization 10CS65
!n mo+ing from x to x$% .e increase the +alue of the true %mathematical( y?ordinate -y an
amount e*ual to the slope of the line' m/ Ce .ill choose to plot !x$%"y# if the difference -et.een
this ne. +alue and y is less than 0/5/
ther.ise .e .ill plot !x$%"y$%#/ !t should -e clear that -y so doing .e minimise the total error
-et.een the mathematical line segment and .hat actually gets dra.n on the display/
)he error resulting from this ne. point can no. -e .ritten -ac2 into ' this .ill allo. us to
repeat the .hole process for the ne&t point along the line' at x$&/
)he ne. +alue of error can adopt one of t.o possi-le +alues' depending on .hat ne. point is
plotted/ !f !x$%"y# is chosen' the ne. +alue of error is gi+en -y:
ther.ise it is:
)his gi+es an algorithm for a DDA .hich a+oids rounding operations' instead using the error
+aria-le to control plotting:
)his still employs floating point +alues/ Consider' ho.e+er' .hat happens if .e multiply across
-oth sides of the plotting test -y and then -y ;:
Dept of CS0' C0C ,age A=
Computer Graphics and Visualization 10CS65
All *uantities in this ine*uality are no. integral/
Su-stitute for / )he test -ecomes:
)his gi+es an integer-only test for deciding .hich point to plot/
)he update rules for the error on each step may also -e cast into form/ Consider the floating?
point +ersions of the update rules:
1ultiplying through -y yields:
.hich is in form/
#sing this ne. bberror__ +alue' ' .ith the ne. test and update e*uations gi+es <resenham_s
integer?only line dra.ing algorithm:
Dept of CS0' C0C ,age AW
Computer Graphics and Visualization 10CS65
!nteger only ? hence efficient %fast(/
1ultiplication -y ; can -e implemented -y left?shift/
)his +ersion limited to slopes in the first octant' /
*. Explain t'e "!'en-#%t'erlan/ line "lippin& al&!rit'$ in /etail. ()%n*+1*, 1+.
An#5 <asic !dea
0ncode the line endpoints
Successi+ely di+ide the line segments so that they are completely contained in the
.indo. or completely lies outside the .indo.
Clipping happens as follo.s :
2. Deri0e t'e $at'e$ati"al f!r$%la f!r 7re#en'a$M# $i/ p!int line al&!rit'$. (De"*+11,
1+.
An#5 Consider dra.ing a line on a raster grid .here .e restrict the allo.a-le slopes of the line
to the range /
Dept of CS0' C0C ,age 50
Computer Graphics and Visualization 10CS65
!f .e further restrict the line?dra.ing routine so that it al.ays increments x as it plots' it -ecomes
clear that' ha+ing plotted a point at !x"y#' the routine has a se+erely limited range of options as to
.here it may put the next point on the line:
!t may plot the point !x$%"y#' or:
!t may plot the point !x$%"y$%#/
So' .or2ing in the first positive octant of the plane' line dra.ing -ecomes a matter of deciding
-et.een t.o possi-ilities at each step/
Ce can dra. a diagram of the situation .hich the plotting program finds itself in ha+ing plotted
!x"y#/
!n plotting !x"y# the line dra.ing routine .ill' in general' -e ma2ing a compromise -et.een .hat
it .ould li2e to dra. and .hat the resolution of the screen actually allo.s it to dra./ #sually the
plotted point !x"y# .ill -e in error' the actual' mathematical point on the line .ill not -e
addressa-le on the pi&el grid/ So .e associate an error' ' .ith each y ordinate' the real +alue of
y should -e / )his error .ill range from ?0/5 to $ust under T0/5/
!n mo+ing from x to x$% .e increase the +alue of the true %mathematical( y?ordinate -y an
amount e*ual to the slope of the line' m/ Ce .ill choose to plot !x$%"y# if the difference -et.een
this ne. +alue and y is less than 0/5/
ther.ise .e .ill plot !x$%"y$%#/ !t should -e clear that -y so doing .e minimise the total error
-et.een the mathematical line segment and .hat actually gets dra.n on the display/
)he error resulting from this ne. point can no. -e .ritten -ac2 into ' this .ill allo. us to
repeat the .hole process for the ne&t point along the line' at x$&/
Dept of CS0' C0C ,age 51
Computer Graphics and Visualization 10CS65
)he ne. +alue of error can adopt one of t.o possi-le +alues' depending on .hat ne. point is
plotted/ !f !x$%"y# is chosen' the ne. +alue of error is gi+en -y:
ther.ise it is:
)his gi+es an algorithm for a DDA .hich a+oids rounding operations' instead using the error
+aria-le to control plotting:
)his still employs floating point +alues/ Consider' ho.e+er' .hat happens if .e multiply across
-oth sides of the plotting test -y and then -y ;:
All *uantities in this ine*uality are no. integral/
Su-stitute for / )he test -ecomes:
)his gi+es an integer-only test for deciding .hich point to plot/
)he update rules for the error on each step may also -e cast into form/ Consider the floating?
point +ersions of the update rules:
Dept of CS0' C0C ,age 5;
Computer Graphics and Visualization 10CS65
1ultiplying through -y yields:
.hich is in form/
#sing this ne. bberror__ +alue' ' .ith the ne. test and update e*uations gi+es <resenham_s
integer?only line dra.ing algorithm:
!nteger only ? hence efficient %fast(/
1ultiplication -y ; can -e implemented -y left?shift/
)his +ersion limited to slopes in the first octant' /
-. 4'at /! y!% $ean 7y antialia#in&= Explain. ()%l*+11, -.
Ans: Rou might ha+e noticed in some of your penG4 pictures that lines' especially nearly
horizontal or nearly +ertical ones' appear $agged/ )hese $aggies appear -ecause the ideal line is
appro&imated -y a series of pi&els that must lie on the pi&el grid/ )he $aggedness is called
aliasing' and this section descri-es antialiasing techni*ues to reduce it/ 9igure 6?; sho.s t.o
Dept of CS0' C0C ,age 5>
Computer Graphics and Visualization 10CS65
intersecting lines' -oth aliased and antialiased/ )he pictures ha+e -een magnified to sho. the
effect/
6. Explain Lian& Bar#8y line "lippin& al&!rit'$ in /etail. ()%n*+1+, 1+.
Ans:
Dept of CS0' C0C ,age 5A
Computer Graphics and Visualization 10CS65
Dept of CSE, CEC Page 55

Potrebbero piacerti anche