130 likes | 140 Views
Learn advanced math concepts, review basic physics formulas, and explore advanced graphics techniques for in-game development. Topics include interpolation, matrices, quaternions, spherical harmonics, basic physics, force fields, and integration methods.
E N D
UW ExtensionCertificate Program inGame Development 2nd quarter:Advanced Graphics Advanced Math
Goals • Learn more advanced math concepts • Review the basic physics formulas
lerp (Linear intERPolation) • Very common operation, appears everywhere • Va= V0*(1-a) + V1*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
Logarithmic space • What’s halfway between a scale of 1 and a scale of 100? • Translation composes by addition: Tab = Ta + Tb • Standard lerp works (arithmetic weighted average) • But scaling composes by multiplication: Sab = Sa * Sb • Lerp should be: Sa = S0(1-a) * S1a (geometricweighted average) • Logarithms to the rescue: • Sa = exp( log(S0) * (1-a) + log(S1) * a ) • Exp and log can be costly, but so can arbitrary powers
Quaternions • 4D vectors used to represent rotations • Always normalized! Q = [QX QY QZ QW] • 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
Quaternions • Often represented as vector and scalar: Q = [QV QW] QV = [QX QY QZ] • Concatenate quaternions: Q12 = Q1 * Q2 • Inverse: Q-1 = [-QV QW] ≈ [QV -QW] • Rotate a vertex: V = [VX VY VZ0] Q * V * Q-1 • Interpretation: QW = cos(θ/2) QV = A * sin(θ/2) • Rotation of θ around axis A • Used because they help make animations smoother
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
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
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 1st coefficient • Integrate a product: dot-product of coefficients • Used for lighting
Basic physics • The Newtonian world is continuous • Ballistics: P = P0 + V0 * t + A/2 * t2 • 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 P0 = initial position V = velocity V0= initial velocity A = acceleration t = elapsed time Δt = time step
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/s2, F = m * A • Position-dependent force (spring): F = K * (C - P) • C = spring’s resting position • Velocity-dependent force (drag): F = -K * V2 • Time-dependent force (wind): F = F(t)
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 P0 = initial position V = velocity V0= initial velocity A = acceleration t = elapsed time Δt = time step Euler midpoint
Runge-Kutta integration • It’s more complex but better behaved • P += Vk * Δt, V += Ak * Δt • Vk = (Va+ 2 * Vb+ 2 * Vc+ Vd) / 6 • Ak = (Aa+ 2 * Ab+ 2 * Ac+ Ad) / 6 • Where: • Pa = P, Va = V, Aa= A(Pa, Va, t) • Pb = P + Va * Δt/2, Vb = V + Aa * Δt/2, Ab= A(Pb, Vb, t + Δt/2) • Pc= P + Vb* Δt/2, Vc= V + Ab* Δt/2, Ac= A(Pc, Vc, t + Δt/2) • Pd= P + Vc* Δt, Vd= V + Ac* Δt, Ad= A(Pd, Vd, t + Δt) P = position P0 = initial position V = velocity V0= initial velocity A = acceleration t = elapsed time Δt = time step