|
Author |
Topic: understanding push and pop and all that (Read 793 times) |
|
kirkjerk
|
understanding push and pop and all that
« on: Jul 29th, 2004, 10:56pm » |
|
After some experimenting, I think I've finally started to get my head around the processing 3D paradigm; it's very different from "put a bunch of stuff into absolute 3D coordinates then position a camera", it's more like "position the canvas in 3D, then draw". One implication of this is if you kind of have a rough idea of a "camera", apply its translation and rotation first (and in that order), so it effects everything that comes after, then push(), translate and rotate so your thing is where it needs to be, then pop(). Does that sound about right? Thinking about it, if I understand correctly, one implication is that the last thing drawn will be what's shown, there's no way to get proper Z-order, is that correct? Anyway, for your momentary amusement, a simple fish in a simple fishtank: final static int SZ=100; void setup() { size(SZ,SZ); noFill(); } float spin; void loop(){ background( 128 ); translate(SZ/2,SZ/2); rotateY((mouseX-(SZ/2))/(float)(SZ/3)); rotateZ(((float)(SZ/2-mouseY))/((SZ*2)/3)); box(SZ/2); push(); rotateY(spin); translate(0,0,SZ/6); drawfish(0,0,0,SZ/30); spin += .01; pop(); } void drawfish(float x, float y, float z, float size){ line(x+size,y,z,x,y-size,z); line(x,y-size,z ,x -size - size, y+size,z); line(x+size,y,z,x,y+size,z); line(x,y+size,z, x -size - size, y-size,z); }
|
|
|
|
narain
|
Re: understanding push and pop and all that
« Reply #1 on: Jul 30th, 2004, 3:40pm » |
|
That's a cute fish Quote:if you kind of have a rough idea of a "camera", apply its translation and rotation first (and in that order), so it effects everything that comes after, then push(), translate and rotate so your thing is where it needs to be, then pop(). Does that sound about right? |
| Yep, that'll work. And it does, in your Fish sketch. Quote:one implication is that the last thing drawn will be what's shown, there's no way to get proper Z-order |
| Processing's smarter than that... It keeps track of how far away everything in the scene is, and only draws the new object in places where it won't be behind anything. (It's all done with a z-buffer, fyi) See Push and Pop sketch in Examples:Transform, it's a bunch of cubes all with their own transforms pushed and popped, all intersecting, and it works!
|
|
|
|
kirkjerk
|
Re: understanding push and pop and all that
« Reply #2 on: Jul 30th, 2004, 4:49pm » |
|
Oh, you're right! I had enhanced the fishtank but kept everything b+w to mask the problem I assumed was there...but Processing is smarter than I am! Or at least smarter than my previous implementations of simple 3D engines: http://kisrael.com/viewblog.cgi?date=2001.03.02 A colorized version of the cute fish, with zooming, plants, and bubbles (anatomically incorrect but hey...I just like a fish to blow bubbles) is at http://kisrael.com/viewblog.cgi?date=2004.07.30 Thanks!
|
|
|
|
|