Inverting Composite Transforms• Say I want to invert a combination of 3 transforms • Option 1: Find composite matrix, invert • Option 2: Invert each transform and swap order • Obvious fr
Trang 1Transformations
Trang 2• 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
Trang 32D transformations
Trang 7Composing 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
Trang 8Inverting Composite Transforms
• Say I want to invert a combination of 3 transforms
• Option 1: Find composite matrix, invert
• Option 2: Invert each transform and swap order
• Obvious from properties of matrices
Trang 93D rotations
Trang 11Rotations in 3D
• Rotations about coordinate axes simple
• Always linear, orthogonal
y
R
Trang 12Geometric Interpretation 3D Rotations
• Rows of matrix are 3 unit vectors of new coord frame
• Can construct rotation matrix from 3 orthonormal vectors
Trang 13Geometric Interpretation 3D Rotations
• Rows of matrix are 3 unit vectors of new coord frame
• Can construct rotation matrix from 3 orthonormal vectors
• Effectively, projections of point into new coord frame
• New coord frame uvw taken to cartesian components xyz
• Inverse or transpose takes xyz cartesian to uvw
Trang 14• Not Commutative (unlike in 2D)!!
• Rotate by x, then y is not same as y then x
• Order of applying rotations does matter
• Follows from matrix multiplication not commutative
– R1 * R2 is not the same as R2 * R1
• Demo: HW1, order of right or up will matter
Trang 15Arbitrary rotation formula
• Rotate by an angle θ about arbitrary axis a
– Homework 1: must rotate eye, up direction
– Somewhat mathematical derivation but useful formula
• Problem setup: Rotate vector b by θ about a
• Helpful to relate b to X, a to Z, verify does right thing
• For HW1, you probably just need final formula
Trang 16Axis-Angle formula
• Step 1: b has components parallel to a, perpendicular
– Parallel component unchanged (rotating about an axis leaves that axis unchanged after rotation, e.g rot about z)
• Step 2: Define c orthogonal to both a and b
– Analogous to defining Y axis
– Use cross products and matrix formula for that
• Step 3: With respect to the perpendicular comp of b
– Cos θ of it remains unchanged
– Sin θ of it projects onto vector c
– Verify this is correct for rotating X about Z
– Verify this is correct for θ as 0, 90 degrees
Trang 17Axis-Angle: Putting it together
Unchanged(cosine)
Componentalong a (hence unchanged)
Perpendicular(rotated comp)
Trang 18Axis-Angle: Putting it together
(x y z) are cartesian components of a
Trang 19• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
• Transforming Normals
• Rotations revisited: coordinate frames
• gluLookAt (quickly)
Trang 20• E.g move x by + 5 units, leave y, z unchanged
• We need appropriate matrix What is it?
Trang 21Homogeneous Coordinates
• Add a fourth homogeneous coordinate (w=1)
• 4x4 matrices very common in graphics, hardware
• Last row always 0 0 0 1 (until next lecture)
Trang 22Representation of Points (4-Vectors)
Homogeneous coordinates
– Divide by 4th coord (w) to get (inhomogeneous) point
– Multiplication by w > 0, no effect
– Assume w ≥ 0 For w > 0, normal finite point For w
= 0, point at infinity (used for vectors to stop translation)
P =
x y z w
Trang 23Advantages of Homogeneous Coords
• Unified framework for translation, viewing, rot…
• Can concatenate any set of transforms to 4x4 matrix
• No division (as for perspective viewing) till end
• Simpler formulas, no special cases
• Standard in graphics software, hardware
Trang 24General Translation Matrix
T
T T
Trang 25Combining Translations, Rotations
• Order matters!! TR is not the same as RT (demo)
• General form for rigid body transforms
• We show rotation first, then translation (commonly used to position objects) on next slide Slide after that works it out the other way
• Demos with applet, homework 1
Trang 26
Combining Translations, Rotations
Trang 27Combining Translations, Rotations
M
Trang 28• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
Trang 29Hierarchical Scene Graph
Trang 30Drawing a Scene Graph
• Draw scene with pre-and-post-order traversal
– Apply node, draw children, undo node if applicable
• Nodes can carry out any function
– Geometry, transforms, groups, color, …
• Requires stack to “undo” post children
– Transform stacks in OpenGL
• Caching and instancing possible
• Instances make it a DAG, not strictly a tree
Trang 31Example Scene-Graphs
Trang 32• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
• Transforming Normals
• Rotations revisited: coordinate frames
• gluLookAt (quickly)
Trang 33• Important for many tasks in graphics like lighting
• Do not transform like points e.g shear
• Algebra tricks to derive correct transform
Incorrect to transform like points
Trang 34Finding Normal Transformation
Trang 35• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
• Transforming Normals
• Rotations revisited: coordinate frames
• gluLookAt (quickly)
Trang 36Coordinate Frames
• All of discussion in terms of operating on points
• But can also change coordinate system
• Example, motion means either point moves backward, or coordinate system moves forward
P = (2,1) P' = (1,1) P = (1,1)
Trang 37Coordinate Frames: In general
• Can differ both origin and orientation (e.g 2 people)
• One good example: World, camera coord frames
Trang 38Coordinate Frames: Rotations
Trang 39• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
• Transforming Normals
• Rotations revisited: coordinate frames
• gluLookAt (quickly)
Trang 40Geometric Interpretation 3D Rotations
• Rows of matrix are 3 unit vectors of new coord frame
• Can construct rotation matrix from 3 orthonormal vectors
Trang 41Axis-Angle formula (summary)
Trang 42• Translation: Homogeneous Coordinates
• Combining Transforms: Scene Graphs
• Transforming Normals
• Rotations revisited: coordinate frames
• gluLookAt (quickly)
Trang 43Case 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
Eye
Up vector
Center
Trang 44• 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
Trang 45Constructing 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
Trang 46Constructing a coordinate frame
• We want to position camera at origin,
looking down –Z dirn
• Hence, vector a is given by eye – center
• The vector b is simply the up vector
b w v = × w u
= a
w
a
Trang 47• 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
Trang 48Geometric Interpretation 3D Rotations
• Rows of matrix are 3 unit vectors of new coord frame
• Can construct rotation matrix from 3 orthonormal vectors
Trang 49• 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
Trang 50• 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
Trang 51Combining Translations, Rotations
M
Trang 52gluLookAt final form