CS 354R: Computer Game Technolog Transformations Fall 207 Universit of Teas at Austin CS 354R Game Technolog S. Abraham
Transformations What are the? Wh should we care? Universit of Teas at Austin CS 354R Game Technolog S. Abraham 2
Representation We can represent a point, p =, ), in the plane As a column vector " # As a row vector [ ] Universit of Teas at Austin CS 354R Game Technolog S. Abraham 3
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: If p is a row vector, M T goes on the right: We will use column vectors. " p = Mp # " " = # a b # c d p " = pm T [ " "]= # b d [ ] a c Universit of Teas at Austin CS 354R Game Technolog S. Abraham 4
Two-dimensional transformations Heres all ou get with a 22 transformation matri M: # " " = # a b # c d So: " = a + b " = c + d We will develop some intimac with the elements: a, b, c, and d Universit of Teas at Austin CS 354R Game Technolog S. Abraham 5
Identit Suppose we choose a = d =, b = c = 0: Gives the identit matri " 0 # 0 Doesn t move the point at all Universit of Teas at Austin CS 354R Game Technolog S. Abraham 6
Scaling Suppose b = c = 0, but let a and d take on an positive value: Gives a scaling matri: " a 0 # 0 d Provides differential non-uniform) scaling in and : 2 2 2 2 2 " 2 0 # 0 2 " 2 0 # 0 2 " = a " = d 2 Universit of Teas at Austin CS 354R Game Technolog S. Abraham 7
Reflection Suppose b = c = 0, but either a or d goes negative Consider: # 0 0 # 0 0 Universit of Teas at Austin CS 354R Game Technolog S. Abraham 8
Shear Now leave a = d = and eperiment with b Consider: " b # 0 " = + b " = " # 0 Universit of Teas at Austin CS 354R Game Technolog S. Abraham 9
Effect on unit square A general 2 2 transformation M on the unit square: " a # c " a # c b [ p q r s]= p q r s d [ ] 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 CS 354R Game Technolog S. Abraham 0
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 CS 354R Game Technolog S. Abraham
Rotation From our observations of the effect on the unit square, the matri for rotation about the origin : Thus M R = Rθ) = cosθ) sinθ) sinθ) ) cosθ) Universit of Teas at Austin CS 354R Game Technolog S. Abraham 2
Linear transformations The unit square observations tell us the 22 matri transformation implies 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 CS 354R Game Technolog S. Abraham 3
Limitations of the 22 matri A 22 linear transformation matri allows: Scaling Rotation Reflection Shearing What important operation does that leave out? Universit of Teas at Austin CS 354R Game Technolog S. Abraham 4
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. Universit of Teas at Austin CS 354R Game Technolog S. Abraham 5
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 CS 354R Game Technolog S. Abraham 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 Universit of Teas at Austin CS 354R Game Technolog S. Abraham 7
Rotation about arbitrar points Until now, we ve onl considered rotation about the origin With homogeneous coordinates, ou can specif a rotation Rq 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 steps in right to left order and multipl. Note: Transformation order is important!! Universit of Teas at Austin CS 354R Game Technolog S. Abraham 8
Universit of Teas at Austin CS 354R Game Technolog S. Abraham Basic 3-D transformations: scaling Some of the 3-D transformations are just like the 2-D ones. For eample, scaling: 9 z z " " " z # = s 0 0 0 0 s 0 0 0 0 s z 0 0 0 0 # z #
Universit of Teas at Austin CS 354R Game Technolog S. Abraham Translation in 3D 20 z z " " " z # = 0 0 t 0 0 t 0 0 t z 0 0 0 # z #
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 z θ) = ) 0 0 0) ) 0 0 0 z Use right hand rule Universit of Teas at Austin CS 354R Game Technolog S. Abraham 2
Universit of Teas at Austin CS 354R Game Technolog S. Abraham Shearing in 3D Shearing is also more complicated. Here is one eample: We call this a shear with respect to the -z plane. 22 z z " " " z # = b 0 0 0 0 0 0 0 0 0 0 0 # z #
Quaternions Mathematical notation for representing object rotation Comple planes rather than Cartesian planes Alternative to Euler angles and matrices No Gimbal lock Simpler representation Quaternion Rotation Gamasutra) Universit of Teas at Austin CS 354R Game Technolog S. Abraham 23
Quaternion Space Jeremiah van Oosten http://3dgep.com/understanding-quaternions/) Universit of Teas at Austin CS 354R Game Technolog S. Abraham 24
Notation Comple Number Notation: 4D Vector Notation: Rotate b angle ϴ about ais v : Universit of Teas at Austin CS 354R Game Technolog S. Abraham 25
Quaternion Interpolation SLERP Spherical Linear Interpolation) Equation for LERP: Equation for SLERP: SQAD Spherical and Quadrangle) Smoothl interpolate over a path of rotations cubic) Defines helper quaternion that acts as a control point Caveat: when the angular distance between p and p2 is small, sinθ) approaches zero. Must switch back to LERP. Universit of Teas at Austin CS 354R Game Technolog S. Abraham 26
Further Reading on Quaternions Understanding Quaternions Jeremiah van Oosten) http://3dgep.com/understanding-quaternions/ Rotating Objects Using Quaternions Nick Bobic) http://www.gamasutra.com/view/feature/3686/ rotating_objects_using_quaternions.php Universit of Teas at Austin CS 354R Game Technolog S. Abraham 27