# What objects do I use matrices for?

This topic is 1894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So, I've been looking alot into matrices lately. I understand all the "math-parts" regarding multiplying, adding them together and all that stuff. What I can't seem to get a grasp of is when do I use them correctly? I know that they are very effective when it comes to camera's. But do I also use them for models?

So that I have a position vector and a rotation vector, load them into a Float buffer and do glLoadMatrix('floafbuffer'); for every model/object that I want to render aswell? Or do I not need to use matrices for theese stuff?

If so, what do I use them for? Only cameras?

Im using Java with OpenGL btw. (LWJGL)

EDIT: I accidentaly posted this in Math and Physics, I meant to post it in "For Beginners". So if any moderator sees this, could you please move it? Thanks! Edited by Slushy

##### Share on other sites
In the context of the graphics pipeline, matrices represent transformations to be applied to vectors, by multiplying the matrix by the vector (there is a choice as to whether you multiply matrices times column vectors or row vectors times matrices, but it's only a matter of convention). You can use them to put a model in the world (by mapping the model coordinates to world coordinates), or to map world coordinates to image coordinates (the camera), or to express the location of a bone with respect to its parent.

For completeness, symmetric square matrices are also used to represent quadratic forms, but there are probably limited uses for this in game development.

##### Share on other sites
That is really helpful, thanks alot! I'll have to read up on some further stuff regarding world/local/image coordinates but thanks again! Edited by Slushy

##### Share on other sites
The three transforms:

World - Changes the vertices from local space to world space. This assigns a position/rotation/scale to the model in the world space. It can be thought of as placing an object in a room.
View - Changes the vertices from world space to 'camera' space. This essentially changes everything so that the camera is the origin. It can be thought of as positioning the camera to look at the object.
Projection - This is the weird one. The camera angle creates a sort of rectangular cone shape. In order to get pixel colors we want that to be a 3D rectangle. In other words we want the near plane of the frustum (the visible area) to have the same width and height of the far plane of the frustum. The result is that things nearer to the camera get stretched a bit so they look closer. Once this is done the graphics hardware can look in straight lines from the center of where each pixel maps to the near plane to the same x/y coordinate on the far plane and if there's an intersection then we fetch a color value for the point on the polygon where the intersection occurs.

Since these transforms can all be described as matrices they can all be multiplied to get a single matrix that can correctly perform all three steps on each vertex in the model.

Here's a Microsoft article that discusses it a bit:

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb206269%28v=vs.85%29.aspx"]http://msdn.microsof...9(v=vs.85).aspx[/url]

You could also use matrices or quaternions to implement complicated rotations in three dimensional space, such as for a flight simulator or spacecraft simulator where where you have to compound several angles/vectors together. Edited by Khatharr