Results 1 to 7 of 7

Thread: Line Control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Question Line Control

    I know the line control can be used for many things but this I have not seen how to do.

    How would you rotate/spin a line control at a constant radius? When it would go round, it should also be able to draw a perfect round circle (well not perfect). A wanted to use this as a radar screen for a game I am thinking about. Does anyone know how I would do this?

    Nathan
    Signed Nathan
    D_man of Programming

  2. #2
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Why not just use the .circle property for the circle part. You should probably whip up a function for the spinning of a line control. Im working on it.

  3. #3
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Making the circle is up to u. But heres the function for moving the line:

    Function SpinLine(Line As Line, Spinpoint As Long, SpintoX As Long, SpintoY As Long)
    With Line
    .X1 = Spinpoint
    .Y1 = Spinpoint
    .X2 = SpintoX
    .Y2 = SpintoY
    End With
    End Function

    Just Copy and Paste that into ur code.

    Line is the line control that u want to spin.

    Spinpoint is line control's x1,y1 locations (the center of the circle)

    SpintoX and SpintoY move the x2,y2 coordinates to wherever u want.this will allow it to spin.

    Use that if u want, or u can improve it, like by setting it up so that u just have to give it a degree (0 - 360) and it spins to that point.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134


    Unfortunately that'll get you nowhere, you need to know how to spin it. Use this, and I'll explain it:
    VB Code:
    1. Function Radar(mLine As Line, CentreX As Long, CentreY As Long, Degree As Long, Radius As Double)
    2. Dim Rad As Double
    3.  
    4.     Rad = Degree * (3.1415926 / 180)
    5.  
    6.     With mLine
    7.         .X2 = CentreX + Cos(Rad) * Radius
    8.         .Y2 = CentreY + Sin(Rad) * Radius
    9.         .X1 = CentreX
    10.         .Y1 = CentreY
    11.     End With
    12.  
    13. End Function
    If you haven't done maths before, here we go. The first line converts the degrees (0 - 359) to Radians. Then, it takes the centre of the circle, and adds the cosine of the radius to it (the horizontal bit). It then multiplies this by the radius to get either a positive or negative value that tells you where the X point is. Same with the Y.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Thumbs up Thanks for your help

    I don't know everything about maths but Im getting there. Thanks for your help everyone.
    Signed Nathan
    D_man of Programming

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Question Question?

    Ive got it working! I have put the timer() function into the code to time twice how long the line will do one revolution and then another, at a specific timer interval (set speed of the rotation). When set to an interval of 100 (1/100 of a second), it runs fine on most computers, spinning the circle at the same rate. But when set to an interval of 1 (1 milisecond), many computers either spin the line faster or slower. Why is this? Is there any way the circle can be run at the this rate on any computer?
    Signed Nathan
    D_man of Programming

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Source Code

    Here is the soucre code. Hope it helps.

    Private Sub Form_Load()

    pi = 4 * Atn(1) ' Calculate the value of pi.

    'Call function to prepare line control in position
    Call DrawCircle(linsec, linsec.X1, linsec.Y1, 0, 1000)

    End Sub

    Function DrawCircle(mLine As Line, CentreX As Long, CentreY As Long, Degree As Long, Radius As Double)

    Dim Rad As Double 'Declare radians

    Degree = Degree + 1 'Increment Degrees

    Rad = Degree * (pi / 180) 'set value for Rad

    'Set co-ordinates for each property position
    With mLine
    .X2 = CentreX + Cos(Rad) * Radius 'X end of line
    .Y2 = CentreY + Sin(Rad) * Radius 'Y end of line
    .X1 = CentreX 'X start of line
    .Y1 = CentreY 'Y "" "" ""
    End With

    End Function

    Private Sub Timer1_Timer()

    'rotate circle
    Call DrawCircle(linsec, linsec.X1, linsec.Y1, Degree, 1000)

    Finish = Timer
    TimeElaps = Finish - Start
    Label1.Caption = TimeElaps 'get time

    'test for 359 degreee and set value to 0 degree
    If Degree >= 359 Then

    If Label2.Caption = 0 Then
    Label2.Caption = TimeElaps: Degree = 0: SecondTime = Label2.Caption

    ElseIf Label2.Caption <> 0 And Label3.Caption = 0 Then

    Label3.Caption = TimeElaps - SecondTime
    Label11.Caption = Label3.Caption / 360

    Call DrawCircle(linsec, linsec.X1, linsec.Y1, 0, 1000)

    Command1.Enabled = True
    Timer1.Enabled = False
    End If

    End If

    Label4 = Degree

    End Sub
    Signed Nathan
    D_man of Programming

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