diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 14 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 03b6ff25a4f..1dcc1c1df49 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -431,6 +431,20 @@ void mat3_to_size(float size[3], const float M[3][3]); void mat4_to_size(float size[3], const float M[4][4]); /** + * Return the largest scale on any axis, the equivalent of calling: + * \code{.c} + * mat3_to_size(size_v3, mat); + * size = size_v3[max_axis_v3(size_v3)]; + * \endcode + * .. without 2x unnecessary `sqrtf` calls. + */ +float mat3_to_size_max_axis(const float M[3][3]); +/** + * Only the first 3 axes are used. + */ +float mat4_to_size_max_axis(const float M[4][4]); + +/** * Extract scale factors from the matrix, with correction to ensure * exact volume in case of a sheared matrix. */ diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index f307672361b..9c719b12756 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -2144,6 +2144,16 @@ void mat4_to_size(float size[3], const float M[4][4]) size[2] = len_v3(M[2]); } +float mat3_to_size_max_axis(const float M[3][3]) +{ + return sqrtf(max_fff(len_squared_v3(M[0]), len_squared_v3(M[1]), len_squared_v3(M[2]))); +} + +float mat4_to_size_max_axis(const float M[4][4]) +{ + return sqrtf(max_fff(len_squared_v3(M[0]), len_squared_v3(M[1]), len_squared_v3(M[2]))); +} + void mat4_to_size_fix_shear(float size[3], const float M[4][4]) { mat4_to_size(size, M); |