We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › HELP!! PUSHMATRIX() AND POPMATRIX()
Page Index Toggle Pages: 1
HELP!! PUSHMATRIX() AND POPMATRIX() (Read 767 times)
HELP!! PUSHMATRIX() AND POPMATRIX()
Feb 16th, 2006, 5:31am
 
Can someone explain what is PushMatrix and PopMatrix in plain english? I have some knowledge of coordinates and matrices but I still do not understand the push/pop matrix concept. Thanks
Re: HELP!! PUSHMATRIX() AND POPMATRIX()
Reply #1 - Feb 16th, 2006, 7:32am
 
pushMatrix <-- saves the current matrix system
popMatrix <-- restores that saved matrix system

So if you want to move something in relation to the main viewpoint, do it between push and pop.

Anytime you want to move the whole thing (whole 'scene'), don't do it between push and pop.
Re: HELP!! PUSHMATRIX() AND POPMATRIX()
Reply #2 - Feb 17th, 2006, 4:21am
 
Thanks for the help. I still don't understand what exactly do you mean by "matrix system" and "main viewpoint", and what is the difference between "moving the whole thing "and "moving something"?. I know that these questions sound stupid but I'm just trying to get the concept right.
Re: HELP!! PUSHMATRIX() AND POPMATRIX()
Reply #3 - Feb 17th, 2006, 6:16am
 
I shouldn't have said 'matrix system'. Replace that with 'tranformation matrix'. I was putting it my own words, which is a bad idea.

Transformations are cumulative, so if I do:

translate(10,0);
translate(10,0);

Net translation afterwards is 20 in x.

If I do

pushMatrix();
translate(10,0);
translate(10,0);
popMatrix();

Net translation afterwards is 0.

Because pushMatrix saves the matrix at that point and popmatrix restores that saves matrix.

This might help explain it:

void setup () {
 size(300,300);

}

void draw () {
 background(255);

 pushMatrix();
 translate(10,0);
 fill(255);
 rect(0,0,10,10); //white square
 translate(10,0);
 fill(255,200,200);
 rect(0,0,10,10); //pink square
 popMatrix();

 fill(255,0,0);
 rect(0,0,10,10); // red square
}

Re: HELP!! PUSHMATRIX() AND POPMATRIX()
Reply #4 - Feb 18th, 2006, 4:42am
 
Thanks for the help again. This time I got it right.
Page Index Toggle Pages: 1