|
-
Aug 19th, 2002, 06:25 AM
#1
Thread Starter
Addicted Member
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:
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Dim dipy As Double
Dim dipx As Double
Dim rot As Integer
Private Sub Timer1_Timer()
If GetKeyState(vbKeyRight) < 0 Then
rot = rot + 10
If rot > 360 Then rot = rot - 360
Line1.Y2 = Line1.Y1 + (Sin(rot * 1.74532925199433E-02) * 500)
Line1.X2 = Line1.X1 + (Cos(rot * 1.74532925199433E-02) * 500)
End If
If GetKeyState(vbKeyLeft) < 0 Then
rot = rot - 10
If rot < 0 Then rot = rot + 360
Line1.X2 = Line1.X1 + (Sin(-rot * 1.74532925199433E-02) * 500)
Line1.Y2 = Line1.Y1 + (Cos(-rot * 1.74532925199433E-02) * 500)
End If
If GetKeyState(vbKeyUp) < 0 Then
Shape1.Left = Shape1.Left + (Cos(rot * 1.74532925199433E-02) * 100)
Shape1.Top = Shape1.Top + (Sin(rot * 1.74532925199433E-02) * 100)
dipx = Line1.X1
dipy = Line1.Y1
Line1.Y1 = Shape1.Top + (Shape1.Width / 2)
Line1.X1 = Shape1.Left + (Shape1.Height / 2)
dipx = dipx - Line1.X1
dipy = dipy - Line1.Y1
Line1.Y2 = Line1.Y2 - dipy
Line1.X2 = Line1.X2 - dipx
End If
Debug.Print rot
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|