diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 4af56c66dde..afce5a602ed 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -486,7 +486,6 @@ int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], c return 1; } - /* moved from effect.c test if the ray starting at p1 going in d direction intersects the triangle v0..v2 return non zero if it does @@ -527,6 +526,35 @@ int isect_ray_tri_v3(const float p1[3], const float d[3], const float v0[3], con return 1; } +int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, int clip) +{ + float p[3], s[3], e1[3], e2[3], q[3]; + float a, f, u, v; + + 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 > -0.00000001f) && (a < 0.00000001f)) return 0; + f = 1.0f/a; + + sub_v3_v3v3(s, p1, v0); + + u = f * dot_v3v3(s, p); + + cross_v3_v3v3(q, s, e1); + + v = f * dot_v3v3(d, q); + + *lambda = f * dot_v3v3(e2, q); + if (clip && (*lambda < 0.0f)) return 0; + + return 1; +} + int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2], const float epsilon) { float p[3], s[3], e1[3], e2[3], q[3]; |