diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-09 19:39:24 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-09 19:39:24 +0400 |
commit | 2433404e4b90581fe65c8259e58baeee14259638 (patch) | |
tree | ae18da5ef1eebbe12869bf72b8575f570295daa1 /source | |
parent | 85f15bb0ed1ee74a86c7877877fc99579bd5605c (diff) |
add inline function mul_project_m4_v3_zfac() to get the z-depth value from a vector & mat4x4
Diffstat (limited to 'source')
6 files changed, 14 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 42a6b90f738..5476978513e 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -108,6 +108,7 @@ MINLINE void mul_v3_v3(float r[3], const float a[3]); MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void mul_v4_fl(float r[4], float f); MINLINE void mul_v4_v4fl(float r[3], const float a[3], float f); +MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]); MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f); MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 69ece9b9ed0..f116c9b8443 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -367,9 +367,7 @@ void mul_mat3_m4_v3(float mat[4][4], float vec[3]) void mul_project_m4_v3(float mat[4][4], float vec[3]) { - const float w = (mat[0][3] * vec[0]) + - (mat[1][3] * vec[1]) + - (mat[2][3] * vec[2]) + mat[3][3]; + const float w = mul_project_m4_v3_zfac(mat, vec); mul_m4_v3(mat, vec); vec[0] /= w; diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 48e7de43a86..c8e8ff9602b 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -398,6 +398,15 @@ MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f) r[3] = a[3] * f; } +/* note: could add a matrix inline */ +MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) +{ + return (mat[0][3] * co[0]) + + (mat[1][3] * co[1]) + + (mat[2][3] * co[2]) + mat[3][3]; +} + + MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f) { r[0] += a[0] * f; diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 27d0010e75b..a74db71175f 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -276,9 +276,7 @@ eV3DProjStatus ED_view3d_project_float_object(ARegion *ar, const float co[3], fl */ float ED_view3d_calc_zfac(RegionView3D *rv3d, const float co[3], bool *r_flip) { - float zfac = (rv3d->persmat[0][3] * co[0]) + - (rv3d->persmat[1][3] * co[1]) + - (rv3d->persmat[2][3] * co[2]) + rv3d->persmat[3][3]; + float zfac = mul_project_m4_v3_zfac(rv3d->persmat, co); if (r_flip) { *r_flip = (zfac < 0.0f); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 5d2a351b233..d5fce1ba313 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1560,11 +1560,7 @@ static void UNUSED_FUNCTION(view3d_align_axis_to_vector)(View3D *v3d, RegionView float ED_view3d_pixel_size(RegionView3D *rv3d, const float co[3]) { - return (rv3d->persmat[3][3] + ( - rv3d->persmat[0][3] * co[0] + - rv3d->persmat[1][3] * co[1] + - rv3d->persmat[2][3] * co[2]) - ) * rv3d->pixsize * U.pixelsize; + return mul_project_m4_v3_zfac(rv3d->persmat, co) * rv3d->pixsize * U.pixelsize; } float ED_view3d_radius_to_persp_dist(const float angle, const float radius) diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 35287c145c6..3088b96c339 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -892,9 +892,7 @@ static void setNearestAxis3d(TransInfo *t) * of two 2D points 30 pixels apart (that's the last factor in the formula) after * projecting them with ED_view3d_win_to_delta and then get the length of that vector. */ - zfac = (t->persmat[0][3] * t->center[0]) + - (t->persmat[1][3] * t->center[1]) + - (t->persmat[2][3] * t->center[2]) + t->persmat[3][3]; + zfac = mul_project_m4_v3_zfac(t->persmat, t->center); zfac = len_v3(t->persinv[0]) * 2.0f / t->ar->winx * zfac * 30.0f; for (i = 0; i < 3; i++) { |