Optimising Challenge

BlitzMax Forums/BlitzMax Programming/Optimising Challenge

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ok

Function TweenAngle:Float(p1:Float , p2:Float , t:Float)
	If Abs(p2 - p1) < 180
		Return p1 + t * (p2 - p1)
	EndIf
	Return (p1 + t * (p2 + p1)) Mod 360
End Function


Thats faster than the Tween360. There might be faster ways perhaps.

Here the "benchmarking"

Strict
Local v1:Float	= 190 Mod 360
Local v2:Float	 = 0 Mod 360


Local time1:Int	 = MilliSecs()

For Local i = 1 To 1000
	v1	 = 190
	v2	 = 0
	
	While v1 < v2 - 0.1 Or v1 > v2 + 0.1
	
		v1	 = TweenAngle(v1 , v2 , 0.001)
	
	Wend
Next
time1	 = MilliSecs() - time1
Print "TweenAngle Time: " + time1

Local time2:Int	 = MilliSecs()

For Local i = 1 To 1000
	v1	 = 190
	v2	 = 0
	
	While v1 < v2 - 0.1 Or v1 > v2 + 0.1
	
		v1	 = tween360(v1 , v2 , 0.001)
	
	Wend
Next
time2	 = MilliSecs() - time2
Print "Tween360 Time: " + time2

End


Function TweenAngle:Float(p1:Float , p2:Float , t:Float)
	If Abs(p2 - p1) < 180
		Return p1 + t * (p2 - p1)
	EndIf
	Return (p1 + t * (p2 + p1)) Mod 360
End Function

Function Tween360:Float( a:Float , b:Float , time:Float )
	Local ix:Float = Sin(a)
	Local iy:Float = Cos(a)
	Local jx:Float = Sin(b)
	Local jy:Float = Cos(b)
	Return ATan2(ix-(ix-jx)*time,iy-(iy-jy)*time)
End Function