What I''m trying to do is figure out how to place object in the 3d world and make them move while, at the same time, controling the camera without gluLookAt
there''s many point I don''t get
1) Why is the original direction of the camera is toward the -z and how can I set it to look in the +z direction ?
2) How and when do I use glPushMatrix and glPopMatrix ?
3) Also when do I use glLoadIdentity ? cause when I use it the camera doesn''t move anymore so I guess I don''t use it right
4) And finally what is the logic of multiple object moving and camera moving at the same time ? ( cause all the toturial I''ve seen have 1 non-moving object and a camera...that''s lame hehe )
Please help me out here.
Thanks a lot guys !
You should read a few of the many excellent tutorials on matrix math and projection matrices, a few of which are available on this site. This answers all your questions except push/pop matrices; these simply copy to/from a stack of current transformation matrices, so you can return to an earlier state without completely recalculating. Read about matrix math; you''ll get it.
I really recommend you purchase the OpenGL Game Programming book...all of this is explained there...
ill try to help anyway...even though im not a "pro"...
well, gluLookAt, what''s your problem with it? it''s efficient, fast, but if u HATE using it, then there''s a thing called viewing matrix (ill explain in a sec) u can change that in order to control the camera. (glu just does it faster and easier)
when u use glLoadIdentity, it loads "Identity Matrix" values into a certain matrix. there are a few predefined matrices in ogl : Viewing Matrix. -> what you do to this matrix affects the camera Modeling Matrix. ->" " " " " " " " " " the vertices u use. Projection Matrix.-> projection type, perspective or ortho-something.
now...all of these matrices are 4x4, so when u use glLoadIdentity it restores the matrix u choose to its default position.
u choose which matrix to affect with glMatrixMode(mode), mode can be GL_MODELVIEW, GL_PROJECTION and some other stuff u don''t really need(GL_TEXTURE). (i dunno which const chooses the camera matrix, cause i use gluLookAt)...
these matrices are 4x4 as i said before, so what glLoadIdentity does to a matrix is this :
1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
so, if u use this code : glMatrixMode(GL_MODELVIEW); glLoadIdentity();
and ur''e gonna draw a predifined point 5,5,5 it''s gonna draw it at 10,5,5 ok? ok.
so if u manually chnage the viewing matrix u can "move the camera" without gluLookAt...
and about moving multiple objects at the smae time...very easy...
matrixmode->modelview loadidentity // returns coord system to 0,0,0
move/rotate/scale your first object //moves coord system
use vertex3f to throw everything into the frame buffer
and again matrixmode->modelview loadidentity // returns coord system to 0,0,0
move/rotate/scale your second object //moves coord system
use vertex3f to throw into the framebuffer,
and so on, and only when u r finished with all of the objects, use swapbuffers....
about the pop and push matrix:
move the your FIRST object //moves coord system vertex3f it to the framebuffer
glPushMatrix at this point will remember the moving or any other transformation uv''e done so far to the modelview matrix (current coord system), and now, after the pushmatrix, opengl will consider the point u r at now (after all the moving) as its initial 0,0,0, so now when u move your second object (AFTER glPushMatrix) lets say 5 units to the right, it wont move 5 units to the right from 0,0,0 but from "move the your FIRST object" position...and so on, and when u do a popmatrix, it reverts to the point that u moved to before the last pushmatrix..(usefull when u make pushmatrix within pushmatrix and so on).
and about the-Z: everytimne u render, MAKE it look up the positive Z, whether by manipulating the viewing matrix (NOT modelview, just view) or using gluLookAt(0,0,1) ...
I really hope this helps, if anything''s unclear just say so...
**> ATi Rules! nvidia doesn''''t...that simple! <**