diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-16 15:04:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-16 15:07:28 +0400 |
commit | b3972aeea05bc6c60d7b7da4e6b59a64b822448a (patch) | |
tree | ee959d88f8be160e01f8633b9c163ba7dc105d0c /source/blender/blenlib | |
parent | 233dac149478624a74831ff24454e5956124622c (diff) |
Math Lib: optimize axis_dominant_v3_to_m3, approx 6x speedup
build the matrix directly rather then calculating with axis/angle
also remove unused function calc_poly_plane
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 30 |
2 files changed, 10 insertions, 22 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 3c1b89fbd44..6ba8910db14 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -303,7 +303,7 @@ bool form_factor_visible_quad(const float p[3], const float n[3], float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], float v3[3], float v4[3]); -bool axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]); +void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]); MINLINE void axis_dominant_v3(int *r_axis_a, int *r_axis_b, const float axis[3]); MINLINE float axis_dominant_v3_max(int *r_axis_a, int *r_axis_b, const float axis[3]) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 45e8c425f64..c2e4799d7cb 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2133,32 +2133,20 @@ void fill_poly_v2i_n( * \param r_mat The matrix to return. * \param normal A unit length vector. */ -bool axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]) +void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]) { - float up[3] = {0.0f, 0.0f, 1.0f}; - float axis[3]; - float angle; - - /* double check they are normalized */ BLI_ASSERT_UNIT_V3(normal); - cross_v3_v3v3(axis, normal, up); - angle = saacos(dot_v3v3(normal, up)); + copy_v3_v3(r_mat[2], normal); + ortho_basis_v3v3_v3(r_mat[0], r_mat[1], r_mat[2]); - if (angle >= FLT_EPSILON) { - if (len_squared_v3(axis) < FLT_EPSILON) { - axis[0] = 0.0f; - axis[1] = 1.0f; - axis[2] = 0.0f; - } + BLI_ASSERT_UNIT_V3(r_mat[0]); + BLI_ASSERT_UNIT_V3(r_mat[1]); - axis_angle_to_mat3(r_mat, axis, angle); - return true; - } - else { - unit_m3(r_mat); - return false; - } + transpose_m3(r_mat); + + BLI_assert(!is_negative_m3(r_mat)); + BLI_assert(fabsf(dot_m3_v3_row_z(r_mat, normal) - 1.0f) < BLI_ASSERT_UNIT_EPSILON); } /****************************** Interpolation ********************************/ |