我有一个程序,其中一个盒子(玩家)可以降落在地面(环境),移动和跳跃。在试图使箱子向前方向独立于环境的过程中,我使用了一对或翻译和旋转。这适用于盒子移动,但现在我不知道盒子的坐标使用相机功能来聚焦它。
void setup() {
size(600,600,P3D);
PVector eye = new PVector(0,0,0);
PVector translations = new PVector(0,0,0);
background(200);
translate(width/2, height/2);
rotateZ(mouseX/(width/PI));
//ground would be drawn here
translate(0,0,-400);
translate(50, 100 ,490);
rotateZ(-mouseX/(width/PI));
box(150);
translations.add(0,0,0);//translations occurring from rotations and translation
eye.add(translations);
eye.add(500, 1000, 500); //translate the eye away from the point its looking at
camera(eye.x, eye.y, eye.z, translations.x, translations.y, translations.z, 0, 0, -1);
eye.mult(0);
translations.mult(0);
}
如何在翻译后找到包装盒的位置?我知道使用sin和cos是必要的,但我不能为我的生活得到一个完美的算法。
编辑:我将代码更改为完整且可验证的