WPF 将 2d 鼠标点击转换为 3d 空间 [英] WPF convert 2d mouse click into 3d space

查看:30
本文介绍了WPF 将 2d 鼠标点击转换为 3d 空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Viewport3D 中有几个几何网格,它们的边界为 (w:1800, h:500, d:25).

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25).

当用户在网格中间单击时,我想要 (900, 500, 25) 的 Point3D...

When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)...

我怎样才能做到这一点?

How can I achieve this?

谢谢!标记

推荐答案

只需将 VisualTreeHelper.HitTest 与回调一起使用即可.

Just use VisualTreeHelper.HitTest with the callback.

  • 如果您有一个包含模型的 Viewport3D,您只需传入一个包含鼠标位置的 PointHitTestParameters.

  • If you have a Viewport3D containing the model, you can just pass in a PointHitTestParameters containing the mouse location.

如果您需要直接在 Visual3D 上进行操作,请传入根据您的相机参数和鼠标位置计算得出的 RayHitTestParameters.

If you need to operate directly on a Visual3D, pass in a RayHitTestParameters computed from your camera parameters and the mouse location.

在任何一种情况下,您的回调都将使用 RayTestHitResult 调用,如果您命中网格,它将是 RayMeshGeometry3DHitTestResult.这包括一个 Point3D 属性,告诉您空间中被击中的 3D 点,以及被击中的网格和三角形.

In either case your callback will be called with a RayTestHitResult, and if you hit a mesh it will be a RayMeshGeometry3DHitTestResult. This includes a Point3D property telling you the 3D point in space that was hit, and also the mesh and triangle that was hit.

请参阅 3D 命中测试了解更多详情.

See 3D Hit testing for more details.

这篇关于WPF 将 2d 鼠标点击转换为 3d 空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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