Results 1 to 4 of 4

Thread: Rotation Problem [Resolved]

Threaded View

  1. #1

    Thread Starter
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166

    Rotation Problem [Resolved]

    Hi all,

    After a few minutes search, i found some code to rotate a shape. So far i have adapted the code, so that the end of a line rotates around the other end of the line.

    I have this code

    To use it. add a shape, timer (set to 20 interval) and a line control to a form.

    VB Code:
    1. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
    2. Dim dipy As Double
    3. Dim dipx As Double
    4. Dim rot As Integer
    5.  
    6. Private Sub Timer1_Timer()
    7.     If GetKeyState(vbKeyRight) < 0 Then
    8.         rot = rot + 10
    9.         If rot > 360 Then rot = rot - 360
    10.         Line1.Y2 = Line1.Y1 + (Sin(rot * 1.74532925199433E-02) * 500)
    11.         Line1.X2 = Line1.X1 + (Cos(rot * 1.74532925199433E-02) * 500)
    12.     End If
    13.  
    14.     If GetKeyState(vbKeyLeft) < 0 Then
    15.         rot = rot - 10
    16.         If rot < 0 Then rot = rot + 360
    17.         Line1.X2 = Line1.X1 + (Sin(-rot * 1.74532925199433E-02) * 500)
    18.         Line1.Y2 = Line1.Y1 + (Cos(-rot * 1.74532925199433E-02) * 500)
    19.     End If
    20.  
    21.     If GetKeyState(vbKeyUp) < 0 Then
    22.         Shape1.Left = Shape1.Left + (Cos(rot * 1.74532925199433E-02) * 100)
    23.         Shape1.Top = Shape1.Top + (Sin(rot * 1.74532925199433E-02) * 100)
    24.         dipx = Line1.X1
    25.         dipy = Line1.Y1
    26.         Line1.Y1 = Shape1.Top + (Shape1.Width / 2)
    27.         Line1.X1 = Shape1.Left + (Shape1.Height / 2)
    28.         dipx = dipx - Line1.X1
    29.         dipy = dipy - Line1.Y1
    30.         Line1.Y2 = Line1.Y2 - dipy
    31.         Line1.X2 = Line1.X2 - dipx
    32.     End If
    33.     Debug.Print rot
    34. End Sub

    If you press the right key to rotate and then press the up key. the shape goes in the direction of the line.

    However, if you press the left key and then press up, the shape goes off on a tangent to the line.

    I can't figure out why though?

    Any ideas?

    Pete
    Last edited by Peter1; Aug 19th, 2002 at 07:52 AM.

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