CS 378: Computer Game Technolog 3D Engines and Scene Graphs Spring 202 Universit of Teas at Austin CS 378 Game Technolog Don Fussell
Representation! We can represent a point, p =,), in the plane! as a column vector! as a row vector [ ] Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 2
Representation, cont.! We can represent a 2-D transformation M b a matri M = a b c d! If p is a column vector, M goes on the left: p = Mp = a b c d! If p is a row vector, M T goes on the right:! We will use column vectors. p = pm T [ ] = [ ] a c Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 3 b d
Two-dimensional transformations! Heres all ou get with a 2 2 transformation matri M: = a b c d! So: = a + b = c + d! We will develop some intimac with the elements a, b, c, d Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 4
Identit! Suppose we choose a=d=, b=c=0:! Gives the identit matri: 0 0! Doesnt move the points at all Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 5
Scaling! Suppose b=c=0, but let a and d take on an positive value:! Gives a scaling matri: a 0 0 d 2 2! Provides differential non-uniform) scaling in and : 2 2 2 0 0 2 = a = d 2 2 2 0 0 2 Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 6
Reflection! Suppose b=c=0, but let either a or d go negative.! Eamples: 0 0 0 0 Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 7
Shear! Now leave a=d= and eperiment with b! The matri b 0 gives: = + b = 0 Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 8
Effect on unit square! Lets see how a general 2 2 transformation M affects the unit square: a c a c b p q r s d [ ] = [ p q r s ] b 0 0 = 0 a a + b b d 0 0 0 c c + d d s r p q Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 9
Effect on unit square, cont.! Observe:! Origin invariant under M! M can be determined just b knowing how the corners,0) and 0,) are mapped! a and d give - and -scaling! b and c give - and -shearing Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 0
Rotation! From our observations of the effect on the unit square, it should be eas to write down a matri for rotation about the origin : cosθ) 0 sinθ) 0 sinθ) cosθ) Thus M R = Rθ) = cosθ) sinθ) sinθ) ) cosθ) Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell
Linear transformations! The unit square observations also tell us the 22 matri transformation implies that we are representing a point in a new coordinate sstem: p = Mp = a b c d [ ] = u v! where u=[a c] T and v=[b d] T are vectors that define a new basis for a linear space.! The transformation to this new basis a.k.a., change of basis) is a linear transformation. = u + v Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 2
Limitations of the 2 2 matri! A 2 2 linear transformation matri allows! Scaling! Rotation! Reflection! Shearing! Q: What important operation does that leave out? Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 3
Affine transformations! In order to incorporate the idea that both the basis and the origin can change, we augment the linear space u, v with an origin t.! Note that while u and v are basis vectors, the origin t is a point.! We call u, v, and t basis and origin) a frame for an affine space.! Then, we can represent a change of frame as: p = u + v + t! This change of frame is also known as an affine transformation.! How do we write an affine transformation with matrices? Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 4
Homogeneous Coordinates! To represent transformations among affine frames, we can loft the problem up into 3-space, adding a third component to ever point: p = Mp a b t = c d t 0 0 = [ u v t] = u + v + t! Note that [a c 0] T and [b d 0] T represent vectors and [t t ] T, [ ] T and [ ] T represent points. Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 5
Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 6 Homogeneous coordinates This allows us to perform translation as well as the linear transformations as a matri operation: p = M T p = 0 t 0 t 0 0 = + t = + t 0 0 2 0 0
Rotation about arbitrar points Until now, we have onl considered rotation about the origin. With homogeneous coordinates, ou can specif a rotation, R q, about an point q = [q q ] T with a matri: q θ. Translate q to origin 2. Rotate 3. Translate back Line up the matrices for these step in right to left order and multipl. Note: Transformation order is important!! Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 7
Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 8 Basic 3-D transformations: scaling Some of the 3-D transformations are just like the 2-D ones. For eample, scaling: = s 0 0 0 0 s 0 0 0 0 s 0 0 0 0
Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 9 Translation in 3D = 0 0 t 0 0 t 0 0 t 0 0 0
Rotation in 3D Rotation now has more possibilities in 3D: 0 0 0 ) 0 cosθ) sinθ) 0 R θ) = ) 0 sinθ) cosθ) 0) ) 0 0 0 cosθ) 0 sinθ) 0 ) 0 0 0 R θ) = ) sinθ) 0 cosθ) 0) ) 0 0 0 cosθ) sinθ) 0 0 ) sinθ) cosθ) 0 0 R θ) = ) 0 0 0) ) 0 0 0 R R R Use right hand rule Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 20
Universit of Teas at Austin CS384G - Computer Graphics Fall 200 Don Fussell 2 Shearing in 3D! Shearing is also more complicated. Here is one eample:! We call this a shear with respect to the - plane. = b 0 0 0 0 0 0 0 0 0 0 0