Problem with matrix stack. Why 2 independents box are rotating together?

Hi everyone! I hope someone can help me here. I'm trying to make 2 independents rotations... I create 2 boxes and I'm trying to rotate them but each one with different parameters. The problem I got: The second box is rotating together with the first. Why? How should I do to make 2 independents rotations? If i comment the code for the first box , the second rotates right and if i comment the code for the second box, the first rotates right...But both boxes together...It never works right :( The link code is below! I'm sorry, I was looking for code quote but I didnt find it so i prefered post the code through sourcepod site


  • Pushmatrix() needs to go around the rotations and translations, not just the call to box () - move the Pushmatrix calls so they are immediately after your BEGIN comments.

  • Hello !

    Using a Matrix correspond to put something in a "virtual-box" on then moving the "box" instead of each element "inside the box".

    When you write "pushMatrix", you create a "virtual box". When you use then "translate" or "rotate", you tell to the box to move around its center and then to move the elements inside the "box" around the center of the "box".

    Everything written between a call of "pushMatrix" and a call of "popMatrix" refeers to what is inside the "box".

    When you say "popMatrix", you're actually saying "kill the virtual-box and leave the elements where they was inside of the box"

    Then, if you write "pushMatrix" 2 times without "popMatrix" , it means that you create 2 "virtual box" but it also means that the second box is located inside the first one, and then the elements located in the second box are affected by the 2 motions.

    It's like if you put a box in a bag. The elements in the box are still have a position relative to the box, then their position come from the position of the box, but because the box is in the bag, the elements are also affected by the motion of the bag that contains the box.

    I hope I'm understandable :) - not so sure about it :) -

  • Thanks so much, I understood everything. Now it works properly! But I got other problem about export aplication, however I started a new discussion about it. If someone can help me I'm glad. thanks!

Sign In or Register to comment.