流浪汉!我正在学习一种有趣的语言:处理。我开始使用 P3D ,并尝试在3D世界中制作“第一人称”相机。问题是,当我移动鼠标时(意味着我更改了相机选项),球形和立方体等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();
}
我希望像现实世界一样具有“正常视图”,但是当我直视某些形状时,它们就会消失! 只有当我看着它们时,它们才能正常显示;当我将视线移到它们上时,雕塑会逐渐消失;更具体地说,它看起来像是被飞机割断的。请帮我解决这个问题。 (或者我的代码中是否存在任何错误编码?)
答案 0 :(得分:0)
球形和立方体之类的3D形状似乎被透明平面切割了。
模型可能会被投影的近平面或远平面限制。
设置透视投影时,必须增加到远平面的距离或减小到近平面的距离。
如果对象被远平面裁剪(剪切),则在设置透视投影(perspective()
)时增加第4个参数(list
)。
如果对象被近平面修剪,请减小到近平面(data.frame
)的距离。
但是请注意,在任何情况下都必须满足条件zFar
和zNear
。