[Bf-blender-cvs] [470407ec3ba] master: 3D View: point-on-plane from screen location utility

Campbell Barton noreply at git.blender.org
Thu Sep 20 03:13:19 CEST 2018


Commit: 470407ec3bac11ae5a5c6174a6e9630caa1a42f7
Author: Campbell Barton
Date:   Thu Sep 20 11:21:34 2018 +1000
Branches: master
https://developer.blender.org/rB470407ec3bac11ae5a5c6174a6e9630caa1a42f7

3D View: point-on-plane from screen location utility

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

M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_project.c

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

diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 82411ba7401..781fd8eaac0 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -236,6 +236,14 @@ void ED_view3d_win_to_3d_int(
         const struct View3D *v3d, const struct ARegion *ar,
         const float depth_pt[3], const int mval[2],
         float r_out[3]);
+bool ED_view3d_win_to_3d_on_plane(
+        const struct ARegion *ar,
+        const float plane[4], const float mval[2],
+        float r_out[3]);
+bool ED_view3d_win_to_3d_on_plane_int(
+        const struct ARegion *ar,
+        const float plane[4], const int mval[2],
+        float r_out[3]);
 void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac);
 void ED_view3d_win_to_origin(const struct ARegion *ar, const float mval[2], float out[3]);
 void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 767df04c0b0..d5b6c60563f 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -537,6 +537,31 @@ void ED_view3d_win_to_3d_int(
 	ED_view3d_win_to_3d(v3d, ar, depth_pt, mval_fl, r_out);
 }
 
+bool ED_view3d_win_to_3d_on_plane(
+        const ARegion *ar,
+        const float plane[4], const float mval[2],
+        float r_out[3])
+{
+	float ray_co[3], ray_no[3];
+	ED_view3d_win_to_origin(ar, mval, ray_co);
+	ED_view3d_win_to_vector(ar, mval, ray_no);
+	float lambda;
+	if (isect_ray_plane_v3(ray_co, ray_no, plane, &lambda, false)) {
+		madd_v3_v3v3fl(r_out, ray_co, ray_no, lambda);
+		return true;
+	}
+	return false;
+}
+
+bool ED_view3d_win_to_3d_on_plane_int(
+        const ARegion *ar,
+        const float plane[4], const int mval[2],
+        float r_out[3])
+{
+	const float mval_fl[2] = {mval[0], mval[1]};
+	return ED_view3d_win_to_3d_on_plane(ar, plane, mval_fl, r_out);
+}
+
 /**
  * Calculate a 3d difference vector from 2d window offset.
  * note that ED_view3d_calc_zfac() must be called first to determine



More information about the Bf-blender-cvs mailing list