Hi,
does anyone know how to linear interpolate (lerp) between two angles in degrees (Tier 1)?
It needs to work even in those special cases:
LerpAngle( 90, 320 ) -> interpolate from 90 to 320 (-40), going left (not up from 90 to 320!)
LerpAngle( 330, 45 ) -> interpolate from 330 to 45, going right (not down from 330 to 45!)
It has to interpolate in the correct direction!
Here are some helper functions that I found:
// Linear Interpolate
function Lerp(start as float, stop as float, factor as float)
if (start = stop)
exitfunction start
elseif (factor <= 0.0)
exitfunction start
elseif (factor >= 1.0)
exitfunction stop
else
exitfunction ((1.0 - factor) * start) + (factor * stop)
endif
endfunction start
// Wrap Angle
function WrapAngle(a as float)
a = a - floor(a / 360) * 360
endfunction a