cs380: introduction to computer graphics frames in ...vclab.kaist.ac.kr/cs380/slide06-frames.pdf ·...
TRANSCRIPT
18/03/22
1
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
CS380:IntroductiontoComputerGraphicsFramesinGraphics
Chapter5
MinH.KimKAISTSchoolofComputing
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
SUMMARYRespect
2
18/03/22
2
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Left-ofrule• Pointistransformedwithrespecttotheframethatappearsimmediatelytotheleftofthetransformationmatrixintheexpression.
• Weread
• Weread
3
f t ⇒
f tS
Sistransformedbywithrespectto f t
f t
istransformedbywithrespectto f t = at A−1 ⇒ atSA−1
S at
f t
f t
at
SA−1A
at =f t A
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Scalingapointoverframe
4
!f t = !at A−1
18/03/22
3
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Rotatingapointoverframe
5
!f t = !at A−1
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Twointerpretationsoftransformations• Twodifferentwaysformultipletransformations:
1. (Localtransformations)Translatewithrespecttothenrotatewithrespecttotheintermediateframe
2. (Globaltransformations)Rotatewithrespecttothentranslatewithrespecttotheoriginalframe
6
f t
f 't
f t
f t
Localtransformations Globaltransformations f t ⇒
f tTR
18/03/22
4
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
FRAMESINGRAPHICSChapter5
7
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
World,objectandeyeframes• Worldframe(worldcoordinates)– abasicright-handedorthonormalframe– weneveralterthisframe– otherframescanbedescribedwrttheworldframe
• Objectframe(objectcoordinates)– modelthegeometryoftheobjectusingvertexcoordinates
– notneedtobeawareoftheglobalplacement– aright-handedorthonormalframeofobject
• Eyeframe(cameracoordinates):lateron8
wt
ot
18/03/22
5
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Worldvs.objectframe• Therelationshipbetweentheworldframeandobjectframe:– affine4-by-4matrix(rigidbodytransformation:rotation+translationonly)
• Themeaningofistherelationshipbetweentheworldframetotheobject’scoordinatesystem.
• Tomovethepositionoftheobjectframeitself,wechangethematrix.
9
ot = wtO
O
O
ot
O
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Theeye’sview• Theworldframeisinred• Theobjectframeisingreen• Theeyeframeisinblue– Theeyeislookingdownitsnegativeztowardtheobject.
10
-Z
objectframe
worldframe
eyeframe
18/03/22
6
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Theeyeframe• Eyeframe(cameracoordinates)– aright-handedorthonormalframe– theeyelooksdownitsnegativezaxistomakeapicture
11
et
et = wtE
-Z
objectframe
worldframe
eyeframe
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Extrinsictransformationoftheeye• weexplicitlystorethematrix
– Objectcoordinates:– Worldcoordinates:– Eyecoordinates:– Calculatingtheeyecoordinatesofeveryvertexes:
12
E
p =otc
cOc
E−1Oc
xeyeze1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
= E−1O
xoyozo1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
=wtOc =
etE−1Oc
!ot = !wtO,!et = !wtE
18/03/22
7
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
MovinganObject
• Wewanttheobjecttorotatearounditsowncenterabouttheviewer’syaxis,whenwemovethemousetotheright.
• Howwecoulddothis?13
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
MovinganObject• Basicidea:setaframe
• MovingtransformationisM.• Whatisthebestauxiliaryframetodothis?
14
at = wt A
ot
=wtO
=at A−1O
⇒atMA−1O
=wt AMA−1O.
at
18/03/22
8
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
MovinganObject• Whatifwechoose• wetransformthisobjectwithrespecttoratherthanwithrespecttoourobservationthroughthewindow.
15
ot
ot
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
MovinganObject• Whatifwetransformwithrespectto• wewillrotateabouttheoriginoftheeye’sframe(itappearstoorbitaroundtheeye).
• Thenwhatframeitshouldbe?
16
ot
et
et
18/03/22
9
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
MovinganObject
• Weactuallywanttwodifferentoperations1. totransform(rotate)theobjectatitsorigin2. buttherotationaxisshouldbetheyaxisofthe
eye.17
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
HowtomoveanObject• RecallingtheAffinetransform.:• Theobject’sAffinetransform.:
(wewanttheobject’srotationabouttheobject’sorigin)• Theeye’sAffinetransform.:
(wewanttheobject’srotationabouttheeye’syaxis)• Thedesiredauxiliaryframe
(imagineinainverseway):
18
A = TRO = (O)T (O)R
E = (E)T (E)R
at = wt (O)T (E)RA = (O)T (E)R
!at
18/03/22
10
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Summary• Fromtheleft,wetranslatetheworldframetotheoriginOoftheobject’sframe,andthenrotatingtheobject’sframebyMaboutthatpointtoalignwiththedirectionsoftheeyeE.
19 at = wt (O)T (E)R
O← AMA−1OA = (O)T (E)R
=etE−1Oc p =
otc =wtOc
!ot = !wtO,!et = !wtE
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Movingtheeye• Weusethesameauxiliarycoordinatesystem.• Butinthiscase,theeyewouldorbitaroundthecenteroftheobject.
• Applyanaffinetransformdirectlytotheeye’sownframe(turningone’shead,first-personmotion)
20
et = wtE,E← EM
18/03/22
11
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Theeyematrix(cameratransform)• Specifyingtheeyematrixby:– theeyepoint– theviewpoint(wheretheeyelooksat)– theupvector
21
z = normalize(p − q)x = normalize(u× z)y = z × xnormalize(c) =
c / c12 + c2
2 + c32
E =
x1 y1 z1 p1x2 y2 z2 p2x3 y3 z3 p30 0 0 1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
p
q
u
et = wtE
x
y=u
z
pq
NBmatrixsenttothevertexshaderisE^{-1}*O
NBP.39containserrors(seeerrata)!!!
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Theviewmatrix(gluLookAt)• Specifyingtheviewmatrix– theeyepoint– theviewpoint(wheretheeyelooksat)– theupvector
22
z = normalize(q − p)x = normalize(u× z)y = x × z
p
q
u
V = E−1
xeyeze1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
= E−1O
xoyozo1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
x y
zu
p
q
V =E−1
modelmatrix:Oviewmatrix:V =E−1
movelviewmatrix:VO=E−1O
18/03/22
12
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
SceneGraph:HierarchyFrames• Anobjectcanbetreatedasbeingassembledbysomefixeandmovablesubobjects.
23
ot = wtO o 't = otO ' at = ot A bt = at B b 't =
bt B '
ct =btC
dt = ctD d 't =
dtD '
f t = otF
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
SceneGraph:HierarchyFrames• WejustupdateitsOmatrixtotheobjectframe,insteadofrelatingittotheworldframe
24
ot = wtO
ot = wtOat = wtOAbt = wtOABb 't = wtOABB 'ct = wtOABCdt = wtOABCDd 't = wtOABCDD '
18/03/22
13
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Matrixstack• Matrixstackdatastructurecanbeusedtokeeptrackofthematrix
• push(M)– createsanew‘topmost’matrix– acopyoftheprevioustopmostmatrix– M.multipliesthisnewtopmatrix
• pop()– removesthetopmostlayerofthestack
• descending– descenddowntoasubobject,whenapushoperationisdone
– thismatrixispoppedoffthestackwhenreturningfromthisdescenttotheparent
25
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Movinglimbs
26
18/03/22
14
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Movinglimbs
27
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Scenegraphpseudocode
28
…matrixStack.initialize(inv(E));matrixStack.push(O);
matrixStack.push(O’); draw(matrixStack.top(),cube);\\bodymatrixStack.pop();\\O’
matrixStack.push(A);\\grouping matrixStack.push(B); matrixStack.push(B’); draw(matrixStack.top(),sphere);\\upperarm matrixstack.pop();\\B’
matrixStack.push(C); matrixStack.push(C’); draw(matrixStack.top(),sphere);\\lowerarm matrixStack.pop();\\C’ matrixStack.pop();\\C matrixStack.pop();\\BmatrixStack.pop();\\A
\\currenttopmatrixisinv(E)*O\\wecannowdrawanotherarm
matrixStack.push(F);…
!p="etE−1OO'c →draw()
!p="etE−1OABB 'c →draw()
!p="etE−1OABCC 'c →draw()
!p="etE−1Oc
18/03/22
15
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Stagesofvertextransformation
29
Modelviewmatrix
Projectionmatrix
Perspectivedivision
Viewporttransforma
tion
eyecoordinates
http://www.glprogramming.com/red/chapter03.html
clipcoordinates
normalizeddevicecoordinates
windowcoordinates
vertex
xeyeze1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
= E−1O
xoyozo1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
xoyozo1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥