Moving objects around in a Viewport3D using mouse ?

I guess this imply transforming mouse position input into 3d world space.

Looking at trackBall sample from Daniel LehenBauer, it seems that there are some methods here

that would help to perform this but i can't find any way to achieve this.

any Hint ?

[279 byte] By [gumtoo] at [2007-12-22]
# 1

Here is one possible method which leverages our hit testing system to avoid doing the math by hand:

  • Use Mouse.GetPosition() to get the mouse position relative to the Viewport3D.
  • Use VisualTreeHelper.HitTest(...) to issue a 2D hit test at that point on the Viewport3D. The WPF will extrude this point into a 3D ray and report hit test results to you. If you hit a Visual3D you can cast the result to a RayHitTestResult. Presumably this is the Visual3D you want to move.
  • Construct a transparent XY plane at the Z depth indicated by RayHitTestResult.PointHit. This is the plane on which you will slide your object when moving the mouse in the X and Y directions. Make the plane transparent by using Brushes.Transparent.
  • As the mouse is moved, watch whene RayHitTestResult.PointHit intersects your transparent plane. Move your object to that point.

For a bit more background on hit testing, this blog post might be helpful. One thing to keep in mind: PointHit is returned in the coordinate space of the Visual3D which contains the content that you hit. You may need to transform this to get the object you are moving and your transparent plane into the same coordinate space.

- Daniel [msft]

All postings are provided "As Is" with no warranties, and confers no rights.

danlehen at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Thank you Daniel, I'm on my way to achieve this the way you just described here.

I would have another related question.

working with Transform3D, i feel i miss something i use a lot in 3d animation app

like for example:

TranslateTransform3D offsetX property is a double . so this is a value type.

but very often when rigging a character for example, i would need a reference type for this

property so i could set this object to multiple 3dnodes offsetX property and then move them along the X axis

by just set the value property of this object.

may be i don't get it because i haven't played much with animation in wpf. is this achieved by let say, create a double animation and make it target the offsetX property of multiple TranslateTransform3D ?

how could i achive to have a reference type on TranslateTransform3D offsetX property ?

would i have to write a class derived from some base abstract class ?

Thank you very much, the 3d namespace in wpf is awesome.

gumtoo at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

Hi

i did HitTesting and i found the visual3d, but can u tell me how should i move that visual3d using the mouse.

- Deepak

DeepakJuneja at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified