Saturday, February 5, 2011

Building a MVVM 3D Editor Application -> Getting Mouse Position?

Hi,

In my 3d editor application, I want to be able to click on and move a scene's entities (meshes, lights, cameras, etc). To do that, I imagine that I need to get the current mouse position relative to my Direct3d view and somehow give it to my ViewModel. How would I go about doing that, considering that my app is built with the MVVM pattern?

Additional Info: The Direct3d renderer is from a C++ DLL and we're using an HwndHost to place it inside our WPF app. It has a WndProc which I imagine I could use to handle mouse messages there but I'd rather avoid it if at all possible.

Thanks!

  • you can get the mouse position with

    Mouse.Position( RelativeToObject ); // get the mouse pos relative to an object
    Mouse.Position( null ); // get the mouse pos relative to the whole screen
    

    if thats not good enough, you can use Win32 calls.

    From Muad'Dib
  • InputManager.Current.PrimaryMouseDevice is probably your best bet.

    From Will
  • The best solution I found is to use an attached behavior. In the control that serves as the placeholder to the HwndHost I set an attached property, like

    b:MouseBehavior.LeftClick="{Binding DoSomeActionCommand}"
    

    where MouseBehavior receives the control and sets mouse events on it.

    It works well for me.

0 comments:

Post a Comment