Advertisement

UGGH! I'm soo confused with opengl

Started by January 25, 2000 04:43 AM
3 comments, last by EB 25 years, 1 month ago
I do not get these transformation matrices. when you call glLoadIdentity() does that load them all with the identity matrix. What I'm trying to do is rotate a model around the y axis by some angle of degrees and then that model is sitting on the ground out in front of me. and I'm looking down toward the ground. by doing this I can get the model to appear on the ground where I want it to: glMatrixMode(GL_VIEWPORT); glLoadIdentity(); glRotatef(25,1,0,0); glTranslatef(0,-usery/10 ,15); but as soon as I want to rotate that model around its own y axis (as if it were standing there in front of me turning in circles) it does the equavalent of: glMatrixMode(GL_VIEWPORT); glLoadIdentity(); glRotatef(25,1,0,0); glTranslatef(0,-usery/10,15); glRotatef(10,0,1,0); I think I've tryed pretty much well every single combination of glLoadIdentities, rotates, translates and MatrixMode(GL_VIEWPORT) & glMatrixMode(GL_MODELVIEW)'s I can think of Edited by - EB on 1/25/00 4:49:53 AM
Hi,
I am a bit confused on what you wrote there. (I have never seen GL_VIEWPORT in the glMatrixMode call ). And i dont understand how you want transform your object. But i think this will help you:

At the beginning of your programm you should setup the projection matrix and the viewport once:
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION); //

glLoadIdentity(); // Clears Projection matrix stacck i think ;-)
gluPerspective(65.0,width*1.0/height*1.0,1,20.0);

glMatrixMode(GL_MODELVIEW); // IMPORTANT never forget this at the end of the projection matrix changes

then for every frame:
...
glPushMatrix(); // pushs the actual matrix on a stack
glTranslatef(0,-usery/10 ,15);
glRotatef(25,0,1,0);
DrawYourObject();
glPopMatrix(); // drops the actual matrix and restores the last matrix


Edited by - TheMummy on 1/25/00 7:15:02 AM
Advertisement
I need to get another rotation in there which is what I''m having problems with.
I am actually Above the object looking down toward it...
think of quake and its armor and you are standing on a ledge not to far away and looking down at a 25 degree angle at it.

Thats where I''m having the problems...
and essentially the object I''m wanting to render is the armor and its rotating in circles just like the quake armor does
I''m fairly new to opengl, but I think I can help.

Firstly, the glLoadIdentity() call sets the CURRENT matrix to an identity. It has no effect on the other matrices.

Secondly, all Camera and Model transformations should occur using the GL_MODELVIEW matrix stack. Do not put camera transforms in the GL_PROJECTION matrix, or lighting will not function properly.

So, to have a camera with an arbitrary orientation viewing an object that''s rotating, do the following:

at the begining of the program (after setting up the projection matrix)

- set the matrix mode to GL_MODELVIEW

at the begining of each frame:

- call glLoadIdentity
- apply camera transformations (gluLookAt, or what have you), based on camera orientation and location

then for each object:

- call glPushMatrix. This pushes the (camera) matrix onto the stack.
- apply object transformations (with glRotatef ect.)
- render the object
- pop the (camera) matrix off the stack, so you can use it for rendering the next object.

Send me an email if you''re still confused.

- genovov
OOOOOOOOOOOOOOHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!
I figured out what was going on....
that wasn''t working either... and then it dawned on me....
it took a full day... but what was happening was I wasn''t using the matrices to translate the models, I was manually translating the vertices before I sent them out...
now everything makes sense, I was wondering why everything wasn''t working the way i was reading it.

This topic is closed to new replies.

Advertisement