[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55139] trunk/blender/source/blender: add inline function mul_project_m4_v3_zfac() to get the z-depth value from a vector & mat4x4

Campbell Barton ideasman42 at gmail.com
Sat Mar 9 16:39:24 CET 2013


Revision: 55139
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55139
Author:   campbellbarton
Date:     2013-03-09 15:39:24 +0000 (Sat, 09 Mar 2013)
Log Message:
-----------
add inline function mul_project_m4_v3_zfac() to get the z-depth value from a vector & mat4x4

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_matrix.c
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/editors/space_view3d/view3d_project.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c
    trunk/blender/source/blender/editors/transform/transform_constraints.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-03-09 15:39:24 UTC (rev 55139)
@@ -108,6 +108,7 @@
 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]);

Modified: trunk/blender/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_matrix.c	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/blenlib/intern/math_matrix.c	2013-03-09 15:39:24 UTC (rev 55139)
@@ -367,9 +367,7 @@
 
 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;

Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2013-03-09 15:39:24 UTC (rev 55139)
@@ -398,6 +398,15 @@
 	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;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_project.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_project.c	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_project.c	2013-03-09 15:39:24 UTC (rev 55139)
@@ -276,9 +276,7 @@
  */
 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);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2013-03-09 15:39:24 UTC (rev 55139)
@@ -1560,11 +1560,7 @@
 
 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)

Modified: trunk/blender/source/blender/editors/transform/transform_constraints.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_constraints.c	2013-03-09 14:57:06 UTC (rev 55138)
+++ trunk/blender/source/blender/editors/transform/transform_constraints.c	2013-03-09 15:39:24 UTC (rev 55139)
@@ -892,9 +892,7 @@
 	 * 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++) {




More information about the Bf-blender-cvs mailing list