Advertisement

What Is The Matrix

Started by January 17, 2002 07:52 PM
4 comments, last by azaxaca 23 years, 1 month ago
Now, im not talking about the movie, im talking about whatever matrix that has to do wit 3d programming. Im looking at a code colony tutorial and the code keeps on glpushing and when its half way through, it keeps glpoppin matrix for every figure drawn sorry if newbies make you frustrated but well, even you had to be a newbie once in your lifetime, so please be generous and teach me stuff.. ========================= ..I still dont get the difference between c and c++...
..I still dont get the difference between c and c++...
Hmm I''m not very experienced with 3D Graphics myself but perhaps you''re talking about the rotation matrix? When you need to rotate every polygon around (because you turned the camera or something) you can use a matrix to do it but I just use flat out equations. Oh well there''s my 2 cents... hope this helps. The rotation equations I use (for example left and right looking) are:
x_new = z_old*sin(degrees*piover180)+x_old*cos(degrees*piover180));
y_new = y_old;
z_new = z_old*cos(degrees*piover180)-x_old*sin(degrees*piover180));

Hmmmm there I think that''s right.


--------------------------
HelloWorld.exe
HelloWorld.cpp - 13 Error(s), 23 Warning(s)
--------------------------HelloWorld.exeHelloWorld.cpp - 13 Error(s), 23 Warning(s)
Advertisement
What your refering to is the matrix stack.

essentially how it works is this.

Each matrix can contan a rotation, translation, and scaling..
or just one of the above.

Say your view is rotating.. the first matrix on the stack would be the world view matrix.. it rotates everything in your view.

then say you wanted to place an object in your world... you want him to be placed relative to the world.. so when the world rotates.. so does he. So you push a matrix on the stack... this essentially pushes a translation, rotation ontop of the world matrix... then you draw the object.
Now if you want to place another object in the world, you pop off the top matrix, and now your operating in the world matrix. You can push on another matrix and draw the new object.

What happens is when the world rotates all the objects will rotate with the world since they are based off the world matrix.
Matrices are what make 3D graphics so much more easy to calculate.

The identity matrix is
1 0 0
0 1 0
0 0 1

Or basically any square matrix (where the columns and rows are of equal length) where the diagonal (from top left to bottom right) has values of 1 and the rest are all 0.

When you draw an object, you don''t want to lose the position you are currently at. So glPush() pushes the current matrix, with whatever transformations you applied to it, onto a stack. You can then use another matrix, such as the identity matrix, and start fresh, or you can use the current matrix and change it, all the while leaving its current state saved on that stack.
So imagine you want to make a robot with a cube object.
You are located at the origin.
You want to make the body, so at the origin you glScale or whatever to make a long box as the body. Now you want to move to the head part. Well, in order to do it without losing your place, you can glPush to keep your original position, along with whatever other transformations you did (such as scaling, if you want), then glTranslate to a point above the current block to make a cube that is glScaled appropriately.
Now instead of moving directly to the arm or leg, you can glPop and return to the original spot at the origin. Then you can move from there.
It makes things easier, especially when you have so many objects to place, and you don''t want to have to worry about how far away they are from each other. Now you only have to worry about how far away they are from the origin or whatever you want to use as your original point.
I think there are probably many more good reasons, but I am still learning so this is as far as I know for now. Hope this helps!

-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
Or you can read the post above and learn what I said in less than half the text! B-)

-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
Thanks for all your help!!

i think i understand what it is now, but i guess in order to
fully understand it, i gota go find some tut about it.

because you helped, it would make things easier for me to
learn more of it


Thanks!

=====================

..I still dont get the difference between c and c++...
..I still dont get the difference between c and c++...

This topic is closed to new replies.

Advertisement