1/41
Looks like no tags are added yet.
Transformation
A change applied to points/vectors to move, resize, or reorient an object. In graphics every transformation is represented as a matrix.
Three standard transformations
Translation, scale, and rotation.
Translation
Moves a point by adding an offset: (x, y, z) -> (x+dx, y+dy, z+dz). It is addition, so it can't be a plain 3x3 matrix. Applied to points only, never to vectors like normals.
Scale
Changes size by multiplying each coordinate by a scale factor: (sxx, syy, sz*z). Works about the origin and makes sense for both points and vectors.
Uniform vs non-uniform scale
Uniform = same factor on every axis. Non-uniform = different factors per axis. Non-uniform scale doesn't preserve angles, and some systems don't support it, so build non-uniform shapes into the model instead.
Rotation
Turns a point by an angle about an axis through the origin. A positive angle means counter-clockwise.
2D rotation equations
x' = x cos(a) - y sin(a), y' = x sin(a) + y cos(a). Derived from the angle-sum identities.
Reflection
Flips an object about a line (2D) or a plane (3D). Built by setting matrix entries to -1, since GLM has no reflection function.
Reflection handedness trap
A 3D reflection with an odd number of -1s turns a right-handed coordinate system into a left-handed one, so objects move in the opposite direction to what you expect.
Shear
Slides one side of an object over relative to the other, like pushing a deck of cards.
Point vs vector
A point is a position and can be translated. A vector is a direction and can't be translated (west is west anywhere). Both are 3 numbers but transform differently.
Homogeneous coordinates
Adding an extra component w to every point/vector: (x, y, z) -> (x, y, z, w), using 4x4 matrices in 3D. This lets translation be written as a matrix multiply, so all transformations share one representation.
Why homogeneous coordinates are needed
A matrix can only multiply and add, while translation adds a constant. The extra component of 1 multiplies the translation column so it gets added in. They're also used for the perspective divide.
w for points vs vectors
Points use w = 1, so translation applies. Vectors use w = 0, so the translation column is multiplied by 0 and vectors automatically ignore translation.
Converting homogeneous to Cartesian
Divide by w: (hx, hy, hz, h) -> (x, y, z). Example: (2,4,8,2) = (1,2,4). Basic transformations keep w = 1.
Vectors as points at infinity
Since vectors have w = 0, dividing by w is impossible, so a vector can be thought of as a point at infinity.
Combining (concatenating) transformations
Applying M then N gives x'' = N(Mx) = (NM)x. Multiply the matrices once, then do one matrix multiply per vertex instead of one per transformation.
Why combine transformations
Efficiency. With 1,000,000 vertices and 3 transforms you do 9M multiplications with one combined matrix instead of 27M doing them separately.
Order of transformations
Read right to left: the matrix closest to the point is applied first. In code, the transformation written last (just before drawing) is applied to the vertices first. A common source of bugs.
Matrix multiplication is not commutative
Order matters: rotate-then-translate gives a different result from translate-then-rotate.
Scale/rotate about a point P
Translate P to the origin, apply the scale/rotation, translate back: M = T(+P) * R * T(-P), read right to left. Needed because scale and rotation always work about the origin.
Two views of scale/rotation
Applied directly, scale/rotation transforms the whole world about the origin. To transform just one object, move it to the origin first, transform it, then move it back.
3D rotation requirements
You need three things: a rotation angle, a centre of rotation (handled with translation), and an axis of rotation.
Why 3D rotation is hard
You can rotate about any axis in 3D, and you can't build the matrix until you know the axis. Historically this caused lots of incorrect code.
Euler angles
Describing a rotation as three rotations about the x, y and z axes. The matrices are easy, but no ordering works for every rotation (Euler proved 3 numbers like this can't specify an arbitrary rotation).
Gimbal lock
With Euler angles, one rotation (e.g. 90 degrees about X) lines one axis up with another (Y onto Z), so a degree of freedom is lost and you can no longer rotate about the original axis.
Rotation matrix rows property
A rotation matrix rotates its own rows onto the x, y and z axes. Its rows are orthonormal unit vectors.
Inverse of a rotation matrix
Its transpose: R R^T = I, so R^-1 = R^T. Cheap to compute.
Building a rotation from 3 orthogonal vectors
Given orthonormal u, v, w, the matrix R with rows u, v, w rotates them onto x, y, z. R^T rotates x, y, z back onto u, v, w. The vectors must be unit length, so normalize first.
Rotation about an arbitrary axis a (idea)
Rotate a onto the z-axis, rotate by the angle about z, then undo the first rotation: M = R^T Rz(theta) R.
Arbitrary axis: building R
Normalize a (it's row 3). Pick t = a with its smallest-magnitude component set to 1 (so it's not collinear with a). u = (t x a)/|t x a|, v = a x u. R has rows u, v, a.
Arbitrary axis not through the origin
Wrap the rotation in translations: translate a point on the axis to the origin, rotate, translate back.
Transforming normal vectors (problem)
Transforming a normal by the same matrix M as the surface may leave it no longer perpendicular, because non-uniform scale doesn't preserve angles.
Normal transformation matrix
Use the inverse transpose of M: n' = (M^-1)^T n, then re-normalize it. In GLM: transpose(inverse(mat3(view*model))).
Why the inverse transpose works
Tangent t transforms as Mt. We need n'.(Mt) = 0 when n.t = 0. With n' = Ln this gives n^T L^T M t = 0, which holds if L^T M = I, so L = (M^-1)^T.
When M can transform normals directly
When M contains only rotations and translations (rigid-body transforms), because for a rotation (R^-1)^T = R. Any scaling needs the inverse transpose.
Normals and the projection matrix
Normals are transformed by view*model only, never by the projection matrix, since projecting a direction makes no sense.
Rigid-body transformation
A transformation that preserves shape, size and angles: only rotation and translation.
Affine transformation
A linear transformation plus translation (includes scale and shear). It doesn't necessarily preserve angles between lines.
Identity matrix
The "no transformation" matrix, glm::mat4(1.0). The usual starting point before applying transforms.
GLM rotation angle units
Radians, e.g. glm::rotate(matrix, angleRadians, axisVector).
Decomposing a transformation
Splitting a given matrix back into simple transforms: a translation (the last column), plus rotations and a scale. Use eigen-decomposition (R S R^T) if the upper block is symmetric, otherwise SVD (U S V).