• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Matrices

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1Bravolino  Members

Posted 08 December 2001 - 10:58 AM

Hello all, My question for you programmers is this: what is a matrix, what is it good for (in terms of game programming and app programming) and how do i use them in Java? Also, if neone has ne good tutorials in Java, post the sites, could ya? Thanx Mike

### #2SIGMA  Members

Posted 09 December 2001 - 03:39 PM

Oh good God in heaven (no, I''m atheist), I never thought I''d see the day. What grade are you in? I was introduced to matrices in somewhere around 9th grade! Matrices are basically a collection of real numbers on a 2d array. Here is an example of a matrix:
[4][5]
[3][4]
It''s not really all that complicated. It just says that if you call block[0][0] it would return a ''4''. block[0][1] would return a ''3'', just so long as your matrix is defined as block[x][y]. Matrices are mainly used for more complex math dealing with vectors, camera transformations, and other junk; however, they can all be used to store 2d tile maps which is a plus. Check out the Articles section here at GameDev, go over to Math, then Matrices. I believe there is an article about matrix math. It explains the concept of various matrix operations, with code in C++, which you probably won''t want. Hope this helps,
Good luck,
-Jesse

### #3Oluseyi  Members

Posted 09 December 2001 - 05:14 PM

quote:
Original post by Bravolino
...what is a matrix?

That''s a fairly existential (but simple to answer) question! A matrix is a rectangular array of numbers or functions. The next question is where the "sheezy" hits the "feezy":
quote:
...what does it mean?

This is related to your "what is it good for" question, and is unbelievably hard to answer (because there is no definite answer). A matrix''s meaning is dependent on the field and circumstance under consideration; it can represent pretty much any kind of linear relationship or transformation from one system to another. In condensed form.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

### #4bpj1138  Members

Posted 09 December 2001 - 05:40 PM

usually, in 3d graphics, you''d use a matrix to define an orientation for an object (that''s what direction it''s pointing at, what is it''s "up" vector, and what position is it at in world coordinates), here''s how you compose such a matrix:

|Rx Ry Rz 0|
|Ux Uy Uz 0|
|Dx Dy Dz 0|
|Px Py Pz 1|

R = right vector
U = up vector
D = direction vector
P = position vector

the R, U, and D vectors have to be "orthogonal", which means they have to be at right angles to each other, just like the xyz axis. they also have to be "unit vectors", meaning their length has to be 1.

if the vectors aren''t orthogonal, then you will sheer or streach the object, and if they''re not unit vectors, you will scale the object along the particular non-unit vector. so if the up vector''s lenth was 2, the object would be twice as tall.

there are two types of matrix operations, one is vector/matrix multiplication and the other is matrix/matrix multiplication. since a 3d model is defined with vectors, to "transform" the model from it''s local coordinate system to world coordinates, you''d multiply each vertex in the model by its orientation matrix. you can also multiply two orientation matricies to compose a "compound orientation". this is used in cases where you have an object with some sub-objects, such as a human body and arms/legs, or a tank with a rotating gun.. the tank has it''s orientation, and the gun has it''s orientation, but the gun''s orientation is relative to the tank''s orientation, so if the tank turns it affects the gun as well, even though the gun might be sitting still.

so to transform the tank model, you''d just have to multiply it by the tank orientation, but to transform the gun model, you''d have to multiply it first by the tank orientation and then by the gun orientation, or multiply the tank orientation by the gun orientation and then transform the gun model by the compound matrix.

### #5Anonymous Poster_Anonymous Poster_*  Guests

Posted 10 December 2001 - 11:37 AM

and those of you who learned about them in 9th grade know how much? Zero? Knowing that they are rectangles of numbers is worthless. Maybe this guy wants to actually understand what he is doing, not just be able to get the answer.

Here''s a partial explanation: Points have a set of values for a given coordinate system, generally x,y,z. So do vectors, so we can look at points as if they were vectors. A vector always has a coordinate system that it is relative to. Unless otherwise noted people assume that you are using the normal coordinate system. Coordinate systems themselves are defined using a set of vectors, called a "basis". The basis used to define our normal x,y coordinate system has two vectors, 1,0 and 0,1, but written vertically. When we write it as a matrix it looks like this:

1 0
0 1

the left side is the vector for the x dimension and the right side is for the y. Now let''s do a little matrix multiplication, since this is matrix multiplication you generally put what you are multiplying by on the left (AB is not the same as BA!). I''m going to use . to format. Let''s multiply 2,3 by the basis of normal 2d space

......2
......3
1 0 = 2
0 1 = 3

we get the same vector back. What if we use a different coordinate system?

......2
......3
2 0 = 4
0 2 = 6

now the vector is bigger, why? Well the original vector was in a coordinate system twice as big as the normal one. To bring the vector into our normal system we multiply by the basis of the space we are leaving. You see 2,0 and 0,2 were the vectors that the axis of the bigger space were relative to. It is hard to explain. Now thing about this, what if instead of 0''s we had different numbers? If you do things right you can use a matrix to rotate a vector. Remember a vector is just a point. What if you want to rotate all the points on your 3d model? Just use a matrix. This stuff is hard to teach online so I suggest you take a linear algebra course at a college. It is considered to be respectable math (math majors take it, english majors don''t) but the only real prereq is basic algebra. So take a class if you can.

### #6Bravolino  Members

Posted 10 December 2001 - 02:03 PM

Thanx everyone. I just wanted to know if anyone could elaborate a little on the whole thing aobut tiles and storing them in matrices. How does this work? If u dun wanna explain it, can u leave a link or something where i can find info? Thanx alot.
Mike

### #7Anonymous Poster_Anonymous Poster_*  Guests

Posted 10 December 2001 - 03:06 PM

no you don''t store tiles in matrices. When you say "matrix" people think of the mathimatical definition, which is what we''ve been discussing. I think you are looking for a two dimensional array, or a vector of vectors if you are using C++. (note: the vector class is horribly named and has nothing to do with vectors)

### #8Peon  Members

Posted 10 December 2001 - 05:26 PM

Yeah, I was getting a bit lost in the discussion up above myself... I've been introduced to matrices and matrix math at least twice now (ninth and tenth grade) but have forgotten completely how to do them. A multidimensional matrix might look like an array, but I understand them a lot better than matrix math stuff

As for storing tile data in arrays, a basic example might go like this:

  Map[2][2] = ({1,1}, {0,1}};

And then you would use two for statements to (one for each "dimension" of the array) and output what it find there. I'm just a newbie, so maybe this is a bad way to do this, but I find that using a case statement and outputting a tile based on the number in the array is pretty effective. The loop part is similar to the following:

  for (int x = 0; x <= 1; x++){ for (int y = 0; y <= 1; y++) { switch(map[y][x]) { case 1: //tile with a 1 in the array { cout<<"[]"; } break; }//end switch }//end for}//end for

Those of you who know what you're talking about, please correct me if I'm not making any sense

Edited by - Peon on December 10, 2001 12:28:47 AM

### #9Xsist10  Members

Posted 11 December 2001 - 01:25 PM

here it is again....
let me solve this problem once and for all...

http://www.sagamedev.co.za/articles/xsist10/matrix1.asp

### #10Bravolino  Members

Posted 11 December 2001 - 02:09 PM

Thanx all. Great help.Mike

### #11Anonymous Poster_Anonymous Poster_*  Guests

Posted 11 December 2001 - 02:30 PM

I just took my final in Linear Algebra today, yikes!! I would suggest you get some Trig under your belt as well as Algebra before you tackle that class.

Cheers
D

### #12Tricron2  Members

Posted 13 December 2001 - 11:53 AM

Learning matrix stuff in grade 9???

Dammit, I''m in grade 12 and my damn curriculum doesn''t cover them. So I don''t get to learn squat, instead I get to learn how to calculate how many different was a f*cking ball can fall down ''n'' connected tubes. A bunch of useless crap THAT is.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.