首页 > 解决方案 > 使用相机处理特定区域的移动

问题描述

嗨,我是处理方面的新编码员。我的代码又长又复杂,但我为您的问题准备了一个简单的代码。

float camX = 0;
float camY = 0;
float camZ = (height/2)/tan(PI/6) - 260;

float x, y, z = 0;

float rotX = 0, rotY = 0;
float lastX, lastY;
float distX, distY;

void setup() {
  size(1600, 1000, P3D);
}


void draw() {
  background(0);

  camera(camX, camY, camZ, //default camera position without 360 degree
    x, y, z, //where it is looking to
    0, 1, 0); //eye openness

  rotateX(rotX + distY);
  rotateY(rotY + distX);

  beginShape(QUADS);
  vertex(-350, 100.1, 350);      // Upper left to Corner     
  vertex(350, 100.1, 350);       // Upper right to Corner
  vertex(350, 100.1, -350);      // Bottom right to Corner
  vertex(-350, 100.1, -350);     // Bottom left to Corner
  endShape();

  if (keyPressed)
  {
    if (key == 'w') {           // GO FRONT
      camZ += 5;
    } else if (key == 's') {    // GO BACK
      camZ -= 5;
    } else if (key == 'a') {    // GO LEFT
      camX += 5;
      x += 5;
    } else if (key == 'd') {    // GO RIGHT
      camX -=5;
      x -= 5;
    }
  }
}

public void mousePressed() {
  lastX = mouseX;
  lastY = mouseY;
}

public void mouseDragged() {
  distX = radians(mouseX - lastX);
  distY = radians(lastY - mouseY);
}

public void mouseReleased() {
  rotX += distY; 
  rotY += distX;
  distX = distY = 0;
}

所以,我想制作一个只能绕过给定顶点的相机。相机不会从白色区域向外移动。如何让这种情况发生?当我在该地区走得更远时也有一个错误。相机在到达一半区域时改变方式。你能帮我修复那个错误吗?谢谢你。

标签: javaprocessing

解决方案


推荐阅读