如何将 Canvas3D 上的运动转换为虚拟 3D 世界中的运动

发布于 2024-09-02 13:25:37 字数 273 浏览 3 评论 0原文

我的目标是以这样的方式移动虚拟世界中的形状,使其最终到达鼠标指针在画布上的位置。

我有什么: - Canvas3D 对象上的鼠标位置 (x,y) -Point3d 对象,表示从 Canvas3D 视口开始的拾取光线与第一个场景对象相交的位置。 (指向我想要开始拖动的 3D 空间)

我想要什么: - 平移 Point3d 坐标的某种方法,以便初始交点(Point3d 对象)始终与画布上的鼠标位置重叠(与我使用拾取射线确定用户从 Canvas3D 对象单击的内容时相同) )。

谢谢!

My goal is to move a shape in the virtual world in such a way so that it ends up where the mouse pointer is on the canvas.

What i have:
-mouse position (x,y) on a Canvas3D object
-Point3d object of where a pick ray starting from the Canvas3D viewport intersects with the first scene object. (point in 3D space of where i want to start the drag)

What i want:
-Some way to translate the Point3d's coordinates so that the initial point of intersection (the Point3d object) is always overlapping the the mouse position on the canvas (same as when i used the pick ray to determine what the user clicked on from the Canvas3D object).

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-09-09 13:25:37

听起来好像您想使用与背景平面平行并包含与对象的交点的平面。即使鼠标移动到实际背景之外,您也可以使用该平面,因为它只是一个延伸到无穷大的数学概念。

我不是 Java 程序员,所以我不能给你代码,但我是一名数学家,所以这是你需要的方程;)

让 P 表示原始交点,并将背景平面单位法线 n 称为 n。该法线也是我们感兴趣的平面的法线。令 R 表示射线上的点,l 表示其单位方向向量。

那么对于平面上的点 x,平面方程为 (xP).n = 0(. 表示两个向量的点积)。射线上一点的方程为 x = R + t*l,其中 t 是任意实数。 时,射线与平面相交。

因此,当(t*l + R - P).n = 0

时,即当

t = (P - R).n / ( ln )

这为您提供了 at 值,可以将其插回到射线方程中,从而给出交点。

It sounds as if you want to use the plane which is parallel to the background plane and contains the intersection point with the object. You can use this plane even when the mouse moves beyond the actual background as it's just a mathematical concept which stretches to infinity.

I'm not a Java programmer so I can't give you code but I am a mathematician so here's equation you need ;)

Let P denote the original intersection point and call the background plane unit normal n. This normal is also the normal of our plane of interest. Let R denote a point on the ray and l denote it's unit direction vector.

Then the equation of the plane is (x-P).n = 0 for a point x in the plane (the . denotes dot product of two vectors). The equation of a point on the ray is x = R + t*l where t is any real number. The ray therefore intersects the plane when

(t*l + R - P).n = 0

i.e. when

t = (P - R).n / ( l.n )

This gives you a t value to plug back into your ray equation to give the intersection point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文