|
-
Aug 17th, 2002, 02:42 AM
#1
Thread Starter
New Member
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
-
Aug 17th, 2002, 12:46 PM
#2
Fanatic Member
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.
-
Aug 17th, 2002, 01:02 PM
#3
Fanatic Member
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.
-
Aug 17th, 2002, 07:44 PM
#4
Good Ol' Platypus

Unfortunately that'll get you nowhere, you need to know how to spin it. Use this, and I'll explain it:
VB Code:
Function Radar(mLine As Line, CentreX As Long, CentreY As Long, Degree As Long, Radius As Double)
Dim Rad As Double
Rad = Degree * (3.1415926 / 180)
With mLine
.X2 = CentreX + Cos(Rad) * Radius
.Y2 = CentreY + Sin(Rad) * Radius
.X1 = CentreX
.Y1 = CentreY
End With
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)
-
Aug 18th, 2002, 03:10 AM
#5
Thread Starter
New Member
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
-
Aug 31st, 2002, 05:02 AM
#6
Thread Starter
New Member
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
-
Aug 31st, 2002, 05:08 AM
#7
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|