Transformations and Matrices
Transformations
- Transform geometry by applying a numerical transformation on every vertex
- Must preserves points, straight lines and parallel lines
- Not necessarily angles or distances
- Mathematically, define linear mapping on many points
- Basic transformations: translate, rotate, scale
glTranslate()
, glRotate()
, glScale()
are accumulated as part of OpenGL's graphics state
Matrices
- Oldest known data structure — a rectangle of numbers!
- Earliest record is from China, in the 2nd century BCE, used to solve simultaneous equations
- Rows represent equations, columns represent coefficients
- Graphics uses matrices to represent linear transformation
- Point or vector is 1x4, transformation matrix is 4x4
- OpenGL keeps one matrix active to represent model transforms:
GL_MODELVIEW
glLoadIdentity
() resets the matrix to the identity
- When combined into one "data structure" (4x4), mathematically, represents affine transformations
- Composition of two functions: a translation and a linear map
- "Extra" row will be used later to incorporate other kinds of transformations
- Product of two matrices represents the composition of two transformations
- Combination is generally NOT commutative (addition is)
- Scale then rotate produces different effect than rotate then scale
- Usual (i.e., least surprising) order of operations is: translate, rotate, scale
Scene Graphs
- Used by most modern graphics systems and game engines
- Data structure for organizing spatial representation of a graphical scene
- Provides structure for managing changes to the graphics state
- May be implicit in the code (order of function calls), in data (3DS format), or in scripting language (VRML)
- Generally optimized to remove duplication of same geometry (the leaf nodes)
- Can be generalized to arrange any attribute of scene
- Naturally recursive accumulation of transformations
pushMatrix()
on your way down the tree, popMatrix()
on your way back up
References