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 › Matrix Stack 101
Page Index Toggle Pages: 1
Matrix Stack 101 (Read 2704 times)
Matrix Stack 101
Apr 23rd, 2007, 12:01am
 
Can you tell me what a matrix stack is, or maybe direct me to a good website that explains it?

Thanks for your explanations/ suggestions.

RC
Re: Matrix Stack 101
Reply #1 - Apr 23rd, 2007, 1:22pm
 
In it's simplest form the matrix stack allows you to say that you wan tto be able to come back to this set of translations/rotations at a later point. It's not quite saving it for later use, since you can only come back to a point, not go up to a point.

The best example I know to demonstrate this is fro drawing a solar-system.

you initially perform some translates and rotates that get you to the middle of the system, i.e. the sun. You then do a pushMatrix(); as you will be wanting to come back here later.
You then do some more translates/rotates to get to a planet, draw that, and then do popMatrix(); which returns the transformations to the state whereby you're at the sun, and now you can pushMatrix(); again, and go off and draw a second planet and so on.

You can also nest push/popMatrix calls, so you coudl have done a pushMatrix(); when your transformations have you at the planet, so you can draw a moon, pop and push again, and go draw a second moon, then pop mack to the planet, and pop again back to the sun.

Re: Matrix Stack 101
Reply #2 - May 9th, 2007, 10:02pm
 
Thank you for your response.  It's helped me move ahead.

Regina
Re: Matrix Stack 101
Reply #3 - May 23rd, 2007, 2:02pm
 
That's a great explanation, thank you.
Re: Matrix Stack 101
Reply #4 - Jul 21st, 2009, 3:59pm
 
So does pushMatrix() automatically record the values of all the declared variables in play? In examples in the Processing book, I see pushMatrix by itself after the variables are declared for the function, without specifically calling out the variables on the same like as pushMatrix, and I'm wondering which variables it recalls.


Other than this question, that was a fantastic explanation. Google links to this thread first after a search for "matrix stack" and boy am I glad.
Re: Matrix Stack 101
Reply #5 - Jul 21st, 2009, 8:06pm
 
No, pushMatrix() simply saves the 3D coordinate matrix at the time it's called. This means that it saves the effects of any rotations, translations, and scales up to that point, since those affect the matrix. It has no effect or interaction with variables in your code.
Re: Matrix Stack 101
Reply #6 - Jul 22nd, 2009, 1:06am
 
For the record, pushStyle() saves also a number of Processing variables (like fill, stroke, etc.).
You have to manage your own variables yourself, as dlp said.
Page Index Toggle Pages: 1