CSCE 552 Spring 2009 Animation By Jijun Tang. Inverse of 4x4.

Post on 06-Jan-2018

236 views 1 download

description

2D Example θ

Transcript of CSCE 552 Spring 2009 Animation By Jijun Tang. Inverse of 4x4.

CSCE 552 Spring 2009

Animation

By Jijun Tang

Inverse of 4x4

1 1 1 111 12 13

1 1 1 1 1 121 22 23

11 1 1 1

31 32 33

1 0 0 0 1

x

y

z

R R R

R R R

R R R

R T

R R T R TM

R T

0

2D Example

θ

Rotation Around Arbitrary VectorRotation about an arbitrary vector Counterclockwise rotation about an arbitrary vector (lx,ly,lz) normalised so that                    by an angle α is given by a matrix

                                                                           

where

Translation

A 3 3 matrix can reorient the coordinate axes in any way, but it leaves the origin fixed

We must add a translation component D to move the origin:

Homogeneous coordinates

Four-dimensional space Combines 3 3 matrix and translation

into one 4 4 matrix

What is Physics Simulation?

The Cycle of Motion: Force, F(t), causes acceleration Acceleration, a(t), causes a change in velocity Velocity, V(t) causes a change in position

Physics Simulation:Solving variations of the above equations over time to emulate the cycle of motion

Concrete Example: Target Practice

F = w eig ht = m gTarget

Projectile LaunchPosition, pinit

Errors

Exact

Euler

Overlap Testing Results

Useful results of detected collision Pairs of objects will have collision Time of collision to take place Collision normal vector

Collision time calculated by moving object back in time until right before collision Bisection is an effective technique

Bisect Testing: collision detected

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Bisect Testing: Iteration I

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Bisect Testing: Iteration II

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Bisect Testing: Iteration III

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Bisect Testing: Iteration IV

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Bisect Testing: Iteration V

B B

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

Time right before the collision

Overlap Testing: Limitations

Fails with objects that move too fast Thin glass vs. bulltes Unlikely to catch time slice during overlap

t0t -1 t1 t2b u lle t

w in d o w

Intersection Testing (a priori)

Predict future collisions When predicted:

Move simulation to time of collision Resolve collision Simulate remaining time step

Intersection Testing:Swept Geometry

Extrude geometry in direction of movement Swept sphere turns into a “capsule” shape

t0

t1

Simplified Geometry

Approximate complex objects with simpler geometry, like this ellipsoid or bounding boxes

Minkowski Sum

By taking the Minkowski Sum of two complex volumes and creating a new volume, overlap can be found by testing if a single point is within the new volume

Minkowski Sum

Y}B and :{ XABAYX

X Y =YX X Y =

Using Minkowski Sum

t0

t1

t0

t1

Reduce Number of Detections

O(n) Time Complexity can be achieved.One solution is to partition space

Achieving O(n) Time Complexity

Another solution is the plane sweep algorithmRequires (re-)sorting in x (y) coordinate

C

B

R

A

x

y

A0 A 1 R 0 B0 R 1 C 0 C 1B1

B0

B1A1

A0

R 1

R 0

C 1

C 0

Animation Overview Fundamental Concepts Animation Storage Playing Animations Blending Animations Motion Extraction Mesh Deformation Inverse Kinematics Attachments & Collision Detection Conclusions

Animation Roles

Programmer – loads information created by the animator and translates it into on screen action.

Animator – Sets up the artwork. Provides motion information to the artwork.

Different types of animation

Particle effects Procedural / Physics “Hard” object animation (door, robot) “Soft” object animation (tree swaying in

the wind, flag flapping the wind) Character animation

2D Versus 3D Animation

Borrow from traditional 2D animation

Understand the limitations of what can be done for real-time games

Designing 3D motions to be viewed from more than one camera angle

Pace motion to match game genre

Animation terms frame – an image that is displayed on the screen, usually as pa

rt of a sequence.

pose – an orientation of an objects or a hierarchy of objects that defines extreme or important motion.

keyframe – a special frame that contains a pose.

tween – the process of going “between” keyframes.

secondary motion – an object motion that is the result of its connection or relationship with another object.

Fundamental Problems

Volume of data, processor limitations

Mathematical complexity, especially for rotations.

Translation of motion

Fundamental Concepts Skeletal Hierarchy The Transform Euler Angles The 3x3 Matrix Quaternions Animation vs Deformation Models and Instances Animation Controls

Skeletal Hierarchy

The Skeleton is a tree of bones Modelling characters Often flattened to an array in practice Each bone has a transform, stored relative to its

parent’s transform Top bone in tree is the “root bone”

Normally the hip May have multiple trees, so multiple roots

Transforms are animated over time Tree structure is often called a “rig”

Example

The Transform

“Transform” is the term for combined: Translation Rotation Scale Shear

Can be represented as 4x3 or 4x4 matrix But usually store as components Non-identity scale and shear are rare

Examples

Euler Angles

Three rotations about three axes Intuitive meaning of values

Euler Angles

This means that we can represent an orientation with 3 numbers

A sequence of rotations around principle axes is called an Euler Angle Sequence

Assuming we limit ourselves to 3 rotations without successive rotations about the same axis, we could use any of the following 12 sequences:

XYZ XZY XYX XZXYXZ YZX YXY YZYZXY ZYX ZXZ ZYZ

Using Euler Angles

To use Euler angles, one must choose which of the 12 representations they want

There may be some practical differences between them and the best sequence may depend on what exactly you are trying to accomplish

Interpolating Euler Angles

One can simply interpolate between the three values independently

This will result in the interpolation following a different path depending on which of the 12 schemes you choose

This may or may not be a problem, depending on your situation

Note: when interpolating angles, remember to check for crossing the +180/-180 degree boundaries

Problems

Euler Angles Are Evil No standard choice or order of axes Singularity “poles” with infinite number of

representations Interpolation of two rotations is hard Slow to turn into matrices

Use matrix rotation

Rotation Matrix

3x3 Matrix Rotation

Easy to use Moderately intuitive Large memory size - 9 values Interpolation is hard

Introduces scales and shears Need to re-orthonormalize matrices after

Quaternions

Quaternions are an interesting mathematical concept with a deep relationship with the foundations of algebra and number theory

Invented by W.R.Hamilton in 1843 In practice, they are most useful to use as a

means of representing orientations A quaternion has 4 components

3210 qqqqq

Quaternions on Rotation

Represents a rotation around an axis Four values <x,y,z,w> <x,y,z> is axis vector times sin(angle/2) w is cos(angle/2) No singularities

But has dual coverage: Q same rotation as –Q This is useful in some cases!

Interpolation is fast

Illustration

Quaternions (Imaginary Space)

Quaternions are actually an extension to complex numbers

Of the 4 components, one is a ‘real’ scalar number, and the other 3 form a vector in imaginary ijk space!

3210 kqjqiqq q

jiijkikkijkjjki

ijkkji

1222

Quaternions (Scalar/Vector)

Sometimes, they are written as the combination of a scalar value s and a vector value v

where

321

0

qqqqs

v

vq ,s

Unit Quaternions

For convenience, we will use only unit length quaternions, as they will be sufficient for our purposes and make things a little easier

These correspond to the set of vectors that form the ‘surface’ of a 4D hypersphere of radius 1

The ‘surface’ is actually a 3D volume in 4D space, but it can sometimes be visualized as an extension to the concept of a 2D surface on a 3D sphere

123

22

21

20 qqqqq

Quaternions as Rotations

A quaternion can represent a rotation by an angle θ around a unit axis a:

If a is unit length, then q will be also2

sin,2

cos

2sin,

2sin,

2sin,

2cos

aq

q

or

aaa zyx

Quaternions as Rotations

112

sin2

cos2

sin2

cos

2sin

2cos

2sin

2sin

2sin

2cos

22222

22222

2222222

23

22

21

20

a

q

zyx

zyx

aaa

aaa

qqqq

Quaternion to Matrix

22

2110322031

103223

213021

2031302123

22

221222222221222222221

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq

To convert a quaternion to a rotation matrix:

Matrix to Quaternion

Matrix to quaternion is doable It involves a few ‘if’ statements, a

square root, three divisions, and some other stuff

Search online if interested

Animation vs. Deformation

Skeleton + bone transforms = “pose” Animation changes pose over time

Knows nothing about vertices and meshes Done by “animation” system on CPU

Deformation takes a pose, distorts the mesh for rendering Knows nothing about change over time Done by “rendering” system, often on GPU

Pose

Model

Describes a single type of object Skeleton + rig One per object type Referenced by instances in a scene Usually also includes rendering data

Mesh, textures, materials, etc Physics collision hulls, gameplay data, etc

Instance

A single entity in the game world References a model Holds current states:

Position & orientation Game play state – health, ammo, etc

Has animations playing on it Stores a list of animation controls Need to be interpolated

Animation Control

Links an animation and an instance 1 control = 1 anim playing on 1 instance

Holds current data of animation Current time Speed Weight Masks Looping state

Animation Storage

The Problem Decomposition Keyframes and Linear Interpolation Higher-Order Interpolation The Bezier Curve Non-Uniform Curves Looping

Storage – The Problem

4x3 matrices, 60 per second is huge 200 bone character = 0.5Mb/sec

Consoles have around 256-512Mb Animation system gets maybe 25% PC has more memory, but also higher

quality requirements

Decomposition Decompose 4x3 into components

Translation (3 values) Rotation (4 values - quaternion) Scale (3 values) Skew (3 values)

Most bones never scale & shear Many only have constant translation But human characters may have higher requirement

Muscle move, smiling, etc. Cloth under winds

Don’t store constant values every frame, use index instead

Keyframes

Motion is usually smooth Only store every nth frame (key frames) Interpolate between keyframes

Linear Interpolate Inbetweening or “tweening”

Different anims require different rates Sleeping = low, running = high Choose rate carefully

Key Frame Example

Recall we have done something in Flash

Linear Interpolation

Higher-Order Interpolation

Tweening uses linear interpolation Natural motions are not very linear

Need lots of segments to approximate well So lots of keyframes

Use a smooth curve to approximate Fewer segments for good approximation Fewer control points

Bézier curve is very simple curve

Bézier Curves (2D & 3D)

Bézier curves can be thought of as a higher order extension of linear interpolation

p0

p1

p0

p1p2

p0

p1

p2

p3

The Bézier Curve

(1-t)3F1+3t(1-t)2T1+3t2(1-t)T2+t3F2

t=0.25

F1

T1

T2

F2t=1.0

t=0.0

The Bézier Curve (2)

Quick to calculate Precise control over end tangents Smooth

C0 and C1 continuity are easy to achieve C2 also possible, but not required here

Requires three control points per curve (assume F2 is F1 of next segment)

Far fewer segments than linear

C0/C1/C2

The curves meet

the tangents are shared

the"speed" is the same before and after

Bézier Variants

Store 2F2-T2 instead of T2

Equals next segment T1 for smooth curves

Store F1-T1 and T2-F2 vectors instead Same trick as above – reduces data stored Called a “Hermite” curve

Catmull-Rom curve Passes through all control points

Catmull-Rom Curve

Defined by 4 points. Curve passes through middle 2 points.

P = C3t3 + C2t2 + C1t + C0

C3 = -0.5 * P0 + 1.5 * P1 - 1.5 * P2 + 0.5 * P3 C2 = P0 - 2.5 * P1 + 2.0 * P2 - 0.5 * P3 C1 = -0.5 * P0 + 0.5 * P2 C0 = P1

Non-Uniform Curves

Each segment stores a start time as well Time + control value(s) = “knot” Segments can be different durations Knots can be placed only where needed

Allows perfect discontinuities Fewer knots in smooth parts of animation

Add knots to guarantee curve values: Transition points between animations

Looping and Continuity

Ensure C0 and C1 for smooth motion At loop points At transition points: walk cycle to run

cycle C1 requires both animations are

playing at the same speed: reasonable requirement for anim system

Playing Animations “Global time” is game-time Animation is stored in “local time”

Animation starts at local time zero Speed is the ratio between the two

Make sure animation system can change speed without changing current local time

Usually stored in seconds Or can be in “frames” - 12, 24, 30, 60 per second

Scrubbing

Sample an animation at any local time Important ability for games

Footstep planting Motion prediction AI action planning Starting a synchronized animation

Walk to run transitions at any time

Avoid delta-compression storage methods Very hard to scrub or play at variable speed

Delta Compression

Delta compression is a way of storing or transmitting data in the form of differences between sequential data rather than complete files.

The differences are recorded in discrete files called deltas or diffs.

Because changes are often small (only 2% total size on average), it can greatly reduce data redundancy.

Collections of unique deltas are substantially more space-efficient than their non-encoded equivalents.

Animation Blending

The animation blending system allows a model to play more than one animation sequence at a time, while seamlessly blending the sequences

Used to create sophisticated, life-like behavior Walking and smiling Running and shooting

Blending Animations

The Lerp Quaternion Blending Methods Multi-way Blending Bone Masks The Masked Lerp Hierarchical Blending

The Lerp

Foundation of all blending “Lerp”=Linear interpolation Blends A, B together by a scalar weight

lerp (A, B, i) = iA + (1-i)B i is blend weight and usually goes from 0 to 1

Translation, scale, shear lerp are obvious Componentwise lerp

Rotations are trickier – normalized quaternions is usually the best method.

Quaternion Blending

Normalizing lerp (nlerp) Lerp each component Normalize (can often be approximated) Follows shortest path Not constant velocity Multi-way-lerp is easy to do Very simple and fast

Many others: Spherical lerp (slerp) Log-quaternion lerp (exp map)

Which is the Best

No perfect solution! Each missing one of the features All look identical for small interpolations

This is the 99% case Blending very different animations looks

bad whichever method you use Multi-way lerping is important So use cheapest - nlerp

Multi-way Blending

Can use nested lerps lerp (lerp (A, B, i), C, j) But n-1 weights - counterintuitive Order-dependent

Weighted sum associates nicely (iA + jB + kC + …) / (i + j + k + … ) But no i value can result in 100% A

More complex methods Less predictable and intuitive Can be expensive

Bone Masks

Some animations only affect some bones Wave animation only affects arm Walk affects legs strongly, arms weakly

Arms swing unless waving or holding something Bone mask stores weight for each bone

Multiplied by animation’s overall weight Each bone has a different effective weight Each bone must be blended separately

Bone weights are usually static Overall weight changes as character changes

animations

The Masked Lerp

Two-way lerp using weights from a mask Each bone can be lerped differently

Mask value of 1 means bone is 100% A Mask value of 0 means bone is 100% B Solves weighted-sum problem

(no weight can give 100% A) No simple multi-way equivalent

Just a single bone mask, but two animations

Hierarchical Blending

Combines all styles of blending A tree or directed graph of nodes Each leaf is an animation Each node is a style of blend

Blends results of child nodes Construct programmatically at load time

Evaluate with identical code each frame Avoids object-specific blending code Nodes with weights of zero not evaluated