View Full Version : Explain Matrices to a 15 Year Old
31337
11222002, 10:43 AM
Can anybody here explain matrices to a 15 year old? I have done kramer's rule in math but thats about it. The way my computer graphics teacher explained glPushMatrix() and glPopMatrix() to me was that any rotations or translations done between them only affect whats drawn between them. However, now I'm running into lots of problems when drawing my terrain in my game. Like when I scroll the mouse wheel and it changes the camera's y position, it also changes the terrain's position. Does anybody have any ideas on what might be causing this? I push and pop the matrix before I draw the terrain.
What exactly is this "rotation matrix"? Can anybody put it into terms I can understand? Thanks
EPHERE
11222002, 12:07 PM
Matrices represent a linear mapping of a system of equations. In other words any system of equations returning distinct results can produce a matrix of the same rank.
What you need is to read an intro to algebra.
nexusone
11222002, 12:43 PM
Of course when you change the camera position the land scape will change to reflect it.
Remember OpenGL does not move the camera, you move the world around it to look like camera is moving.
You must keep this in mind this when drawing your world.
Originally posted by 31337:
Can anybody here explain matrices to a 15 year old? I have done kramer's rule in math but thats about it. The way my computer graphics teacher explained glPushMatrix() and glPopMatrix() to me was that any rotations or translations done between them only affect whats drawn between them. However, now I'm running into lots of problems when drawing my terrain in my game. Like when I scroll the mouse wheel and it changes the camera's y position, it also changes the terrain's position. Does anybody have any ideas on what might be causing this? I push and pop the matrix before I draw the terrain.
What exactly is this "rotation matrix"? Can anybody put it into terms I can understand? Thanks
31337
11222002, 03:34 PM
How do these matrices work into opengl though? I don't see the relation
Arnt the matrix setting up OpenGl? And OpenGl uses them. You don't need to know a lot about them. I know that when you want to rotate something a "rotation matix is mulitpled with the transformation matrix" or the modal matix. Like glRotatef(). The rendering is created though those matrixs. But yer how that happen I have know idear.
EPHERE
11232002, 06:32 AM
I do not know the insights of opengl as I didn't develop it. But my bet is that every vertex (being in Eucledian space) is multiplied by a transformation matrix that is generated by glRotatef, Translatef etc.
When you reset the matrix it simply makes an identity matrix.
Same thing is done for camera (perspective, orthographic, paraperspective) projections in projective and affine spaces. Basically everything in geometry (hence OpenGL) is driven by matrices.
This way help
Shows how a matrix is used to transform a point in 3D space.
outx = mtx[0][0]*pntx + mtx[1][0]*pnty + mtx[2][0]*pntz + mtx[3][0];
outy = mtx[0][1]*pntx + mtx[1][1]*pnty + mtx[2][1]*pntz + mtx[3][1];
outz = mtx[0][2]*pntx + mtx[1][2]*pnty + mtx[2][2]*pntz + mtx[3][2];
Matrixes are difficult to understand but
much easier than getting someone to buy you
beer outside the 711 http://www.opengl.org/discussion_boards/ubb/smile.gif
nexusone
11232002, 11:32 AM
In the simpless form, the matrix is applied to each vertex point.
example we tell the matrix to do a translate on 5,0,0, every X vertex drawn after the translate command will be subtracted by 5.
Originally posted by 31337:
How do these matrices work into opengl though? I don't see the relation
Eucledian space what that? superfical 3d space like x,y,z in data.
All Opengl basically does is rasterize(draw) primitives(like tris etc.) which are defined by points.In order to define a point of course you need a coordinate system.Say our initial coord. system(with the identity modelview matrix) where we have defined a quad looks like this:
^

 xx
  
 xx

+>

Now say we load a rotation matrix instead of an identity and then draw the same quad.The quad vertices' coords. will be the same but they'll be multiplied by the modelview(rotation) matrix (among others,more on that later) which will cause a rotation of the coord. system.Something like that:
^ x
\ /\
\ x/ x /
\ \ / /
\ x/ /
\ /
\ /
\/
/\
(I know it sucks but it's the best I can do with ascii art)
Now when viewed relatively to the new coordinate systm the quad is exactly the same as in the first figuer but when viewed relatively to the initial coord. system the quad has been rotated.It's in 2D here due to technical limitiation but the same goes for 3d.
The modelviewm matrix maps vertices from world space to object space.As they go down the rendering pipeline vertices are mapped to clip space and device space by the projection and viewport matrices.
Read the initial chapters of the Red book(the online old version will do fine) and so a google search (www.google.com).There's nothing hard about matrices.
[This message has been edited by zen (edited 11232002).]
31337
11242002, 06:16 AM
I get it now! Zen and nexusone you guys helped a lot.
Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.