Results 1 to 9 of 9

Thread: Line rotation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80

    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?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Huh I think you need some trig, it's not easy so unless you really really need it, you should forget about it
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Oops sorry Sas, looks like I was too slow hehe
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80

    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?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    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?

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    I'm glad we were of some help
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  9. #9
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Actually I don't hehe
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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