urgent : Rotation problem
hello , i have two rectangles . I want to rotate them seperately with different keys.Second rectangle works perfectly but when i rotate the first rectangle second one rotates too . Part of my code is below
//rectangleOne
glTranslatef(-3,0,0);
glRotatef(a,0.0, 0.0, -20);
DrawRecOne();
//RectangleTwo
glTranslatef(-3,0,0);
glRotatef(b,0.0, 0.0, -20);
DrawRecTwo();
I actually now that rotatef() function rotates everything after its line but i dont now how to avoid that.. THX
Whenever you do a translation or rotation you really are multiplying the active OpenGL matrix, that's why it affects the two objects. To avoid that you can put the current matrix in the matrix stack and pop it when you need to restore the previus matrix:
glPushMatrix();
//rectangleOne
glTranslatef(-3,0,0);
glRotatef(a,0.0, 0.0, -20);
DrawRecOne();
glPopMatrix();
glPushMatrix();
//RectangleTwo
glTranslatef(-3,0,0);
glRotatef(b,0.0, 0.0, -20);
DrawRecTwo();
glPopMatrix();
glPushMatrix();
//rectangleOne
glTranslatef(-3,0,0);
glRotatef(a,0.0, 0.0, -20);
DrawRecOne();
glPopMatrix();
glPushMatrix();
//RectangleTwo
glTranslatef(-3,0,0);
glRotatef(b,0.0, 0.0, -20);
DrawRecTwo();
glPopMatrix();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement