Results 1 to 11 of 11

Thread: x_new,y_new from x_old,y_old

  1. #1

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8

    Arrow x_new,y_new from x_old,y_old

    I would like to be able to move the mouse from the old x,y to the
    new x,y pixel by pixel. I have no problem with moving the mouse
    it's a way of moving it from point A to B smoothly that i do not know how to do.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    use a timer, and move the mouse a little bit for each timer event.
    -= a peet post =-

  3. #3

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8
    i'm using a for loop to get the to the new position but it the mouse does this

    ^
    |
    |
    \
    \
    \
    \
    ^

    i want

    ^
    \
    \
    \
    \
    \
    \
    ^

    there is my code

    GetCursorPos z
    xm = z.x
    ym = z.y
    x2 = Val(Mid(f(line), 3, 5))
    y2 = Val(Mid(f(line), 8, 5))
    Do Until xm = x2 And ym = y2
    If x2 < xm Then xm = xm - 1
    If x2 > xm Then xm = xm + 1
    If y2 < ym Then ym = ym - 1
    If y2 > ym Then ym = ym + 1
    retval = SetCursorPos(xm, ym)
    Sleep (1)
    Loop

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    ^
    |
    |
    \
    \
    \
    \
    ^

    i want

    ^
    \
    \
    \
    \
    \
    \
    ^
    what do u mean ?

    I'm slow
    -= a peet post =-

  5. #5

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8
    the lines are the mouse movement. never mind the dots

    ...|
    ...|
    ....\
    ......\
    ........\

    i need this

    ....\
    ......\
    ........\
    ..........\
    ............\

  6. #6
    Lively Member venom8's Avatar
    Join Date
    Jul 2001
    Location
    Quezon City, PHIL.
    Posts
    87
    so, u want to move the mouse diagonally only?
    You never become a failure, unless you quit on trying!!!

  7. #7

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8
    a straight line is easy to plot but moving the mouse diagonally is the problem.

  8. #8

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8
    this one i found in C but i can't covert it to VB and get it to work


    /**************************************************************************
    * line_fast *
    * draws a line using Bresenham's line-drawing algorithm, which uses *
    * no multiplication or division. *
    **************************************************************************/

    void line_fast(int x1, int y1, int x2, int y2, byte color)
    {
    int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;

    dx=x2-x1; /* the horizontal distance of the line */
    dy=y2-y1; /* the vertical distance of the line */
    dxabs=abs(dx);
    dyabs=abs(dy);
    sdx=sgn(dx);
    sdy=sgn(dy);
    x=dyabs>>1;
    y=dxabs>>1;
    px=x1;
    py=y1;

    VGA[(py<<8)+(py<<6)+px]=color;

    if (dxabs>=dyabs) /* the line is more horizontal than vertical */
    {
    for(i=0;i<dxabs;i++)
    {
    y+=dyabs;
    if (y>=dxabs)
    {
    y-=dxabs;
    py+=sdy;
    }
    px+=sdx;
    plot_pixel(px,py,color);
    }
    }
    else /* the line is more vertical than horizontal */
    {
    for(i=0;i<dyabs;i++)
    {
    x+=dxabs;
    if (x>=dyabs)
    {
    x-=dyabs;
    px+=sdx;
    }
    py+=sdy;
    plot_pixel(px,py,color);
    }
    }
    }

  9. #9
    Lively Member venom8's Avatar
    Join Date
    Jul 2001
    Location
    Quezon City, PHIL.
    Posts
    87
    u can try this code, if u really just want to plot (x1,y1) to (x2,y2), i used the Line Method to connect the dots...

    1. add a command button and name it cmdPlot
    2. add two labels namely lblPoint1 and lblPoint2
    3. and paste this code in the general declaration

    '---------------------------------------------------------------------------------

    Option Explicit
    Dim CX1 As Integer, CY1 As Integer 'point 1 of the line
    Dim CX2 As Integer, CY2 As Integer 'point 2 of the line
    Dim curX As Integer, curY As Integer 'current Xpos and Ypos

    Dim maxDot As Integer

    Private Sub cmdPlot_Click()
    If cmdPlot.Caption = "&Plot" Then
    'draw a line
    Line (CX1, CY1)-(CX2, CY2)
    cmdPlot.Caption = "&Another Try"
    ElseIf cmdPlot.Caption = "&Another Try" Then
    lblPoint1.Caption = ""
    lblPoint2.Caption = ""
    maxDot = 0
    cmdPlot.Caption = "&Plot"
    cmdPlot.Enabled = False
    End If
    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    maxDot = maxDot + 1

    If maxDot <= 2 Then 'limit the user to plot 2 points only
    Select Case maxDot
    Case 1
    CX1 = curX
    CY1 = curY
    lblPoint1.Caption = curX & ", " & curY
    Case 2
    CX2 = curX
    CY2 = curY
    lblPoint2.Caption = curX & ", " & curY
    cmdPlot.Enabled = True
    End Select
    'draw a dot
    PSet (curX, curY), vbRed
    Else
    Exit Sub
    End If

    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    curX = X
    curY = Y
    Form1.Caption = curX & ", " & curY
    End Sub

    '-----------------------------------------------------------------------------------

    i'll try to code same program but this time i'll be using the bresenham's line algorithm. i think there are many things to consider in ploting a point using the said algorithm...
    You never become a failure, unless you quit on trying!!!

  10. #10

    Thread Starter
    New Member dt2's Avatar
    Join Date
    Jul 2001
    Posts
    8
    Thanks but thats what i'm looking for. I want to plot x1,y1 to x2,y2 like you did but the mouse has to know how to get from x1,y1 to x2,y2.

    example:

    x1=10: y1=10 'mouse starts here <<< this is known
    x2=15: y2=20 ' mouse will stop here <<<<this is known

    tell mouse how to move
    xm=10:ym=10 'start here
    xm=11:ym=11
    xm=11:ym=12
    xm=12:ym=13
    xm=12:ym=14
    xm=13:ym=15
    xm=13:ym=16
    xm=14:ym=17
    xm=14:ym=18
    xm=15:ym=19
    xm=15:ym=20 'end here

    i've tried to use Bresenham's line-drawing algorithm i found but can not get it to work.

  11. #11
    Lively Member venom8's Avatar
    Join Date
    Jul 2001
    Location
    Quezon City, PHIL.
    Posts
    87
    ok. then u should check this site, the algorithm here is a little bit easy to understand :

    http://www.totse.com/en/computers/co...logy/bres.html

    i am trying to convert it in VB but so far im not succesful !!! maybe i'll focus on it when i have free time, coz i have to finished my project . . .
    You never become a failure, unless you quit on trying!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width