Download presentation
Presentation is loading. Please wait.
Published byTodd Terry Modified over 9 years ago
1
3D Graphics for Game Programming (J. Han) Chapter XI Character Animation
2
3D Graphics for Game Programming (J. Han) 2 11-2 Keyframe Animation in 2D In the traditional hand-drawn cartoon animation, the senior key artist would draw the keyframes, and the junior artist would fill the in-between frames. The similar applies to computer animation. For a 30-fps animation, for example, much fewer than 30 frames are defined per second. They are the keyframes. In real-time computer animation, the in-between frames are automatically filled at run time. The key data are assigned to the keyframes, and they are interpolated to generate the in-between frames. Any data that change in the time domain can be interpolated.
3
3D Graphics for Game Programming (J. Han) Euler Angles 3 2-3 Recall Euler angles and Euler transform.
4
3D Graphics for Game Programming (J. Han) 4 11-4 Keyframe Animation in 3D Keyframe animation in 3D: Seven teapot instances are defined by sampling the graphs seven times.
5
3D Graphics for Game Programming (J. Han) 5 11-5 Keyframe Animation (cont’d) Smoother animation may often be obtained using a higher-order interpolation.
6
3D Graphics for Game Programming (J. Han) 6 11-6 A Problem of Euler Angles A problem of Euler angles is that they are not always correctly interpolated.
7
3D Graphics for Game Programming (J. Han) 7 11-7 Quaternion A quaternion is an extended complex number. Conjugate Magnitude (If the magnitude of a quaternion is 1, it’s called a unit quaternion.)
8
3D Graphics for Game Programming (J. Han) 8 11-8 Quaternion (cont’d) Recall 2D rotation Let us represent (x,y) by a complex number x+yi, and denote it by p. Given the rotation angle , the polar form of a unit-length complex number is defined as cos +sin i. Let us denote it by q. Then, we have the following: Surprisingly, the real and imaginary parts of pq represent the rotated coordinates.
9
3D Graphics for Game Programming (J. Han) 9 11-9 Quaternion (cont’d) 3D rotation can be similarly described using quaternions. Consider rotating a 3D vector p about an axis u by an angle . Both the vector to be rotated and the rotation are represented in quaternions. Vector p to a quaternion p The rotation axis u and rotation angle define another quaternion q. (The axis u is divided by its length to make a unit vector u.) Then, the rotated vector is equivalent to the imaginary part of.
10
3D Graphics for Game Programming (J. Han) 10 11-10 Quaternion (cont’d) Proof
11
3D Graphics for Game Programming (J. Han) 11 11-11 Quaternion (cont’d) Consider two unit quaternions, p and q, which represent rotations. They can be interpolated using parameter t in the range of [0,1]: This is called spherical linear interpolation (slerp). If quaternions are defined for the keyframes, they can be interpolated for the in-between frames.
12
3D Graphics for Game Programming (J. Han) 12 11-12 Quaternion (cont’d) Proof
13
3D Graphics for Game Programming (J. Han) 13 11-13 Quaternion (cont’d) A quaternion q representing a rotation can be converted into a matrix form. If q = (q x,q y,q z,q w ), the rotation matrix is defined as follows: Conversely, given a rotation matrix, we can compute the corresponding quaternion.
14
3D Graphics for Game Programming (J. Han) 14 11-14 Quaternion (cont’d) Proof
15
3D Graphics for Game Programming (J. Han) 15 11-15 Quaternion (cont’d) Summary A 3D rotation is represented in a quaternion. Quaternions are well interpolated through spherical linear interpolation. A quaternion can be converted into a rotation matrix.
16
3D Graphics for Game Programming (J. Han) 16 11-16 Quaternion (cont’d)
17
3D Graphics for Game Programming (J. Han) 17 11-17 Skeleton A popular method for animating a character is to use a skeleton, which is composed of bones. The skeleton is embedded into the polygon mesh. When the skeleton is animated, the vertices of the polygon mesh will be accordingly animated.
18
3D Graphics for Game Programming (J. Han) 18 11-18 Skeleton (cont’d) Skeleton editing and embedding The skeleton template such as 3ds Max biped is positioned in the default pose. The bones are edited. The skeleton is made to fit to the polygon mesh.
19
3D Graphics for Game Programming (J. Han) 19 11-19 Skeleton (cont’d)
20
3D Graphics for Game Programming (J. Han) 20 11-20 Skeleton (cont’d)
21
3D Graphics for Game Programming (J. Han) 21 11-21 Space Change between Bones The bones are connected at joints, which allow the rigid skeleton to animate in an articulated fashion. See the example, which consists of three bones (upper arm, forearm, and hand) and three joints (shoulder, elbow, and wrist). When the forearm moves, for example, v f has to move accordingly. It is simply achieved if v f is defined in the forearm's object space. Initially, all vertices of the default pose are defined in the object space of the character. To avoid confusion with the object space of a bone, let’s use the term, world space, instead of the character’s object space. Every world-space vertex of the default pose needs to be transformed into the object space of the bone (which we call bone space henceforth) it belongs to. For example, v f will be transformed into the forearm's bone space so as to have the coordinates (2,0).
22
3D Graphics for Game Programming (J. Han) 22 11-22 Space Change between Bones (cont’d) For now, consider the opposite direction, i.e., from the bone space to the world space. If we can compute such a bone-to-world transform, its inverse can be used to convert a world-space vertex into the bone space. Consider the to-parent transform of the forearm, which transforms a forearm vertex to the space of its parent. Now consider the to-parent matrix of the hand. Given a vertex at a bone, we can concatenate the to-parent matrices so as to transform the vertex into the bone space of any ancestor in the skeleton.
23
3D Graphics for Game Programming (J. Han) 23 11-23 World Space to Bone Space The root node (pelvis) is associated with a transform used to position and orient it in the world space for the default pose. It is an identity matrix because the world space is in fact the object space of the character. Let us denote the world matrix by M 1,d. The spine's world transform The clavicle’s world transform Let’s generalize
24
3D Graphics for Game Programming (J. Han) 24 11-24 World Space to Bone Space (cont’d) So far, we have considered the world transform from the bone space to the world space. However, what is needed in an articulated-body animation is its inverse. Once the default pose is fixed, the inverse world transforms can be computed for all bones. In the default pose, M i,p -1 can be immediately obtained. Computing M i,d -1 requires M i-1,d -1 to be computed in advance, and therefore the skeleton hierarchy is travdersed top down.
25
3D Graphics for Game Programming (J. Han) 25 11-25 Forward Kinematics The inverse of the world transform converts a world-space vertex “in the default pose” to the i-th bone's space. Now the i-th bone is animated. Then, the vertices belonging to the bone are accordingly animated. The animation is often called local transform. For rendering, the animated vertices should be transformed back to the world space. (Then, they will be transformed to the camera space and so forth, along the pipeline.) Let us call the transform matrix M 5,w.
26
3D Graphics for Game Programming (J. Han) 26 11-26 Forward Kinematics (cont’d) As the first step for computing the world-space position of “animated v 5,” let us find its coordinates in the upper arm's space. The upper arm can also be animated. Let M 4,w denote the matrix that transforms the animated vertices of the upper arm into the world space. Then, M 5,w for transforming “animated v 5 ” into the world space is defined. Let’s generalize.
27
3D Graphics for Game Programming (J. Han) 27 11-27 Forward Kinematics (cont’d) When the artist defines the animated pose of the i-th bone, M i,l is obtained. M i,p was obtained from the default pose. So, computing M i,w simply requires M i-1,w to be computed in advance. M 1,w representing the pose of the animated pelvis is defined by the artist. We can compute the world transforms of all bones “in the animated pose” also in the top-down fashion. When v d and v w denote the world-space vertices “in the default pose” and “in the animated pose,” respectively, we have the following relation:
28
3D Graphics for Game Programming (J. Han) When v 2 belongs to the forearm, M f,w M f,d -1 produces v 2 ´. Similarly, v 1 ´ and v 3 ´ can be produced. In skinning, v 2 is transformed not only by M f,w M f,d -1 but also by M u,w M u,d -1. Then, the transformed vertices are interpolated using the predefined weights. The same applies to v 1 and v 3. 28 11-28 Skinning
29
3D Graphics for Game Programming (J. Han) 29 11-29 Skinning (cont’d) Suppose that w 5 and w 6 are equal.
30
3D Graphics for Game Programming (J. Han) 30 11-30 Skinning in Keyframe Animation Recall the following: The local transform M i,l is an affine transform (usually a rotation). The to-parent transform M i,p is a space-change matrix composed of a translation and a rotation. Let us combine M i,l and M i,p into a single matrix and name it M c. Its upper-left 3x3 sub-matrix represents a combined rotation. Its fourth column represents a combined translation. For a keyframe, the rotation part of M c is stored as a quaternion, and the translation is stored as a vector. They form the key data “of a bone.” For an in-between frame, both the quaternions and translational vectors of the keyframes are interpolated. The interpolated quaternion is converted into a matrix. The interpolated translation vector fills the fourth column of the matrix, which can then be called the “interpolated M c.” It is combined with the parent bone's world transform M i-1,w so as to complete M i,w. (For this purpose, top-down traversal is needed.)
31
3D Graphics for Game Programming (J. Han) 31 11-31 Skinning in Keyframe Animation (cont’d) The following CPU pseudo computes Mi, which is M i,w M i,d -1, and store it in the matrix palette.
32
3D Graphics for Game Programming (J. Han) 32 11-32 Skinning in Keyframe Animation (cont’d)
33
3D Graphics for Game Programming (J. Han) 33 11-33 Skinning in Keyframe Animation (cont’d) The indices of MatrixIndex are three times the actual indices, e.g., not (0,2,7,18) but (0,6,21,54).
34
3D Graphics for Game Programming (J. Han) 34 11-34 Skinning in Keyframe Animation (cont’d)
35
3D Graphics for Game Programming (J. Han) 35 11-35 Motion Capture
36
3D Graphics for Game Programming (J. Han) 36 11-36 Inverse Kinematics In robotics, an end effector refers to the device located at the end of a robotic arm. Forward kinematics computes the pose of the end effector as a function of the joint angles of the robotic arm. The reverse process is called inverse kinematics (IK). Given the desired pose of the end effector along with the initial pose of the robotic arm, the joint angles of the final pose are calculated. The number of independent variables defining the state of an object is called the degrees of freedom (DOF).
37
3D Graphics for Game Programming (J. Han) 37 11-37 Inverse Kinematics - Analytic Solution
38
3D Graphics for Game Programming (J. Han) 38 11-38 Inverse Kinematics - Cyclic Coordinate Descent
39
3D Graphics for Game Programming (J. Han) 39 11-39 Inverse Kinematics - Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.