[Bf-blender-cvs] [99142ec] master: BLI_math: isect_ray_plane_v3 now takes 4d plane

Campbell Barton noreply at git.blender.org
Thu Oct 15 18:12:06 CEST 2015


Commit: 99142ec7e0975203a60215d24db2d565dc10cc07
Author: Campbell Barton
Date:   Fri Oct 16 02:59:30 2015 +1100
Branches: master
https://developer.blender.org/rB99142ec7e0975203a60215d24db2d565dc10cc07

BLI_math: isect_ray_plane_v3 now takes 4d plane

Was taking a triangle and doing ray-tri intersect.

===================================================================

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index b3526b6..dfc5189 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -176,7 +176,7 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
 
 bool isect_ray_plane_v3(
         const float p1[3], const float d[3],
-        const float v0[3], const float v1[3], const float v2[3],
+        const float plane[4],
         float *r_lambda, const bool clip);
 
 bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3]);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 164009a..e5fb553 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1256,38 +1256,27 @@ bool isect_ray_tri_v3(
 /**
  * if clip is nonzero, will only return true if lambda is >= 0.0
  * (i.e. intersection point is along positive d)
+ *
+ * \note #line_plane_factor_v3() shares logic.
  */
 bool isect_ray_plane_v3(
         const float p1[3], const float d[3],
-        const float v0[3], const float v1[3], const float v2[3],
+        const float plane[4],
         float *r_lambda, const bool clip)
 {
-	const float epsilon = 0.00000001f;
-	float p[3], s[3], e1[3], e2[3], q[3];
-	float a, f;
-	/* float  u, v; */ /*UNUSED*/
-
-	sub_v3_v3v3(e1, v1, v0);
-	sub_v3_v3v3(e2, v2, v0);
-
-	cross_v3_v3v3(p, d, e2);
-	a = dot_v3v3(e1, p);
-	/* note: these values were 0.000001 in 2.4x but for projection snapping on
-	 * a human head (1BU == 1m), subsurf level 2, this gave many errors - campbell */
-	if ((a > -epsilon) && (a < epsilon)) return false;
-	f = 1.0f / a;
-
-	sub_v3_v3v3(s, p1, v0);
-
-	/* u = f * dot_v3v3(s, p); */ /*UNUSED*/
-
-	cross_v3_v3v3(q, s, e1);
-
-	/* v = f * dot_v3v3(d, q); */ /*UNUSED*/
-
-	*r_lambda = f * dot_v3v3(e2, q);
-	if (clip && (*r_lambda < 0.0f)) return false;
+	float h[3], plane_co[3];
+	float dot;
 
+	dot = dot_v3v3(plane, d);
+	if (dot == 0.0f) {
+		return false;
+	}
+	mul_v3_v3fl(plane_co, plane, (-plane[3] / len_squared_v3(plane)));
+	sub_v3_v3v3(h, p1, plane_co);
+	*r_lambda = -dot_v3v3(plane, h) / dot;
+	if (clip && (*r_lambda < 0.0f)) {
+		return false;
+	}
 	return true;
 }




More information about the Bf-blender-cvs mailing list