#### Archived

This topic is now archived and is closed to further replies.

# 4 * 4 Matrices

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

## Recommended Posts

What are 4 * 4 matrices and when/why would I ever use them? In my book, 'Programming RPGs With DirectX' it says that matrices 'make the math easier'. (sarcasm) Gee thanks! That helped, and I now totally understand how to use them! (/sarcasm) How can only 16 nodes control a whole world of verteces, and howcome I need those imaginary matrices, or matrices that store color information (why not just RGB?)....? The true general first seeks victory, then seeks battle - Sun Tzu [edited by - Drakkcon on May 9, 2004 10:55:24 PM] [edited by - Drakkcon on May 9, 2004 10:55:50 PM]

##### Share on other sites
Your ''world'' is made up of vertices. All your vertices will be multiplied by a matrix at some point. A matrix multiplied with a vertex results in a new vertex. If you want to rotate your entire world 90 degrees you must rotate all the vertices of your world by 90 degrees. You can do this by multiplying all of your vertices by a rotation matrix. A rotation matrix is a matrix with a specific set of numbers in each position. All vertices mutltiplied by this matrix will result in a 90 degree rotation.

If you think about it you can now define your camera as a matrix, rotate your camera 90 degrees and your world rotates 90 degrees. You can do much more but that''s the basic idea, you use matrices to manipulate (move, rotate, scale, project{don''t worry about this one}) a group of vertices.

Also, matrices don''t store colour information as far as I know.

You might try reading a game programming book with a linear algebra section, a linear alegbra textbook, or taking a class.

------------
- outRider -

##### Share on other sites
Thank you. So:

4567
1234
5647
8567

if the camara turned right the vertices would be multiplied by three? I''m afraid I still have no idea. I''m too young to attend a class, but really want to understand this.

The true general first seeks victory, then seeks battle
- Sun Tzu

##### Share on other sites
I haven''t really learnt matrices properly yet either, but I know what they are used for and do, so this might make a bit more sense to someone like yourself.

Imagine a matrix as a magic box which takes each vertex and performs a transformation on it, be in scaling, rotation or translation. Kinda like a function, actually (no doubt the maths buffs will severely harm me for saying this, but it makes sense to me).

When you put each vertex into one of these boxes, the world matrix, it takes your model''s local co-ordinates (the model''s center is based around the origin) and puts the vertices into the world.

The second magic box, the view matrix, takes these vertices, which are now in the world, and puts them in front of the camera.

The third magic box, the projection matrix, is kinda hard to explain. It defines how the 3D co-ordinates appear on your 2D screen. For example, you''d use this matrix to do a fish-eye style of view.

Sorry if I sound patronizing, but this is the best way for me to think of it.

If you want, and if you''re using DirectX, you can use the D3DX library to set up your matrices for you, all you need to do is define where you want them to put your vertices in 3D space, what scale, what rotation, the maximum viewable distance, and view angle. For more information, see MSDN archives, your DirectX documentation, or someone else''s code or tutorials.

Stay Clausal,

Red Sodium

##### Share on other sites
Clicky
EDIT: More (vectors+matrices)

[edited by - nonpop on May 10, 2004 8:50:15 AM]

##### Share on other sites
Thanks everyone (especially red_sodium) for explaining it to me. Here''s how I understand it now:
The world matrix for instance, takes each vertex, and applies the closest number it has to that particular vertex (based on its position), and it takes that value and runs it through a function to determine a vertex''s transformation according to the number. Now I see how they''re useful, you don''t have to perform calculations on each vertex, just have them automatically assign to a value in the matrix, and be changed correctly. Thanks again!

##### Share on other sites
I think you've misunderstood something here.
quote:
The world matrix for instance, takes each vertex, and applies the closest number it has to that particular vertex

What closest number? I don't fully understand what you mean but I'm quite sure you have it wrong (no offense meant, I was quite confused myself in the beginning).
quote:
Now I see how they're useful, you don't have to perform calculations on each vertex

No, you still have to perform the calculations (matrix-vector multiplication) on each vertex. I think the most usefull thing about matrices is that you can combine different transformations into one matrix. Thus, for example, you first combine the rotation and projection matrices into one and apply that on each vertex as opposed to transforming each vertex two times. (You could do this without matrices, too, but matrices make representing stuff easier.)

Let's take an example. You have a vertex at (1,2,3). You want to first move it one unit to the right (positive X axis) and then two units up (positive Y axis). Here are the according matrices:
Move one to the right:[1 0 0 1][0 1 0 0][0 0 1 0][0 0 0 1]Move two units up:[1 0 0 0][0 1 0 0][0 0 1 2][0 0 0 1]To combine these transformations we multiply the matrices:[1 0 0 1][1 0 0 0]   [1 0 0 1][0 1 0 0][0 1 0 0] = [0 1 0 0][0 0 1 0][0 0 1 2]   [0 0 1 2][0 0 0 1][0 0 0 1]   [0 0 0 1]Now, since we use 4x4 matrices, we must represent the vertexwith a 4x1 matrix. We'll fill the last component with a '1'(search for homogenous coordinates to find out why). To applythe transformation to the vertex we multiply the transformationmatrix by the vertex matrix:[1 0 0 1][1]   [2][0 1 0 0][2] = [2][0 0 1 2][3]   [5][0 0 0 1][1]   [1]And so we have a new vertex.

That wasn't much of a good example but you should get some idea about it. I'm quite sure the tutorials in the GameDev.net resources section are better at explaining this (see my last post for the links).

EDIT: Fixed a bug

[edited by - nonpop on May 10, 2004 5:50:14 PM]

[edited by - nonpop on May 10, 2004 5:52:17 PM]

##### Share on other sites
Don''t look at matrices as some kind of lookup tables, because they aren''t. Look at them as a set of "directions" or vectors specifying up, right, and forward, plus position and some perspective crap that you don''t use much At least that''s a good way to view them as a newbie.

##### Share on other sites
I still have no clue why I would ever want to use them....

##### Share on other sites
Quoting myself...
quote:
I think the most usefull thing about matrices is that you can combine different transformations into one matrix.

Also, D3D and OpenGL use matrices for transformations. So, at least you have to build the matrices and feed them to the API.

• 10
• 17
• 9
• 14
• 41
• ### Forum Statistics

• Total Topics
631067
• Total Posts
2997740
×