我有个大球体。在球体上有一个红色的圆点。我想跟着那个红点,当它移动到球体的时候。所以我的相机必须用红点移动。但有个问题。现在,我正在体验的是展览B中所显示的内容,我希望我的动画能够实现在展览A中所显示的观点。

这是我到目前为止的代码。我觉得很简单。我有3个变量控制我的眼睛,我有3个变量控制目标的位置。红点也位于目标位置。我在x-y中增加了2架飞机,这有助于我在旋转时不会感到太混乱。
这里有一把小提琴:
https://jsfiddle.net/da8nza6y/
float radius = 1000;
float view_elevation = 1500;
float target_elevation = 300;
float x_eye;
float y_eye;
float z_eye;
float x_aim;
float y_aim;
float z_aim;
float h;
float theta;
void setup() {
size(600, 600, P3D);
theta = 0;
h = 30;
}
void draw() {
theta += 0.5;
theta = theta%360;
x_eye = (radius+view_elevation)*cos(theta*PI/180);
y_eye = 0;
z_eye = (radius+view_elevation)*sin(theta*PI/180);
x_aim = (radius+target_elevation)*cos((theta+h)*PI/180);
y_aim = 0;
z_aim = (radius+target_elevation)*sin((theta+h)*PI/180);
camera(x_eye, y_eye, z_eye, x_aim, y_aim, z_aim, 0, 0, -1);
background(255);
// the red dot
pushMatrix();
translate(x_aim, y_aim, z_aim);
fill(255, 0, 0, 120);
noStroke();
sphere(10);
popMatrix();
// the big sphere
noStroke();
fill(205, 230, 255);
lights();
sphere(radius);
// the orange plane
pushMatrix();
translate(0, 0, 10);
fill(255, 180, 0, 120);
rect(-2000, -2000, 4000, 4000);
popMatrix();
// the green plane
pushMatrix();
translate(0, 0, -10);
fill(0, 180, 0, 120);
rect(-2000, -2000, 4000, 4000);
popMatrix();
}因此,问题是,当红色点(它在x-z平面中的位置由角度(theta+h)和距离(radius+target_elevation)从原点给出)穿过x-y平面时,所有东西都会被上下翻转。
现在,我试图控制camera()函数中的最后3个变量,但我感到困惑。该功能的文档如下:
有人能找到解决这个问题的办法吗?
而且,我确信我可以旋转球体(我可以做到),没有这些问题,但我确定我要用这个动画的方向,我觉得有一些事情会更容易用这种方法。尽管我可能弄错了。
发布于 2017-11-21 03:38:58
我相信我已经解决了自己的问题。
在调用camera()函数之前,我在绘图中添加了以下行:
if ((x_eye- x_aim) < 0) {
z_orientation = 1;
} else {
z_orientation = -1;
}我注意到触发翻转的不是(theta+h),而是视图和目标的相对位置。
这里有一个最新的小提琴:
https://stackoverflow.com/questions/47404178
复制相似问题