# Drawn object stops moving away?

**URL:** <https://discourse.processing.org/t/drawn-object-stops-moving-away/17493>\
**Category:** Coding Questions\
**Created:** [February 1, 2020, 2:23am UTC](https://discourse.processing.org/t/drawn-object-stops-moving-away/17493 "2020-02-01T02:23:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jedslater](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jedslater](https://discourse.processing.org/u/jedslater)\
**Post date:** [February 1, 2020, 2:23am UTC](https://discourse.processing.org/t/drawn-object-stops-moving-away/17493/1 "2020-02-01T02:23:50Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 2, 2020, 2:17am UTC](https://discourse.processing.org/t/drawn-object-stops-moving-away/17493/2 "2020-02-02T02:17:08Z")

</div>

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:

```auto
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 )

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 2, 2020, 3:11am UTC](https://discourse.processing.org/t/drawn-object-stops-moving-away/17493/3 "2020-02-02T03:11:01Z")

</div>

Hello,

Welcome to the forum.

You are experiencing clipping.

The Perspective section discusses this:  
[https://processing.org/tutorials/p3d/](https://processing.org/tutorials/p3d/)

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