Arkadiusz Brzoza
Arkadiusz Brzoza

Reputation: 23

Get Movement Direction of Mouse

I know this has been Asked but in my Case i dont know if i Can use the MouseEventArgs since its a Rendering / Input Loop where Im trying to use it Here is the Whole Rendering / Input Loop, I can only Move with the Keyboard which is Rather inconvinient.

public void update()
    {


        //--do raycast--//
        raycast();

        //=========================//
        //=====take user input=====//
        //=========================//

        KeyboardState state = Keyboard.GetState();

        bool lArrowKeyDown = state.IsKeyDown(Keys.Left) || state.IsKeyDown(Keys.A);

        //MouseLeft
        if (lArrowKeyDown)
        {
            rotate(rotSpeed);
        }
        //MouseRight
        bool rArrowKeyDown = state.IsKeyDown(Keys.Right) || state.IsKeyDown(Keys.D);

        if (rArrowKeyDown)
        {
            rotate(-rotSpeed);
        }
        //MouseUp
        bool uArrowKeyDown = state.IsKeyDown(Keys.Up) || state.IsKeyDown(Keys.W);
        bool shift = state.IsKeyDown(Keys.LeftShift);
        if (uArrowKeyDown)
        {
            move(moveSpeed);
        }
        if (uArrowKeyDown && shift)
        {
            move(moveSpeed+0.01);
        }

        bool dArrowKeyDown = state.IsKeyDown(Keys.Down) || state.IsKeyDown(Keys.S);
        //MouseDown
        if (dArrowKeyDown)
        {
            move(-moveSpeed);
        }

        //=========================//
        //=====user input end======//
        //=========================//
    }

This is the Whole Rendering / Input Loop, Would it be Possible to add a MouseEventArgs? Im unsure of if a MouseEventArgs Loops too when this Loops. Could someone help me Here?

Upvotes: 2

Views: 97

Answers (1)

Thomas Angeland
Thomas Angeland

Reputation: 471

I’m not entirely sure what you are asking for, but if you want to get movement direction from a mouse event, unless the mouse event has a last position and new position property, you need to keep track of the last position (x and y value) and use it with the current position to calculate the angle.

For calculating the angle, see Calculating the angle between the line defined by two points

I can provide a better answer with more information.

Upvotes: 0

Related Questions