3d 当尝试沿X轴旋转摄影机时,它会缩小

3d 当尝试沿X轴旋转摄影机时,它会缩小,3d,processing,3d,Processing,所以我正在尝试学习如何在我的处理程序中添加3D。在学习的过程中,我看到了相机的功能,并开始玩弄它。它的工作方式是,如果按下d键,相机会移动,如果按下a键,相机会移动到另一个方向。W缩小,S放大。我的问题是,当它在X轴上旋转时,它开始缩小 float z = (height/2) / tan(PI/5); float x = width/2; char lastpressed; void setup() { size(640, 360, P3D); } void draw() { came

所以我正在尝试学习如何在我的处理程序中添加3D。在学习的过程中,我看到了相机的功能,并开始玩弄它。它的工作方式是,如果按下d键,相机会移动,如果按下a键,相机会移动到另一个方向。W缩小,S放大。我的问题是,当它在X轴上旋转时,它开始缩小

float z = (height/2) / tan(PI/5);
float x = width/2;
char lastpressed;
void setup() {
  size(640, 360, P3D);
}
void draw() {
  camera(x, height/2, z, width/2, height/2, 0, 0, 1, 0);
  background(0);
  if (keyPressed && key == 'd') {
    x += 5;
    lastpressed = 'd';
  }
  if (keyPressed && key == 'a') {
    lastpressed = 'a';
    x -= 5;
  }
  if (keyPressed && key == 's') {
    z += 5;
    lastpressed = 's';
  }
  if (keyPressed && key == 'w' && z >= 40) {
    z -= 5;
    lastpressed = 'w';
  }
  translate(width/2, height/2, -100);
  lights();
  box(200);
}

虽然它给人的印象是旋转和变焦,但相机只是沿着X轴移动,描述了他们所说的X轴。我尝试了一下,同时更改了最少的代码,我得出了以下结论:

float radius = 300;
float angle = 0;
char lastpressed;
void setup() {
  size(640, 360, P3D);
}
void draw() {
  translate(width/2, height/2, 0);
  float ypos= 0;
  float xpos= cos(radians(angle))*radius;
  float zpos= sin(radians(angle))*radius;

  camera(xpos, ypos, zpos, 0, 0, 0, 0, -1, 0);

  background(0);
  if (keyPressed && key == 'd') {
    lastpressed = 'd';
    angle+=5;
  }
  if (keyPressed && key == 'a') {
    lastpressed = 'a';
    angle-=5;
  }
  if (keyPressed && key == 's') {
    lastpressed = 's';
    radius += 20;
  }
  if (keyPressed && key == 'w' && radius > 200) {
    lastpressed = 'w';
    radius -= 20;
  }

  lights();
  box(200);
}

我在代码中没有看到任何与旋转相关的内容。