Lecture 2: linear algebra, animation basics. The magnitude (length) of a vector is: Unit vector...

67
Computer Animation Lecture 2: linear algebra, animation basics

Transcript of Lecture 2: linear algebra, animation basics. The magnitude (length) of a vector is: Unit vector...

Page 1: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Computer AnimationLecture 2: linear algebra, animation basics

Page 2: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Vector Arithmetic

zyx

zyx

zzyyxx

zzyyxx

zyx

zyx

sasasas

aaa

bababa

bababa

bbb

aaa

a

a

ba

ba

b

a

Page 3: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Vector Magnitude

The magnitude (length) of a vector is:

Unit vector (magnitude=1.0)

222zyx vvv v

v

v

Page 4: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Dot Product

cosbaba

ba

iizzyyxx babababa

Page 5: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Angle Between Vectors

How do you find the angle θ between vectors a and b?

a

b θ

Page 6: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Angle Between Vectors

ba

ba

ba

ba

baba

1cos

cos

cos

a

b θ

Page 7: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Dot Products with Unit Vectors

bθ a

a·b = 00 < a·b < 1

a·b = -1

a·b = 1

-1 < a·b < 0

cos

0.1

ba

baa·b

Page 8: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Dot Products with Non-Unit Vectors If a and b are arbitrary (non-unit)

vectors, then the following are still true:

If θ < 90º then a·b > 0 If θ = 90º then a·b = 0 If θ > 90º then a·b < 0

Page 9: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Dot Products with One Unit Vector

a

u

a·u

If |u|=1.0 then a·u is the length of the projection of a onto u

Page 10: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Cross Product

xyyxzxxzyzzy

zyx

zyx

babababababa

bbb

aaa

kji

ba

ba

Page 11: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Properties of the Cross Product

ba

ba

ba

baba

0

sin

area of parallelogram ab

is perpendicular to both a and b, in the direction defined by the right hand rule

if a and b are parallel

Page 12: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Area of a Triangle

Find the area of the triangle defined by 3D points a, b, and c

ab

c

Page 13: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Area of a Triangle

acab 2

1area

b-a

c-a

ab

c

Page 14: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Alignment to Target

An object is at position p with a unit length heading of h. We want to rotate it so that the heading is facing some target t. Find a unit axis a and an angle θ to rotate around.

ph

t

Page 15: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example: Alignment to Target

ph

tt-p

θ

a

pt

pth

pth

ptha

1cos

Page 16: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Trigonometry

1.0

cos θ

sin θ

θ

cos2θ + sin2θ = 1

Page 17: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Laws of Sines and Cosines

a

b

c

β

γ

α

cos2

sinsinsin

222 abbac

cba

Law of Sines:

Law of Cosines:

Page 18: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Matrices

Computer graphics apps commonly use 4x4 homogeneous matrices

A rigid 4x4 matrix transformation looks like this:

Where a, b, & c are orthogonal unit length vectors representing orientation, and d is a vector representing position

1

0

0

0

zyx

zyx

zyx

zyx

ddd

ccc

bbb

aaa

Mx

y

z

a

b

c d

Page 19: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Matrices

The right hand column can cause a projection, which we won’t use in character animation, so we leave it as 0,0,0,1

Some books store their matrices in a transposed form. This is fine as long as you remember that: (A·B)T = BT·AT

Page 20: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Orthonormality

If all row vectors and all column vectors of a matrix are unit length, that matrix is said to be orthonormal

This also implies that all vectors are perpendicular to each other

Orthonormal matrices have some useful mathematical properties, such as: M-1 = MT

Page 21: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Orthonormality

If a 4x4 matrix represents a rigid transformation, then the upper 3x3 portion will be orthonormal

bac

acb

cba

cba

1

Page 22: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Determinants

The determinant of a 4x4 matrix with no projection is equal to the determinant of the upper 3x3 portion

cba

zyx

zyx

zyx

zyx

zyx

zyx

zyx

ccc

bbb

aaa

ddd

ccc

bbb

aaa

1

0

0

0

Page 23: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Determinants

The determinant is a scalar value that represents the volume change that the transformation will cause

An orthonormal matrix will have a determinant of 1, but non-orthonormal volume preserving matrices will have a determinant of 1 also

A flattened or degenerate matrix has a determinant of 0

A matrix that has been mirrored will have a negative determinant

Page 24: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Transformations

To transform a vector v by matrix M:

v’=v·M

If we want to apply several transformations, we can just multiply by several matrices:

v’=(((v·M1)·M2)·M3)·M4…

Or we can concatenate the transformations into a single matrix:

Mtotal=M1·M2·M3·M4…v’=v·Mtotal

Page 25: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Matrix Transformations

We usually transform vertices from some local space where they are defined into a world space

v’ = v·W Once in world space, we can perform operations

that require everything to be in the same space (collision detection, high quality lighting…)

Then, they are transformed into a camera’s space, and then projected into 2D

v’’ = v’·C-1·P In simple situations, we can do this all in one

step:v’’ = v·W·C-1·P

Page 26: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Inversion

If M transforms v into world space, then M-1 transforms v’ back into local space

IMM

Mvv

Mvv

1

1

Page 27: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Vector Dot Vector

zzyyxx

zyx

zyx

bababa

bbb

aaa

ba

b

a

Page 28: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Vector Dot Matrix

zzzyzxz

yzyyyxy

xzxyxxx

zyx

cvbvavv

cvbvavv

cvbvavv

vvv

Mvv

v

zyx

zyx

zyx

ccc

bbb

aaa

M

cbav zyx vvv

Page 29: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Matrix Dot Matrix

NML

333231

232221

131211

333231

232221

131211

333231

232221

131211

nnn

nnn

nnn

mmm

mmm

mmm

lll

lll

lll

32132212121112 nmnmnml

Ncc

Nbb

Naa

ML

ML

ML

Page 30: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Homogeneous Vectors

Technically, homogeneous vectors are 4D vectors that get projected into the 3D w=1 space

w

z

w

y

w

xwzyx v

v

v

v

v

vvvvv

Page 31: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Homogeneous Vectors

Vectors representing a position in 3D space can just be written as:

Vectors representing direction are written:

The only time the w coordinate will be something other than 0 or 1 is in the projection phase of rendering, which is not our problem

1zyx vvv

0zyx vvv

Page 32: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Position Vector Dot Matrix

1

1

w

zzzzyzxz

yyzyyyxy

xxzxyxxx

zyx

v

dcvbvavv

dcvbvavv

dcvbvavv

vvv

Mvv

v

dcbav zyx vvv

1

0

0

0

zyx

zyx

zyx

zyx

ddd

ccc

bbb

aaa

M

Page 33: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)

Page 34: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)x

y

World Space

(0,0,0)

a

b

d

Matrix M

Page 35: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)x

y

World Space

(0,0,0)

a

b

d

v’

Page 36: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Direction Vector Dot Matrix

0

0

w

zzzyzxz

yzyyyxy

xzxyxxx

zyx

v

cvbvavv

cvbvavv

cvbvavv

vvv

Mvv

v

cbav zyx vvv

1

0

0

0

zyx

zyx

zyx

zyx

ddd

ccc

bbb

aaa

M

Page 37: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Matrix Dot Matrix (4x4)

1

0

0

0

zyx

zyx

zyx

zyx

ddd

ccc

bbb

aaa

MNMM

The row vectors of M’ are the row vectors of M transformed by matrix N

Notice that a, b, and c transform as direction vectors and d transforms as a position

Page 38: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Identity

Take one more look at the identity matrix It’s a axis lines up with x, b lines up with y, and c

lines up with z Position d is at the origin Therefore, it represents a transformation with no

rotation or translation

1000

0100

0010

0001

I

Page 39: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Animation basics

Page 40: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Animation Process

while (!finished){ UpdateEverything(); DrawEverything();}

Interactive vs. Non-Interactive Real Time vs. Non-Real Time

Page 41: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Frame Rates

Film 24 fps Imax 48 fps NTSC TV 30 fps (interlaced) PAL TV 25 fps (interlaced) HDTV 50-60 fps Computer >60 fps

Page 42: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Animation Tools

Animation tools: Maya 3D Studio Max MotionBuilder Blender

Game/graphics engines: OGRE3D Unity Unreal

Page 43: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Virtual Characters

Applications of animated characters Health

▪ Analyzing walking styles▪ Analyzing muscle activations▪ Analyzing joint movement limits

Ergonomics▪ Usability of devices▪ Measuring comfort

Safety▪ Simulated worlds for crisis

management Entertainment

▪ Games, movies

Page 44: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Virtual Characters

Different approaches: Keyframe animation Motion Capture Physics-based animation Procedural animation

Page 45: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Different levels of character motion

Virtual Characters

Page 46: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Representation: skeletal model A VH is represented by a polyhedral

model (or mesh) An underlying skeleton deforms this

mesh▪ Joints, connected by bones

A pose is defined by the rotations of the joints and the position of the root joint

Several standards ▪ H-Anim

Virtual Characters

Page 47: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Kinematics

Kinematics The analysis of motion independent of physical

forces. Kinematics deals with position, velocity, acceleration, and their rotational counterparts, orientation, angular velocity, and angular acceleration.

Forward Kinematics The process of computing world space

geometric data from DOFs Inverse Kinematics

The process of computing a set of DOFs that causes some world space goal to be met (I.e., place the hand on the door knob…)

Page 48: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Skeletons

Skeleton A pose-able framework of joints arranged in a

tree structure. Joint

Allows relative movement within the skeleton. Are essentially 4x4 matrix transformations Can be rotational, translational, or other Synonym: bone

Page 49: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

DOFs

Degree of Freedom (DOF) A variable φ describing a particular axis or

dimension of movement within a joint Joints typically have around 1-6 DOFs (φ1…

φN) Changing the DOF values over time

results in the animation of the skeleton Note: in a mathematical sense, a free rigid

body has 6 DOFs: 3 for position and 3 for rotation

Page 50: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Example Joint Hierarchy

Root

Torso

Neck

Pelvis

HipL HipR

Head ElbowL

WristL

ElbowR

WristR

KneeL

AnkleL

KneeR

AnkleR

ShoulderL ShoulderR

Page 51: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Joints

Core Joint Data DOFs (N floats) Local matrix: L World matrix: W

Additional Data Joint offset vector: r DOF limits (min & max value per DOF) Type-specific data (rotation/translation axes,

constants…) Tree data (pointers to children, siblings,

parent…)

Page 52: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Skeleton Posing Process

1. Specify all DOF values for the skeleton (done by higher level animation system)

2. Recursively traverse through the hierarchy starting at the root and use forward kinematics to compute the world matrices (done by skeleton system)

3. Use world matrices to deform skin & render (done by skin system)

Note: the matrices can also be used for other things such as collision detection, FX, etc.

Page 53: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Forward Kinematics

In the recursive tree traversal, each joint first computes its local matrix L based on the values of its DOFs and some formula representative of the joint type:

Local matrix L = Ljoint(φ1,φ2,…,φN)

Then, world matrix W is computed by concatenating L with the world matrix of the parent joint

World matrix W = L · Wparent

Page 54: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Joint Offsets

It is convenient to have a 3D offset vector r for every joint which represents its pivot point relative to its parent’s matrix

1

0100

0010

0001

zyx

offset

rrr

L

Page 55: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

DOF Limits

It is nice to be able to limit a DOF to some range (for example, the elbow could be limited from 0º to 150º)

Usually, in a realistic character, all DOFs will be limited except the ones controlling the root

Page 56: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Poses

One can then adjust each of the DOFs to specify the pose of the skeleton

We can define a pose Φ more formally as a vector of N numbers that maps to a set of DOFs in the skeleton

Φ = [φ1 φ2 … φN] A pose is a convenient unit that can be

manipulated by a higher level animation system and then handed down to the skeleton

Usually, each joint will have around 1-6 DOFs, but an entire character might have 100+ DOFs in the skeleton

Page 57: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Joint Types

Page 58: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Joint Types

Rotational Hinge: 1-DOF Universal: 2-DOF Ball & Socket: 3-DOF

▪ Euler Angles▪ Quaternions

Translational Prismatic: 1-DOF Translational: 3-DOF (or any number)

Compound Free Screw Constraint Etc.

Non-Rigid Scale Shear Etc.

Design your own...

Page 59: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Hinge Joints (1-DOF Rotational)

1

0cossin0

0sincos0

0001

zyx

xx

xxxRx

rrr

L

Rotation around the x-axis:

Page 60: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Hinge Joints (1-DOF Rotational)

1

0cos0sin

0010

0sin0cos

zyx

yy

yy

yRy

rrr

L

Rotation around the y-axis:

Page 61: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Hinge Joints (1-DOF Rotational)

1

0100

00cossin

00sincos

zyx

zz

zz

zRz

rrr

L

Rotation around the z-axis:

Page 62: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Hinge Joints (1-DOF Rotational)

Rotation around an arbitrary axis a:

1

0)1()1()1(

0)1()1()1(

0)1()1()1(

22

22

22

zyx

zzxzyyzx

xzyyyzyx

yzxzyxxx

Ra

rrr

acasacaasacaa

sacaaacasacaa

sacaasacaaaca

L

Page 63: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Universal Joints (2-DOF)

For a 2-DOF joint that first rotates around x and then around y:

Different matrices can be formed for different axis combinations

1

0

0

00

,

zyx

yxxyx

yxxyx

yy

yxRxy

rrr

ccssc

cscss

sc

L

Page 64: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Ball & Socket (3-DOF)

For a 3-DOF joint that first rotates around x, y, then z:

Different matrices can be formed for different axis combinations

1

0

0

0

,,

zyx

yxzxzyxzxzyx

yxzxzyxzxzyx

yzyzy

zyxRxyz

rrr

cccssscsscsc

csccssssccss

ssccc

L

Page 65: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Quaternions

wzyx qqqqq

12222 wzyx qqqqq

2cos

2sin

2sin

2sin

zyx aaaq

1

02212222

02222122

02222221

22

22

22

zyx

yxxwzyywzx

xwzyzxzwyx

ywzxzwyxzy

Q

rrr

qqqqqqqqqq

qqqqqqqqqq

qqqqqqqqqq

qL

Page 66: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Prismatic Joints (1-DOF Translation)

1-DOF translation along an arbitrary axis a:

1

0100

0010

0001

zzyyxx

Ta

atratratr

tL

Page 67: Lecture 2: linear algebra, animation basics.  The magnitude (length) of a vector is:  Unit vector (magnitude=1.0)

Translational Joints (3-DOF)

For a more general 3-DOF translation:

1

0100

0010

0001

zzyyxx

Txyz

trtrtr

tL