🔒 Locked
Matrix
Advertisement
Original Post
Hi.
Newbie here. =)
I''ve pretty much followed the tutorials quite slavish up until now(lesson 10).. When I had read it, and gotten it to work, I figured it would be cool to add lighting(and quads, and dynamic textures, and dynamic normals(all these seem to work, yey!)) to it. So I, somewhat hackish, added lesson 7 to the project. Big dissappointment. After trying, for a couple of hours, to find out what was wrong, I came to the conclusion that light positions are defined in camera space, instead of world space(heh, my own expressions. Ain''t I good?=)..(2 things.. 1: why the heck is it that way, and 2: why cant someone just tell us about it, using that simple sentance).. After even more searching on converting world space(own word again. hehe) into cameraspace(glLightfv( GL_LIGHTx, GL_POSITION, float pos[3] ); ), I was told(on the forum) by Akura that I should use the, and here it comes...
use the inverse matrix of the projection matrices.
Now, since I''m not good, I instantly go "HUH??"..
As a response, I get "Buy a linear algebra book".. Now this might be a problem, seeing as 1: I just got TOTWGPG, and 2: I''m broke. It was an expensive book(though great). So..
To make a VERY long(or so it seems to me, I useually post short) post short...
What a matrix, whats it used for, and how do I inverse it. :=)
ERJO
- Ducks and covers
Actually, what the Anonymous Poster described is Matrix transposal.
Besides a complicated hand-done procedure (which I don''t think would be optimal for 3D graphics) and API functions that''ll do it for you, I don''t know how to go about finding the inverse of a Matrix.
Hopefully somebody else will respond with that info.
Besides a complicated hand-done procedure (which I don''t think would be optimal for 3D graphics) and API functions that''ll do it for you, I don''t know how to go about finding the inverse of a Matrix.
Hopefully somebody else will respond with that info.
I''m not sure exactly what you want, but if you want to be able to move the camera around in your scene, and you have a
float Camera[3] or something like that that holds the XYZ coordinates of the camera, just do
glTranslatef(-Camera[0],-Camera[1],-Camera[2]); near the beginning of your program.
Oh wait I just read your post again and think I know what you mean now
The light is moving with the camera? If that''s the problem just call glLightfv(GL_LIGHT0,GL_POSITION,lightpos); assuming lightpos is the location of the light, AFTER you make the movements for the camera.
e.g.
glTranslatef(-Camera[0],-Camera[1],-Camera[2]); //Move camera
glLightfv(GL_LIGHT0,GL_POSITION,lightpos); //Move light
I believe this will make the light remain stationary.
Sorry if this is not your question.
-David
float Camera[3] or something like that that holds the XYZ coordinates of the camera, just do
glTranslatef(-Camera[0],-Camera[1],-Camera[2]); near the beginning of your program.
Oh wait I just read your post again and think I know what you mean now
e.g.
glTranslatef(-Camera[0],-Camera[1],-Camera[2]); //Move camera
glLightfv(GL_LIGHT0,GL_POSITION,lightpos); //Move light
I believe this will make the light remain stationary.
Sorry if this is not your question.
-David
Matrix''s are a way to solve equations in Algebra. I am learning Matrix''s in a week or two at college but from what I can see without doing anything with it is the X,Y,Z cordinates can be determined with algerba right? And if y=mx+b to find slope of a line and to add depth your going to have to factor in some other equation doing this with matrix''s would be faster and easier right? I am a newbie to you caught me!
anyway I would think this is close to how it is being used.
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Um... I dunno the answer, as I''m a newbie, but I just want to say that I learned matrices in 6th or 7th grade, and still remember them. They''re just a bunch of numbers encased in brackets, and unfortunately, I''d have to find my long-lost graphing calculator manual to tell you how to inverse one. Sorry.
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
I just get a kick out of people who say they learned all of this math in 6 and 7 grade like my college math prof. If that was the case then they shouldn''t have to teach this stuff in college! Hell they ought to be teaching the chaos theory of math!! In your freshmen year of college! Na I don''t think so, you might get this stuff in H.S. but it isn''t the same degree of knowledge you learn for a univeristy.
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Okay erjo,
Bear with me! The math for this is a little complicated. I hope there''s an easier way to compute it, but this is the way I learned it when I took linear algebra. Perhaps you can go through the math in terms of variables and find equations to cut down on all the manipulation you have to do.
First, take your matrix A:
4 -2 3
2 0 5
2 1 7
Now, you''ll append it''s identiry matrix to it''s right side as so:
4 -2 3 1 0 0
2 0 5 0 1 0
3 1 7 0 0 1
In case you don''t know what an identity matrix is, it''s a matrix that when you multiply any matrix to it, it will return the original matrix you started with (note, you can only multiply matrixes of the same dimensions).
Okay, so you have this gross looking 3x6 matrix (note, in general a nx2n matrix). You need to transform the matrix into reduced echelon form. Okay ... let me explain.
Echelon form is when you make the leading element of every row by itself in the column. This is done by manipulating the equations in each row according to matrix rules (each row can be though of as an equation, each column can be thought of as a different variable). Allow me to demonstrate:
4 -2 3
2 0 5
3 1 7
becomes
4 -2 3
0 10 19
0 0 1
The leading elements are in this case 4, 10, and 1. Notice that this forms a triangular matrix (the elements below the diagonal are all zero, and the only ones we care about create a triangle). Now technically, we should make each leading (nonzero) element in each row 1, so we should really get:
1 -.5 .75
0 1 1.9
0 0 1
Now ... this is echelon form, but we need to do REDUCED echelon form, which means more math. Let''s start with the 3x6 matrix:
4 -2 3 1 0 0
2 0 5 0 1 0
3 1 7 0 0 1
becomes
1 -.5 .75 .25 0 0
0 1 1.9 -.3 0 .4
0 0 1 -.125 .625 -.25
Now, to make it reduced echelon form, we work our way up from the bottom! In this instance, we want to turn this part of the matrix:
1 -.5 .75
0 1 1.9
0 0 1
into an identity matrix:
1 0 0
0 1 0
0 0 1
Again, this can be accomplished by row manipulation, and trying to make terms cancel. The thing is that while you are doing these manipulations to revert back to the identity matrix, the other half of the matrix is being influenced too! If you reduce the echelon form of the 3x6 matrix above, it becomes:
1 0 0 .3125 -1.0625 .625
0 1 0 -.0625 -1.1875 .825
0 0 1 -.125 .625 -.25
And presto! That 3x3 matrix next to the identity matrix? That''s your inverse matrix! So the inverse of:
4 -2 3
2 0 5
3 1 7
is:
.3125 -1.0625 .625
-.0625 -1.1875 .825
-.125 .625 -.25
Note that you can do the SAME procedure with the above matrix (by appending an identity matrix to the right side and reducing it to reduced echelon form), and you will get the matrix that you started with!
However, this is very math intensive, and you are most likely going to want to use a function in the API. They are NOT fun to do by hand. In fact, I used my TI-85 to do the computations for me
.
Anyway, THAT is what is meant by an inverse matrix! And as the name suggests, if you multiply a matrix by it''s inverse, you get back an identity matrix!
If anyone knows of an EASIER method, I''d be much obliged to learn, as I have always found it painful to do it this way!
Hope I''ve been helpful!
eriol
Bear with me! The math for this is a little complicated. I hope there''s an easier way to compute it, but this is the way I learned it when I took linear algebra. Perhaps you can go through the math in terms of variables and find equations to cut down on all the manipulation you have to do.
First, take your matrix A:
4 -2 3
2 0 5
2 1 7
Now, you''ll append it''s identiry matrix to it''s right side as so:
4 -2 3 1 0 0
2 0 5 0 1 0
3 1 7 0 0 1
In case you don''t know what an identity matrix is, it''s a matrix that when you multiply any matrix to it, it will return the original matrix you started with (note, you can only multiply matrixes of the same dimensions).
Okay, so you have this gross looking 3x6 matrix (note, in general a nx2n matrix). You need to transform the matrix into reduced echelon form. Okay ... let me explain.
Echelon form is when you make the leading element of every row by itself in the column. This is done by manipulating the equations in each row according to matrix rules (each row can be though of as an equation, each column can be thought of as a different variable). Allow me to demonstrate:
4 -2 3
2 0 5
3 1 7
becomes
4 -2 3
0 10 19
0 0 1
The leading elements are in this case 4, 10, and 1. Notice that this forms a triangular matrix (the elements below the diagonal are all zero, and the only ones we care about create a triangle). Now technically, we should make each leading (nonzero) element in each row 1, so we should really get:
1 -.5 .75
0 1 1.9
0 0 1
Now ... this is echelon form, but we need to do REDUCED echelon form, which means more math. Let''s start with the 3x6 matrix:
4 -2 3 1 0 0
2 0 5 0 1 0
3 1 7 0 0 1
becomes
1 -.5 .75 .25 0 0
0 1 1.9 -.3 0 .4
0 0 1 -.125 .625 -.25
Now, to make it reduced echelon form, we work our way up from the bottom! In this instance, we want to turn this part of the matrix:
1 -.5 .75
0 1 1.9
0 0 1
into an identity matrix:
1 0 0
0 1 0
0 0 1
Again, this can be accomplished by row manipulation, and trying to make terms cancel. The thing is that while you are doing these manipulations to revert back to the identity matrix, the other half of the matrix is being influenced too! If you reduce the echelon form of the 3x6 matrix above, it becomes:
1 0 0 .3125 -1.0625 .625
0 1 0 -.0625 -1.1875 .825
0 0 1 -.125 .625 -.25
And presto! That 3x3 matrix next to the identity matrix? That''s your inverse matrix! So the inverse of:
4 -2 3
2 0 5
3 1 7
is:
.3125 -1.0625 .625
-.0625 -1.1875 .825
-.125 .625 -.25
Note that you can do the SAME procedure with the above matrix (by appending an identity matrix to the right side and reducing it to reduced echelon form), and you will get the matrix that you started with!
However, this is very math intensive, and you are most likely going to want to use a function in the API. They are NOT fun to do by hand. In fact, I used my TI-85 to do the computations for me
Anyway, THAT is what is meant by an inverse matrix! And as the name suggests, if you multiply a matrix by it''s inverse, you get back an identity matrix!
If anyone knows of an EASIER method, I''d be much obliged to learn, as I have always found it painful to do it this way!
Hope I''ve been helpful!
eriol
No offense or anything, but I could have understood that math after Algebra I, which I did go through in 7th grade. Again, no offense.
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
See that is what I am talking about. Linear Algebra is a college level class. That isn''t fun or easy. Yea people now these days use TI-82 and above calculators to do math but if you don''t understand what is going on what good is the calculator do you? I haven''t taken Matrix Algebra or Linear Algebra and don''t plan on it I only need Calculus to get my degree. Why beat my brain against the wall for nothing? If I need that kind of math I will learn it on my own and not throw away $500 for a semester class and get a D or F for a grade!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
I said "no offense". Besides, I meant to say MOST OF the math... then the calculator takes over, and all of my problems are solved! I admit that I think my calculator is the greatest thing on the face of the earth (J/K) and I don''t see what''s wrong with them. They were made to make your lives easier by NOT having to do all of the math by hand, and I think everyone should appreciate that.
P.S. I am slightly confused with that Echelon Form Thingie, which is why I reiterate that I understand only MOST of the math. How did you get those 2nd and 3rd rows like that? Other than that, it''s just division by the leading numbers.
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
P.S. I am slightly confused with that Echelon Form Thingie, which is why I reiterate that I understand only MOST of the math. How did you get those 2nd and 3rd rows like that? Other than that, it''s just division by the leading numbers.
-Nutty C. Schmo
"Am I the site only this person on grammar good with?"
NuttySchmo,
No offense taken. Sorry if it was a little too lengthy, but not everyone may have had the background you do, so I was trying to make sure I didn''t assume anything. True, you may have taken this in 6th and 7th grade, but I for one had to wait until my freshman year of college. I am a junior now, and people STILL have problems with this stuff.
But you are right, it isn''t hard (once you understand it). It just is hardly incorporated in most of our educational math, and as with anything ... if you don''t use it, you lose it!
Personally, I don''t find linear algebra to be a waste, I find it very useful and interesting. You really use a lot of it in graphics and robotics, as well as many other engineering aspects. Yes, some people have been kind and taken a lot of the complexity out of it, but it always helps to understand what is going on. But again, it''s not something for everyone.
So ... no offense taken, but I was being painfully explicit for clarity''s sake.
eriol
No offense taken. Sorry if it was a little too lengthy, but not everyone may have had the background you do, so I was trying to make sure I didn''t assume anything. True, you may have taken this in 6th and 7th grade, but I for one had to wait until my freshman year of college. I am a junior now, and people STILL have problems with this stuff.
Personally, I don''t find linear algebra to be a waste, I find it very useful and interesting. You really use a lot of it in graphics and robotics, as well as many other engineering aspects. Yes, some people have been kind and taken a lot of the complexity out of it, but it always helps to understand what is going on. But again, it''s not something for everyone.
So ... no offense taken, but I was being painfully explicit for clarity''s sake.
eriol
HEY! guess what I was looking thru Algebra.com and guess what I found! A matrix inversing tool. heh you want the address. . . you''ll have to pay me for it. . no here it is. . .
http://www.algebra.com/algebra/college/linear/
read that page and you''ll know where to go from there. I hope that helped. I know nothing about 3d programming yet So I don''t know if thats what you want. But it sounds like it!
_BUSTER_
Check out my for sale domain name!
http://www.theatermonkey.com
http://www.algebra.com/algebra/college/linear/
read that page and you''ll know where to go from there. I hope that helped. I know nothing about 3d programming yet So I don''t know if thats what you want. But it sounds like it!
_BUSTER_
Check out my for sale domain name!
http://www.theatermonkey.com
Dam I wish I had my scanner hooked up right now! I am only 5 sections away from inverses of matrices!!! I could then scan it and post it or else just head to Barnes and Noble and read up on it in a math book! Having to much fun with LOG and LN and e^2 and oh my! Fun!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Windows 98/SE/ME SUCKS!
Deal with it!
if(windows crashes)
run Linux
else
yea right!!
Ugh, just lost some intro text 
There''s a theory in my linear alg. book that states that a matrix is "orthogonal" ( A-1=AT) only when the vectors formed by the matrice''s columns form an orthonormal (think-axises of length 1 that are also mutually perpendicular to each other) set.
Well,... all of the matrices that are commonly used in computer graphics start off with the standard basis of X, Y and Z and rotate and translate it, placing objects at different points of the process until the scene is populated with objects and it is time to render the next frame. Neither translating nor rotating the basis should change the basic mutually perpendicular property that you started off with (the x, y, and z axis''s all intersecting each other at 90 degree angles).
So,...given a transformation matrix (of nXn size, this usually means the rotation matrix), the inverse of the matrix is just its transpose. The transpose is defined as taking the first row of a matrix and write it back as the first column of the transpose. The second row of the matrix is written back as the second column of the transpose and so on....
There is a problem, and that is, with time, the condition on the column vectors of the matrix may become violated because of errors that creep into the matrix (computers aren''t perfect) due to rounding error, etc.
There is a solution to this, however I am too tired to give it here. It involves, naturally, forcing all the vectors to become mutually perpendicular once more. This sounds computationally expensive (and it is), but it only needs to be run once in a while.
I hope that this helped anyone who is reading, because it took me a while to figure out for myself.
There''s a theory in my linear alg. book that states that a matrix is "orthogonal" ( A-1=AT) only when the vectors formed by the matrice''s columns form an orthonormal (think-axises of length 1 that are also mutually perpendicular to each other) set.
Well,... all of the matrices that are commonly used in computer graphics start off with the standard basis of X, Y and Z and rotate and translate it, placing objects at different points of the process until the scene is populated with objects and it is time to render the next frame. Neither translating nor rotating the basis should change the basic mutually perpendicular property that you started off with (the x, y, and z axis''s all intersecting each other at 90 degree angles).
So,...given a transformation matrix (of nXn size, this usually means the rotation matrix), the inverse of the matrix is just its transpose. The transpose is defined as taking the first row of a matrix and write it back as the first column of the transpose. The second row of the matrix is written back as the second column of the transpose and so on....
There is a problem, and that is, with time, the condition on the column vectors of the matrix may become violated because of errors that creep into the matrix (computers aren''t perfect) due to rounding error, etc.
There is a solution to this, however I am too tired to give it here. It involves, naturally, forcing all the vectors to become mutually perpendicular once more. This sounds computationally expensive (and it is), but it only needs to be run once in a while.
I hope that this helped anyone who is reading, because it took me a while to figure out for myself.
joeG
wow..., what a big mess you guys are making for this.
Just do it this way:
On the begining on the DrawGLScene, do
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Now, do the translation of the camera in model_view, re-assign the position of the light, enable fog, etc etc.., all of this should be made in the MODELVIEW mode.
take a look at this link, you will understand better what i mean.
http://www.3dgamedev.com/articles/projection_abuse.htm
take care,
Bruno
Edited by - Bruno on April 21, 2001 6:33:51 AM
Just do it this way:
On the begining on the DrawGLScene, do
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Now, do the translation of the camera in model_view, re-assign the position of the light, enable fog, etc etc.., all of this should be made in the MODELVIEW mode.
take a look at this link, you will understand better what i mean.
http://www.3dgamedev.com/articles/projection_abuse.htm
take care,
Bruno
Edited by - Bruno on April 21, 2001 6:33:51 AM
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement