简体   繁体   English

在给定视图方向和光标位置变化的情况下,如何平移3d网格

[英]how to translate 3d mesh, given a view direction and a change in cursor position

My question is similar to 3D Scene Panning in perspective projection (OpenGL) except I don't know how to compute the direction in which to move the mesh. 我的问题类似于透视投影(OpenGL)中的3D场景平移,但我不知道如何计算移动网格的方向。

I have a program in which various meshes can be selected. 我有一个可以选择各种网格的程序。 Once a mesh is selected I want it to translate when click-dragging the cursor. 一旦选择了网格,我希望在单击并拖动光标时进行平移。 When the cursor moves up, I want the mesh to move up, and so on for the appropriate direction. 当光标向上移动时,我希望网格向上移动,依此类推。 In other words, I want the mesh to translate in directions along the plane that is perpendicular to the viewing direction. 换句话说,我希望网格沿垂直于观察方向的平面的方向平移。

I have the Vector2 for the Delta (x,y) in cursor postion, and I have the Vector3 viewDirection of the camera and the center of the mesh. 我在光标位置有一个Delta(x,y)的Vector2,并且我有相机的Vector3 viewDirection和网格的中心。 How can I figure out which way to translate the mesh in 3d space with the Delta and viewDirection? 如何确定使用Delta和viewDirection在3d空间中转换网格的方法? Will I need other information in order to to this calculation (such as the up, or eye)? 我是否需要其他信息以进行此计算(例如向上或眼睛)?

It doesn't matter if if the scale of the translation is off, I'm just trying to figure out the direction right now. 是否关闭翻译规模并不重要,我只是想立即找出方向。

EDIT: for some reason I had a confusion about getting the up direction. 编辑:由于某种原因,我对获得向上的方向感到困惑。 Clearly it can be calculated by applying the camera rotation to the specified perspective up vector. 显然,可以通过将相机旋转应用于指定的透视向上矢量来计算。

You'll need an additional vector, upDirection , which is the unit vector pointing "up" from your camera. 您将需要一个附加向量upDirection ,它是指向摄像机“向上”的单位向量。 You can now cross-product viewDirection and upDirection to get rightDirection , the vector pointing "right" from your camera. 现在,您可以交叉乘积viewDirectionupDirection来获取rightDirection ,即从相机指向“右”的向量。

You want to map y deltas to motion along upDirection (or -upDirection ) and x deltas to motion in rightDirection . 要映射y增量运动沿着upDirection (或-upDirection )和x增量在运动rightDirection These vectors are in world-space. 这些向量在世界空间中。

You may want to scale the translation speed to match the mouse speed. 您可能需要缩放翻译速度以匹配鼠标速度。 If you are using perspective projection you'll want to scale the translation speed with your model's depth with respect to your camera (The further the object is from your camera, the faster you will need to move it if you want it to match the mouse.) 如果您使用的是透视投影,则需要根据模型相对于相机的深度来缩放平移速度(对象离相机越远,如果要使其与鼠标匹配,则移动速度就越快。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM