当我更改相机设置时形状消失

Shapes disappear when I change camera settings

鲜花们!我正在学习一种有趣的语言:Processing。我开始使用 P3D 并尝试在 3D 世界中制作 'First-person' 相机 。问题是,当我移动鼠标(意味着我更改了相机选项)时,球体和立方体等 3D 形状似乎被透明平面切割。

我做了一些尝试来解决我的问题(例如,更改 camera() 的第三个因素)但它仍然不起作用。让我展示一下我的代码。

这是我程序的主要绘图部分。

pushMatrix();
translate(width/2, height, 0);

// P is player-class, and view method controls the camera option
P.view(P.looking_at());

fill(0); stroke(255);
for (int i=0; i<1000; i+=1) {
  if (isNear(shapes[i])) // just checking for distance, it doesn't matter
    shapes[i].locate();
}

popMatrix(); // now, the origin is top left

这就是形状的定位功能

void locate() {
  // these are coordinate of the shape
  translate(location.x, location.y, location.z); 
  // sphere or cube
  translate(-location.x, -location.y, -location.z);
}

最后,这是我为 P.view() 写的:

void view(PVector watch_point) { // camera setting
  hint(ENABLE_DEPTH_TEST);
  camera(location.x, location.y, location.z, // these are coordinate of player
    watch_point.x, watch_point.y, watch_point.z, // sight direction, updated when the mouse is moved
    0, -1, 0); // 3rd factor for camera
  lights();
}

我希望 "normal view" 和现实世界一样,但是当我正视某些形状时,它们消失了! 它们只有在我注视它们时才显得正常,而当我将视线移向它们时,雕塑会逐渐消失;更具体地说,它看起来像是被飞机切割过的。请帮我解决这个问题。 (或者我的代码中有任何编码错误?)

3D shapes such as spheres and cubes seem to be cut by a transparent plane.

可能模型被投影的近平面或远平面裁剪了。
当你设置透视投影时,你必须增加到远平面的距离或减少到近平面的距离。
如果物体被远平面裁剪(切割),则增加第4个参数(zFar),当你设置透视投影时(perspective())。
如果对象被近平面裁剪,则减小到近平面的距离(zNear)。
但请注意条件 0 < zNearzNear < zFar 在任何情况下都必须满足。