PDA

View Full Version : PushMatrix, PopMatrix



jirkamelich
11-26-2002, 09:54 AM
Hi, i wrote following source code, it works alomost well, I have the squad before my camera even if i move or rotate the camera. But there is a small problem. If i move camera in way of axe Y, or i rotate it , the quad is moving. If i move the camera on axe Y so just a little bit. Does somebody know how could i make it work ?
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRotatef(0,1,0,0);
glRotatef(0,0,1,0);
glRotatef(0,0,0,1);
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,0.1);
glVertex3f(100,10,0.1);
glVertex3f(100,0,0.1);
glVertex3f(0,0,0.1);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

nexusone
11-26-2002, 10:04 AM
glPush/Pop matrix() between objects:

glPushMatrix()
glTranslatef(.....)
glRotatef(......)
draw_object();
glPopMatrix()


Look at my comments to your program.

glMatrixMode(GL_PROJECTION);
glPushMatrix(); // do not use here.
glRotatef(0,1,0,0); //remove these from the project matrix
glRotatef(0,0,1,0); //remove
glRotatef(0,0,0,1); //remove
glLoadIdentity(); // This voids the past rotate commands, so you glRotate's before do nothing
glOrtho(0,100,0,133,-10,10);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,0.1);
glVertex3f(100,10,0.1);
glVertex3f(100,0,0.1);
glVertex3f(0,0,0.1);
glEnd();
glMatrixMode(GL_PROJECTION); // remove
glPopMatrix(); // remove
glMatrixMode(GL_MODELVIEW); // remove

[This message has been edited by nexusone (edited 11-26-2002).]