Jump to content
  • Advertisement
Sign in to follow this  
barantamer

urgent : Rotation problem

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!