Nearest way to new angle?

BlitzMax Forums/BlitzMax Programming/Nearest way to new angle?

ozak(Posted 2006) [#1]
I know it's been mentioned before, but the search turned up nothing.

If I have an old angle, and a new one I want to rotate towards.
How do I rotate the shortest way towards the new angle?

Thanks in advance

EDIT: Never mind. I figured it out. Was quite easy ;)


deps(Posted 2006) [#2]
Could you post some code to show how to do it?
Would be nice to have it here if anyone tries to search for it again. ;)


GW(Posted 2006) [#3]
Here is the way I do it.
http://www.blitzbasic.com/Community/posts.php?topic=52437#609499


ozak(Posted 2006) [#4]
I just hacked another function to just return my rotation speed:

' Get turn direction
Function GetAngleDir:Int(A1#, A2#)

	Local ret:Int
	
	ret = A1-A2
	If ret >= 180
		ret = -(360 - ret)
	Else
		If ret <= -180
			ret = ret + 360
		EndIf
	EndIf

	' Adjust to speed as I don't want the range to next angle :)
	If (ret <= 0) Return 6
    Return -6

End Function



To get the rotational range to next angle, simply replace

' Adjust to speed as I don't want the range to next angle :)
	If (ret <= 0) Return 6
    Return -6


with


return ret