Vanishing objects when using ortho()

Hey everyone,
I’m creating a sketch using orthographic perspective and I get strange effects here.
If I run the code the white rectangles in the background can’t be seen through the gaps left between the black ones. Only when the camera rotates you begin to see them, with exceptions of some seemíngly random glitches of rectangles shining through where they shouldn’t.
Any ideas?
Thank you

float camRotSpd=1;
float camOutSpd=1;
float camR0=30;
int d=50;
float t=0;
float tScl=0;
float Scl0=1;
float zRot=0;
float zRot2=0;
PGraphics bg;

void setup() {

  size(1080, 1080, P3D);
  bg = createGraphics(width, height);
  bg.beginDraw();
  bg.background(120, 120);
  bg.endDraw();
  noStroke();
  frameRate(30);
}

void draw() {
  ortho(-width/2, width/2, -height/2, height/2,0,9999999);
  float tEase;
  if (t<0.5)
    tEase=ease(t, 2);
  else
    tEase=t;
  camera(sin(TWO_PI*camRotSpd*tEase)*(camR0), 0, cos(TWO_PI*camRotSpd*tEase)*(camR0), 0, 0, 0, 0, 1, 0);
  background(120);
  scale(2*pow(3, -tScl*0.2)+5*ease(Scl0, 3), 2*pow(3, -tScl*0.2)+5*ease(Scl0, 3), 2*pow(3, -tScl*0.2));
  float zRotEase;
  if (zRot<0.5)
    zRotEase=ease(zRot, 2);
  else
    zRotEase=zRot;
  rotateZ(zRotEase);
  // translate(-width/2,-height/2);
  // image(bg,0,0);
  // translate(width/2,height/2);
  for (int i=1; i<1000; i++) {
    pushMatrix();
    rotateZ(zRot2*i);
    translate(0, 0, d*i*pow(-1, i));
    for (int j=0; j<4; j++) {
      fill(127.5+127.5*pow(-1, i));
      rect(i*d, (i-1)*d, -2*i*d, d); 
      rotate(HALF_PI);
    }
    popMatrix();
  }

  tScl+=0.01;

  if (Scl0>0)
    Scl0-=0.005;
  if (Scl0<0.3)
    t+=0.002;
  if (t>1.25)
    zRot+=0.01;
  if(t>1.75)
    zRot2+=0.0001;
}

float ease(float x, float ez){
  if(x<=0.5)
  x=pow(x*2,ez)/2;
  if(x>0.5)
  x=1-pow(2-2*x,ez)/2;
  return x;
}
  
1 Like

https://processing.org/reference/ortho_.html
play with
near float: maximum distance from the origin to the viewer

  ortho(-width/2, width/2, -height/2, height/2, 300, 9999999);

p.s. i like your show with or without ortho !

actually why not play:

  ortho(-width/2, width/2, -height/2, height/2, mouseX, 9999999);
2 Likes

Thanks for your answer kII!
I got the idea for the “near” parameter in ortho() wrong. It actually needed a negative value!
Thanks for pointing me in the right direction there, and thanks for your feedback… try it with a big negative value and you should like my show even more :smiley:

1 Like