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>2015-10-15 18:59:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-15 19:06:12 +0300
commit99142ec7e0975203a60215d24db2d565dc10cc07 (patch)
treed9f3772d02a41c370afb831c650ed31c5648c65f /source/blender/blenlib/intern/math_geom.c
parent2746bbe30ece2636e1231930cdaac9d897ebe717 (diff)
BLI_math: isect_ray_plane_v3 now takes 4d plane
Was taking a triangle and doing ray-tri intersect.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r--source/blender/blenlib/intern/math_geom.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 164009ab882..e5fb5533728 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;
}