3 D view ing under the hood CS 4 7 3 1 : Com put e r Gr a phics Le ct ur e 1 2 : M or e 3 D Vie w ing Modeling Viewing Projection Em m anuel Agu Transformation Transformation Transformation Viewport Transformation Display 3 D view ing under the hood View ing Transform ation Topics of Interest: � � Transform the object from world to eye space Const ruct eye coordinat e fram e � � Viewing transform ation � Const ruct m at rix t o perform coordinat e t ransform at ion Flexible Cam era Cont rol � Projection transform ation � 1
View ing Transform ation Eye Coordinate Fram e Recall OpenGL way to set cam era: � � gluLookAt (Ex, Ey, Ez, c x, cy, cz, Up_x , Up_y , Up_z) Known: eye position, center of interest, view- up vect or � � The view up vect or is usually ( 0,1,0) To find out: new origin and three basis vectors � � Rem em ber t o set t he OpenGL m at rix m ode t o GL_MODELVI EW first Assum ption: direct ion of view is � Modelview m atrix: ort hogonal t o view plane ( plane � com binat ion of m odeling m at rix M and Cam era t ransform s V t hat obj ect s will be proj ect ed ont o) cent er of int erest ( COI ) � gluLookAt fills V part of m odelview m atrix eye � What does gluLookAt do with param eters ( eye, COI , up o vector ) you provide? 90 Eye Coordinate Fram e Eye Coordinate Fram e Origin: eye position (that was easy) � How about u and v? � Three basis vectors: � � one is t he norm al vect or ( n ) of t he view ing plane, v � ot her t wo ( u and v ) span t he viewing plane • We can get u first - V _ u p u • u is a vector that is perp n is point ing away from t he to the plane spanned by v world because we use left u COI N and view up vector (V_up) eye hand coordinat e syst em n Cent er of int erest ( COI ) eye N = ey e – COI n n = N / | N | U = V_up x n world origin u = U / | U | Rem em ber u,v,n should be all unit vectors ( u,v,n should all be ort hogonal) 2
Eye Coordinate Fram e Eye Coordinate Fram e Eye space or igin: ( Eye .x , Eye .y, Eye .z) How about v? � Put it all together � Basis vectors: v V _ u p Knowing n and u, getting v n = ( ey e – COI ) / | eye – COI | u is easy v u = ( V_up x n ) / | V_up x n | V _ u p v = n x u u COI v = n x u eye n COI v is a lr e a dy n or m a liz e d eye n W orld to Eye Transform ation W orld to Eye Transform ation � Transform ation m atrix (M w2e ) ? Rotate the eye fram e to “align” it with the world fram e � P’ = M w2e x P Translate (- ex, - ey, - ez) � Rot at ion: ux uy uz 0 vx vy v z 0 v v 1. Com e up wit h t he t ransform at ion u u nx ny nz 0 sequence t o m ove eye coordinat e y y 0 0 0 1 n n fram e t o t he world P (ex, e y, ez) 2. And t hen apply t his sequence t o t he world world point P in a reverse order Translation: 1 0 0 - ex x x 0 1 0 - ey 0 0 1 - ez z z 0 0 0 1 3
W orld to Eye Transform ation W orld to Eye Transform ation � Head tilt: Rotate your head by δ Transform ation order: apply the transform ation to the � object in a reverse order - translation first, and then � Just rotate the object about the eye space z rotate axis - δ cos(- δ) -sin( - δ) 0 0 ux uy ux 0 1 0 0 -e x ux uy ux 0 1 0 0 - ex sin( - δ) cos (- δ) 0 0 vx vy v z 0 0 1 0 -ey � M w2e = vx vy vz 0 0 1 0 -e y 0 0 1 0 nx ny nz 0 0 0 1 -ez M w2e = nx ny nz 0 0 0 1 -ez 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 v u v u Why - δ ? y n y n (ex, e y, ez) world When you rot at e your head by δ , it is lik e world x rot at e t he obj ect by – δ x z z 4
Recommend
More recommend