Friday, October 17, 2014

Feelings concerning the "Matrix"

Hello all,

Its me again just getting back to blogs for my Game Engine design and implementation course.


This time I have decided to have a quick talk about Matrices, because they are a huge part of every game and an element that cannot be avoided when preforming transformations.


Lets go over the base topic of transformations just for a second and speak about it in laymen terms, just so everyone can understand properly moving forward.

Transformation Matrices

When you are scaling, rotating or translating anything! Firstly lets look at how a Transformation Matrix is built! The picture below will give some form of reference, then I will go ahead and explain further.



So the image above may seem a tad confusing lets just focus on the first one in the very top left of the image for now. 

What that is called, is an identity matrix, it is a matrix with literally no change, it is what every matrix will look like before you apply other operations to it, to make it rotate things or move things. Think of the identity matrix as the start of the life of every matrix, before a matrix is made into something that moves or changes something else, it must first be a child and that child is the identity matrix.

Moving forward, the translate matrix, scale matrix and the rotate matrix (top middle, top right and left middle respectively). Are the main matrices that matter in terms of translations and rotations in games. In face they are so important that they are ALL made into one "Homogeneous Matrix" which is a 4x4 matrix, that I will most likely touch on in another tutorial all together.

I will post a video at the very bottom that does a decent job at re-explaining my points here along with moving toward the topic of The "Transformation Matrix" Aka "Homogeneous Matrix".

Great so just to recap, we have our identity matrix which is a 3x3 matrix, why? Well because we are trying to translate, rotate and or scale a point in 2D space, which means (and the video will also explain this) that we need an imaginary dimension to allow this translation to happen.

Example time:

Alright so lets take our point [x,y] which is a point in 2D space. Lets think about this point and then look up to our matrices and see how we would apply some sort of Translation lets say to this point [x,y] to move it.

Well first of all, lets think of our point [x,y] as a small matrix for now, which is obviously 1x2, now if we know anything about matrix multiplication, we would know that to multiply a matrix you must at least meet one of the dimensions. For example if we have a 3x3 matrix, we can multiply that with a 1x3 or a 3x1, because we are matching the dimensions.

Good so lets look at what we have then for our multiplication of our [x,y] matrix with our translation matrix which is [1,0,x][0,1,y][0,0,1] (Think of the [] stacked on top of each other). One of our matrices is 1x2 and the other is a 3x3... well since none of the dimensions match, we cannot multiply these values together.

So the only solution is to take our [x,y] and give it an imaginary dimension such that it will fit the rules of matrix multiplication! For arguments sake lets make the extra imaginary dimension "w" and we will set that to 1 which means our point is now [x,y,1], now remember this does not make the point 3D, THIS is an IMAGINARY dimension.

Now we have a 1x3 and a 3x3, which means YES these matrices can be multiplied together.

The interesting part is that when you multiply these two together, our point has actually been moved by the amount we specified in the translation matrix in the spots of x and y!

Is that not neat? Now using this same method any one of these matrices listed in the image above can be used to move, rotate, mirror, scale your point/object just by the simple task of matrix multiplication!


As this is the end of the tutorial, please let me know if any of this confused you. Again we simply were going over how to transform a point using a matrix, the next few tutorials will expand on this idea and really bring it into a new light.

Thank you so much for reading! Have a great day!


Regards,
Stephen

Here is that video I promised have fun!