4 ms·
Matrices are a way of accumulating a bunch of separate transformations you might want to perform on a point (in the lingo, points are vectors because each coord
by barrkel 11y ago
Matrices are a way of accumulating a bunch of separate transformations you might want to perform on a point (in the lingo, points are vectors because each coordinate of the point is an element of the vector).
Suppose figuring out where a world point (in a game map, for example) should show up on screen (in pixels) looked like a bit like this function call sequence (this is simplified):
screenPoint = perspective(move(rotate(move(worldPoint))))
Think of a camera moving around the world; in virtual reality, this is exactly equivalent to the camera staying put and the world moving around instead. That's more or less how 3D graphics works. You have a virtual box that logically lives behind your screen, with the same x and y coordinates as your screen resolution, and z coordinates handled by a Z buffer that's used to determine what overlaps what. A big chunk of the matrix work is about moving, rotating and squishing the whole virtual world until the bit you want to look at fits into the virtual box that lives behind the screen.
Each function (perspective, move (aka translate), rotate, scale, etc.) can be expressed in the form of multiplication by a matrix. See [1], for example. That turns it into something like this:
screenPoint = perspectiveMatrix * moveMatrix * rotateMatrix * moveMatrix * worldPoint
But because matrix multiplication is associative, we can calculate a single matrix to do all the work:
transformMatrix = perspectiveMatrix * moveMatrix * rotateMatrix * moveMatrix
screenPoint = transformMatrix * worldPoint
And this is much more efficient because there's fewer calculations that need to be performed per point.
[1] https://en.wikipedia.org/wiki/Rotation_matrix https://en.wikipedia.org/wiki/Rotation_matrix
- djhworld 11y agoWonderful explanation, thanks