How to get the shortest way off screen?
Blitz3D Forums/Blitz3D Programming/How to get the shortest way off screen?
| ||
Okay, I must be more dumb or tired than I think I am, because I can't quite figure out how to do this...and I usually don't have problems with SIN and COS. This problem needs to calculate distance though, and that probably needs SQR and I'm not so strong there. What I need is an easy way to calculate the angle of the shortest distance from the cursor to any edge of the screen. The following example doesn't do what I want, but it's a framework. Can someone help me with the code needed to calculate the angle to draw the shortest possible line, from the cursor to the edge of the screen? Thanks. |
| ||
The shortest way off the screen will always be a horizontal or vertical line. So, given Width and Height equal to the width and height of the screen... Lowest = Mx ToX = 0 ToY = My If My < Lowest Lowest = My ToX = Mx ToY = 0 EndIf If Width-Mx < Lowest Lowest = Width-Mx ToX = Width ToY = My EndIf If Height-My < Lowest ToX = Mx ToY = Height EndIf |
| ||
D'oh! - that makes sense. There you see - sometimes you can just overcomplicate things by thinking too much...so I'll try not to think too much in the future. :-) Thank you. Have a nice weekend. :-) |