Matrices and Transformations...
Ok, I've finally went back and dabbed into learning OpenGL. I get most of it pretty well, but there's something I was never able to grasp, and that would be what the hell matrix transformations are. I've Googled on stuff about Matrix Multiplication and Linear Transformation but that stuff is pretty complicated for me (I'm usually really good at math but that got me good). I'm still having trouble figuring out what it all has to do with 3D anyway, 'cause I have no idea how it ties into it....
If someone could point me towards a less intense tutorial about this or maybe shine a little light on the subject I would really appreciate it....
If someone could point me towards a less intense tutorial about this or maybe shine a little light on the subject I would really appreciate it....
Ah, good old matrices... I've been using OpenGL for about 6 months now, and I'm only beginning to grasp how they work. Sometimes, it's best to just think of them as a black box. If you really want to understand how they work, there's some pretty heavy math involved.
This is one of the best web pages I've found on the subject: http://skal.planetd.net/demo/matrixfaq.htm
Basically, a matrix contains four 4dimensional vectors. One vector points to the right, one vector points up, one points forward (backward?), and one stores a positional offset. A 4x4 matrix contains all the information you need to translate from one coordinate system to another, including rotation, scaling, and translation.
A matrix looks something like this:
The numbers along the edges show the array indices you'd use to access that cell with a standard OpenGL matrix. For example, the cell in the 3rd row, 2nd column, +2/+4, would be at array index 6.
A special matrix called the identity matrix performs no transformations at all. Here's what it looks like:
This is what you get when you call glLoadIdentity(). Subsequent calls to glScale*(), glRotate*(), and glTranslate*() alter the values in the matrix.
Your timing on posting this was spoton; I'm currently deeply immersed in learning how matrices work. Let me know if you want me to elaborate on any of this.
Alex Diener
EDIT: I'm posting this at 1:00 AM, and my sleepy brain may have fuzzed over some of the details. Matrix experts feel free to correct me.
This is one of the best web pages I've found on the subject: http://skal.planetd.net/demo/matrixfaq.htm
Basically, a matrix contains four 4dimensional vectors. One vector points to the right, one vector points up, one points forward (backward?), and one stores a positional offset. A 4x4 matrix contains all the information you need to translate from one coordinate system to another, including rotation, scaling, and translation.
A matrix looks something like this:
Code:
Rght Up Frnt Offs.
+0 [x ] [x ] [x ] [x ]
+1 [y ] [y ] [y ] [y ]
+2 [z ] [z ] [z ] [z ]
+3 [w ] [w ] [w ] [w ]
+0 +4 +8 +12
The numbers along the edges show the array indices you'd use to access that cell with a standard OpenGL matrix. For example, the cell in the 3rd row, 2nd column, +2/+4, would be at array index 6.
A special matrix called the identity matrix performs no transformations at all. Here's what it looks like:
Code:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
This is what you get when you call glLoadIdentity(). Subsequent calls to glScale*(), glRotate*(), and glTranslate*() alter the values in the matrix.
Your timing on posting this was spoton; I'm currently deeply immersed in learning how matrices work. Let me know if you want me to elaborate on any of this.
Alex Diener
EDIT: I'm posting this at 1:00 AM, and my sleepy brain may have fuzzed over some of the details. Matrix experts feel free to correct me.
ThemsAllTook Wrote:http://skal.planetd.net/demo/matrixfaq.htmOr if you'd prefer not to burn your eyeballs out then try this link instead: http://www.j3d.org/matrix_faq/
Dealing with matrices as we use it for 3D is usually referred to as Linear Algebra. In my experience Linear Algebra has little to do with 3D but hey... So what does matrix algebra have to do with 3D? The answer: It's magic! Plain and simple. You can make points move around each other using conventional trig like sin cos and tan but those operations pound processors silly if used too much. Using matrices is a slick trick to avoid using those heavy trig functions for every vertex, multiple times, adnauseum. Doing matrix math by hand is very tedious and error prone (oh the bad college memories...) but computer processors absolutely shine at tedious tasks. Matrix math is usually the long way around things but it works VERY well with computers and that's why we do it that way.
http://pages.infinit.net/jstlouis/3dbhole/ might be something to look at. There are a zillion different sources of info on this subject so just try to find something that's readable to you. Search for 3d matrix math on google and I'm sure you'll find good stuff. flipcode and gamedev are sure to have good tutorials as well.
AnotherJake Wrote:Or if you'd prefer not to burn your eyeballs out then try this link instead: http://www.j3d.org/matrix_faq/
Dealing with matrices as we use it for 3D is usually referred to as Linear Algebra. In my experience Linear Algebra has little to do with 3D but hey...
I haven't took Linear Algebra yet, but I know the dot product, cross product, and normalizing vectors are used heavily in my 3D Games, but thats probably just a small piece of linear algebra.
I'm going to look into those links and try hard to comprehend it. (I might get it eventually). Well it does make me feel better that I'm not quite alone on the subject. I always thought I was stupid for not being able to understand them. Anyway, Math is one of my strongest areas so I shouldn't have too much trouble with it.
Anyway, the main reason is, whenever I come across a curious piece of code or something, I have to know what it does and how it works. A lot of people will just copy the code knowing what it does but having no clue how it really works. Me, I can't stand the thought of not knowing how it works or how to use it. Which is why I don't want to just throw it in there and see if it works. I know that 3D heavily uses dot products, cross products, and whatnot, but I never had a clue as to how they fit into the whole 3D thing.
I dunno. Anyway, pretty much all the math I'm learning, I'm learning completely on my own. All my math classes have basically been review for me so I'm pretty much on my own when it gets more advanced, so I guess I better get to work on that....
Anyway, the main reason is, whenever I come across a curious piece of code or something, I have to know what it does and how it works. A lot of people will just copy the code knowing what it does but having no clue how it really works. Me, I can't stand the thought of not knowing how it works or how to use it. Which is why I don't want to just throw it in there and see if it works. I know that 3D heavily uses dot products, cross products, and whatnot, but I never had a clue as to how they fit into the whole 3D thing.
I dunno. Anyway, pretty much all the math I'm learning, I'm learning completely on my own. All my math classes have basically been review for me so I'm pretty much on my own when it gets more advanced, so I guess I better get to work on that....
Nevada Wrote:Anyway, the main reason is, whenever I come across a curious piece of code or something, I have to know what it does and how it works. A lot of people will just copy the code knowing what it does but having no clue how it really works. Me, I can't stand the thought of not knowing how it works or how to use it.
I've always been the exact same way, but there have been times when it's simply not reasonable for me to expect to understand something. Quaternions are a prime example. They work wonderfully, the code you need to implement them is simple and very efficient, yet how they work is a total mystery. Matrices are similar, although I'm finding them to be a little bit easier to understand than quaternions.
Anyway, being able to understand things is great, but don't get too hung up on it if it's not essential. If you just want to work with the basics in OpenGL at this point, I wouldn't really bother trying to understand the inner workings of matrices. The only reason I'm trying so hard right now is because I'm working on some code that makes use of them heavily, and does all the matrix math itself (as opposed to letting OpenGL do it for me).
Alex Diener
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Fast font rendering with percharacter transformations  moridinbg  5  6,583 
Oct 22, 2009 12:56 PM Last Post: moridinbg 

D3D(yuck) and OGL matrices  Fenris  9  4,963 
Jul 4, 2004 12:04 AM Last Post: kelvin 