BLI_math: isect_ray_plane_v3 now takes 4d plane

Was taking a triangle and doing ray-tri intersect.
This commit is contained in:
Campbell Barton 2015-10-16 02:59:30 +11:00
parent 2746bbe30e
commit 99142ec7e0
2 changed files with 16 additions and 27 deletions

View File

@ -176,7 +176,7 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
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);
bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3]);

View File

@ -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;
}