Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-04-02 07:05:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-04-02 07:05:49 +0400
commitf1b42a129f0f9299a9e67eb0495131a37464c9cc (patch)
tree99bda9a0c293524a04f0ba4cfd91cc87c378810f /source/blender/blenlib/intern/math_rotation.c
parent69bd72c3b6aa1fdaab0c1232a6ba1e3e4c9029fa (diff)
add angle wrapping functions: angle_wrap_rad(), angle_wrap_deg().
use with mathutils.
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c16
1 files changed, 16 insertions, 0 deletions
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;
+}