urgent : Rotation problem

Started by
1 comment, last by barantamer 16 years, 5 months ago
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
Advertisement
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();
That was quick :))
Thanks a lot man .. U have been very helpful

This topic is closed to new replies.

Advertisement