Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can _MOUSEMOVEMENTX & Y be used for something like this?
#1
I'm trying to grasp using_MOUSEMOVEMENTX & Y in  a program, not sure I fully understand these two functions yet.  I have run the wiki examples, but I'm not seeing how they could be used for something like below.   Could those functions be used to easier compute mouse movement for like grabing an object and move it only for as much as the mouse has moved since clicking on it?

Here's some code I was playing with for testing.  Could something like this be streamlined with _MOUSEMOVEMENTX & Y instead of using another DO/LOOP to calculate mouse movement?

- Dav 

Code: (Select All)

Screen _NewImage(800, 600, 32)

cx = 400: cy = 400

Do

    Cls , _RGB(32, 0, 0)

    Locate 1, 1: Print "Click on and drag curves to shape...";

    While _MouseInput: Wend

    'grabbed screen
    If _MouseButton(1) Then
        startmx = _MouseX: startmy = _MouseY

        '=====================================================
        'Can _MOUSEMOVEMENTX/Y be used instead of below?
        Do
            Cls , _RGB(32, 0, 0)
            While _MouseInput: Wend
            newcx = cx + (_MouseX - startmx)
            newcy = cy + (_MouseY - startmy)
            For c = -300 To 300 Step 20
                Curve 400, 100, 400, 500, newcx + c, newcy, _RGB(255, 0, 0)
            Next
            _Limit 30
            _Display
        Loop Until _MouseButton(1) = 0
        cx = newcx: cy = newcy
        '=====================================================

    End If

    For c = -300 To 300 Step 20
        Curve 400, 100, 400, 500, cx + c, cy, _RGB(255, 0, 0)
    Next

    _Limit 30
    _Display
Loop

Sub Curve (x1, y1, x2, y2, cx, cy, clr&)
    'Draws a curved line using a quadratic bezier curve formula
    'x1/y1 = start point
    'x2/y2 = end point
    'cx.cy = control point
    Do While t <= 1
        x = (1 - t) ^ 2 * x1 + 2 * (1 - t) * t * cx + t ^ 2 * x2
        y = (1 - t) ^ 2 * y1 + 2 * (1 - t) * t * cy + t ^ 2 * y2
        PSet (x, y), clr&
        t = t + .001
    Loop
End Sub

Find my programs here in Dav's QB64 Corner
Reply
#2
I think a lot of folks misunderstand what MouseMovementX and MouseMovementY are for.  

First thing to note:  They're NOT for tracking your mouse's absolute position on the screen.  There's _MouseX and _MouseY for that.

So what are they for??

Let's move our thinking from QB64PE out to just playing some game.  Now, in this game, you're in a spaceship flying through outer space.  To control your ship, it's set up to use a simple scroll ball as the navigation tool.

Scroll that ball right, and the ship turns right.
Scroll that ball left, and the ship turns left.
Scroll that ball up, and the ship flys down.  (The arse end goes up, the nose goes down.)
Scroll that ball down, and the ship flys up.  (The arse end goes down, the nose goes up.)

Now, tracking mouse position in this situation is just foolish.  You scroll right.... right... right.... right.... Hit the edge of the screen with the mouse, and BOOM!!  Your ship can no longer rotate to the right in outer space!!

See the problem with trying to use _MouseX in this situation?   You can turn right and go around in circles till the end of time.  Your mouse cursor, however, is going to stop at the edge of your screen.

So, how to track this "ball rotated right" event??    _MouseMovementX.    Even if the mouse is at the right edge of the screen, you can scroll that mouseball on your desk endlessly to the right.  It won't move the mouse pointer -- it's already at the limit -- but _MouseMovementX will record that rotation and report it to you.

MouseMovementX  simply tells you if your mouseball has rotated left or right.
MouseMovementY tells you if that mouseball has rotated up or down.

It has nothing to do with screen coordinates.  Just mouse wheel scrolling itself.
Reply
#3
Does this do what you want?

Code: (Select All)

Screen _NewImage(800, 600, 32)

cx = 400: cy = 400

Do

    Cls , _RGB(32, 0, 0)

    Locate 1, 1: Print "Click on and drag curves to shape...";

    While _MouseInput

        'grabbed screen
        If _MouseButton(1) Then

            '=====================================================
            'Can _MOUSEMOVEMENTX/Y be used instead of below?

            Cls , _RGB(32, 0, 0)

            newcx = cx + _MouseMovementX
            newcy = cy + _MouseMovementY

            For c = -300 To 300 Step 20
                Curve 400, 100, 400, 500, newcx + c, newcy, _RGB(255, 0, 0)
            Next
            _Limit _Width * 10000
            _Display
            cx = newcx: cy = newcy
            '=====================================================

        End If
    Wend
    For c = -300 To 300 Step 20
        Curve 400, 100, 400, 500, cx + c, cy, _RGB(255, 0, 0)
    Next

    _Limit 30
    _Display
Loop Until InKey$ = Chr$(27)

Sub Curve (x1, y1, x2, y2, cx, cy, clr&)
    'Draws a curved line using a quadratic bezier curve formula
    'x1/y1 = start point
    'x2/y2 = end point
    'cx.cy = control point
    Do While t <= 1
        x = (1 - t) ^ 2 * x1 + 2 * (1 - t) * t * cx + t ^ 2 * x2
        y = (1 - t) ^ 2 * y1 + 2 * (1 - t) * t * cy + t ^ 2 * y2
        PSet (x, y), clr&
        t = t + .001
    Loop
End Sub
Reply
#4
Ahh, I think I get it now.  Yeah, I misunderstood these alright.  Thanks for the explanation!

EDIT:  Sorry, James, I didn't notice your post before I replied.  Well, yeah, but the original worked too, I just wondered if I could bypass the 2nd mousey DO/LOOP and drawing, by just using _MOUSEMOVEMENT positions instead, but thanks for trying to help me out, I appreciate it.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#5
Try this out @Dav : https://qb64phoenix.com/forum/showthread.php?tid=2102
Reply




Users browsing this thread: 1 Guest(s)