2

My application has a split screen mode where just half of the screen is used to display the 3d scene. So I want the vanishing point to be placed in the middle of the left half.

I already tried various combinations of camera() and translate() but the vanishing point doesn't move one pixel from the center of the sketch window..

void setup(){
  size(800,400, P3D);
  fill(255,120);
}

void draw(){

  background(111);

  float camEyeX = 0;
  float camEyeY = 400;
  float camEyeZ = (height/2) / tan(PI/6);
  float camCenterX = 0;
  float camCenterY = -200;
  float camCenterZ = 0;
  float camUpX = 0;
  float camUpY = 1;
  float camUpZ = 0;

  pushMatrix();
  camera( camEyeX, camEyeY, camEyeZ, camCenterX, camCenterY, camCenterZ, camUpX, camUpY, camUpZ );
  translate( -200, 0, 0);
  rectMode(CENTER);
  rect(0,0, 800,400);
  rect(0,0, 100,100);
  popMatrix();
  hint(DISABLE_DEPTH_TEST);
  rectMode(CORNER);
  rect(400,0, 400,400);
  hint(ENABLE_DEPTH_TEST);
}

On this topic I just found this unanswered question asked a decade ago... Does anyone know if this is possible to achieve at all?

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
piaaaac
  • 61
  • 1
  • 9

1 Answers1

0

You could just use the createGraphics() function to create a buffer for your left viewport, then draw to the buffer, then draw the buffer to the screen.

PGraphics leftSide;

void setup(){
  size(800,400, P3D);
  leftSide = createGraphics(width/2, height, P3D);
}

void draw(){

  leftSide.beginDraw();
  leftSide.background(111);

  float camEyeX = 0;
  float camEyeY = 400;
  float camEyeZ = (height/2) / tan(PI/6);
  float camCenterX = 0;
  float camCenterY = -200;
  float camCenterZ = 0;
  float camUpX = 0;
  float camUpY = 1;
  float camUpZ = 0;

  leftSide.pushMatrix();
  leftSide.camera( camEyeX, camEyeY, camEyeZ, camCenterX, camCenterY, camCenterZ, camUpX, camUpY, camUpZ );
  leftSide.translate( -200, 0, 0);
  leftSide.rectMode(CENTER);
  leftSide.rect(0,0, 800,400);
  leftSide.rect(0,0, 100,100);
  leftSide.popMatrix();
  leftSide.hint(DISABLE_DEPTH_TEST);
  leftSide.rectMode(CORNER);
  leftSide.rect(400,0, 400,400);
  leftSide.hint(ENABLE_DEPTH_TEST);

  leftSide.endDraw();

  image(leftSide, 0, 0);
}

vanishing point in left half

More info can be found in the reference.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Thanks Kevin, this sounds like the right way of doing it. (unfortunately that project is long over but as soon as I have a chance I'll try to implement your suggestion: the only possible problem I can think of might be performance..) – piaaaac Oct 03 '16 at 08:24