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 › explain ()  MATRIX STACK.
Page Index Toggle Pages: 1
explain (?)  MATRIX STACK. (Read 764 times)
explain (?)  MATRIX STACK.
Sep 21st, 2005, 11:38am
 
hi, i am trying to learn processing and am just a few weeks old, i've picked up the basic syntax of the language.
can anybody explain(?) the concept of the 'MATRIX STACK'.
Re: explain (?)  MATRIX STACK.
Reply #1 - Sep 21st, 2005, 11:47pm
 
http://en.wikipedia.org/wiki/Stack_%28computing%29

( my name's ali too! Cheesy )
Re: explain (?)  MATRIX STACK.
Reply #2 - Sep 30th, 2005, 6:10pm
 
Thanks for this. I'm a newbie too, and have had difficulty getting my head around the push and pop stuff. However, I know what a stack is, but not having touched OpenGL before, I have no idea what a matrix is or why it might be useful.

Can anyone slip me the URL of a helpful beginner's tutorial? TIA
Re: explain (?)  MATRIX STACK.
Reply #3 - Oct 2nd, 2005, 3:56pm
 
One really useful reference is the OpenGL redbook. If you go to www.opengl.org and look around, you can find an older version available as a PDF. For what you want to do in P5, this is probably more than sufficient, and if you want to do more, the $50 the newed release costs is worth it, from what I've heard.

The matrix stack is, well.. if you know linear algebra, you know that geometry can be transformed by matrix multiplication. OpenGL uses this so, for example, you can define a mesh relative to the origin (0,0,0) then transform it to somewhere other than (0,0,0) and draw it.  In practice, it works like this:

start out with the default matrix, with (0,0,0) being the origin in world-space
push the matrix to the stack
transform where you want to be (this changes your matrix, so now 0,0,0 is the origin in object-space, but isn't necessarily at the origin in world-space)
draw some stuff relative to the new origin
pop the matrix off the stack (this puts you back with (0,0,0) as the origin in world-space.

The nice thing about the matrix stack is that you don't have to keep track of where you are in the world to get back to the origin, or any other previous level of transform.

This is important because, if you look at the 3d functions in P5 (or in opengl itself, for that matter) you can only do relative transforms/rotations.  So you can move +5,+3,-1 from your current location, but you can't, say, arbitrarily jump to world-space coord +5,+3,-1.  But since the bottom matrix on the stack is always the default world-space matrix, you can just pop matricies until you're back at the lowest level, then start moving again from there.

Does that make any sense? IANARGP (I am not a real GL programmer) but that's how I think of it... I hope this is helpful.  If you want more help, you should probably ask more specific questions in the 3D/OpenGL forum
Page Index Toggle Pages: 1