WPF 3D:以鼠标指针坐标为中心缩放模型

发布于 2024-08-27 12:20:50 字数 856 浏览 4 评论 0原文


平台:

  • .NET 3.5 与 C#
  • WPF
  • 3DTools

我正在使用 Codeplex 网站上的 3DTools (3D 工具)用于旋转和平移 3D 模型。这很好用。 Trackball 类还包含使用鼠标滚轮缩放模型的方法。然而,该方法总是以Point(0,0,0)为缩放中心来缩放模型。但我想缩放到鼠标指针的坐标(就像谷歌地图一样,这里你不缩放到地图的中心,而是缩放到鼠标指针的坐标)。

我尝试了不同的方法来解决这个问题:

  • 将 Trackball 类的 ScaleTransform3D 对象的 CenterX/Y/Z 设置为鼠标指针坐标 ->它无法
  • 缩放后平移模型 ->也没用;因为鼠标指针的坐标没有改变,因此我无法计算平移距离,例如
    • 缩放前的鼠标指针坐标 -> 334、210
    • 从 Trackball 类调用 Zoom(-e.Delta)
    • 缩放后的鼠标指针坐标 -> 334、210
    • 如果鼠标指针坐标发生变化,例如 330、205,我可以将模型向左平移 4 点,向上平移 5 点(我的程序也有 2D 模式,坐标会发生变化)
  • 移动相机位置->没用;根据当前相机位置和 MouseWheelEventArgs.Delta 我计算了新的相机位置

有人知道如何解决这个问题吗?


Plattform:

  • .NET 3.5 with C#
  • WPF
  • 3DTools

I'm using 3DTools from the Codeplex site (3D Tools) for rotating and panning of 3D Models. This works fine. The Trackball class also contains a method for zooming models with the mouse wheel. However, this method always scales the model with Point(0,0,0) as the center of the zooming. But I'd like to zoom to the coordinates of the mouse pointer (like Google Maps, here you do not zoom to the center of the map but to the mouse pointer coordinates).

I tried different things solving this issue:

  • set CenterX/Y/Z of the ScaleTransform3D object of the Trackball class to the mouse pointer coordinates -> it didn't work
  • pan the model after zooming -> didn't work too; because the coordinates of the mouse pointer do not change, thus I can not calculate the panning distance, e.g.
    • MousePointer Coordinates before zooming -> 334, 210
    • call Zoom(-e.Delta) from the Trackball class
    • MousePointer Coordinates after zooming -> 334, 210
    • if the MousePointer Coordinates would change, e.g. 330, 205, I could pan the model 4 points left and 5 points up (my program has also a 2D mode and there the coordinates change)
  • move the camera position -> didn't work; based on the current camera position and the MouseWheelEventArgs.Delta I calculated the new camera position

Has somebody a clue how this problem can be solved?

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

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

发布评论

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

评论(1

静待花开 2024-09-03 12:20:50

3DTools 项目在 .NET 3.5 上运行不佳,因为它旨在在 .NET 3.0 版本的 WPF 上运行。

3D 工具的使命(因此功能)是使在 .NET 3.0 的 WPF 上更轻松地在 3D 上编码 2D 控件。如果您有 .NET 3.5,则已经支持 2D on 3D 编程以及 WPF XAML 支持。

虽然.NET 3.5基本上是.NET 3.0 SP1 + LINQ,但.NET 3.0 SP1上的WPF子系统与.NET 3.0版本的WPF相比有相当大的差异,例如上面的差异。

访问 MSDN Library 上的此页面:

http:// msdn.microsoft.com/en-us/library/bb613588(v=VS.90).aspx

此外,.NET 3.0 SP1 的 WPF 也不能很好地支持鼠标跟踪。我建议您重写鼠标跟踪代码并在.NET 3.5环境下重新编译(将项目定位到.NET 3.5)。

The 3DTools project doesn't work well on .NET 3.5, because it's meant to run on WPF of .NET 3.0 release.

The mission (hence functionality) of the 3D Tools is to make coding 2D controls on 3D easier on WPF of .NET 3.0. If you have .NET 3.5, you already have support for 2D on 3D programming and also WPF XAML support.

Although .NET 3.5 is basically .NET 3.0 SP1 + LINQ, the WPF subsystem on .NET 3.0 SP1 has quite large differences such as above, compared to WPF of .NET 3.0 release.

Visit this page on MSDN Library:

http://msdn.microsoft.com/en-us/library/bb613588(v=VS.90).aspx

Also the mouse tracking isn't not well supported on the WPF of .NET 3.0 SP1. I suggest you to rewrite the mouse tracking code and recompile it under .NET 3.5 environment (target the project to .NET 3.5).

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