Maths and Technologies for Games Animation: Interpolation
description
Transcript of Maths and Technologies for Games Animation: Interpolation
![Page 1: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/1.jpg)
Maths and Technologies for GamesAnimation: Interpolation
CO3303
Week 2
![Page 2: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/2.jpg)
Interpolation for AnimationInterpolation for Animation
• Given two transforms for a model, we can calculate the transforms in between the two:– This is called interpolation
• Animation is stored as a sequence of key frames (transforms)
• To get frames between the key frames, we use interpolation
• For example a rotating arm has 2 key frames stored– One at the start of rotation (T1), one at the end (T2)
– Calculate (don’t store) frames in between with interpolation
![Page 3: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/3.jpg)
Previous InterpolationPrevious Interpolation
• We have interpolated between elements before:– Alpha blending – source and destination colours– Skinning – the effects of multiple bones
• We used Linear Interpolation each time:– Alpha blending:
Dest.R = Source.A * Source.R + (1-Source.A) * Dest.R
– Skinning (with two bones)
– Do you see a pattern?
• N.B. Details for this section in Van Verth
)1(
1 where
121
21221
ww
wwww
VMVMP
VMVMP
1
1
![Page 4: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/4.jpg)
• General linear interpolation between two mathematical elements P0 and P1 takes the form:
• Typically t is in the range [0,1] - note that:
• The parameter t selects a element P(t) in between the start and end elements P0 and P1
2/)()2/1( and )1( ,)0( 1010 PPPPPPP
tPtPtP 10 )1()(
Linear Interpolation (Lerp)Linear Interpolation (Lerp)
• If P0 & P1 are points, then P(t) will be on the line between them:
• Hence linear interpolation
![Page 5: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/5.jpg)
Linear Interpolation of TransformsLinear Interpolation of Transforms
• A transformation is typically made up of a position, a rotation and a scaling component– Can be stored in several ways, e.g.
• Position: vector / scalars (x,y,z) or a matrix• Rotation: Euler angles, a matrix or a quaternion• Scaling: vector / scalars or a matrix• Can have a single combined matrix for everything
• We will consider the effect of linear interpolation on each of the components separately
• Then consider how this affects our storage choice
![Page 6: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/6.jpg)
Linear Interpolation of PositionLinear Interpolation of Position
• Linear interpolation applied to key-frame positions will give sensible in-between positions:
• With several key-frames we get piecewise linear interpolation
• Motion between points has sharp changes in direction:
• May prefer smoother motion and we can use higher order interpolations to do this– But linear interpolation works and will
suffice for nowPiecewise Linear Interpolation
Higher Order Interpolation
![Page 7: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/7.jpg)
Linear Interpolation of ScalingLinear Interpolation of Scaling
• Scaling can also be interpolated linearly:
• Works fine for one pair of key-frames• Again, linear interpolation over many frames will cause
scaling rate to change sharply at each key-frame:– The speed of shrinking/expanding changes suddenly– Generally a less noticeable effect
• Again, possible to calculate smoother result with higher order interpolation
![Page 8: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/8.jpg)
Linear Interpolation of RotationLinear Interpolation of Rotation
• Can apply linear interpolation to rotations if they are in matrix or quaternion form:– Ineffective with Euler angles
• Unlike position and scale, the result is not correct– Even with just one pair of
key-frames
• The tips of the rotated vectors are interpolated
– Resulting in an unwanted scaling– Incorrect angles – want quarter steps, but here α ≠ β
![Page 9: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/9.jpg)
Normalised Lerp (Nlerp)Normalised Lerp (Nlerp)
• Can normalise the rotations to remove the scaling effect
• Still have inaccurate angles– Normalising quaternions is trivial
– Gram-Schmidt orthogonalisation used to normalise matrices (see Van Verth early chapter)
• Allows us to use linear interpolation of rotations– If the overall rotation is small enough
• Otherwise we need linear interpolation of the angles
![Page 10: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/10.jpg)
Spherical Lerp (Slerp)Spherical Lerp (Slerp)
• Linear interpolation of angles is same as linear interpolation of an arc on a sphere
ttslerp )(),,( 1QPPQP
• So this technique is called spherical linear interpolation or slerp
• The formula is different from linear interpolation:
• As before – take a start and end rotation (P, Q), and a value t from [0,1]
• Formula calculates the correct interpolated rotation
![Page 11: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/11.jpg)
Slerp for MatricesSlerp for Matrices
• We can apply the slerp formula if P, Q are matrices
• Matrix multiplication / inverse are understood• But how to calculate a matrix raised to a power?
– i.e. Mt
• Need to convert the matrix to axis-angle format, then calculate θ
t, then convert back• Very expensive
– More than 100 operations
tt,slerp )(),( 1QPPQP
![Page 12: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/12.jpg)
Slerp for QuaternionsSlerp for Quaternions
• Can show that slerp for quaternions is:
• Expensive, mainly because of the sin functions– But sin θ can be precalculated
• It’s constant for any pair of key frames
qp
qpqp
and between angle theis wheresin
)sin())1sin((),(
ttt,slerp
• Has potential accuracy problems for small θ
• However, more usable than the matrix version
![Page 13: Maths and Technologies for Games Animation: Interpolation](https://reader035.fdocuments.us/reader035/viewer/2022081603/56814532550346895db1fa55/html5/thumbnails/13.jpg)
Interpolation SummaryInterpolation Summary
• We want to interpolate between two key frames
• Can use simple linear interpolation (lerp) for the position and scaling
• For rotation, consider angle between the frames:– Can often use lerp on rotations & normalise the result– For large angles, use slerp
• In any case store rotations as quaternions if you intend to interpolate them– Matrices expensive to interpolate, Eulaer angles ineffective
• Note: there are some newer methods to approximate or avoid slerp