Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2020-06-18 06:00:43 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2020-06-18 06:01:05 +0300
commitd8206602feed27088b0b07bfb567f67754ad0359 (patch)
tree5b70a8979148b8401d9b8ed15e654a1b922773c3 /source/blender/blenlib/intern/math_geom.c
parent18ccf328ac5611221e073aebaddde1b0b2169984 (diff)
Transform: Snap to the intersection between constraint and geometry
This commit changes the behavior of 4 snapping combinations: **1. While constraining to a plane, snap to an edge element:** The snap is made at the intersection between the edge direction and the constraint plane. **2. While constraining to a plane, snap to a face element:** The snap is made to the nearest point between the snap point and the line that intersects the face plane with the constraint plane. **3. While constraining to an axis, snap to an edge/line element:** The snap is made to the nearest point on the axis to the edge/line. **4. While constraining to an axis, snap to a face element:** The snap is made at the intersection of the axis and the plane defined by the face. To avoid unpredictable jumps outside view boundaries, an alignment check is made for each of these snapping combinations. Resolve/fix T66422 Differential Revision: https://developer.blender.org/D5608
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r--source/blender/blenlib/intern/math_geom.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index e7c1fc8c2d9..d3dc4729617 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -3248,19 +3248,27 @@ bool isect_ray_aabb_v3_simple(const float orig[3],
}
}
-/* find closest point to p on line through (l1, l2) and return lambda,
- * where (0 <= lambda <= 1) when cp is in the line segment (l1, l2)
+float closest_to_ray_v3(float r_close[3],
+ const float p[3],
+ const float ray_orig[3],
+ const float ray_dir[3])
+{
+ float h[3], lambda;
+ sub_v3_v3v3(h, p, ray_orig);
+ lambda = dot_v3v3(ray_dir, h) / dot_v3v3(ray_dir, ray_dir);
+ madd_v3_v3v3fl(r_close, ray_orig, ray_dir, lambda);
+ return lambda;
+}
+
+/**
+ * Find closest point to p on line through (l1, l2) and return lambda,
+ * where (0 <= lambda <= 1) when cp is in the line segment (l1, l2).
*/
float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
{
- float h[3], u[3], lambda;
+ float u[3];
sub_v3_v3v3(u, l2, l1);
- sub_v3_v3v3(h, p, l1);
- lambda = dot_v3v3(u, h) / dot_v3v3(u, u);
- r_close[0] = l1[0] + u[0] * lambda;
- r_close[1] = l1[1] + u[1] * lambda;
- r_close[2] = l1[2] + u[2] * lambda;
- return lambda;
+ return closest_to_ray_v3(r_close, p, l1, u);
}
float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])