Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rotating a line 1

Status
Not open for further replies.

peter11

Instructor
Mar 16, 2001
334
US
I am trying to create a simple game that uses a line as a cannon barell.

I want to use a horizontal slider to set the angle of the cannon.
Here is the starting position of the line.
Static xx As Integer
Static yy As Integer

xx = 0
yy = 200

line.x1 = 0
line.y1= 200
line.x2 = 50
line.y2= 200

The horizontal scroller starts at 0 and ends at 90.

Here is the code that I was trying.

conv = Val(hsbAngle.value) / 180 * 3.141592654 'convert radians to degrees
Line1.X2 = 50 * Cos(conv)
Line1.Y2 = -yy + (50 * Sin(conv))

 
Try This
Code:
    Dim conv                        As Double
    Dim linelen                     As Double
    
    With Line1
        .X1 = 0
        .X2 = 50
        .Y1 = 200
        .y2 = 200
        linelen = .X2 - .X1

        conv = Val(hsbAngle.Value) / 180 * 3.141592654
        .X2 = .X1 + linelen * Cos(conv)
        .y2 = .Y1 - (linelen * Sin(conv))
    End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top