diff options
author | YimingWu <xp8110@outlook.com> | 2019-08-20 16:09:55 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2019-08-20 16:09:55 +0300 |
commit | 8bee9af462238936087e0056d97cf086c2f7059a (patch) | |
tree | a103e0e42dccc788f5897782837093ce724e106d | |
parent | a942d97b7971dc0e7add44e3e9ba1c02fb914f7d (diff) |
BLI: double version of some math functions.
m--------- | release/datafiles/locale | 0 | ||||
m--------- | release/scripts/addons | 0 | ||||
m--------- | release/scripts/addons_contrib | 0 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 11 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 8 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 122 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 17 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 34 | ||||
m--------- | source/tools | 0 |
11 files changed, 198 insertions, 0 deletions
diff --git a/release/datafiles/locale b/release/datafiles/locale -Subproject 63f65770e67f38db29f76ac910dd87bd9841b91 +Subproject ad82c4ce43ef2801ef51e75af1f9702992478b0 diff --git a/release/scripts/addons b/release/scripts/addons -Subproject 37a8bdc661649cb6197e73b5eb96481cd5fb0c5 +Subproject 8e6f485cf5b160c425d7da7c743879b20f3d6a9 diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib -Subproject d9ed9d4d064c74c86e2767cd4be32d602a0ee31 +Subproject 7077ff07384491d1f7630484995557f1c7302da diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 5b941f570de..deb29605552 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -112,6 +112,7 @@ MINLINE float saasin(float fac); MINLINE float sasqrt(float fac); MINLINE float interpf(float a, float b, float t); +MINLINE double interpd(double a, double b, double t); MINLINE float min_ff(float a, float b); MINLINE float max_ff(float a, float b); diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 52d976daa2d..f5d87667b73 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -41,6 +41,7 @@ void zero_m4(float R[4][4]); void unit_m2(float R[2][2]); void unit_m3(float R[3][3]); void unit_m4(float R[4][4]); +void unit_m4_db(double m[4][4]); void copy_m2_m2(float R[2][2], const float A[2][2]); void copy_m3_m3(float R[3][3], const float A[3][3]); @@ -48,9 +49,14 @@ void copy_m4_m4(float R[4][4], const float A[4][4]); void copy_m3_m4(float R[3][3], const float A[4][4]); void copy_m4_m3(float R[4][4], const float A[3][3]); +void copy_m4_m4_db(double m1[4][4], const double m2[4][4]); + /* double->float */ void copy_m3_m3d(float R[3][3], const double A[3][3]); +/* float->double */ +void copy_m4d_m4(double R[4][4], const float A[4][4]); + void swap_m3m3(float A[3][3], float B[3][3]); void swap_m4m4(float A[4][4], float B[4][4]); @@ -82,6 +88,8 @@ void mul_m3_m3m3_uniq(float R[3][3], const float A[3][3], const float B[3][3]); void mul_m3_m3_pre(float R[3][3], const float A[3][3]); void mul_m3_m3_post(float R[3][3], const float B[3][3]); void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4]); +void mul_m4_m4m4_db_uniq(double R[4][4], const double A[4][4], const double B[4][4]); +void mul_m4db_m4db_m4fl_uniq(double R[4][4], const double A[4][4], const float B[4][4]); void mul_m4_m4_pre(float R[4][4], const float A[4][4]); void mul_m4_m4_post(float R[4][4], const float B[4][4]); @@ -173,11 +181,14 @@ void _va_mul_m4_series_9(float R[4][4], void mul_m4_v3(const float M[4][4], float r[3]); void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3]); +void mul_v3_m4v3_db(double r[3], const double mat[4][4], const double vec[3]); +void mul_v4_m4v3_db(double r[4], const double mat[4][4], const double vec[3]); void mul_v2_m4v3(float r[2], const float M[4][4], const float v[3]); void mul_v2_m2v2(float r[2], const float M[2][2], const float v[2]); void mul_m2v2(const float M[2][2], float v[2]); void mul_mat3_m4_v3(const float M[4][4], float r[3]); void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3]); +void mul_v3_mat3_m4v3_db(double r[3], const double M[4][4], const double v[3]); void mul_m4_v4(const float M[4][4], float r[4]); void mul_v4_m4v4(float r[4], const float M[4][4], const float v[4]); void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3]); /* v has implicit w = 1.0f */ diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 2815046865d..ccb42683d5a 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -106,6 +106,7 @@ MINLINE void add_v2_v2(float r[2], const float a[2]); MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]); MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2]); MINLINE void add_v3_v3(float r[3], const float a[3]); +MINLINE void add_v3_v3_db(double r[3], const double a[3]); MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void add_v4_v4(float r[4], const float a[4]); MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4]); @@ -119,6 +120,7 @@ MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2]); MINLINE void sub_v3_v3(float r[3], const float a[3]); MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3]); +MINLINE void sub_v3_v3v3_db(double r[3], const double a[3], const double b[3]); MINLINE void sub_v4_v4(float r[4], const float a[4]); MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]); @@ -127,6 +129,7 @@ MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3]) MINLINE void mul_v2_fl(float r[2], float f); MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f); MINLINE void mul_v3_fl(float r[3], float f); +MINLINE void mul_v3db_db(double r[3], double f); MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f); MINLINE void mul_v2_v2(float r[2], const float a[2]); MINLINE void mul_v2_v2v2(float r[2], const float a[2], const float b[2]); @@ -189,9 +192,12 @@ MINLINE float dot_v4v4(const float a[4], const float b[4]) ATTR_WARN_UNUSED_RESU MINLINE double dot_v3db_v3fl(const double a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE double dot_v3v3_db(const double a[3], const double b[3]) ATTR_WARN_UNUSED_RESULT; + MINLINE float cross_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void cross_v3_v3v3_hi_prec(float r[3], const float a[3], const float b[3]); +MINLINE void cross_v3_v3v3_db(double r[3], const double a[3], const double b[3]); MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3]); @@ -231,9 +237,11 @@ MINLINE double normalize_v3_d(double n[3]); /******************************* Interpolation *******************************/ void interp_v2_v2v2(float r[2], const float a[2], const float b[2], const float t); +void interp_v2_v2v2_db(double target[2], const double a[2], const double b[2], const double t); void interp_v2_v2v2v2( float r[2], const float a[2], const float b[2], const float c[2], const float t[3]); void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t); +void interp_v3_v3v3_db(double target[3], const double a[3], const double b[3], const double t); void interp_v3_v3v3v3( float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]); void interp_v3_v3v3v3v3(float p[3], diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 8f30255a08b..320f8a0f1ab 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -171,6 +171,11 @@ MINLINE float interpf(float target, float origin, float fac) return (fac * target) + (1.0f - fac) * origin; } +MINLINE double interpd(double target, double origin, double fac) +{ + return (fac * target) + (1.0f - fac) * origin; +} + /* used for zoom values*/ MINLINE float power_of_2(float val) { diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 7c64206134b..ffdd03d3568 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -71,6 +71,15 @@ void unit_m4(float m[4][4]) m[3][0] = m[3][1] = m[3][2] = 0.0f; } +void unit_m4_db(double m[4][4]) +{ + m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0f; + m[0][1] = m[0][2] = m[0][3] = 0.0f; + m[1][0] = m[1][2] = m[1][3] = 0.0f; + m[2][0] = m[2][1] = m[2][3] = 0.0f; + m[3][0] = m[3][1] = m[3][2] = 0.0f; +} + void copy_m2_m2(float m1[2][2], const float m2[2][2]) { memcpy(m1, m2, sizeof(float[2][2])); @@ -87,6 +96,11 @@ void copy_m4_m4(float m1[4][4], const float m2[4][4]) memcpy(m1, m2, sizeof(float[4][4])); } +void copy_m4_m4_db(double m1[4][4], const double m2[4][4]) +{ + memcpy(m1, m2, sizeof(double[4][4])); +} + void copy_m3_m4(float m1[3][3], const float m2[4][4]) { m1[0][0] = m2[0][0]; @@ -127,6 +141,29 @@ void copy_m4_m3(float m1[4][4], const float m2[3][3]) /* no clear */ m1[3][3] = 1.0f; } +void copy_m4d_m4(double m1[4][4], const float m2[4][4]) +{ + m1[0][0] = m2[0][0]; + m1[0][1] = m2[0][1]; + m1[0][2] = m2[0][2]; + m1[0][3] = m2[0][3]; + + m1[1][0] = m2[1][0]; + m1[1][1] = m2[1][1]; + m1[1][2] = m2[1][2]; + m1[1][3] = m2[1][3]; + + m1[2][0] = m2[2][0]; + m1[2][1] = m2[2][1]; + m1[2][2] = m2[2][2]; + m1[2][3] = m2[2][3]; + + m1[3][0] = m2[3][0]; + m1[3][1] = m2[3][1]; + m1[3][2] = m2[3][2]; + m1[3][3] = m2[3][3]; +} + void copy_m3_m3d(float R[3][3], const double A[3][3]) { /* Keep it stupid simple for better data flow in CPU. */ @@ -231,6 +268,61 @@ void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4]) #endif } +void mul_m4_m4m4_db_uniq(double R[4][4], const double A[4][4], const double B[4][4]) +{ + BLI_assert(R != A && R != B); + + /* matrix product: R[j][k] = A[j][i] . B[i][k] */ + + R[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0] + B[0][3] * A[3][0]; + R[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1] + B[0][3] * A[3][1]; + R[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2] + B[0][3] * A[3][2]; + R[0][3] = B[0][0] * A[0][3] + B[0][1] * A[1][3] + B[0][2] * A[2][3] + B[0][3] * A[3][3]; + + R[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0] + B[1][3] * A[3][0]; + R[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1] + B[1][3] * A[3][1]; + R[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2] + B[1][3] * A[3][2]; + R[1][3] = B[1][0] * A[0][3] + B[1][1] * A[1][3] + B[1][2] * A[2][3] + B[1][3] * A[3][3]; + + R[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0] + B[2][3] * A[3][0]; + R[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1] + B[2][3] * A[3][1]; + R[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2] + B[2][3] * A[3][2]; + R[2][3] = B[2][0] * A[0][3] + B[2][1] * A[1][3] + B[2][2] * A[2][3] + B[2][3] * A[3][3]; + + R[3][0] = B[3][0] * A[0][0] + B[3][1] * A[1][0] + B[3][2] * A[2][0] + B[3][3] * A[3][0]; + R[3][1] = B[3][0] * A[0][1] + B[3][1] * A[1][1] + B[3][2] * A[2][1] + B[3][3] * A[3][1]; + R[3][2] = B[3][0] * A[0][2] + B[3][1] * A[1][2] + B[3][2] * A[2][2] + B[3][3] * A[3][2]; + R[3][3] = B[3][0] * A[0][3] + B[3][1] * A[1][3] + B[3][2] * A[2][3] + B[3][3] * A[3][3]; +} + +void mul_m4db_m4db_m4fl_uniq(double R[4][4], const double A[4][4], const float B[4][4]) +{ + BLI_assert(R != A && R != B); + + /* matrix product: R[j][k] = A[j][i] . B[i][k] */ + + R[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0] + B[0][3] * A[3][0]; + R[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1] + B[0][3] * A[3][1]; + R[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2] + B[0][3] * A[3][2]; + R[0][3] = B[0][0] * A[0][3] + B[0][1] * A[1][3] + B[0][2] * A[2][3] + B[0][3] * A[3][3]; + + R[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0] + B[1][3] * A[3][0]; + R[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1] + B[1][3] * A[3][1]; + R[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2] + B[1][3] * A[3][2]; + R[1][3] = B[1][0] * A[0][3] + B[1][1] * A[1][3] + B[1][2] * A[2][3] + B[1][3] * A[3][3]; + + R[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0] + B[2][3] * A[3][0]; + R[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1] + B[2][3] * A[3][1]; + R[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2] + B[2][3] * A[3][2]; + R[2][3] = B[2][0] * A[0][3] + B[2][1] * A[1][3] + B[2][2] * A[2][3] + B[2][3] * A[3][3]; + + R[3][0] = B[3][0] * A[0][0] + B[3][1] * A[1][0] + B[3][2] * A[2][0] + B[3][3] * A[3][0]; + R[3][1] = B[3][0] * A[0][1] + B[3][1] * A[1][1] + B[3][2] * A[2][1] + B[3][3] * A[3][1]; + R[3][2] = B[3][0] * A[0][2] + B[3][1] * A[1][2] + B[3][2] * A[2][2] + B[3][3] * A[3][2]; + R[3][3] = B[3][0] * A[0][3] + B[3][1] * A[1][3] + B[3][2] * A[2][3] + B[3][3] * A[3][3]; + +} + void mul_m4_m4_pre(float R[4][4], const float A[4][4]) { BLI_assert(A != R); @@ -604,6 +696,26 @@ void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3]) r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; } +void mul_v3_m4v3_db(double r[3], const double mat[4][4], const double vec[3]) +{ + const double x = vec[0]; + const double y = vec[1]; + + r[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; + r[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; + r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; +} +void mul_v4_m4v3_db(double r[4], const double mat[4][4], const double vec[3]) +{ + const double x = vec[0]; + const double y = vec[1]; + + r[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; + r[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; + r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; + r[3] = x * mat[0][3] + y * mat[1][3] + mat[2][3] * vec[2] + mat[3][3]; +} + void mul_v2_m4v3(float r[2], const float mat[4][4], const float vec[3]) { const float x = vec[0]; @@ -646,6 +758,16 @@ void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3]) r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2]; } +void mul_v3_mat3_m4v3_db(double r[3], const double mat[4][4], const double vec[3]) +{ + const double x = vec[0]; + const double y = vec[1]; + + r[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2]; + r[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2]; + r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2]; +} + void mul_project_m4_v3(const float mat[4][4], float vec[3]) { /* absolute value to not flip the frustum upside down behind the camera */ diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 1977558ac88..961850d3a9a 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -1392,4 +1392,21 @@ void mul_vn_db(double *array_tar, const int size, const double f) } } +void interp_v3_v3v3_db(double target[3], const double a[3], const double b[3], const double t) +{ + const double s = 1.0f - t; + + target[0] = s * a[0] + t * b[0]; + target[1] = s * a[1] + t * b[1]; + target[2] = s * a[2] + t * b[2]; +} + +void interp_v2_v2v2_db(double target[2], const double a[2], const double b[2], const double t) +{ + const double s = 1.0f - t; + + target[0] = s * a[0] + t * b[0]; + target[1] = s * a[1] + t * b[1]; +} + /** \} */ diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 865c2f5dc25..8cb618ae14e 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -374,6 +374,13 @@ MINLINE void add_v3_v3(float r[3], const float a[3]) r[2] += a[2]; } +MINLINE void add_v3_v3_db(double r[3], const double a[3]) +{ + r[0] += a[0]; + r[1] += a[1]; + r[2] += a[2]; +} + MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]) { r[0] = a[0] + b[0]; @@ -450,6 +457,13 @@ MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3]) r[2] = a[2] - b[2]; } +MINLINE void sub_v3_v3v3_db(double r[3], const double a[3], const double b[3]) +{ + r[0] = a[0] - b[0]; + r[1] = a[1] - b[1]; + r[2] = a[2] - b[2]; +} + MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3]) { r[0] = (double)a[0] - (double)b[0]; @@ -492,6 +506,13 @@ MINLINE void mul_v3_fl(float r[3], float f) r[2] *= f; } +MINLINE void mul_v3db_db(double r[3], double f) +{ + r[0] *= f; + r[1] *= f; + r[2] *= f; +} + MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f) { r[0] = a[0] * f; @@ -836,6 +857,11 @@ MINLINE double dot_v3db_v3fl(const double a[3], const float b[3]) return a[0] * (double)b[0] + a[1] * (double)b[1] + a[2] * (double)b[2]; } +MINLINE double dot_v3v3_db(const double a[3], const double b[3]) +{ + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + MINLINE float cross_v2v2(const float a[2], const float b[2]) { return a[0] * b[1] - a[1] * b[0]; @@ -859,6 +885,14 @@ MINLINE void cross_v3_v3v3_hi_prec(float r[3], const float a[3], const float b[3 r[2] = (float)((double)a[0] * (double)b[1] - (double)a[1] * (double)b[0]); } +MINLINE void cross_v3_v3v3_db(double r[3], const double a[3], const double b[3]) +{ + BLI_assert(r != a && r != b); + r[0] = a[1] * b[2] - a[2] * b[1]; + r[1] = a[2] * b[0] - a[0] * b[2]; + r[2] = a[0] * b[1] - a[1] * b[0]; +} + /* Newell's Method */ /* excuse this fairly specific function, * its used for polygon normals all over the place diff --git a/source/tools b/source/tools -Subproject aa9cc18913aca559e932d5b7894e3c222ccffae +Subproject 2afbb8ec472cac5102eb239f57b006f8c938768 |