Lines enlarge with camera position changes... why?

edited July 2015 in Library Questions

I have a structure and I move through it with the camera by a simple increment along the z-axis. The problem is that the 4 long lines that stretch from the beginning of the structure to the end enlarge / become thicker as the camera moves through the structure. I don't understand why. Here is my code.

import java.util.*;
import toxi.geom.*;

Structure struct = new Structure();

boolean sketchFullScreen() {
  return true;
}

int i = 0;
int cameraXPos;
int cameraYPos;
int cameraZPos;

void setup() {
  size(displayWidth, displayHeight, P3D);
  cameraXPos = width / 2 + 100; // width must be even...
  cameraYPos = height / 2 + 100; // height must be even...
  cameraZPos = -10000;
  
  // initial camera position
  camera(cameraXPos, cameraYPos, 0,
         cameraXPos, cameraYPos, -1,
         0,          1,          0);
  
  // initialize
  background(255);
}

void draw() {  
  background(255);
  struct.display();
  moveCameraAlongZ();
  
  // fill(0);
  // text("wii:", 1, 10);
  // text(wiiMovement, 40, 10);
}

void moveCameraAlongZ() {
  camera(cameraXPos, cameraYPos, i,
         cameraXPos, cameraYPos, i - 1,
         0,          1,          0);
  i -= 50;
}

class Structure {
  int lengthOfStructure = 1000000;
  int distanceOfEachSection = 200;
  int numSections = int(lengthOfStructure / distanceOfEachSection);
  boolean finishedDrawingTheFirstTime = false;
  List randomFloats = new ArrayList();
  int randomFloatIterator = 0;
  
  int getLengthOfStructure() {
    return lengthOfStructure;
  }
  
  boolean chance(float percentChance) {
    float r = rnd(0, 100);
    if (r <= percentChance) {
      return true;
    } else {
      return false;
    }
  }

  float rnd(float min, float max) {
    if (finishedDrawingTheFirstTime) {
      float r = randomFloats.get(randomFloatIterator);
      randomFloatIterator++;
      return r;
    } else {
      float r = random(min, max);
      randomFloats.add(r);
      return r;
    }
  }
  
  void display() {
    randomFloatIterator = 0;
    stroke(0);
    strokeWeight(4);
    
    //// ESTABLISH LONG LINES AT EACH CORNER>>>>> WHY DO THESE GET "BIGGER"
    line(0,      0,      0,          0,      0,      -1 * lengthOfStructure);
    line(0,      height, 0,          0,      height, -1 * lengthOfStructure);
    line(width,  0,      0,          width,  0,      -1 * lengthOfStructure);
    line(width,  height, 0,          width,  height, -1 * lengthOfStructure);
    
    int currentZPos = 0;
    
    for (int i = 0; i < numSections; i++) {
      
      int previousZPos = currentZPos - distanceOfEachSection;
      
      // current
      Vec3D cBL = new Vec3D(0, height, currentZPos); // current bottom left
      Vec3D cBR = new Vec3D(width, height, currentZPos); // current bottom right
      Vec3D cTL = new Vec3D(0, 0, currentZPos); // current top left
      Vec3D cTR = new Vec3D(width, 0, currentZPos); // current top right
      // previous (last currnetZPos)
      Vec3D pBL = new Vec3D(0, height, previousZPos);
      Vec3D pBR = new Vec3D(width, height, previousZPos);
      Vec3D pTL = new Vec3D(0, 0, previousZPos);
      Vec3D pTR = new Vec3D(width, 0, previousZPos);
      
      
  
      // the squares of each chunk
      stroke(0);
      strokeWeight(int(rnd(1, 4)));
      line(cTL.x, cTL.y, cTL.z,        cTR.x, cTR.y, cTR.z);
      line(cTR.x, cTR.y, cTR.z,        cBR.x, cBR.y, cBR.z);
      strokeWeight(int(rnd(1, 4)));
      line(cBR.x, cBR.y, cBR.z,        cBL.x, cBL.y, cBL.z);
      line(cBL.x, cBL.y, cBL.z,        cTL.x, cTL.y, cTL.z);
      
      // draw cross x on bottom
      if(chance(90)) {
        strokeWeight(int(rnd(1, 4)));
        line(cBL.x, cBL.y, cBL.z,        pBR.x, pBR.y, pBR.z);
        line(cBR.x, cBR.y, cBR.z,        pBL.x, pBL.y, pBL.z);
      }
      
      // draw cross x (independently) on right wall
      if(chance(80)) {
        strokeWeight(int(rnd(1, 4)));
        line(cTR.x, cTR.y, cTR.z,        pBR.x, pBR.y, pBR.z);
      }
      if(chance(80)) {
        strokeWeight(int(rnd(1, 4)));
        line(cBR.x, cBR.y, cBR.z,        pTR.x, pTR.y, pTR.z);
      }
      
      // draw cross x on left wall
      if(chance(70)) {
        strokeWeight(int(rnd(2, 4)));
        line(cTL.x, cTL.y, cTL.z,        pBL.x, pBL.y, pBL.z);
        line(cBL.x, cBL.y, cBL.z,        pTL.x, pTL.y, pTL.z);
      }
      
      // do top x
      if(chance(50)) {
        strokeWeight(int(rnd(1, 3)));
        line(cTR.x, cTR.y, cTR.z,        pTL.x, pTL.y, pTL.z);
      } else {
        line(cTL.x, cTL.y, cTL.z,        pTR.x, pTR.y, pTR.z);
      }
      
      // draw either + or x in main area
      if(chance(30)) {
        if (chance(50)) {
          strokeWeight(int(rnd(1, 3)));
          line(cTL.x, cTL.y, cTL.z,        cBR.x, cBR.y, cBR.z);
          line(cBL.x, cBL.y, cBL.z,        cTR.x, cTR.y, cTR.z);
        } else {
          strokeWeight(int(rnd(2, 4)));
          line(int(cTR.x / 2), cTR.y, cTR.z,        int(cBR.x / 2), cBR.y, cBR.z);
          line(cBL.x, int(cBL.y / 2), cBL.z,        cBR.x, int(cBR.y / 2), cBR.z);
        }
      }
      
      currentZPos -= distanceOfEachSection;
    }
    finishedDrawingTheFirstTime = true;
  }
}
Tagged:

Answers

  • doesn't happen in processing 1.5.1, but does in 2

    but things DO look thicker the nearer they are - a pencil held at arm's length appears thinner then one 6"s away.

    apparently it is by design: http://forum.processing.org/two/discussion/1195/strokeweight-are-scaled-in-processing-2-1

    but it would be nice to be able to disable it.

  • Well. I'm not quite sure I understand. Because my camera movement is moving in the z direction only, it shouldn't get nearer or farther away from either of those lines... right? The distance from the camera position each of those lines should remain the same throughout... correct?

  • the one end of the line is closer to the camera than the other end of the line though, surely. so it's thicker.

  • ha, ok, i see what you mean now - i left the sketch running and it got blacker and blacker...

  • Yeah. So any suspicion what could be causing that?

Sign In or Register to comment.