33
Character Motion 王王王 [email protected] 2014

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

Embed Size (px)

Citation preview

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

Character Motion

王銓彰[email protected]

2014

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

■ 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

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

■ 3D球座標系■ P(ϱ,φ,q)

Spherical Coordinate System

+y-y

-z

+z

-x

+x

x

y

zP(, ,)

P(x,y)

r

z=P·cos

o

x=r·cos=·sin·cosy=r·sin= ·sin·sin

3D Spherical Coordinates

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

■ 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 + DV’ = VSV’ = VR

where D is a translation vector andS and R are scaling and rotation matrices

Matrices (1/3)

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

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 + Tx

y’ = y + Ty

z’ = z + Tz

V’ = VT

[x’ y’ z’ 1] = [x y z 1]

= [x y z 1] T

1 0 0 00 1 0 00 0 1 0Tx Ty Tz 1

Matrices (2/3)

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

Net Transformation matrix

[x’ y’ z’ 1] = [x y z 1] M1

and

[x” y” z” 1] = [x’ y’ z’ 1] M2

then the transformation matrices can be concatenated

M3 = M1 M2

and

[x” y” z” 1] = [x y z 1] M3

M1 M2 = M2 M1

Matrices (3/3)

Matrix multiplication are not commutative

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

Two representations :

Transformation for Vertices

<V’> = <V> [M1]

The vertices are in row matrix form.

{V’} = [M2 ]{V}

The vertices are in column matrix form

If these two transformations are identical, M1 & M2 are transpose.

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

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(q1, q2, q3) represents an x-roll, followed by y-roll, followed by z-roll

R(q1, q2, q3) = c2c3 c2s3 -s2 0 s1s2c3-c1s3 s1s2s3+c1c3 s1c2 0 c1s2c3+s1s3 c1s2s3-s1c3 c1c2 0 0 0 0 1 where si = sinqi and ci = cosqi

Euler Angles

There are 6 possible ways to define a rotation. 3!

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

Interpolation happening on each angle Multiple routes for interpolation More keys for constrains

z

x

y

Rz

x

y

R

Euler Angles & Interpolation

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

R(q, n), n is the rotation axis.

n

r Rr

q

n

r

rv

rh

V

qrv

V

Rr

rh = (n.r)nrv = r - (n.r)n , rotate into position Rrv

V = nxrv = nxr

Rrv = (cosq)rv + (sinq)V-> Rr = Rrh + Rrv

= rh + (cosq)rv + (sinq)V = (n.r)n + (cosq) (r - (n.r)n) + (sinq) nxr = (cosq)r + (1-cosq) n (n.r) + (sinq) nxr

Angular Displacement – Rotation with An Arbitrary Axis

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

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 i2 = j2 = k2 = -1 ij = k & ji = -k, cyclic permutation i-j-k-i q = (s, v), where (s, v) = s + vxi + vyj + vzk

Quaternion

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

q1 = (s1, v1) and q2 = (s2, v2)

q3 = q1q2 = (s1s2 - v1.v2 , s1v2 + s2v1 + v1xv2)

Conjugate of q = (s, v), q = (s, -v)

qq = s2 + |v|2 = |q|2

A unit quaternion q = (s, v), where qq = 1

A pure quaternion p = (0, v)

Non-commutative

Quaternion Algebra

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

Take a pure quaternion p = (0, r)and a unit quaternion q = (s, v) where qq = 1and define Rq(p) = qpq-1 where q-1 = q for a unit quaternion

Rq(p) = (0, (s2 - v.v)r + 2v(v.r) + 2svxr)

Let q = (cosf, sin f n), |n| = 1

Rq(p) = (0, (cos2 f - sin2f)r + 2sin2f n(n.r) + 2cosfsinf nxr) = (0, cos2fr + (1 - cos2f)n(n.r) + sin2f nxr)

Conclusion :The act of rotating a vector r by an angular displacement (q, n) is the same as taking this displacement, ‘lifting’ it into quaternion space, by using a unit quaternion (cos(q/2), sin(q/2) n)

Quaternion VS Angular Displacement

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

1-2y2-2z2 2xy-2wz 2xz+2wy 02xy+2wz 1-2x2-2z2 2yz-2wx 02xz-2wy 2yz+2wx 1-2x2-2y2 0 0 0 0 1

q = (w,x,y,z)

Quaternion VS Rotation Matrix

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

M0 M1 M2 0M3 M4 M5 0M6 M7 M8 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]; }

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

Spherical linear interpolation, slerp

A

B

P

f

t

slerp(q1, q2, t) = q1 + q2

sin((1 - t)f)sinf sinf

sin(tf)

Quaternion Interpolation

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

Bone structure Motion Pose management Skin deformation

Characters in Games

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

In regular, we implement a biped character in the game engine. Hierarchical bone structure

– Easy to implement– Implement with the scene tree

Root-base system– Base object

» The parent node of the whole body– Movement controls

With geometry on bones or not– Rigid skin

Skin deformation in game

Skeleton (1/2)

Base

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

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_lhand_r

Base

head

body

up arm

fore arm

handgroin

thigh

shinfoot

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

Pivot– Offset position in parent space– Local rotation center– Fixed length

Transformation

A Bone

Parentbone

Joint = pivot(px,py,pz) in A

A

B

(x,y,z,q,axis)

(q,axis)

<v’> = <v> [RB][TB][RA][TA]

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

Base node is used for movement control. Root nodes are used for playing poses.

Base

Root(groin)

Base

The Root-Base Concept

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

Position– Fixed pivot– Time-dependent position

Rotation– Rotation with pivot

Scaling– Rare to use– Use carefully

Motion Data in Games

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

Euler angles– 3 floating-point reals

Quaternion– 4 floating-point reals

Rotation with an arbitrary axis– Angular displacement– 4 floating-point real numbers

Matrix– 9 floating-point real numbers

Rotation Data on Joints (1/2)

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

Rotation Data on Joints (2/2)

Quaternion interpolationMatrix

(q, n)

Euler angles

Bone

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

Run-time or pre-processing 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

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

walkstart_frame end_frame

cut_frame

Parameter { start_frame end_frame cut_frame}

Pose Definition

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

walk

0 4 8

Frame 5.3

1. If the motion data is in quaternion form2. Get the motion data on frame 5 & 63. Convert the data into quaternion format4. Apply slerp(5, 6, 0.3) to get the interpolation on frame 5.35. Convert the result of step 3 into a rotation matrix6. Apply the matrix to the object for its transformation

Play a Pose

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

Pose 1

Pose 2

cut_frame

start_frame

length

Pose Connection

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

29

Motion blending in run-time Quaternion is used “Blend Tree”

– Cross fade– Continuous blending– Feather blending

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

ForwardMotion

FallDown

Walk

Run

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

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

Natural Pose

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

Weights to assign the influences of the deformation by bones on skin vertices– 1-weight– 2-weight– N-weight

CPU cost Another way to perform the skin deformation calculation is using vertex

shader 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

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

Bone A(root object)

Bone B(Bone A’s child)

base

base

1. Apply motion data to bones2. Convert the vertex from “base” space to its associated

bone’s space using the natural pose’s inverse transformation

3. Multiple the influence weight4. Accumulate all influences5. Then the vertex is deformed by the bone in “base” space

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

Mb = RbTpivot

Ma = RaTposition

Mvb = Mnb-1 MbMa

Mva = Mna-1Ma

vin_base = vs*waMva + vs*wbMvb

A two-weight skin vertex example