Results 1 to 8 of 8

Thread: [RESOLVED] direction vectors !!!

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Resolved [RESOLVED] direction vectors !!!

    Hi all,
    Hope someone out there can help me.I am tring to make an image controller fly from one point to another point ..But I seem to have problems locating the
    following code. All I have is an "image" name=graphic ..What is P2:X or P1.Y ? ..Could you make it work...?
    thanks

    VB Code:
    1. Private Sub Timer1_Timer()
    2. Dim speed As Long
    3. Dim X As Long
    4. Dim Y As Long
    5. speed = 10
    6. DistX = p2.X - p1.X
    7. distY = p2.Y - p1.Y
    8. dist = Sqr(DistX * DistX + distY * distY)
    9. Unitx = DistX / dist
    10. Unity = distY / dist
    11. graphic.Move graphic.Left + speed * Unitx, graphic.Top + speed * Unity
    12. End Sub

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: direction vectors !!!

    try this,
    VB Code:
    1. Private Type POINTAPI
    2.         x As Long
    3.         y As Long
    4. End Type
    5.  
    6. Dim p1 As POINTAPI
    7. Dim p2 As POINTAPI
    8.  
    9. Private Sub Form_Load()
    10.     p1.x = 1000
    11.     p1.y = 1000
    12.     p2.x = 5000
    13.     p2.y = 100
    14. End Sub
    15.  
    16. Private Sub Timer1_Timer()
    17.     Dim speed As Long
    18.        
    19.         speed = 50
    20.         DistX = p2.x - p1.x
    21.         DistY = p2.y - p1.y
    22.         dist = Sqr(DistX * DistX + DistY * DistY)
    23.         Unitx = DistX / dist
    24.         Unity = DistY / dist
    25.        
    26.         graphic.Move graphic.Left + speed * Unitx, graphic.Top + speed * Unity
    27.    
    28. End Sub
    although this will move the image forever, even make it cross the form boundaries, so you need to make it stop it at one time, according to your project need.

    Harsh Gupta
    Show Appreciation. Rate Posts.

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: direction vectors !!!

    BTW, i forgot. changes the speed value to 50 from 10, because it was tooo.. slow!!

    Harsh Gupta
    Show Appreciation. Rate Posts.

  4. #4

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: direction vectors !!!

    Thanks Harsh,
    I understood the logic..it works ok..
    Actually the speed value is not too slow for me .. I use /Form/ScaleMode/Pixel
    one more question..What is the shortest code for a scrolling background ?

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [RESOLVED] direction vectors !!!

    Scrolling background?? do you mean that a picture in the background is automatically moving from 1 side to another?
    Show Appreciation. Rate Posts.

  6. #6

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: [RESOLVED] direction vectors !!!

    Scrolling background?? do you mean that a picture in the background is automatically moving from 1 side to another?
    __________________
    yes

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [RESOLVED] direction vectors !!!

    all right, i tried a small project, but very noobish kinda project. i am sure that there are more better solutions available for this.

    Harsh Gupta

    EDIT: if you want to get more results, you could remove the RESOLVED thing from the subject line
    Attached Files Attached Files
    Show Appreciation. Rate Posts.

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [RESOLVED] direction vectors !!!

    Unless you are using DirectX/OpenGL, scrolling picture is always a very slow and processor intensive job on GDI.
    Try this code. It claims it is faster.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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