Tal's picture

MouseDevice bug?

Just now I have noticed that MouseDevice[MouseButton.X] rerurn true even when X is not pressed.
I test it for X=Left and X=Right so it's not only on one button.
It occurred when I test(just run, not like NUnit) my DirectedCameraManager which smillar to "float camera". When the user press the button, he can rotate the camera. With this "bug" it's possible that the user won't press on the X button but the camera would roll like he would press the X button(again, Left or Right). After this "bug" occurred, MouseDevice[MouseButton.X] stay true until I press the X button, and not other button. I also make sure that it is not bug of my code, by putting a debug point when I noticed the camera rotate even when I dont press the mouse. Here is the code generally:

if (...)
{
    if (... && Mouse[MouseButton.Right])//Mouse is a field here, not a class.
    {
        ...//Here I put the debug point.
        return;
    }
    //else
    ...
}
lastFocused = false;

If you want to see the full code, here is the part of a function that updating the DirectedCameraManager.

if (GameBinding.Focused)
{
    if (lastFocused && Mouse[MouseButton.Right])//Mouse is a field here, not a class.
    {
        float currentX = Mouse.X;
        float currentY = Mouse.Y;
        float deltaX = currentX - lastX;
        float deltaY = currentY - lastY;
        float dampened = elapsedTime * 0.17f;
        deltaX *= dampened;
        deltaY *= dampened;
        Quaternion rotate = Quaternion.FromAxisAngle(Vector3.UnitX, deltaY);
        Quaternion rotateX = Quaternion.FromAxisAngle(Vector3.UnitY, deltaX);
        Quaternion.Multiply(ref rotate, ref rotateX, out rotate);
        Camera.Rotate(ref rotate);
        return;
    }
    //else
    lastX = Mouse.X;
    lastY = Mouse.Y;
    lastFocused = true;
    return;
}
lastFocused = false;

I have rc1 and the SVN fix.