Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 52 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
52
Dung lượng
7,71 MB
Nội dung
Transformations Goals • This unit is about the math for these transformations – Represent transformations using matrices and matrix-vector multiplications • General Idea – – – – – Object in model coordinates Transform into world coordinates Represent points on object as vectors Multiply by matrices Demos with applet 2D transformations (Nonuniform) Scale sx Scale(s x , s y ) = 0 sx 0 0 sy 0 ÷ sy S −1 s = x sx x ÷ ÷ ÷ ÷ y ÷ = sy y ÷ ÷ s z÷ sz ÷ z z −1 x −1 ÷ sy ÷ Shear 1 a Shear = 1 S −1 −a = 0 Rotations • • 2D simple, 3D complicated [Derivation? Examples?] 2D? x ' cos θ y ' = sin θ • • − sin θ x ' cos θ y ' Linear Commutative R(X+Y) = R(X)+R(Y) Composing Transforms • • • • Often want to combine transforms E.g first scale by 2, then rotate by 45 degrees Advantage of matrix formulation: All still a matrix Not commutative!! Order matters – X2 = SX1 – X3 = RX2 – X3 = R(SX1) = (RS)X1 – X3 ≠ (SR)X1 Inverting Composite Transforms • • • • Say I want to invert a combination of transforms Option 1: Find composite matrix, invert Option 2: Invert each transform and swap order Obvious from properties of matrices = M1M2M3 M M −1 −1 −1 −1 −1 =M M M −1 −1 −1 M M = M (M (M M1 )M2 )M3 3D rotations Rotations Review of 2D case x ' cos θ y ' = sin θ • − sin θ x ' cos θ y ' Orthogonal? T R R=I Coordinate Frames: Rotations y v P' θ α cos θ R= sin θ P P x − sin θ u cos θ ÷= cos θ v sin θ α θ u − sin θ x ÷ cos θ y Outline • • • • • Translation: Homogeneous Coordinates Combining Transforms: Scene Graphs Transforming Normals Rotations revisited: coordinate frames gluLookAt (quickly) Geometric Interpretation 3D Rotations • • Rows of matrix are unit vectors of new coord frame Can construct rotation matrix from orthonormal vectors Ruvw = xu x v xw yu yv yw zu ÷ zv ÷ ÷ zw ÷ u = xu X + y uY + zu Z Axis-Angle formula (summary) (b \ a)ROT = (I3×3 cos θ − aaT cos θ )b + ( A* sin θ )b (b → a)ROT = (aaT )b R(a,θ ) = I3×3 cos θ + aaT (1 − cos θ ) + A* sin θ R(a,θ ) = cos θ + (1 − cos θ ) + sin θ 0÷ x xy xz ÷ −z y ÷ 0 0÷ xy y yz ÷ z −x ÷ ÷ ÷ ÷ ÷ ÷ 2÷ 0 − y x xz yz z Outline • • • • • Translation: Homogeneous Coordinates Combining Transforms: Scene Graphs Transforming Normals Rotations revisited: coordinate frames gluLookAt (quickly) Case Study: Derive gluLookAt • Defines camera, fundamental to how we view images – – gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) Camera is at eye, looking at center, with the up direction being up Up vector Eye Center Steps • gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) – • • • Camera is at eye, looking at center, with the up direction being up First, create a coordinate frame for the camera Define a rotation matrix Apply appropriate translation for camera (eye) location Constructing a coordinate frame? We want to associate w with a, and v with b – – But a and b are neither orthogonal nor unit norm And we also need to find u a w= a b ×w u= b ×w v = w ×u from lecture Constructing a coordinate frame a w= a • • • b ×w u= b ×w We want to position camera at origin, looking down –Z dirn v = w ×u Up vector Hence, vector a is given by eye – center The vector b is simply the up vector Eye Center Steps • gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) – • • • Camera is at eye, looking at center, with the up direction being up First, create a coordinate frame for the camera Define a rotation matrix Apply appropriate translation for camera (eye) location Geometric Interpretation 3D Rotations • • Rows of matrix are unit vectors of new coord frame Can construct rotation matrix from orthonormal vectors Ruvw = xu x v xw yu yv yw zu ÷ zv ÷ ÷ zw ÷ u = xu X + y uY + zu Z Steps • gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) – • • • Camera is at eye, looking at center, with the up direction being up First, create a coordinate frame for the camera Define a rotation matrix Apply appropriate translation for camera (eye) location Translation • gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) – • • Camera is at eye, looking at center, with the up direction being up Cannot apply translation after rotation The translation must come first (to bring camera to origin) before the rotation is applied Combining Translations, Rotations P ' = (RT )P = MP = R(P + T ) = RP + RT M = = R11 R12 R13 ÷ 0 Tx ữ R3ì3 R3ì3T3ì1 ữ ÷ R ÷ 0 T ÷ R R 22 23 y 21 ÷ ÷ 1×3 R31 R32 R33 ÷ 0 Tz ÷ ÷ 0 0 ÷ 0 gluLookAt final form xu x v xw 0 xu x v xw 0 yu zu yv yw zv zw yu zu yv yw zv zw 0÷ 0÷ ÷ 0÷ 1÷ 1 0 0 0 0 0 0 −ex ÷ −ey ÷ ÷ −ez ÷ ÷ − xuex − y uey − zuez ÷ − xv ex − yv ey − zv ez ÷ ÷ − xw ex − y w ey − zw ez ÷ ÷ ...Goals • This unit is about the math for these transformations – Represent transformations using matrices and matrix-vector multiplications • General Idea –... world coordinates Represent points on object as vectors Multiply by matrices Demos with applet 2D transformations (Nonuniform) Scale sx Scale(s x , s y ) = 0 sx 0 0 sy 0 ÷ sy S −1