注意:这是在处理 IDE 中
我正试图让球形轨道下降,我几乎已经做到了。这是我到目前为止所拥有的:
float cameraTheta, cameraPhi, cameraRadius; //camera position in spherical coordinates
float camx, camy, camz;
void setup() {
size(500, 500, P3D);
background(255);
cameraRadius = 200.0f;
cameraTheta = 2.80;
cameraPhi = 2.0;
recomputeOrientation();
}
void draw() {
background(255);
lights();
mouseMotion();
camera(camx, camy, camz, 0, 0, 0, 0, -1, 0);
sphereDetail(10);
sphere(25);
}
void mouseMotion()
{
if (mousePressed) {
cameraTheta += (mouseX - pmouseX)*0.05;
cameraPhi += (mouseY - pmouseY)*0.05;
}
recomputeOrientation(); //update camera (x,y,z) based on (radius,theta,phi)
}
void recomputeOrientation()
{
camx = cameraRadius * sin(cameraTheta)*sin(cameraPhi);
camz = cameraRadius * -cos(cameraTheta)*sin(cameraPhi);
camy = cameraRadius * -cos(cameraPhi);
redraw();
}
x 旋转效果很好,但是 y 旋转有点从上到下翻滚,然后随着 mouseY 的变化一遍又一遍地备份,我需要的是只要鼠标移动它就可以继续向一个方向翻滚随着鼠标向下移动,向上和向后移动另一个方向。谁能帮我解决这个问题?