170 likes | 181 Views
What you wi l l l earn about today. C a m e r a s i n O pen GL W h e r e t h is f its i n to w or ld t r a n s for m a ti ons V a r i ou s t yp e s o f c a m e r a s. What i s mov i ng?. f ra m e1. f ra m e3. f ra m e2. Let ’ s E x a mi n e t h e C a mera.
E N D
Whatyouwill learnabouttoday • CamerasinOpenGL • Wherethisfitsintoworldtransformations • Varioustypesofcameras
Whatismoving? frame1 frame3 frame2
Let’s ExaminetheCamera • IfIgaveyouaworld,andsaidIwantto renderitfromanotherviewpoint,whatinformationdoI havetogiveyou? • Position • Whichwaywearelooking • Whichwayis“up” • AspectRatio • FieldofView • NearandFar
glm::lookat Orientsandpositionsthe“camera” lookat(eyex,eyey,eyez, centerx,centery,centerz, upx,upy, upz); eye– thepositionofthecamerainworld coordinates center– thecamerais pointedatthispoint up – thedirectiondefinedtobe up for thecamera
Movingthecamera Howcanwe translatethecamera? add avectortotheeyeand centerparametersHowfarwillthismoveit? thelengthofthevector What happens ifyou don’t changethecenter? thecamerawillstayfixed on theoriginalpoint
Camerawithoutglm::lookat? • Howcanwetranslateand orientthe camerawithout lookat? • inversetransforms:translate(-x,-y,-z);rotate(-angle,a,b,c)Wheredoesthisgo inyouropenGLprogram (using lookatornot)? • usuallyatthebeginningofyourdisplayfunction
Camera:sideview View Right View Up View Normal View Direction
Camera:lookingthroughthe camera View Up View Right What arethevectors?
TransformationWorld->Camera View Right= u 1 0 0 camerax 0 1 0 0 0 1 0 0 0 View Up=V • camera T y • cameraz 1 nN (n,n ,n) 123 N uV N (u,u ,u ) 123 V N View Direction=-N vnu(v1,v2,v3) u1u2u30 v v v 0 R 3 n1n2n30 0 0 0 1 12 MWCVCRT
FirstPersonCamera • Howisthisimplemented? • Where is the‘eye’? • What is thelook atpoint? • What is up? • up • center • eye
FirstPersonCamera • Howdo we movethecamera? • Addavectorto eyeandcenter up movedir center eye
FirstPersonCamera • Howdo we rotatethecamera? • Move thecenterpoint- add avectortoit • Upvector • Sidevector:lookatx up • center • up • eye
Lookatimplementationoddities • What willhappenifup ==lookatdirection? • Spins aroundtheup axisinaweird way • Whydoesthishappen? • Twoaxesof yourcameraframearealigned! • Howcanwe avoidthis? • Maintainanorthogonalcameraframe-Resettheup vectorusinglookatXside(e.g., morecommoninflight games) • Constrainthelookatdirectiontonot getto closetotheup vector(e.g.,commoninFPSgames) • Use quaternions
3rd PersonCamera • Howisthisimplemented? • Where is the‘eye’? • What is thelook atpoint? • What is up?
3rd PersonCamera • Remember,initiallythecamera is • Attheoriginlookingdown–z) • • Same as glm::lookat(0,0,0,0,0,-1,0,1,0) • Howcanthisbemoreeasilyimplemented withoutglm::lookat? • translatethecharactersoyoucanseeit • Drawthecharacter • RotatetheworldaroundYatthefixedpointofthecharacter • Translatetheworldinverselytothecharacterposition • Rendertheworld
BirdsEyeCamera • Howisthisimplemented? • Where is the‘eye’? • • • • What is thelook atpoint? What is up?
Review:Whatyoulearnedabout today • CamerasinOpenGL • Wherethisfitsintoworldtransformation • Thecameratransformisperformedaftertheworld transform • IS THESAMEAS: • Thecamerais alwaysat0,0,0 lookingdown–z • Theworldtransforms instead • Varioustypesofcameras • 1st,3rd, birdseye