Angle Question...
BlitzPlus Forums/BlitzPlus Programming/Angle Question...
| ||
Hiya all, I have a little problem :) In the code below, I have a small dot that follows the mouse, and when I hit the mouse button, I want the dot to travel from the point of the mouse, to another point on the screen! But, it's not working! Well, it is (ish), so... the question is, how do I get it working properly? :/ Thanks in advance Dabz P.S. If this eventually works, it should go straight in the archives, because it's a right bugger of a problem, especially for someone who got a D in maths! :D *EDIT* Just noticed, the dot travels through the two points exactly half way... mmmm Dabz starts scratching his head!!!! |
| ||
I found this anyway:- http://www.blitzbasic.com/codearcs/codearcs.php?code=940 Dabz |
| ||
Not perfect, but it works:- I'll sleep better tonight knowing that's sorted! :) Dabz |
| ||
Function Angle(basex, basey, targetx, targety) If targety>basey-1 Then angle=ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey))) Else If targetx>basex-1 Then angle=270+90-ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey))) Else angle=360-ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey))) EndIf EndIf If targetx=basex And targety=basey Then Return 0 Else Return angle End Function Function Distance#(x1#, y1#, x2#, y2#) Return Sqr((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) End Function |
| ||
Thanks Andres, nice functions them! :) Dabz |