380 likes | 471 Vues
Delve into the world of matrices to understand how translation, rotation, scaling, and more are vital for 2D and 3D games. Learn about matrix multiplication, transposing, inverses, and special matrices for rotations. Discover how matrices can transform points, and explore the interplay between matrices and geometric operations, all while examining practical applications through hands-on examples and explanations.
E N D
The Math Lecture (Part I - Matrices)
Introduction • For 2D games, we use a lot of trigonometry • For 3D games, we use a lot of linear algebra • Most of the time, we don’t have to usecalculus • A matrix can: • Translate (move) a vertex • Rotate a vertex • Scale a vertex • Math libraries cover up these details • Learn it anyway!
Introduction • For 2D games, we use a lot of trigonometry • For 3D games, we use a lot of linear algebra • Most of the time, we don’t have to usecalculus • A matrix can: • Translate (move) a vertex • Rotate a vertex • Scale a vertex • Math libraries cover up these details • Learn it anyway!
MAtrices • The foundation of all geometric operations (translation, rotation, scaling, skewing…) • Have multiple rows and columns (usually 3x3 or 4x4) • Below is an identity matrix • We can multiply a matrix • with another matrix, and get a matrix • with a vector of “appropriate” dimension (later)
Transposing a Matrix • Have a transpose (denoted ) where • In other words, make the rows columns! Transpose
Transposing a Matrix • Have a transpose (denoted ) where • In other words, make the rows columns! • Mirror image along the diagonal Transpose The Matrix has you…
Matrices • There’s also an inverse matrix (denoted ) where • Not all matrices are invertible • Can check by getting the determinant of the matrix (looking for non-zero)
Matrices • There’s also an inverse matrix (denoted ) where • Not all matrices are invertible • Can check by getting the determinant of the matrix (looking for non-zero)
Matrices • There’s also an inverse matrix (denoted ) where • Not all matrices are invertible • Can check by getting the determinant of the matrix (looking for non-zero)
Matrices • There’s also an inverse matrix (denoted ) where • Not all matrices are invertible • Can check by getting the determinant of the matrix (looking for non-zero)
Matrices • There’s also an inverse matrix (denoted ) where • Not all matrices are invertible • Can check by getting the determinant of the matrix (looking for non-zero) Follow the white rabbit…
Matrix Multiplication • Multiplying a point by a matrix gives us a new point! • Let’s say that we want to rotate the point around the z axis by 90 degrees • Points are always stored with a 1 for the 4th element = Oldpoint Newpoint
Matrix Multiplication • Multiplying a point by a matrix gives us a new point! • Let’s say that we want to rotate the point around the z axis by 90 degrees • Points are always stored with a 1 for the 4th element = -1 0
Matrix Multiplication • Multiplying a point by a matrix gives us a new point! • Let’s say that we want to rotate the point around the z axis by 90 degrees • Points are always stored with a 1 for the 4th element =
Matrix Multiplication • Multiplying a point by a matrix gives us a new point! • Let’s say that we want to rotate the point around the z axis by 90 degrees • Points are always stored with a 1 for the 4th element =
Matrix Multiplication • Multiplying a point by a matrix gives us a new point! • Let’s say that we want to rotate the point around the z axis by 90 degrees • Points are always stored with a 1 for the 4th element = What IS real?
Translation • It’s a piece of cake, because the 4th column is the translation!
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: =
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: =
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: =
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: =
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: = Why, oh why, didn’t I take the blue pill?
Translation • It’s a piece of cake, because the 4th column is the translation! • Imagine we want to move the point by (2, 1, -3). Then: =
SCALING • It’s a piece of cake too, because it’s the diagonal! • We can scale along just one axis, or more than one! • Imagine we want to scale the point by the values x, y and z. Then: = Trace program: running
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix There is no spoon…
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix ?
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix =
Matrix Multiplication • What if you want to rotate a point and then translate it? • Need a rotation matrix • Need a translation matrix • Returns a 4x4 matrix = Oldpoint Newpoint