Let’s say I’m writing a computer game, which features a robot holding a gun. I have a list of vectors representing the 3D model of the gun, but how do I know where to draw those points on screen? To transform the gun model to screen coordinates I just need to do this simple process:
scale the gun model so it’s the right size for the game
rotate and translate it so it will be in the same coordinate space as the robot’s hand, where the wrist joint is at (0,0,0)
rotate again to reflect the current angle of the wrist, now it aligns with the forearm
translate by forearm length so the elbow joint is at (0,0,0)
rotate again to reflect elbow angle, now it aligns with upper arm
translate by upper arm length so the shoulder joint is at (0,0,0)
rotate again to reflect shoulder angle, now it aligns with body
translate by shoulder position so body center of rotation is at (0,0,0)
OK let’s just assume we’re defining body position directly, so we’ll apply another rotation and translation to reflect the robot’s position, now our coordinates are in “game space”
of course the “camera” through which we view the action might be moving as well, so we’ll need another rotation and translation so transform the coordinates into “camera space”
we need to apply 3D perspective to get the on-screen coordinates. If the z axis of camera space were in the direction we are looking, with 0 at the view point, you could get x and y screen coordinates by dividing camera space coordinates by z, and scaling the result as needed to fit the screen
Oh dear, that wasn’t so simple. Are we going to do this for every vector in the gun model?
Well, as it turns out, the first 10 steps are all linear transformations that can be represented by a matrix. And we can encapsulate the entire process by multiplying those matrices together, so instead of 10 operations, we can combine it into one, a single matrix which will take us all the way from the gun model to a position in camera space. So we just need to pass the graphics card some instructions to tell it what to do, plus the list of vectors for the gun model, plus the combined matrix for transforming them.
There’s many other cool things to do with matrices in graphics programming but that’s a starting point.
Let’s say I’m writing a computer game, which features a robot holding a gun. I have a list of vectors representing the 3D model of the gun, but how do I know where to draw those points on screen? To transform the gun model to screen coordinates I just need to do this simple process:
Oh dear, that wasn’t so simple. Are we going to do this for every vector in the gun model? Well, as it turns out, the first 10 steps are all linear transformations that can be represented by a matrix. And we can encapsulate the entire process by multiplying those matrices together, so instead of 10 operations, we can combine it into one, a single matrix which will take us all the way from the gun model to a position in camera space. So we just need to pass the graphics card some instructions to tell it what to do, plus the list of vectors for the gun model, plus the combined matrix for transforming them.
There’s many other cool things to do with matrices in graphics programming but that’s a starting point.
great explanation, thanks
You’re welcome, it was a very valid question