问题描述
给定相机朝向的方向的 3D 向量和 3D 空间中 3D 对象的方向/方向向量,我如何计算鼠标指针在屏幕上必须遵循的二维斜率在视觉上沿着所述物体的方向移动?
Given the 3D vector of the direction that the camera is facing and the orientation/direction vector of a 3D object in the 3D space, how can I calculate the 2-dimensional slope that the mouse pointer must follow on the screen in order to visually be moving along the direction of said object?
基本上我希望能够点击一个箭头并通过拖动它来让它来回移动,但前提是鼠标指针沿着箭头的长度(大致)拖动,即它的方向指向.
Basically I'd like to be able to click on an arrow and make it move back and forth by dragging it, but only if the mouse pointer drags (roughly) along the length of the arrow, i.e. in the direction that it's pointing to.
谢谢
推荐答案
我不确定我是否 100% 理解您的问题.你介意贴一张图吗?
I'm not sure I 100% understand your question. Would you mind posting a diagram?
您可能会对这些感兴趣.我回答了以前的问题 计算给定相机方向的局部 XYZ 轴(看)向量,还有一个问题 在平行于相机的平面中平移物体.
You might find these of interest. I answered previous questions to calculate a local X Y Z axis given a camera direction (look at) vector, and also a question to translate an object in a plane parallel to the camera.
这两个例子都使用矢量点积,向量叉积 来计算所需的向量.在您的示例中,矢量点积 也可用于输出两个矢量之间的角度找到了.
Both of these examples use Vector dot product, Vector cross product to compute the required vectors. In your example the vector dot product can be also used to output the angle between two vectors once you have found them.
这篇关于3D 空间:跟随对象指向的方向,使用鼠标指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!