#### Archived

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

# Math is not my forte. Would somebody mind explaining matrices?

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I''ve been going through various demos, I''ve searched through articles and forum posts, but I''m still a bit at a loss. (I found a post that asked, "why uses matrices?", only to find it went on to ask why they didn''t use an even more advanced concept even further beyond my limited means.) As a bit of background, I''ve got a college-graduated level of education in everything but math. Math is my one downfall, and while I can understand most of the concepts as they''re explained to me, I don''t really have the understanding of the terminology or the lettering used. I''m art-focused, I already work as an artist, but I want to know how the other half works, so that I can put into effect my own game designs, start to finish. I''ve done 2D programming, but I kept running into limitations which are easier to fix in 3D. I''m currently taking an OpenGL class, but the third chapter of the book goes into this stuff, and I''m at a loss. I''ve seen identity matrices, and I *somewhat* understand the concept, but I don''t understand the reasoning behind it, at least I haven''t seen anything explaining the reasoning. I''ve seen that the bottom row contains the direct positioning, relative to the origin point. What about the other three rows? And what''s the point of the 1''s down the middle? I understand that that''s what defines an identity matrix (I''ve seen about a dozen different articles and books define that, with no other explaination), but I don''t understand why they are what they are. It partially doesn''t help that my c++ knowledge, for understanding examples given here and elsewhere, is extremely limited, mostly to what I''ve learned inside Java, with a few of the differences in comparison. (Pointers are my friend.) So, can anyone help the poor lost art-guy?

#### Share this post

##### Share on other sites
An identity matrix is just a matrix that when multiplied by another matrix, will always equal the other matrix.
It''s like muliplying a number by one.
That''s because mutiplying two square matrices is just a process of doing dot products between the columns of the right matrix with the rows of the left matrix.

#### Share this post

##### Share on other sites
Perhaps learning how to write your own Matrix class is the way to go. You''ll understand what''s happnening. Heck, I should too.

--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net

#### Share this post

##### Share on other sites
quote:
Original post by gtdelarosa
An identity matrix is just a matrix that when multiplied by another matrix, will always equal the other matrix.
It''s like muliplying a number by one.
That''s because mutiplying two square matrices is just a process of doing dot products between the columns of the right matrix with the rows of the left matrix.

And you''ve already lost me. What''s the process behind multiplying matrices?

And what''s a dot product? as I said, I have very little experience in math. I understand sin()/cos(), and a²+b²==c², at least in application, but that''s about the extend of my geometry.

A matrix class? Okay. And what exactly does a matrix class need that I would need to write one to understand it? I''m still working through the basics here.

#### Share this post

##### Share on other sites
http://www.martinb.com/maths/algebra/matrix/index.htm

Do google searches for linear algebra, I really doubt you'll find someone who can explain linear algebra in one web forum post... I dont think it is possible... there is a reason that linear algebra is an entire semester course in most computer science undergrad programs

[edited by - duke on May 19, 2004 6:23:31 PM]

#### Share this post

##### Share on other sites
Try to get a good book on linear algebra. A matrix is best understood as what it is instead of a magical block of numbers; it''s the representation of a linear transformation. At least, think of it as a function. And once you understand the mathematical concepts, you can do a lot more without having to do guesswork. Maybe ask someone in a math program for what book they use, if you don''t find a good book on Amazon.

#### Share this post

##### Share on other sites

Quote: "I really doubt you'll find someone who can explain linear algebra in one web forum post..."

What the heck, I've got nothing better to do

IMO, mathematicians and graphics programmers look to matricies to solve two different types of problems. A matrix, as it applies to the graphics programmer, represents a transformation from one coordinate system to another coordinate system. This matrix can have a different position, orientation, and scale independant of the original coordinate system. When you multiply an object by a matrix (using a dot product), you are transforming that object into a new coordinate space, possibly moving the object, rotating the object, and scaling the object in one operation. For example, suppose you had a matrix that represented a coordinate system that was five feet to your right and was flipped upside down. If you were to multiply an object by this matrix, the object would move five feet right of its previous location, and flip upside down. Matrices can also be multiplied by other matrices, which yields a matrix capable of performing many transformations in one operation. Suppose I had matrix A which moved an object 5 feet to the right, and matrix B which flipped an object upside down. I *could* multiply the object by matrix A to move it, and then multiply the object by matrix B to flip it. However, the best way would be to multiply matrix A by matrix B, creating matrix C which would be capable of moving AND fliping, and then multiply the object by matrix C. Using the product of the two matrices is preferable in a situation where you have more than one object, because this will result in fewer multiplications. In implementation, a matrix to perform two dimensional transformations is just a 3 x 3 grid of floating-point numbers.

Ex: 3x3 Identity matrix

[ [ 1, 0, 0 ],
[ 0, 1, 0 ],
[ 0, 0, 1 ] ]

A matrix to perform three dimensional transformations is a 4 x 4 grid of floating-point numbers. I hope this helps somewhat...

[edited by - EvilSteve on May 19, 2004 7:06:05 PM]

#### Share this post

##### Share on other sites
quote:
Original post by duke
http://www.martinb.com/maths/algebra/matrix/index.htm

Do google searches for linear algebra, I really doubt you'll find someone who can explain linear algebra in one web forum post... I dont think it is possible... there is a reason that linear algebra is an entire semester course in most computer science undergrad programs

[edited by - duke on May 19, 2004 6:23:31 PM]

Oh, oh! I found what I needed. Off of that link, there's a tutorial which demonstrates a 3D model being manipulated through alterations to the itentity matrix. Adding to or changing each number simply alters the other corresponding dimensions of the model. They also include an exploratory program.

(Edit: Nevermind. The program is rather buggy and I can't make heads or tails of it from the documents it's referenced in.)

Still, the other post gets the idea down.

[edited by - Leonidus on May 19, 2004 7:22:44 PM]

#### Share this post

##### Share on other sites
quote:
Original post by EvilSteve

Quote: "I really doubt you''ll find someone who can explain linear algebra in one web forum post..."

What the heck, I''ve got nothing better to do

(clipped for space)

A matrix to perform three dimensional transformations is a 4 x 4 grid of floating-point numbers. I hope this helps somewhat...

[edited by - EvilSteve on May 19, 2004 7:06:05 PM]

Ah, yes, that helps a great deal. I''m used to dealing in 3 dimensions, I''m a game artist, including 3d game meshes, so most of this stuff is familiar to me through various numeric tools in the modeller I use. I just need to learn how to associate my previous knowledge with this new application.

There, that wasn''t so hard, now, was it?

#### Share this post

##### Share on other sites
quote:
Original post by Leonidus
quote:
Original post by EvilSteve

Quote: "I really doubt you'll find someone who can explain linear algebra in one web forum post..."

What the heck, I've got nothing better to do

(clipped for space)

A matrix to perform three dimensional transformations is a 4 x 4 grid of floating-point numbers. I hope this helps somewhat...

[edited by - EvilSteve on May 19, 2004 7:06:05 PM]

Ah, yes, that helps a great deal. I'm used to dealing in 3 dimensions, I'm a game artist, including 3d game meshes, so most of this stuff is familiar to me through various numeric tools in the modeller I use. I just need to learn how to associate my previous knowledge with this new application.

There, that wasn't so hard, now, was it?

Jeez, I don't think anyone who has to deal with 3d everyday would forget something as simple and as frequently used as this, I don't think you are serious or you got up on the wrong side of the bed today . |suspicious| Are you sure you are
quote:
3 dimensions, I'm a game artist, including 3d game meshes
|/suspicious|

[edited by - snyp on May 19, 2004 7:31:36 PM]

#### Share this post

##### Share on other sites
Well, that''s just the thing, I''ve never really used it. I''ve numerically rotated, scaled, translated, etc, IN the modelling prog, but neevr really all in the same statement.

#### Share this post

##### Share on other sites
Im abit like you, i don't understand how matrices really work to produce what you see onscreen.

Basically a matrix stores transformations which affect how anything drawn onscreen appears. Many transformations can be contained in 1 matrix making it efficient to store multiple transformations in a matrix. Multiplying matrices combines their effects into 1 matrix result.

Usually you wont be calculating matrices by yourself, that is what modelling programs are for, they can export the needed matrices for you. All you have to do is mulitply them with the current modelview matrix and you will get what you want.

That is about all you need to know, and with OpenGL, you dont even have to bother with it as you can use glTranslatef glRotatef.

What im trying to say is that there comes a time in games programming when knowing the reasoning behind it matters less than knowing how to use it.
EG : You know how to use sin/cos, but how many people feel the need to know how sin/cos actually work internally?

Mystique Legacy : Rise of the Forgotten World

[edited by - GamerSg on May 20, 2004 2:06:03 AM]

#### Share this post

##### Share on other sites
quote:
Original post by GamerSg
That is about all you need to know, and with OpenGL, you dont even have to bother with it as you can use glTranslatef glRotatef.

and yet, if calling translate and rotate is all your knowledge about "matrices" and you just see them as magical black box without at least understanding what the single columns represent you will spend a lot of time writing inefficient code with tons of rotate and translate calls.

example: how will you set the modelview to make a billboard face the camera? hopefully not by starting to calculate angles and calling rotate.