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.
Page Index Toggle Pages: 1
Basic 3D (Read 542 times)
Basic 3D
Feb 10th, 2010, 11:34am
 
I haven't used 3D in processing yet.

I wanted to create an effect where each draw loop moves towards a vanishing point in the center of the screen.

A rectangle drawn in this sketch would give the impression of a tunnel, stretching off to the middle of the screen.

Not quite sure how to describe this.

I have looked for a 3D tutorial but to no avail.

Thanks,
TB

Re: Basic 3D
Reply #1 - Feb 10th, 2010, 11:57am
 
This might help get you started

Code:
void setup(){
 size(420,320, P3D);
}

void draw(){
 background(0);
 stroke(255);
 strokeWeight(1);
 translate(width/2,height/2);
 for(int i = 0; i < 10; i++){
   // a rectangleDraw
   line(-200, -200, -i*60,  200, -200, -i*60);
   line( 200, -200, -i*60,  200,  200, -i*60);
   line( 200,  200, -i*60, -200,  200, -i*60);
   line(-200,  200, -i*60, -200, -200, -i*60);
 }
}  
 


Also look at line() reference.

The size of the rectangles are determined through perspective.
Re: Basic 3D
Reply #2 - Feb 10th, 2010, 1:46pm
 
Thanks - i'll look at the perspective command.

Ultimately I wanted to create something like this, though that actually works.  This is the best representation I could come up with with my limited processing knowledge.

So as time progresses, what a person drew gradually moves off into the distance.

Code:

PImage screenShot;
int x = 0;
int y = 0;
int imgWidth;
int imgHeight;
int i = 0;
int increment = 1;

void setup(){
size(640,480);
background(0);
noFill();
stroke(255);
imgWidth = width;
imgHeight = height;

}

void draw(){

line(mouseX,mouseY,pmouseX,pmouseY);
if(i%20==0){
println("HERE");
x += increment;
y += increment;
imgWidth -= 2*increment;
imgHeight -= 2*increment;
save("screenShot.tif");
screenShot = loadImage("screenShot.tif");
image(screenShot, x, y, imgWidth, imgHeight);

}
i++;
}

Re: Basic 3D
Reply #3 - Feb 11th, 2010, 1:02am
 
Forget the perspective command for now.

You have a working program but it is slow because you are saving the image to a file (on disc) and then retrieve it. To speed this up you might consider creating your own images using createImage() to store the intermediate image (rather than disc).

That is a possible 2D solution but you might eventually consider a 3D solution. The following code is messy and has issues but is probably easier to understand than the logic than a full blown solution. Try it out.

Code:
int count = 0;
int x = 0;
int y = 0;

ArrayList xp = new ArrayList();
ArrayList yp = new ArrayList();

void setup(){
size(640,480, P3D);
background(0);
noFill();
stroke(255);
strokeWeight(2);
}

void draw(){
background(0);
int sx,ex,sy,ey;
float z = 0;
xp.add(mouseX);
yp.add(mouseY);
if(xp.size() > 1){
for(int i = xp.size()-1 ; i > 0 ; i--){
sx = (Integer) xp.get(i);
ex = (Integer) xp.get(i-1);
sy = (Integer) yp.get(i);
ey = (Integer) yp.get(i-1);
line(sx,sy,z,ex,ey,z-10);
z -= 10;
}
}
count++;
}

Page Index Toggle Pages: 1