开发者

WPF 3D: Zoom model with mouse pointer coordinates as center


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开发者_Python百科 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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜