在 Processing 中移动透视消失点

Moving the perspective vanishing point in Processing

我的应用程序有一个分屏模式,其中只有一半的屏幕用于显示 3d 场景。所以我想让消失点放在左半边的中间。

我已经尝试了 camera()translate() 的各种组合,但是消失点不会从草图的中心移动一个像素 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);
}

关于这个话题,我刚发现 this unanswered question 十年前问过... 有谁知道这是否有可能实现?

您可以只使用 createGraphics() 函数为您的左视口创建缓冲区,然后绘制到缓冲区,然后将缓冲区绘制到屏幕。

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);
}

可以在 the reference 中找到更多信息。