-Don't work on degrees. Otherwise you need to continuously change from deg to radians and vice versa.
-I didn't know that the mod fucntion existed. So I wrote my own version.
The right code should be this:
Given an angle of the child bone: Alpha (radians), you want to calculate the angle that fits in a [-pi,pi]. pi=180 deg
Code: Select all
function mod_2pi(Alpha)
if (Alpha > math.pi)
Alpha = Alpha-math.ceil(Alpha/(math.pi))*math.pi
if(Alpha < -1*math.pi)
Alpha = Alpha-math.floor(Alpha/(math.pi))*math.pi
return Alpha
end
Examples:
Alpha = 190 deg
returns= 190-ceil(190/180)*180=190-2*180 = -170
Alpha = -190 deg
returns= -190-floor(-190/180)*180=-190+2*180 = 170
Alpha = 590 deg
returns= 590-ceil(590/180)*180=590-4*180 = -130
Alpha = -590 deg
returns= -590-floor(-590/180)*180=-590+4*180 = 130
Hope it works. I've not tested it

-G