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:
authorCampbell Barton <ideasman42@gmail.com>2016-04-14 04:45:37 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-04-14 05:00:16 +0300
commit416064cd5b6d3df577e71e301599fba36264f19b (patch)
tree38ee7e3b6dd5da0d3d283fc986d3bb58f68c43b1 /source/blender/blenlib/intern/math_geom.c
parentbbcb9c68c938980b780e92f8dcc68d5fc5359e10 (diff)
Math Lib: ray_point_factor_v3 functions
Gives a bit better precision than creating a line in some cases, use for ED_view3d_win_to_3d.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r--source/blender/blenlib/intern/math_geom.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 482709e572f..49b52690a5b 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2506,6 +2506,22 @@ float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2],
return lambda;
}
+float ray_point_factor_v3_ex(
+ const float p[3], const float ray_origin[3], const float ray_direction[3],
+ const float epsilon, const float fallback)
+{
+ float p_relative[3];
+ sub_v3_v3v3(p_relative, p, ray_origin);
+ const float dot = dot_v3v3(ray_direction, ray_direction);
+ return (fabsf(dot) > epsilon) ? (dot_v3v3(ray_direction, p_relative) / dot) : fallback;
+}
+
+float ray_point_factor_v3(
+ const float p[3], const float ray_origin[3], const float ray_direction[3])
+{
+ return ray_point_factor_v3_ex(p, ray_origin, ray_direction, 0.0f, 0.0f);
+}
+
/**
* A simplified version of #closest_to_line_v3
* we only need to return the ``lambda``