Skeletons CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2018
Matrix Review
Coordinate Systems Right handed coordinate system y x z
3D Models Let’s say we have a 3D model that has an array of position vectors describing its shape We will group all of the position vectors used to store the data in the model into a single array: v n where 0 ≤ n ≤ NumVerts-1 Each vector v n has components v nx v ny v nz
Translation Let’s say that we want to move our 3D model from it’s current location to somewhere else… In technical jargon, we call this a translation We want to compute a new array of positions v ′ n representing the new location Let’s say that vector d represents the relative offset that we want to move our object by We can simply use: v ′ n = v n + d to get the new array of positions
Transformations v ′ n = v n + d This translation represents a very simple example of an object transformation The result is that the entire object gets moved or translated by d From now on, we will drop the n subscript, and just write v ′ = v + d remembering that in practice, this is actually a loop over several different v n vectors applying the same vector d every time
Transformations v v d Always remember that this compact equation can be expanded out into v v d x x x v v d y y y v v d z z z Or into a system of linear equations: v v d x x x v v d y y y v v d z z z
Rotation Now, let’s rotate the object in the xy plane by an angle θ , as if we were spinning it around the z axis v cos v sin v x x y v sin v cos v y x y v v z z Note: a positive rotation will rotate the object counterclockwise when the rotation axis (z) is pointing towards the observer
Rotation v cos v sin v x x y v sin v cos v y x y v v z z We can expand this to: v cos v sin v 0 v x x y z v sin v cos v 0 v y x y z v 0 v 0 v 1 v z x y z And rewrite it as a matrix equation: v cos sin 0 v x x v sin cos 0 v y y v 0 0 1 v z z Or just: v M v
Rotation We can represent a z-axis rotation transformation in matrix form as: v cos sin 0 v x x v sin cos 0 v y y v 0 0 1 v z z or more compactly as: v M v where cos sin 0 M R sin cos 0 z 0 0 1
Rotation We can also define rotation matrices for the x , y , and z axes: 1 0 0 R 0 cos sin x 0 sin cos cos 0 sin R 0 1 0 y sin 0 cos cos sin 0 R sin cos 0 z 0 0 1
Linear Transformations Like translation, rotation is an example of a linear transformation True, the rotation contains nonlinear functions like sin()’s and cos()’s, but those ultimately just end up as constants in the actual linear equation We can generalize our matrix in the previous example to be: a b c 1 1 1 M a b c v M v 2 2 2 a b c 3 3 3
Linear Equation A general linear equation of 1 variable is: f v av d where a and d are constants A general linear equation of 3 variables is: f v , v , v f v av bv cv d x y z x y z 2 , Note: there are no nonlinear terms like v x v y , v x sin( v x )…
System of Linear Equations Now let’s look at 3 linear equations of 3 variables v x , v y , and v z v a v b v c v d x 1 x 1 y 1 z 1 v a v b v c v d y 2 x 2 y 2 z 2 v a v b v c v d z 3 x 3 y 3 z 3 Note that all of the a n , b n , c n , and d n are constants (12 in total)
Matrix Notation v a v b v c v d x 1 x 1 y 1 z 1 v a v b v c v d y 2 x 2 y 2 z 2 v a v b v c v d z 3 x 3 y 3 z 3 v a b c v d x 1 1 1 x 1 v a b c v d y 2 2 2 y 2 v a b c v d z 3 3 3 z 3 v M v d
Translation Let’s look at our translation transformation again: v v d x x x v v d v v d y y y v v d z z z If we really wanted to, we could rewrite our three translation equations as: v 1 v 0 v 0 v d x x y z x v 0 v 1 v 0 v d y x y z y v 0 v 0 v 1 v d z x y z z
Identity We can see that this is equal to a transformation by the identity matrix v 1 v 0 v 0 v d x x y z 1 v 0 v 1 v 0 v d y x y z 2 v 0 v 0 v 1 v d z x y z 3 v 1 0 0 v d x x 1 v 0 1 0 v d y y 2 v 0 0 1 v d z z 3
Identity Multiplication by the identity matrix does not affect the vector 1 0 0 I 0 1 0 0 0 1 v I v
Uniform Scaling We can apply a uniform scale to our object with the following transformation v s 0 0 v x x v 0 s 0 v y y v 0 0 s v z z If s >1, then the object will grow by a factor of s in each dimension If 0< s <1, the object will shrink If s<0, the object will be reflected across all three dimensions, leading to an object that is ‘inside out’
Non-Uniform Scaling We can also do a more general nonuniform scale , where each dimension has its own scale factor v s 0 0 v x x x v 0 s 0 v y y y v 0 0 s v z z z which leads to the equations: v s v x x x v s v y y y v s v z z z
Reflections A reflection is a special type of scale operation where one of the axes is negated causing the object to reflect across a plane For example, a reflection along the x-axis would look like: Given an arbitrary 3x3 matrix M , we can tell if it has been reflected by checking if the matrix determinant is negative
Shears A shear is a translation along one axis by an amount proportional to the value along a different axis It causes a deformation similar to writing with italics (i.e., it causes a rectangle to deform into a parallelogram) For example a shear along x proportional to the value of y would look like:
Multiple Transformations If we have a vector v , and an x-axis rotation matrix R x , we can generate a rotated vector v ′: v v R x If we wanted to then rotate that vector around the y-axis, we could simply: v R v y v R R v y x
Recommend
More recommend