15-462: Computer Graphics
Total Page:16
File Type:pdf, Size:1020Kb
!"#$%&'()*+,-./0(102,3456 72.3(8*0()*+,-./0(102,3456 ! #$%&'()*$+)#$,-. / 01'2$+( / 345-2&$6()*$+)'5+71()-6,)(5+*-'1( 8 9:%;&'&2)145-2&$6( 8 <-+-:12+&')145-2&$6( / =-+.'162+&')>$$+,&6-21( !" #$%&'(')*+,-.)'/01 2 !"#$%&%'()*+,'%-./ .3+*.*4.5*)/*6+7'0+* (-38+1*.06*1-37.(+19 2 #0*!:;*.*(-38+*(.0*<+*6+7'0+6*<5 0=1;2>*?*" 7/3*1/$+*1(.&.3*7-0()'/0*0 /7*1 .06*29 2 #0*@:;*.*1-37.(+*(.0*<+*6+7'0+6*<5 0=1;234>*?*" 7/3*1/$+*1(.&.3*7-0()'/0*0 /7*1;*2;*.06*49 !" #$%&'(')*+,-.)'/01 2 34+*5-0()'/0*! +6.&-.)+1*)/*7*.)*+6+89*%/'0)* /0*)4+*(-86+*/8*1-85.(+:*.0;*')*+6.&-.)+1*)/* .*0/0<=+8/*8+.&*0-$>+8*.)*.&&*/)4+8*%/'0)1? 2 @-&)'%&9'0A*! >9*.*0/0<=+8/*(/+55'('+0)* %8+1+86+1*)4'1*%8/%+8)9:*1/*B+*(.0*8+B8')+ !C":#D*E*7 .1*$!C":#D*E*7 5/8*.09*0/0<=+8/*$? 2 34+*'$%&'+;*(-86+*'1*-0.55+()+;? !" f(x,y) + - "#$%&'&()*+,-(&./0 !"#$%&'#()*+,#-.$+/0 1 2-.$3435*67*43(4$+ 1 2-.$3435*67*$38+ 1 2-.$3435*97*.$#8+ !! #$%&'(')*+,-.)'/01 2 3+*(.&&*)4+1+*+,-.)'/01*5'$%&'(')6 7+(.-1+* .&)4/-84*)4+9*'$%&9*.*(-:;+*/:*1-:<.(+=* )4+9*(.00/)*+>%&'(')&9*8+0+:.)+*)4+*%/'0)1* )4.)*(/$%:'1+*')? 2 #0*/:@+:*)/*8+0+:.)+*%/'0)1=*A+*0++@* .0/)4+:*</:$B !" #$%$&'(%)*+',-$()./0 1 !"#"$%&#'()%*+"&',-. .22'%+(3'+*$4$5)6)(7+(.+ 8'/'%$('+*./()/-.-0+*-%9'0+$/:+0-%2$*'0; 1 <.%+*-%9'0=+4$%$&'(%)*+',-$()./0+($>'+(3'+ 2.%& / ?+0@&A 1)2) 3@&A 4 ?+5@&A 1 <.%+BC+0-%2$*'0=+D'+3$9' / ?+0@.=&A 1)2)3@.=&A 4 ?+5@.=&A !" #$%$&'(%)*+',-$()./0 1 23'+!"#"$%&%#' 4.%+(3'0'+',-$()./0+$%'+ 0*$5$%0+(3$(+%$/6'+.7'%+$+*./()/-.-0+ 89.00):5;+)/4)/)('<+)/('%7$5= 1 >$%;)/6+(3'+9$%$&'('%0+.7'%+(3')%+'/()%'+ )/('%7$50+0&..(35;+6'/'%$('0+'7'%;+9.)/(+ ./+(3'+*-%7'+.%+0-%4$*'= !" #$%&'(')*+,-.)'/01 !"#$%&'#()*+,#-.$+/0 1 2#(#-+3(45*67*$48+ 1 2#(#-+3(45*/."+(+ !" #$%&'()*$+)#$,-. / 01'2$+( / 345-2&$6()*$+)'5+71()-6,)(5+*-'1( / 8-+.'162+&')9$$+,&6-21( : ;<.)=-+.'162+&')'$$+,&6-21(> : ;<-2)-+1)=-+.'162+&')'$$+,&6-21(> !" #$%&'()%*+,-).*&*//)0.,(-+12 c 3 4).(,56+1&()+&-$+&78,0(9+,-(6& :).9.-.;+&81+0&.,&<=&9/0+6.,5& :)/5)(91> 3 4).(,56+1&()+&1-/)+0&(1&(& b 1+?8+,*+&/7&-$)++&;+*-/)1@&+(*$& a 0+7.,.,5&(&;+)-+A> 3 B7-+,@&C+&D,/C&.,7/)9(-./,& ('/8-&-$+&;+)-.*+1@&18*$&(1&*/6/)@& -$(-&C+E0&6.D+&-/&.,-+):/6(-+&/;+)& -$+&C$/6+&-).(,56+> !" Barycentric Color Interpolation #$%&'%()'*%(+,)-&(.,',//(0.-%&)12 c 3 4$)'1.567)1&'8%+'&/'0/'&$.1' .-&)(6/7%&./-'.1'!"#$%&'(#)%* %++#,)'"(&-9 3 4$)'-%5)',/5)1':(/5'&$)';())<' 8/(0'!"#.- =$)%>+?'*),%@1)'&$)' b ,//(0.-%&)1'%()'8).A$&1'%11.A-)0' a &/'&$)'>)(&.,)19 3 B/.-&'a /-'&$)'&(.%-A7)'.1'&$)'/(.A.-' /:'&$)'-/-C/(&$/A/-%7',//(0.-%&)' 1+1&)59Goal: Assign a every point (x,y) or (x,y,z) to 3 4$)'>),&/(1':(/5'barycentric coordinatesa &/'b %-0':(/5' (α,β,γa). &/'c %()'&%<)-'%1'*%1.1'>),&/(19 !" Barycentric Coordinates c b a source: http://en.wikipedia.org/wiki/File:Barycentric_coordinates_1.png Solution: x = αa + βb + γc #$%&'%()'*%(+,)-&(.,',//(0.-%&)12 c Some cool properties: 3 4/.-&'p .1'.-1.0)'&$)'&(.%-56)'.7 %-0'/-6+'.7 8'9'! 9'": b 8'9'" 9'": a 8'9'# 9'" 3 ;7'/-)',/<=/-)-&'.1'>)(/:'p .1'/-'%-')05)? 3 ;7'&@/',/<=/-)-&1'%()'>)(/:'p .1'/-'%'A)(&)B? 3 C$)',//(0.-%&)1',%-'*)'D1)0'%1'@).5$&.-5' 7%,&/(1'7/('=(/=)(&.)1'/7'&$)'A)(&.,)1:'6.E)',/6/(? !" Barycentric Color Interpolation c b x a If: x = αa + βb + γc Then: color(x)=αcolor(a)+βcolor(b)+γcolor(c) #$%&'()*%+','--%.+)$*(/ !"#$%&'#()*+,#-.$+/0 1 !'23+(/4'2*5('-*67*!#(8+/4#2 1 !'23+(/4'2*5('-*97*!#(8+/4#2 !" Transformations Translation,Translation, rotation,rotation, scalingscaling 2D2D 3D3D HomogeneousHomogeneous coordinatescoordinates TransformingTransforming normalsnormals ExamplesExamples Shirley Chapter 6 Uses of Transformations • Modeling – build complex models by positioning simple components – transform from object coordinates to world coordinates • Viewing – placing the virtual camera in the world – specifying transformation from world coordinates to camera coordinates • Animation – vary transformations over time to create motion CAMERA OBJECT WORLD Computer Graphics 15-462 3 Rigid Body Transformations Rotation angle and line about which to rotate Computer Graphics 15-462 4 Non-rigid Body Transformations Distance between points on object do not remain constant Computer Graphics 15-462 5 Basic 2D Transformations Scale Shear chalkboard Rotate Computer Graphics 15-462 6 Composition of Transformations • Created by stringing basic ones together, e.g. – “translate p to the origin, rotate, then translate back” can also be described as a rotation about p • Any sequence of linear transformations can be collapsed into a single matrix formed by multiplying the individual matrices together • Order matters! • Can apply a whole sequence of transformations at once chalkboard 0 1 2 3 Translate to the origin, rotate, then translate back. Computer Graphics 15-462 7 3D Transformations • 3-D transformations are very similar to the 2-D case • Scale • Shear • Rotation is a bit more complicated in 3-D – different rotation axes chalkboard Computer Graphics 15-462 8 Fixed Euler Angles for 3-D Rotations • Independent rotations about each coordinate axis – angle interpolation for animation generates bizarre motions – rotations are order-dependent, and there are no conventions about the order to use • Widely used anyway, because they're “simple” Computer Graphics 15-462 9 Euler Angles for 3-D Rotations Computer Graphics 15-462 10 Other representations of 3D orientation • Relative rather than fixed Euler angles • Axis/Angle: rotate by ! about axis V • Quaternions: – a generalization of complex numbers –3 give the rotation axis - magnitude is sin !/2 –1 gives cos !/2 (the amount of rotation) –unit magnitude - points on a 4-D unit sphere Computer Graphics 15-462 11 But what about translation? •Translation is not linear--how to represent as a matrix? chalkboard Computer Graphics 15-462 12 But what about translation? •Translation is not linear--how to represent as a matrix? chalkboard •Trick: add extra coordinate to each vector •This extra coordinate is the homogeneous coordinate, or w •When extra coordinate is used, vector is said to be represented in homogeneous coordinates •We call these matrices Homogeneous Transformations Computer Graphics 15-462 13 W? Where did that come from? • Practical answer: –W is a clever algebraic trick. –Don’t worry about it too much. The w value will be 1.0 for the time being (until we get to perspective viewing transformations) • More complete answer: –(x,y,w) coordinates form a 3D projective space. –All nonzero scalar multiples of (x,y,1) form an equivalence class of points that project to the same 2D Cartesian point (x,y). –For 3-D graphics, the 4D projective space point (x,y,z,w) maps to the 3D point (x,y,z) in the same way. Computer Graphics 15-462 14 Homogeneous 2D Transformations The basic 2D transformations become Translate: Scale: Rotate: !" %" !" %" 10tx sx 00 !cos" ( )sin( 0%" $" '" $" '" 01ty 0 sy 0 $"sin( cos( 0'" $" '" $" '" $" 001'" #"001&" #"001&" #" &" Now any sequence of translate/scale/rotate operations can be combined into a single homogeneous matrix by multiplication. 3D transforms are modified similarly Computer Graphics 15-462 15 Rigid Body Transformations Rotation angle and line about which to rotate Computer Graphics 15-462 16 Rigid Body Transformations •A transformation matrix of the form xx xy tx yx yy ty 001 where the upper 2x2 submatrix is a rotation matrix and column 3 is a translation vector, is a rigid body transformation. •Any series of rotations and translations results in a rotation and translation of this form (and no change in the distance between vertices) Computer Graphics 15-462 17 Sequences of Transformations x' x' x' x' x' x' x' x' x' TRANSFORMED POINTS M PARAMETERS Often the same MATRICES transformations are applied M to many points Calculation time for the M matrices and combination is negligible compared to that of transforming the points x x x x x x x x x x UNTRANSFORMED Reduce the sequence to a POINTS single matrix, then transform Computer Graphics 15-462 18 Collapsing a Chain of Matrices. • Consider the composite function ABCD, i.e. p’ = ABCDp • Matrix multiplication isn’t commutative - the order is important • But matrix multiplication is associative, so can calculate from right to left or left to right: ABCD = (((AB) C) D) = (A (B (CD))). • Iteratively replace either the leading or the trailing pair by its product M ! D M ! A M ! CM or M ! MB both give the same result. M ! BM M ! MC M ! AM M ! MD Premultiply Postmultiply Computer Graphics 15-462 19 What is a Normal?– refresher Indication of outward facing direction for lighting and shading Order of definition of vertices in OpenGL Right hand rule Computer Graphics 15-462 20 Transforming Normals • It’s tempting to think of normal vectors as being like porcupine quills, so they would transform like points • Alas, it’s not so. • We need a different rule to transform normals. chalkboard Computer Graphics 15-462 21 Examples • Modeling with primitive shapes Computer Graphics 15-462 22 Announcements • Reading for Thursday: Shirley Ch: 2,6, & 7 • Project 1 due next Tuesday... • Style: 10% • Any questions? • Bulletin Board Mini-Demonstration.