|
-
Dec 7th, 2001, 05:24 PM
#1
Thread Starter
Lively Member
Line rotation
How would I make this simple line rotate? So far I can just move it foward and backward wherever it points.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static posx As Integer
Static posz As Integer
Static lookx As Integer
Static lookz As Integer
Static vecx As Integer
Static vecz As Integer
Static length As Integer
length = Line1.x2 - Line1.X1
Label1.Caption = length
posx = Line1.X1
posz = Line1.Y1
lookx = Line1.x2
lookz = Line1.Y2
vecx = lookx - posx
vecz = lookz - posz
If KeyCode = vbKeyUp Then
posz = posz + vecz
lookz = lookz + vecz
posx = posx + vecx
lookx = lookx + vecx
Line1.X1 = posx
Line1.Y1 = posz
Line1.x2 = lookx
Line1.Y2 = lookz
Shape1.Left = posx - 135
Shape1.Top = posz - 135
End If
If KeyCode = vbKeyDown Then
posz = posz - vecz
lookz = lookz - vecz
posx = posx - vecx
lookx = lookx - vecx
Line1.X1 = posx
Line1.Y1 = posz
Line1.x2 = lookx
Line1.Y2 = lookz
Shape1.Left = posx - 135
Shape1.Top = posz - 135
End If
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Dec 7th, 2001, 05:54 PM
#2
Good Ol' Platypus
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 7th, 2001, 06:01 PM
#3
Frenzied Member
Huh I think you need some trig, it's not easy so unless you really really need it, you should forget about it
-
Dec 7th, 2001, 06:06 PM
#4
Frenzied Member
Oops sorry Sas, looks like I was too slow hehe
-
Dec 7th, 2001, 11:08 PM
#5
Thread Starter
Lively Member
Drakon
Ok, I got it to rotate. However, when you change the direction it rotates, the line changes it's orientation then starts to rotate... I'm bad at explaining things in words sometimes, so feel free to try the code... it just needs a line, shape, and a label.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static posx As Integer
Static posz As Integer
Static lookx As Integer
Static lookz As Integer
Static vecx As Integer
Static vecz As Integer
Static length As Integer
Static angle As Double
Static speed As Integer
Label1.Caption = length
posx = Line1.X1
posz = Line1.Y1
lookx = Line1.x2
lookz = Line1.Y2
vecx = lookx - posx
vecz = lookz - posz
length = Sqr(((lookx - posx) ^ 2) + ((lookz - posz) ^ 2))
If KeyCode = vbKeyUp Then
posz = posz + vecz
lookz = lookz + vecz
posx = posx + vecx
lookx = lookx + vecx
Line1.X1 = posx
Line1.Y1 = posz
Line1.x2 = lookx
Line1.Y2 = lookz
Shape1.Left = posx - 135
Shape1.Top = posz - 135
End If
If KeyCode = vbKeyDown Then
posz = posz - vecz
lookz = lookz - vecz
posx = posx - vecx
lookx = lookx - vecx
Line1.X1 = posx
Line1.Y1 = posz
Line1.x2 = lookx
Line1.Y2 = lookz
Shape1.Left = posx - 135
Shape1.Top = posz - 135
End If
angle = angle + ((2 * 3.14) / 320)
If KeyCode = vbKeyRight Then
lookx = posx + (length * Cos(angle))
lookz = posz + (length * Sin(angle))
Line1.x2 = lookx
Line1.Y2 = lookz
End If
If KeyCode = vbKeyLeft Then
lookz = posz + (length * Cos(angle))
lookx = posx + (length * Sin(angle))
Line1.x2 = lookx
Line1.Y2 = lookz
End If
End Sub
Any help would be appreciated
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Dec 8th, 2001, 09:49 AM
#6
Thread Starter
Lively Member
Oh well I figured it out on my own
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Dec 9th, 2001, 12:38 PM
#7
Frenzied Member
I'm glad we were of some help
-
Dec 9th, 2001, 03:00 PM
#8
Good Ol' Platypus
Do you write anything useful?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 9th, 2001, 03:37 PM
#9
Frenzied Member
Actually I don't hehe
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
|