700 likes | 845 Views
H331: Computer Graphics. http://www.cs.kuleuven.ac.be/~graphics/H331/ Philip Dutré Department of Computer Science Friday, October 12. Announcement. Practicum 1 available!!!. Today. Transformations of Objects Perspective Viewing Book: Chapter 5, 7. Transformations.
E N D
H331: Computer Graphics http://www.cs.kuleuven.ac.be/~graphics/H331/Philip Dutré Department of Computer Science Friday, October 12
Announcement • Practicum 1 available!!!
Today • Transformations of Objects • Perspective Viewing • Book: Chapter 5, 7
Transformations • Last week: window-to-viewport transformation • But … we also want to transform objects in 2D and 3D.
Why are transformations useful? • Define objects only once, then transform to compose bigger objects • Translations, rotations, scaling, …
Why are transformations useful? • Define motif, then construct object from motif Use 8 times
Why are transformations useful? • Move camera around
Why are transformations useful? • Computer animation • Translate / rotate / warp object over time
2D transformations • Each point can be expressed in a coordinate system: P = Pxi + Pyj + origin P (Px, Py,1) j Homogeneous coordinates origin i
2D Transformations • Q = T(P) • Affine transformation: coordinates of Q are linear combination of coordinates of P
Affine 2D Transformations translation rotation scaling shear
2D Translation Y Y (Qx, Qy,1) Tx Ty (Px, Py,1) X X
2D Scaling Y Y (Qx, Qy,1) (Px, Py,1) X X
2D Rotation Y (Qx, Qy,1) (Px, Py,1) R R + f X
2D Shear Y Y (Qx, Qy,1) (Px, Py,1) X X
Composing transformations • Rotate over 30 degrees • Translate Matrix multiply
Composite transformations • Order is important!!! Y Y Y rotate translate X X X Y Y Y rotate translate X X X
Composite transformations • E.g. Rotating about point • Standard rotation is about origin • Translate rotation centre to origin • Rotate around origin • Translate origin back to rotation centre
Composite transformations Y R X Y X Y Y X X R Tx -Ty Ty -Tx X
Window to viewport: revisited • Window to viewport transformation can also be expressed as 2D transform!!! Object Coordinate System Screen Coordinate System viewport window
Properties of 2D transforms • Affine transformations preserve affine linear combinations
Properties of 2D transforms • Affine transformations preserve lines and planes • Line:
Properties of 2D transforms • Parallellism of lines and planes is preserved • Parallel lines:
Transform of coordinate system • origin = (0 0 1); i = (1 0 0); j = (0 1 0)
Transform of coordinate system m2 m1 m3 j origin i
Other properties • Relative ratios are preserved • Areas:
3D affine transformations • Same idea, but 4x4 matrices
3D Translation Z Z Y Y TZ TY X X TX
3D Scaling Z Z Y Y SY SZ X X SX
3D Rotation around X-axis Z Z qx Y Y X X
3D Rotation around Y-axis Z Z qy Y Y X X
3D Rotation around Z-axis Z Z Y Y qz X X
Composite 3D transformations • Same ideas as 2D • E.g. rotation around arbitrary axis u • 2 rotations such that u is aligned with x-axis • X-rotation over desired angle • Undo the two rotations to restore u to original direction
Properties of 3D transformations • Preservation of affine linear combinations • Preservation of lines and planes • Parallelism of lines and planes is preserved • Columns reveal transformed coordinate frame • Ratios are preserved • Volumes are scaled by |detM|
Changing coordinate systems • Different way of thinking about coordinate transforms • More natural: • Objects are modeled in their own coordinate system • What are the coordinates of the the transformed object in the world coordinate system?
Changing coordinate systems World coordinate system Object coordinate systems
Changing coordinate systems j’ i’ o’=M.origin i’ = M.i j’ = M.j o’ j origin i M transforms (origin, i, j) to (o’, i’, j’)
Changing coordinate systems j’ P b d i’ P = (c,d,1) in (o’, i’, j’) c o’ j origin a i What are the coordinates (a,b,1) of P in (origin, i, j)?
Changing coordinate systems j’ P b d i’ c o’ j origin a i
Changing coordinate systems • M1 to change coordinate system 1 to 2 • M2 to change coordinate system 2 to 3 • What are the coordinates of P in 1? • Different order of matrices as transforms for points!
Changing coordinate systems Local object coordinate system P Express P in world coordinates: R.T.P First R, then T
Viewing in 3D • Camera has its own coordinate system
What do we know so far? • Objects are described in their own coordinate system • To place objects in the world, we need to apply transformation matrices • Transformations: • Translation; scaling; rotations
Viewing in 3D • Perspective! • Precise control over camera position and orientation
Camera setup Z Camera Near plane X Y Far plane View direction