From f1b42a129f0f9299a9e67eb0495131a37464c9cc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 2 Apr 2011 03:05:49 +0000 Subject: add angle wrapping functions: angle_wrap_rad(), angle_wrap_deg(). use with mathutils. --- source/blender/blenlib/intern/math_rotation.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/blender/blenlib/intern/math_rotation.c') diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 4e37de93ded..dfd715ccbf2 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1675,3 +1675,19 @@ float angle_to_lens(float angle) { return 16.0f / tanf(angle * 0.5f); } + +/* 'mod_inline(-3,4)= 1', 'fmod(-3,4)= -3' */ +static float mod_inline(float a, float b) +{ + return a - (b * floorf(a / b)); +} + +float angle_wrap_rad(float angle) +{ + return mod_inline(angle + (float)M_PI, (float)M_PI*2.0f) - (float)M_PI; +} + +float angle_wrap_deg(float angle) +{ + return mod_inline(angle + 180.0f, 360.0f) - 180.0f; +} -- cgit v1.2.3