透视投影(OpenGL)中的3D场景平移 [英] 3D Scene Panning in perspective projection (OpenGL)

查看:779
本文介绍了透视投影(OpenGL)中的3D场景平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个C ++类,用于从跟踪球旋转,缩放和平移中抽象出用户。我已经得到旋转(使用轨迹球)和缩放工作按预期。但是,平移的行为不如预期。当我选择一个点和拖动,我期望在完成拖动,挑选的点继续在鼠标下。我对透视投影中的平移的理解如下。目标和相机位置都将受到平移操作的影响。相机目标和相机位置(眼睛)应与拖曳成正比。平移可以是基于z深度。



平移在正交投影中是直接的,但是在透视中造成问题。如果可以解释 OpenGL 的数学和实现细节,这将是有用的。

解决方案

不知道OpenGL的细节,但如果我正确理解你的问题,我可以帮助数学:



我假设你已经选择了对象,通过单击



要理解以下内容:

p>



现在,您可以沿着向量 t拖动鼠标。使用截距定理,您可以很容易地计算向量 s ,其中 p 必须翻译为保持在光标下:



| p | / | q | = | s | / | t |



| s | = |(| p | / | q |)* | t |



p平行于t,所以它被t归一化乘以| s |:



s = t / | t | * | s |



s = t / | t | *(| p | / | q |)* | t |



s = t *(| p | / | q |)



如果你正在平移,你正在做同样的事情,只是你不是通过 移动 ,但你必须翻译你的整个场景 -


I have designed a C++ class that abstracts the user from trackball rotation, zooming and panning. I have got the rotation (using trackball) and zooming working as expected. However, panning does not behave as expected. When I pick a point and drag, I expect that on finishing drag, the picked point continues to be under the mouse. My understanding of panning in perspective projection is as follows. The target and the camera position, both will be affected by a pan operation. The camera target and the camera position (eye) should be translated proportional to the drag. The proportionality (may not be constant) should be based on z depth.

Panning is straight forward in orthographic projection but poses a problem in perspective. It will be useful if one can explain the math and the implementation detail for OpenGL.

解决方案

I don't know about the OpenGL specifics, but if I understand your question correctly I can help out with the mathematics:

I assume you have already selected the object, by clicking the object and thus "sending" a ray through your scene that hits your object in the anchorpoint p.

To understand the following:

Now you drag your mouse along vector t. Using the intercept theorem you can easily calculate the vector s by which p has to be translated to "keep it under the cursor":

|p| / |q| = |s| / |t|

|s| = ( |p| / |q| ) * |t|

s is parallel to t, so it is t normalized multiplicated by |s|:

s = t / |t| * |s|

s = t / |t| * ( |p| / |q| ) * |t|

s = t * ( |p| / |q| )

If you are panning, you are doing the exact same thing, just that you are not shifting p by s, but you have to translate your whole scene by -s.

这篇关于透视投影(OpenGL)中的3D场景平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆