CS 430/536 Computer Graphics I Outline 3D Transformations World Window to Viewport Transformation Week 2, Lecture 4 • World window to viewport transformation • 3D transformations • Coordinate system transformation David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University 1 http://gicl.cs.drexel.edu 2 The Window-to-Viewport Transformation Window-to-Viewport Transformation • Problem: Screen windows cannot display the whole world (window management) • How to transform and clip: Objects to Windows to Screen • Given a window and a viewport, what is the transformation from WCS to VPCS? Three steps: • Translate • Scale • Translate 3 4 1994 Foley/VanDam/Finer/Huges/Phillips ICG Pics/Math courtesy of Dave Mount @ UMD-CP Transforming World Coordinates to Viewports • Clipping to the Viewport 3 steps • Viewport size may not be big enough for everything • Display only the pixels inside the viewport 1. Translate 2. Scale 3. Translate Overall Transformation: P'= M wv P 5 1994 Foley/VanDam/Finer/Huges/Phillips ICG • Transform lines in world • Then clip in world • Transform to image • Then draw • Do not transform pixels 6 1994 Foley/VanDam/Finer/Huges/Phillips ICG ! 1 Another Example 3D Transformations • Scan-converted – Lines – Polygons – Text – Fill regions • Clip regions for display 7 9 1994 Foley/VanDam/Finer/Huges/Phillips ICG Representation of 3D Transformations 3D Homogenous Coordinates • Z axis represents depth • Right Handed System • Homogenous coordinates for 2D space requires 3D vectors & matrices • Homogenous coordinates for 3D space requires 4D vectors & matrices • [x,y,z,w] – When looking down at the origin, positive rotation is CCW • Left Handed System – When looking down , positive rotation is in CW – More natural interpretation for displays, big z means far (into screen) 10 11 1994 Foley/VanDam/Finer/Huges/Phillips ICG 3D Transformations: Scale & Translate 3D Transformations: Rotation • Scale • One rotation for each world coordinate axis – Parameters for each axis direction • Translation 12 13 2 Rotation Around an Arbitrary Axis Rotation Around an Arbitrary Axis The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. • Rotate a point P around axis n (x,y,z) by angle θ # tx 2 + c % txy " sz R =% %txz + sy % $ 0 ! txy + sz txz " sy ty 2 + c tyz + sx tyz " sx tz 2 + c 0 0 • c = cos(θ) • s = sin(θ) • t = (1 - c) • Also can be expressed as the Rodrigues Formula 0& ( 0( 0( ( 1' Graphics Gems I, p. 466 & 498 Prot = P cos(" ) + (n # P)sin(" ) + n(n $ P)(1% cos(" )) 14 ! 15 Improved Rotations • Euler Angles have problems – How to interpolate keyframes? – Angles aren t independent – Interpolation can create Gimble Lock, i.e. loss of a degree of freedom when axes align • Solution: Quaternions! 16 17 ! p = (0, x ) ! 18 19 3 20 21 What about interpolating multiple keyframes? • Shoemake suggests using Bezier curves on the sphere • Offers a variation of the De Casteljau algorithm using slerp and quaternion control points • See K. Shoemake, Animating rotation with quaternion curves , Proc. SIGGRAPH 85 A & B are quaternions slerp – Spherical linear interpolation Need to take equals steps on the sphere 22 23 3D Transformations: Shear 3D Transformations: Reflect & Shear " X'% " 1 $ ' $ x $ Y ' ' = $ Shy $ Z' ' $ Shzx $ ' $ #1& # 0 • Reflection: about x-y plane Shxy 1 Shxz Shyz Shzy 0 1 0 0% " X % ' $ ' 0' $ Y ' ( 0' $ Z ' ' $ ' 1& # 1 & X ' = X + ShxyY + Shxz Z • Shear: (function of z) ! 24 Y ' = Shyx X +Y + Shyz Z Z ' = Shzx X + ShzyY + Z 25 4 Example: Composition of 3D Transformations Example • Goal: Transform P1P2 and P1P3 26 27 Pics/Math courtesy of Dave Mount @ UMD-CP 1994 Foley/VanDam/Finer/Huges/Phillips ICG Example (Cont.) • Process 1. 2. 3. 4. Translate P1 to (0,0,0) Rotate about y Rotate about x Rotate about z Final Result • What we ve really done is transform the local coordinate system Rx, Ry, Rz to align with the origin x,y,z (1) (2-3) (4) 28 29 1994 Foley/VanDam/Finer/Huges/Phillips ICG Example 2: Composition of 3D Transformations • Airplane defined in x,y,z • Problem: want to point it in Dir of Flight (DOF) centered at point P • Note: DOF is a vector • Process: 1994 Foley/VanDam/Finer/Huges/Phillips ICG Example 2 (cont.) • Zp axis to be DOF • Xp axis to be a horizontal vector perpendicular to DOF – y x DOF • Yp, vector perpendicular to both Zp and Xp (i.e.Zp x Xp) – Rotate plane – Move to P 30 1994 Foley/VanDam/Finer/Huges/Phillips ICG 31 1994 Foley/VanDam/Finer/Huges/Phillips ICG 5 Transformations to Change Coordinate Systems • Issue: the world has many different relative frames of reference • How do we transform among them? • Example: CAD Assemblies & Animation Models Transformations to Change Coordinate Systems • 4 coordinate systems 1 point P M 1!2 = T (4,2) M 2!3 = T (2,3) • S (0.5,0.5) M 3!4 = T (6.7,1.8) • R(45! ) 32 33 1994 Foley/VanDam/Finer/Huges/Phillips ICG Coordinate System Example (1) • Transformation M 5"1 = M 5"4 • M 4"3 • M 3"2 • M 2"1 Composition: • Translate the House to the origin M1"2 = T(x1, y1 ) M 2"1 = ( M1"2 ) ! #1 = T(#x1,#y1 ) ! Coordinate System Example (2) P1 The matrix Mij that maps points from coordinate system j to i is the inverse of the matrix Mji that maps points from 34 coordinate system j to coordinate system i. 35 1994 Foley/VanDam/Finer/Huges/Phillips ICG World Coordinates and Local Coordinates • To move the tricycle, we need to know how all of its parts relate to the WCS • Example: front wheel rotates on the ground wrt the front wheel s z axis: P (wo) = T("r,0,0) # Rz (" ) # P (wh ) Coordinates of P in wheel coordinate system: P'(wh ) = Rz (" ) # P (wh ) 1994 Foley/VanDam/Finer/Huges/Phillips ICG Questions about Homework 1? • Go to web site 36 37 1994 Foley/VanDam/Finer/Huges/Phillips ICG ! ! 6