Drawn object stops moving away?

Hi there! I’ve been working on some sketches using the contours of a 3D object to draw onto the canvas. In order to give the appearance of the object (in this case a box) moving into the distance, I increment the value of z and subtract it from the z-parameter in translate(). Code here:

int z;
int c;
boolean inc;

void setup() {
  size(640, 640, P3D);
  colorMode(HSB, 360, 100, 100);
  background(0);
  z = 0;
  c = 0;
  inc = true;
}

void draw() {
  camera(width/2, height/2, ((height/100.0) / tan(PI/6)), width/2, height/2, 0, 0, 1, 0);
  translate(width/2, height/2, -z);
  rotateX(radians(z));
  rotateY(radians(z));
  rotateZ(radians(z));
  stroke(360-c,100,100);
  //noFill();
  box(100);
  z+=10;
  //z+=frameCount/100.0;
  if (c >= 360 && inc){
    c--;
    inc = false;
  }
  else if(inc){
    c++;
  }
  else if(c <= 0){
    c++;
    inc = true;
  }
  else{
    c--;
  }
  //println(frameCount);
}

What I’ve noticed is that after a while, the object stops moving entirely, as if the draw() loop has stopped executing. However, I can tell by logging the frame count that the sketch is continuing to execute. No matter how quickly the object approaches the stopping point (i.e. how quickly I change the value of z), it always stops at the same distance.

Why does the object stop? Is there a minimum value of translate() that I’m hitting? Is another approach more appropriate if I want the object to vanish to, say, a single point?

As a related, more theoretical question: the maximum width and the maximum height of my image are set when I call size() in setup(). What determines the maximum depth of the image, if one exists? I have searched the forums and documentation but haven’t yet found a good answer, so any answers you can provide would be helpful!

yes, good find

but you could have worked on it more to narrow it down

  • is it a int float problem?
  • is it a bad camera start?
  • rotation goes wrong with big numbers?
  • or a real translate problem?
  • at what exact numbers does it happen?

use println(z);


my test version:

float z=0;

void setup() {
  size(640, 640, P3D);
}

void draw() {
  background(200, 200, 0);
  translate(width/2, height/2, -z);
  box(1000); //________________ invisible at z 5500
  rect(0,0,1000,1000); //______ invisible at z 5000
  z=map(mouseX, 0, width, 0, 10000);
  println("z ", z);
}

so possibly a bug in translate math P3D ( and might need new issue report )

Hello,

Welcome to the forum.

You are experiencing clipping.

The Perspective section discusses this:
https://processing.org/tutorials/p3d/

And you can adjust the z-far parameter using perspective():
https://processing.org/reference/perspective_.html

1 Like