java - 使用相机处理特定区域的移动
问题描述
嗨,我是处理方面的新编码员。我的代码又长又复杂,但我为您的问题准备了一个简单的代码。
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;
}
所以,我想制作一个只能绕过给定顶点的相机。相机不会从白色区域向外移动。如何让这种情况发生?当我在该地区走得更远时也有一个错误。相机在到达一半区域时改变方式。你能帮我修复那个错误吗?谢谢你。
解决方案
推荐阅读
- javascript - 如何创建一个简单的解决方案来绕过声音而不是自动播放?
- android - Android 解析设置
- unit-testing - 如何用 axios 测试异步功能?
- jenkins - 如何检查 Jenkins 构建是否正在等待输入?
- python - 将步长添加到线性优化
- python - 检查 NaN 时如何选择特定列 Pandas 数据框
- specflow - Specflow 场景大纲示例表 - 反对?
- javascript - 如何替换字符串中的一组字符
- r - 将多个日期格式因子转换为 R 中的日期类型
- iterm2 - iterm2 中的字体大小更改不会更改我的标签标题的字体大小。我怎样才能做到这一点?