Presentation is loading. Please wait.

Presentation is loading. Please wait.

Character Motion 王銓彰 2014. ■ We use Cartesian coordinate system ( 笛卡兒座標系 ) for 3D. ■ We use right-hand rule for axis orientation. ■ x.

Similar presentations


Presentation on theme: "Character Motion 王銓彰 2014. ■ We use Cartesian coordinate system ( 笛卡兒座標系 ) for 3D. ■ We use right-hand rule for axis orientation. ■ x."— Presentation transcript:

1 Character Motion 王銓彰 cwang001@mac.com 2014

2 ■ We use Cartesian coordinate system ( 笛卡兒座標系 ) for 3D. ■ We use right-hand rule for axis orientation. ■ x cross y = z ■ We use Z-up orientation. 3D Coordinate System Y Z X ■ For 2D, we used to use left-hand rule for axis orientation. Screen viewport (ox, oy) x y

3 ■ 3D 球座標系 ■ P( ϱ,φ,  ) Spherical Coordinate System +y -y -z +z -x +x x y z P( , ,  ) P(x,y) r    z=P·cos  o x=r·cos  =  ·sin  ·cos  y=r·sin  =  ·sin  ·sin  3D Spherical Coordinates

4 ■ Transformations in Matrix form ■ A point or a vector is a row matrix (de facto convention) V = [x y z] Using matrix notation, a point V is transformed under translation, scaling and rotation as : V’ = V + D V’ = VS V’ = VR where D is a translation vector and S and R are scaling and rotation matrices Matrices (1/3)

5 To make translation be a linear transformation, we introduce the homogeneous coordinate system V (x, y, z, w), where w is always 1 Translation Transformation x’ = x + T x y’ = y + T y z’ = z + T z V’ = VT [x ’ y ’ z ’ 1] = [x y z 1] = [x y z 1] T 1 0 0 0 0 1 0 0 0 0 1 0 T x T y T z 1 Matrices (2/3)

6 Net Transformation matrix [x ’ y ’ z ’ 1] = [x y z 1] M 1 and [x” y” z” 1] = [x’ y’ z’ 1] M 2 then the transformation matrices can be concatenated M 3 = M 1 M 2 and [x” y” z” 1] = [x y z 1] M 3 M 1 M 2 = M 2 M 1 Matrices (3/3) Matrix multiplication are not commutative

7 Two representations : Transformation for Vertices = [M 1 ] The vertices are in row matrix form. {V’} = [M 2 ]{V} The vertices are in column matrix form If these two transformations are identical, M 1 & M 2 are transpose.

8 A rotation is described as a sequence of rotations about three mutually orthogonal coordinates axes fixed in space X-roll, Y-roll, Z-roll R(  1,  2,   ) represents an x-roll, followed by y-roll, followed by z-roll R(  1,  2,    c 2 c 3 c 2 s 3 -s 2 0 s 1 s 2 c 3 -c 1 s 3 s 1 s 2 s 3 +c 1 c 3 s 1 c 2 0 c 1 s 2 c 3 +s 1 s 3 c 1 s 2 s 3 -s 1 c 3 c 1 c 2 0 0 0 0 1 where s i = sin  i and c i = cos  i Euler Angles There are 6 possible ways to define a rotation. 3!

9 Interpolation happening on each angle Multiple routes for interpolation More keys for constrains z x y R z x y R Euler Angles & Interpolation

10 R( , n), n is the rotation axis. n rRr  n r rvrv rhrh V  rvrv V r h = (n. r)n r v = r - (n. r)n, rotate into position Rr v V = nxr v = nxr Rr v = (cos  )r v + (sin  )V -> Rr = Rr h + Rr v = r h + (cos  )r v + (sin  )V = (n. r)n + (cos  )  r - (n. r)n) + (sin  ) nxr = (cos  )r + (1-cos  ) n (n. r) + (sin  ) nxr Angular Displacement – Rotation with An Arbitrary Axis

11 Sir William Hamilton (1843) From Complex numbers (a + ib), i 2 = -1 16,October, 1843, Broome Bridge in Dublin 1 real + 3 imaginary = 1 quaternion q = a + bi + cj + dk i 2 = j 2 = k 2 = -1 ij = k & ji = -k, cyclic permutation i-j-k-i q = (s, v), where (s, v) = s + v x i + v y j + v z kQuaternion

12 q 1 = (s 1, v 1 ) and q 2 = (s 2, v 2 ) q 3 = q 1 q 2 = (s 1 s 2 - v 1. v 2, s 1 v 2 + s 2 v 1 + v 1 xv 2 ) Conjugate of q = (s, v), q = (s, -v) qq = s 2 + |v| 2 = |q| 2 A unit quaternion q = (s, v), where qq = 1 A pure quaternion p = (0, v) Non-commutative Quaternion Algebra

13 Take a pure quaternion p = (0, r) and a unit quaternion q = (s, v) where qq = 1 and define R q (p) = qpq -1 where q -1 = q for a unit quaternion R q (p) = (0, (s 2 - v. v)r + 2v(v. r) + 2svxr) Let q = (cos , sin  n), |n| = 1 R q (p) = (0, (cos 2  - sin 2  )r + 2sin 2  n(n. r) + 2cos  sin  nxr) = (0, cos2  r + (1 - cos2  )n(n. r) + sin2  nxr) Conclusion : The act of rotating a vector r by an angular displacement ( , n) is the same as taking this displacement, ‘lifting’ it into quaternion space, by using a unit quaternion (cos(  /2), sin(  /2) n) Quaternion VS Angular Displacement

14 1-2y 2 -2z 2 2xy-2wz 2xz+2wy 0 2xy+2wz 1-2x 2 -2z 2 2yz-2wx 0 2xz-2wy 2yz+2wx 1-2x 2 -2y 2 0 0 0 0 1 q = (w,x,y,z) Quaternion VS Rotation Matrix

15 M 0 M 1 M 2 0 M 3 M 4 M 5 0 M 6 M 7 M 8 0 0 0 0 1 float tr, s; tr = m[0] + m[4] + m[8]; if (tr > 0.0f) { s = (float) sqrt(tr + 1.0f); q->w = s/2.0f; s = 0.5f/s; q->x = (m[7] - m[5])*s; q->y = (m[2] - m[6])*s; q->z = (m[3] - m[1])*s; } else { float qq[4]; int i, j, k; int nxt[3] = {1, 2, 0}; i = 0; if (m[4] > m[0]) i = 1; if (m[8] > m[i*3+i]) i = 2; j = nxt[i]; k = nxt[j]; s = (float) sqrt((m[i*3+i] - (m[j*3+j] + m[k*3+k])) + 1.0f); qq[i] = s*0.5f; if (s != 0.0f) s = 0.5f/s; qq[3] = (m[j+k*3] - m[k+j*3])*s; qq[j] = (m[i+j*3] + m[j+i*3])*s; qq[k] = (m[i+k*3] + m[k+i*3])*s; q->w = qq[3]; q->x = qq[0]; q->y = qq[1]; q->z = qq[2]; }

16 Spherical linear interpolation, slerp A B P  t slerp(q 1, q 2, t) = q 1 + q 2 sin((1 - t)  ) sin  sin(t  ) Quaternion Interpolation

17 Bone structure Bone structure Motion Motion Pose management Pose management Skin deformation Skin deformation Characters in Games

18 In regular, we implement a biped character in the game engine. In regular, we implement a biped character in the game engine. Hierarchical bone structure Hierarchical bone structure –Easy to implement –Implement with the scene tree Root-base system Root-base system –Base object »The parent node of the whole body –Movement controls With geometry on bones or not With geometry on bones or not –Rigid skin Skin deformation in game Skin deformation in game Skeleton (1/2) Base

19 An example of a skeleton scene tree An example of a skeleton scene tree Skeleton (2/2) groin body head thigh_r thigh_l shin_r shin_l foot_r foot_l up_arm_l up_arm_r fore_arm_l fore_arm_r hand_l hand_r Base head body up arm fore arm hand groin thigh shin foot

20 Pivot Pivot –Offset position in parent space –Local rotation center –Fixed length Transformation Transformation A Bone Parentbone Joint = pivot(p x,p y,p z ) in A A B (x,y,z, ,axis) ( ,axis) = [R B ][T B ][R A ][T A ] = [R B ][T B ][R A ][T A ]

21 Base node is used for movement control. Base node is used for movement control. Root nodes are used for playing poses. Root nodes are used for playing poses. Base Root (groin) Base The Root-Base Concept

22 Position Position – Fixed pivot – Time-dependent position Rotation Rotation – Rotation with pivot Scaling Scaling – Rare to use – Use carefully Motion Data in Games

23 Euler angles Euler angles – 3 floating-point reals Quaternion Quaternion – 4 floating-point reals Rotation with an arbitrary axis Rotation with an arbitrary axis – Angular displacement – 4 floating-point real numbers Matrix Matrix – 9 floating-point real numbers Rotation Data on Joints (1/2)

24 Rotation Data on Joints (2/2) Quaternion interpolation Matrix ( , n) Euler angles Bone

25 Run-time or pre-processing Run-time or pre-processing Issues : Issues : –Motion re-targeting »Run-time –Re-key-framing »Pre-processing –Interpolation between frames »Run-time –Motion blending »Run-time –Motion connection »Run-time Motion Editing

26 walk start_frameend_frame cut_frame Parameter { start_frame start_frame end_frame end_frame cut_frame cut_frame} Pose Definition

27 walk 048 Frame 5.3 1.If the motion data is in quaternion form 2.Get the motion data on frame 5 & 6 3.Convert the data into quaternion format 4.Apply slerp(5, 6, 0.3) to get the interpolation on frame 5.3 5.Convert the result of step 3 into a rotation matrix 6.Apply the matrix to the object for its transformation Play a Pose

28 Pose 1 Pose 2 cut_frame start_frame length Pose Connection

29 29 Motion blending in run-time Motion blending in run-time Quaternion is used Quaternion is used “Blend Tree” “Blend Tree” –Cross fade –Continuous blending –Feather blending Reference Reference –Game Developers Conference 2003 –Proceedings CD, Programming Track –“Animation Blending : Achieving Inverse Kinematics and More” –Jerry Edsall –Mech Warrior blend tree Pose Blending Fall Transition Forward Motion Fall Down Walk Run

30 Natural pose Natural pose –Reset pose –The pose where the skin model models Natural Pose

31 Weights to assign the influences of the deformation by bones on skin vertices Weights to assign the influences of the deformation by bones on skin vertices –1-weight –2-weight –N-weight CPU cost CPU cost Another way to perform the skin deformation calculation is using vertex shader Another way to perform the skin deformation calculation is using vertex shader Skin deformation Skin deformation –Convert the skin vertices to the associated bone’s local space »Using the inverse matrix of the bone in natural pose –Convert the skin vertices to the base node’s space »Using the matrix of the bone at the frame –Vertex blending with the bone weights Skin Deformation

32 Bone A (root object) Bone B (Bone A’s child) base base 1.Apply motion data to bones 2.Convert the vertex from “base” space to its associated bone’s space using the natural pose’s inverse transformation 3.Multiple the influence weight 4.Accumulate all influences 5.Then the vertex is deformed by the bone in “base” space

33 M b = R b T pivot M a = R a T position M vb = M nb -1 M b M a M va = M na -1 M a v in_base = v s *w a M va + v s *w b M vb A two-weight skin vertex example


Download ppt "Character Motion 王銓彰 2014. ■ We use Cartesian coordinate system ( 笛卡兒座標系 ) for 3D. ■ We use right-hand rule for axis orientation. ■ x."

Similar presentations


Ads by Google