150 likes | 250 Views
UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics. Math Review. Goals. Review the basic math operations used in graphics Learn other, more advanced operations Learn/review how to reason with matrix algebra. Vectors.
E N D
UW ExtensionCertificate Program inGame Development 2nd quarter:Advanced Graphics Math Review
Goals • Review the basic math operations used in graphics • Learn other, more advanced operations • Learn/review how to reason with matrix algebra
Vectors • Represent entities like colors, points and directions • Addition, subtraction: per-component • Scalar product: same direction, and magnitude multiplied by the scalar • Dot product: product of magnitudes and cosine of the angle between the vectors (scalar) • Cross product (3D only): Orthogonal to both operands. Magnitude is product of magnitudes and sine of the angle between the vectors • Not commutative!
Matrices • Represent entities like orientations, transformations and reference frame transfers • Addition, subtraction: per-component • Scalar product: multiply all components with scalar • Matrix product: dot product per component of result • Not commutative! Not all matrices have inverse! • Transposed, determinant, eigenvalues, eigenvectors • Convention: Direct3D multiplies vectors on the left (uses row vectors). OpenGL does it the other way
Translation vector P’ Q’ P Y Q Box Box X O
Rotation matrix Q’ P’ Box Box Q P Y X O
Scale matrix P’ Q’ P Box Y Q Box X O
Shear matrix P P’ Q Q’ Y Box Box X O
Algebra • Standard real-number algebra: • ABx + C = D • Find x: • Matrix algebra: • ABx + C = D • Find x: • It’s different – you need to be careful
Reference frames • Vectors must be expressed on a reference frame • Gives meaning to the coordinate values • Reference frame specifies • Where the origin is • Where each axis is • What scale each axis is • Defined by as many vectors as dimensions, plus one (for the origin) • Again, vectors normally expressed in some reference frame
Reference frames Frame F={O, X, Y} Y’ O’ X’ Frame F’={O’, X’, Y’} P Y X O
Reference frames Y’ O’ X’ P Y X O
Transform “sandwich” • Use to transform the transforms • Or to apply a transform defined in a different reference frame • Apply shear H along orientation defined by R: • H’ = R-1 * H * R • Apply transformation M, defined in reference frame F • M’ = F * M * F-1 • Think like this: v * M’ = v * F * M * F-1
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