【发布时间】:2011-06-03 19:35:36
【问题描述】:
在我的场景中,我想要“抓取”地形,然后在移动光标时让相机平移(高度、视图矢量、视野等都保持不变)。
所以最初的“抓取”点将是世界空间中的工作点,我希望在拖动时该点保持在光标下方。
我当前的解决方案是获取先前和当前的屏幕点,将它们取消投影,从另一个中减去一个,然后使用该向量平移我的相机。这接近我想要的,但光标不会完全停留在初始场景位置上,如果您从地形边缘附近开始,这可能会出现问题。
// Calculate scene points
MthPoint3D current_scene_point =
camera->screenToScene(current_point.x, current_point.y);
MthPoint3D previous_scene_point =
camera->screenToScene(previous_point.x, previous_point.y);
// Make sure the cursor didn't go off the terrain
if (current_scene_point.x != MAX_FLOAT &&
previous_scene_point.x != MAX_FLOAT)
{
// Move the camera to match the distance
// covered by the cursor in the scene
camera->translate(
MthVector3D(
previous_scene_point.x - current_scene_point.x,
previous_scene_point.y - current_scene_point.y,
0.0));
}
感谢任何想法。
【问题讨论】:
-
您是在尝试“抓取”地形上的实际 3D 点,还是可以接受抓取 Z=0 的 2D 点?
-
这个想法是光标将保持在地形上的初始 3D 点上,所以这就是我试图“抓取”的内容。例如,如果您正在查看远处有山脉的场景,并且您“抓住”了一座山峰,当您向下拖动(或拉动)光标时,当光标保持打开时,这座山将向您靠近整个时间的高峰。
-
现在想出一个体面的解决方案为时已晚,但您要做的是解决系统问题:{ peak € ray from camera to mouse ; mountain.position.y = 0 },对吗?