From 82636ab0fbbeeccd3ca76d6ceb7ab018445acbc1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Apr 2013 08:47:07 +0000 Subject: improved method of getting the tangent axis from a bmesh triangle, rather then getting the longest edge, get the edge which which is most different from the 2 others ends up giving more useful results: for an isosceles triangle it returns the base weather its longer or shorter then the other sides. --- source/blender/blenlib/intern/math_vector.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source/blender/blenlib/intern/math_vector.c') diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 58d444f5794..572bc4526af 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -527,6 +527,28 @@ void dist_ensure_v2_v2fl(float v1[2], const float v2[2], const float dist) } } +void axis_sort_v3(const float axis_values[3], int r_axis_order[3]) +{ + float v[3]; + copy_v3_v3(v, axis_values); + +#define SWAP_AXIS(a, b) { \ + SWAP(float, v[a], v[b]); \ + SWAP(int, r_axis_order[a], r_axis_order[b]); \ +} (void)0 + + if (v[0] < v[1]) { + if (v[2] < v[0]) { SWAP_AXIS(0, 2); } + } + else { + if (v[1] < v[2]) { SWAP_AXIS(0, 1); } + else { SWAP_AXIS(0, 2); } + } + if (v[2] < v[1]) { SWAP_AXIS(1, 2); } + +#undef SWAP_AXIS +} + /***************************** Array Functions *******************************/ double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) -- cgit v1.2.3