XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

ScrollWheelValue difference - not working.

Last post 12/05/2009 3:06 by omega797. 5 replies.
  • 12/09/2007 13:23

    ScrollWheelValue difference - not working.

    It seems simple enough, but it's just not working - something must be wrong with my logic.

    float ScrollWheelChange = (float)(OldMouseState.ScrollWheelValue - 
    CurrentMouseState.ScrollWheelValue);

    Camera.Zoom += ScrollWheelChange;

    Even when I set a breakpoint and use the immediate window, ScrollWheelChange = 0.0.

    Ideas, anyone?

  • 12/09/2007 13:35 In reply to

    Re: ScrollWheelValue difference - not working.

    Answer
    Reply Quote

    This works well for me in the Update() overload of an empty project

                MouseState CurrentMouseState = Mouse.GetState();
    float ScrollWheelChange = (float)(OldMouseState.ScrollWheelValue - CurrentMouseState.ScrollWheelValue);
    Debug.Print(ScrollWheelChange.ToString());
    OldMouseState = CurrentMouseState;

    Make sure you declare OldMouseState outside the method so it retains its value.

    I did notice that mouse of the time it will output 0 since its running at 60fps and you can't keep the scrolling up unless you really try..

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 13/09/2007 10:27 In reply to

    Re: ScrollWheelValue difference - not working.

    One thing I thought I'd mention:
    If you create and open a dialog like a OpenFileDialog (or probably any kind of Form using the ShowDialog method) on Windows, close the dialog and then return to your main window on which XNA renders, the scroll wheel might stop working. I saw this bug on two machines up to now, yet on my primary development machine it doesn't occur. The mouse buttons and movement still work, but not the mouse wheel... wierdest bug ever.

    The fix I found was that after the dialog has been closed, you need to set the Mouse.WindowHandle to IntPtr.Zero and then back to Game.Window.Handle. You need to feed a zero pointer before setting it back because else the setter won't see a change in value and it'll have no effect.

    Since this occurs on some machines and others not, I suspect it's a .NET framework bug, since the two machines that have the bug aren't up-to-date with Windows Update. Still, making the fix doesn't hurt and prevents the bug.
  • 13/09/2007 12:57 In reply to

    Re: ScrollWheelValue difference - not working.

    XNA mouse wheel value is exactly 120 unit  increment/decrement
    per  notch,  starting at 0 when your game begins. I also use mouse
    wheel to control the zooming of my camera. Dividing by 120  will gives
    you the total  number  of  wheel  rotation per notch  from  the  last 
    wheel value  subtracted by current mouse wheel value.  just give some
    offset value if you want to zoom faster or slower.
     
     
     
    //! Scroll-Up | Zoom In
    if (CurrentMouseState.WheelValue > OldMouseState.WheelLastValue)
    {
    WheelVal = ( CurrentMouseState.WheelValue -
    OldMouseState.WheelLastValue ) / 120;
    //
    ZoomOutVal = 0;
    ZoomInVal += ( WheelVal * ZoomOffSetVal);
    }

    //! Scroll-Down | Zoom Out
    if ( CurrentMouseState.WheelValue < OldMouseState.WheelLastValue )
    {
    WheelVal = ( OldMouseState.WheelLastValue -
    CurrentMouseState.WheelValue ) / 120;
    //
    ZoomInVal = 0;
    ZoomOutVal += (WheelVal * ZoomOffSetVal );
    }


    //! Consuming zomm value per frame
    if ( ZoomInVal > 0 ) ZoomInVal--;
    if ( ZoomOutVal > 0 ) ZoomOutVal--;
     
     
  • 13/09/2007 13:16 In reply to

    Re: ScrollWheelValue difference - not working.

    Note that relying on 120 and doing integer divisions using that value may cause you problems in the future or with devices that do not have the 'notches'.

    See this thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1922079&SiteID=1

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 12/05/2009 3:06 In reply to

    Re: ScrollWheelValue difference - not working.

    Zaknafein:
    The fix I found was that after the dialog has been closed, you need to set the Mouse.WindowHandle to IntPtr.Zero and then back to Game.Window.Handle. You need to feed a zero pointer before setting it back because else the setter won't see a change in value and it'll have no effect.


    This hack worked for me. Thanks!
Page 1 of 1 (6 items) Previous Next