PDA

View Full Version : glPushMatrix question



joker40
03-19-2011, 08:35 PM
I have problem moving the little cube which is inside big cube.


void myCube(void) {

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glRotatef(angle, 0.0, 1.0, 0.0);
glBegin(GL_LINE_LOOP);
//draw
glEnd();
glBegin(GL_LINE_LOOP);
//draw
glEnd();
glBegin(GL_LINE_LOOP);
//draw
glEnd();
glBegin(GL_LINE_LOOP);
//draw
glEnd();

glPushMatrix();
glLoadIdentity();
glTranslated(15, 1, 0);
createLittleCube(50);
glPopMatrix();

glutSwapBuffers();
glFlush();

}

int main(int argc, char **argv){

glutInit(&argc, argv);
glutInitWindowSize(800, 700);
glutInitWindowPosition(200 , 70);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("move cube");
glutDisplayFunc(myCube);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0, 0.0, 0.0, 1.0);
menuInit();
glutMainLoop();

}


Can anyone give me suggestion on how to move little cube without big cube moving.

Thank you

Snow_56767
08-20-2011, 07:54 PM
Try this:

1)Draw Big Cube at fixed position
2)glPushMatrix();
3)Translate the little cube
4)draw the little cube
5)glPopMatrix();