Download presentation
Presentation is loading. Please wait.
Published byMelissa Nelson Modified over 8 years ago
1
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Advanced Math
2
Goals 1. Learn more advanced math concepts 2. Review the basic physics formulas
3
lerp (Linear intERPolation) Very common operation, appears everywhere V a = V 0 *(1-a) + V 1 *a More complex interpolations often expressed using lerps For example, Bezier curves are composition of lerps The problem: lerp doesn’t work with matrices Resulting matrix is not a rotation It works, sort of, with quaternions Need to renormalize afterwards Speed is not constant
4
Logarithmic space What’s halfway between a scale of 1 and a scale of 100? Translation composes by addition: T ab = T a + T b Standard lerp works (arithmetic weighted average) But scaling composes by multiplication: S ab = S a * S b Lerp should be: S a = S 0 (1-a) * S 1 a (geometric weighted average) Logarithms to the rescue: S a = exp( log(S 0 ) * (1-a) + log(S 1 ) * a ) Exp and log can be costly, but so can arbitrary powers
5
Quaternions 4D vectors used to represent rotations Always normalized! Q = [Q X Q Y Q Z Q W ] Two quaternions Q and –Q represent the same rotation Addition, subtraction: per-component Scalar product: multiply all components with scalar Used for linear interpolation, renormalize afterwards Quaternion product Follows a pattern similar to complex number multiplication
6
Quaternions Often represented as vector and scalar: Q = [Q V Q W ] Q V = [Q X Q Y Q Z ] Concatenate quaternions: Q 12 = Q 1 * Q 2 Inverse: Q -1 = [-Q V Q W ] ≈ [Q V -Q W ] Rotate a vertex: V = [V X V Y V Z 0] Q * V * Q -1 Interpretation: Q W = cos( θ /2) Q V = A * sin( θ /2) Rotation of θ around axis A Used because they help make animations smoother
7
slerp (Spherical LERP) For rotations, it is done using quaternions That’s the main reason for their existence, besides the compactness It is a complex operation: Extract angle Ω between 4D quaternions Standard slerp: Be careful with quaternion duplicity (Q ≈ -Q) Watch out for math singularities
8
Quaternion logarithms Rotations also compose by multiplying And we do have quaternion logarithms! Q = [V*sin( θ /2) cos( θ /2)] log(Q) = [V * θ /2 0] It can also encode multiple loops It’s like a 3D rotation “angle” It can be tricky to use, like angles but worse log(Q) ≈ log(Q) + K * π Finding shortest route can be very tricky
9
Spherical harmonics It’s like a polynomial, but instead of giving values for values, it gives values for directions Arbitrary number of coefficients More coefficients more detail Coefficients must be a square: 1, 4, 9, 16, 25, … Can be rotated by operating on the coefficients Integrate (average) a function: choose 1 st coefficient Integrate a product: dot-product of coefficients Used for lighting
10
Basic physics The Newtonian world is continuous Ballistics: P = P 0 + V 0 * t + A/2 * t 2 We use discrete approximations Ballistics: P += V * Δ t, V += A * Δ t We call this “Euler integration” of the differential equations: V = P ′, A = P ″ The acceleration changes between frames A(P, V, t), works well with Euler integration P = position P 0 = initial position V = velocity V 0 = initial velocity A = acceleration t = elapsed time Δ t = time step
11
Force fields Acceleration basically same as force F(P, V, t) = m * A(P, V, t), but the mass is typically constant Constant force (gravity): A = 9.8 m/s 2, F = m * A Position-dependent force (spring): F = K * (C - P) C = spring’s resting position Velocity-dependent force (drag): F = -K * V 2 Time-dependent force (wind): F = F(t)
12
Midpoint integration Euler integration isn’t very precise It can diverge and misbehave Midpoint is simple and can behave better: P += V * Δ t + A * Δ t/2, V += A * Δ t Perfect results for ballistic trajectories P = position P 0 = initial position V = velocity V 0 = initial velocity A = acceleration t = elapsed time Δ t = time step midpointEuler
13
Runge-Kutta integration It’s more complex but better behaved P += V k * Δ t, V += A k * Δ t V k = (V a + 2 * V b + 2 * V c + V d ) / 6 A k = (A a + 2 * A b + 2 * A c + A d ) / 6 Where: P a = P, V a = V, A a = A(P a, V a, t) P b = P + V a * Δ t/2, V b = V + A a * Δ t/2, A b = A(P b, V b, t + Δ t/2) P c = P + V b * Δ t/2, V c = V + A b * Δ t/2, A c = A(P c, V c, t + Δ t/2) P d = P + V c * Δ t, V d = V + A c * Δ t, A d = A(P d, V d, t + Δ t) P = position P 0 = initial position V = velocity V 0 = initial velocity A = acceleration t = elapsed time Δ t = time step
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.