We are about to switch to a new forum software. Until then we have removed the registration on this forum.
i am trying to relearn processing but i cant get my head around these functions.
im using 1.5.1 processing.
Vertex shape goes (0,0) (1,0) (1,1) (0,1) but why? shouldnt it go vertex (0,0) (1,0) (0,1) (1,1) when creating a shape. this seems like the logical way ?
Translate: if i translate to (0,0,0) in a loop its always (0,0,0) but if i translate to (4,0,0) it pushes X so 4 8 12 16 etc can anyone explain why this is?
Pushmatrix and popmatrix if i use these functions in a loop it effects the object. i cant understand these functions, i know they have a stack. where is the stack ? how big is the stack ?
how does translate and push and pop work together? if i pushmatrix before translate it act differently. is pushmatrix just a buffer stack which is similar to a loop?
its driving me nuts trying to understand these function again.
Answers
Vertex data for a shape is always listed in the anti clockwise direction because OpenGL expects it in that order to draw the shape correct;y
Translate is cumulative so if we have this loop
Then it will draw 3 rectangles at positions [tx, ty, tz], [2tx, 2 ty, 2* tz] and [3tx, 3 ty, 3* tz]
If tx = ty = tz = 0 then all 3 positions are [0,0,0] but if tx = 4 and ty = tz = 0 then we have 3 distinct locations [4,0,0], [8,0,0] & [12,0,0]
pushMatrix and popMatrix are used to save and restore the transformation matrix. The most common use of these function is to isolate transformations. Let me give an example, image the wild west and we want to display a gun-fighter.
The position of the gun-fighter will be in world coordinates, but what about his gun. If they are expressed in world coordinates the gun will be left behind when the gun-fighter moves unless we update its coordinates as well. It would be better to express the guns position relative to the gun-fighter. So to draw the gunfighter we have something like.
I forgot about rotation and start point 0,0 when using translate.
0,0 is centre point at X Y then right to 1,0 then right up to 1,1 then left to 0,1.
i was thinking wrong as a binary counter not as X Y coordinates locations.
translate always anoyed me before when i used it i had to undo translate. i still think its stupid to have a cumulative translate thats labelled translate.
i think i understand push and pop now.
so instead of doing a screen update of all objects, pushmatrix updates the location of the objects inside the push pop matrix.
in your example its says back to world coordinates. so is this correct then.
translate world.
draw world.
pushmatrix() ( so this push, pushes the world translate? ).
translate gun fighter ( move gun fighter ).
draw gun fighter.
pushmatrix() ( and this push, pushes the gun fighter translate? ).
translate gun ( move gun ).
popmatrix() ( back to gun fighter position ).
popmatrix() ( back to world position ).
so why dont i need to push pop the gun ?
this is what makes push pop confusing to me its not a set point, such as using a label in other languages.
this is why i dont like using it, labels make sense push pop is an undefined jump to a previous location.
thanks.
so why dont i need to push pop the gun ?
the inner push/pop matrix ops translate to the guns position before drawing it
im still confused about pushmatrix.
so is the pushmatrix for pre push locations or post push locations?
what happens if i popmatrix and no translate has happened, will it just stay the same or translate back to another location ? ( undefined jump , no label .......!!!! )
does the popmatrix clear the previous location, if it doesnt and i call a sketch with another popmatrix will this pop back to the wrong location?
thanks for the help. i will just use another way. this push pop matrix stuff is just crazy to understand without knowing whats going on and no documents on any of these problems.