[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59383] trunk/blender/source/blender: add utility functions for dealing with planes

Campbell Barton ideasman42 at gmail.com
Thu Aug 22 17:30:25 CEST 2013


Revision: 59383
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59383
Author:   campbellbarton
Date:     2013-08-22 15:30:24 +0000 (Thu, 22 Aug 2013)
Log Message:
-----------
add utility functions for dealing with planes
- plane_point_side_v3(), a bit like line_point_side_v2()
- isect_point_planes_v3(), moved from paint_hide.c

functions to convert between point/normal pairs.
- plane_from_point_normal_v3()
- plane_to_point_normal_v3()

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenlib/intern/math_geom_inline.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_hide.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-22 13:51:00 UTC (rev 59382)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-22 15:30:24 UTC (rev 59383)
@@ -61,6 +61,14 @@
 float area_poly_v3(int nr, float verts[][3], const float normal[3]);
 float area_poly_v2(int nr, float verts[][2]);
 
+/********************************* Planes **********************************/
+
+void  plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3]);
+void  plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]);
+MINLINE float plane_point_side_v3(const float plane[4], const float co[3]);
+
+/********************************* Volume **********************************/
+
 float volume_tetrahedron_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
 
 int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
@@ -120,6 +128,7 @@
                         const float v0[3], const float v1[3], const float v2[3],
                         float *r_lambda, const int clip);
 
+bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3]);
 bool isect_line_plane_v3(float out[3], const float l1[3], const float l2[3],
                          const float plane_co[3], const float plane_no[3], const bool no_flip);
 

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-22 13:51:00 UTC (rev 59382)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-22 15:30:24 UTC (rev 59383)
@@ -183,6 +183,28 @@
 	return fabsf(0.5f * area);
 }
 
+/********************************* Planes **********************************/
+
+/**
+ * Calculate a plane from a point and a direction,
+ * \note \a point_no isn't required to be normalized.
+ */
+void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
+{
+	copy_v3_v3(r_plane, plane_no);
+	r_plane[3] = -dot_v3v3(r_plane, plane_co);
+}
+
+/**
+ * Get a point and a normal from a plane.
+ */
+void plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3])
+{
+	const float length = normalize_v3_v3(r_plane_no, plane);
+	madd_v3_v3v3fl(r_plane_co, r_plane_no, r_plane_no, (-plane[3] / length) - 1.0f);
+}
+
+
 /********************************* Volume **********************************/
 
 /**
@@ -1043,6 +1065,22 @@
 }
 
 /**
+ * Check if a point is behind all planes.
+ */
+bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3])
+{
+	int i;
+
+	for (i = 0; i < totplane; i++) {
+		if (plane_point_side_v3(planes[i], p) > 0.0f) {
+			return false;
+		}
+	}
+
+	return true;
+}
+
+/**
  * Intersect line/plane, optionally treat line as directional (like a ray) with the no_flip argument.
  *
  * \param out The intersection point.
@@ -1757,7 +1795,7 @@
 	if (div == 0.0f) /* parallel */
 		return 1;
 
-	t = -(dot_v3v3(p1, plane) + plane[3]) / div;
+	t = -plane_point_side_v3(plane, p1) / div;
 
 	if (div > 0.0f) {
 		/* behind plane, completely clipped */
@@ -1811,7 +1849,7 @@
 		const float div = dot_v3v3(dp, plane);
 
 		if (div != 0.0f) {
-			const float t = -(dot_v3v3(p1, plane) + plane[3]) / div;
+			const float t = -plane_point_side_v3(plane, p1) / div;
 			if (div > 0.0f) {
 				/* clip a */
 				if (t >= 1.0f) {
@@ -3616,4 +3654,3 @@
 	/* linetests, the 2 diagonals have to instersect to be convex */
 	return (isect_line_line_v2(v1, v3, v2, v4) > 0);
 }
-

Modified: trunk/blender/source/blender/blenlib/intern/math_geom_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom_inline.c	2013-08-22 13:51:00 UTC (rev 59382)
+++ trunk/blender/source/blender/blenlib/intern/math_geom_inline.c	2013-08-22 15:30:24 UTC (rev 59383)
@@ -185,4 +185,9 @@
 	}
 }
 
+MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
+{
+	return dot_v3v3(co, plane) + plane[3];
+}
+
 #endif /* __MATH_GEOM_INLINE_C__ */

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_hide.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_hide.c	2013-08-22 13:51:00 UTC (rev 59382)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_hide.c	2013-08-22 15:30:24 UTC (rev 59383)
@@ -71,18 +71,6 @@
 
 #include <assert.h>
 
-static int planes_contain_v3(float (*planes)[4], int totplane, const float p[3])
-{
-	int i;
-
-	for (i = 0; i < totplane; i++) {
-		if (dot_v3v3(planes[i], p) + planes[i][3] > 0)
-			return 0;
-	}
-
-	return 1;
-}
-
 /* return true if the element should be hidden/shown */
 static int is_effected(PartialVisArea area,
                        float planes[4][4],
@@ -95,7 +83,7 @@
 		return mask > 0.5f;
 	}
 	else {
-		int inside = planes_contain_v3(planes, 4, co);
+		bool inside = isect_point_planes_v3(planes, 4, co);
 		return ((inside && area == PARTIALVIS_INSIDE) ||
 		        (!inside && area == PARTIALVIS_OUTSIDE));
 	}

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-08-22 13:51:00 UTC (rev 59382)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-08-22 15:30:24 UTC (rev 59383)
@@ -220,10 +220,10 @@
 
 static bool view3d_clipping_test(const float co[3], float clip[6][4])
 {
-	if (0.0f < clip[0][3] + dot_v3v3(co, clip[0]))
-		if (0.0f < clip[1][3] + dot_v3v3(co, clip[1]))
-			if (0.0f < clip[2][3] + dot_v3v3(co, clip[2]))
-				if (0.0f < clip[3][3] + dot_v3v3(co, clip[3]))
+	if (plane_point_side_v3(clip[0], co) > 0.0f)
+		if (plane_point_side_v3(clip[1], co) > 0.0f)
+			if (plane_point_side_v3(clip[2], co) > 0.0f)
+				if (plane_point_side_v3(clip[3], co) > 0.0f)
 					return false;
 
 	return true;




More information about the Bf-blender-cvs mailing list