WPF转换2D鼠标点击到​​三维空间 [英] WPF convert 2d mouse click into 3d space

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

问题描述

我有几个几何图形网格在我的Viewport3D,这些有界(附: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)的三维点...

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 的回调。

  • 如果你有一个 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 。这包括三维点属性,告诉你在空间中的三维点被击中,也网格和三角形被击中。

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点击测试了解更多详情。

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

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