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 :-)

'demonstration code to break tween angle

'note that angle1 and angle 2 will both move at their own pace
'with a gap between them from 0..360 to test

SuperStrict
Graphics 640,480,0

Global sourceAngle:Float , destAngle:Float
Global angle1:Float = 0
Global angle2:Float = 15

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	'test tweenAngle
	angle1:+1
	angle2:+1
	If angle1>360 angle1 :- 360
	If angle2>360 angle2 :- 360
	
	Local ang:Float = TweenAngle( angle1 , angle2 , 0.5 )
	
	'draw	
	DrawLine 320 , 240 , 320-Cos(ang)*32 , 240-Sin(ang)*32
	Flip
Wend

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


Remember it has to work both ways :)