diff options
Diffstat (limited to 'src/intersect.h')
-rw-r--r-- | src/intersect.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/intersect.h b/src/intersect.h index 0b713c8..b1713d7 100644 --- a/src/intersect.h +++ b/src/intersect.h @@ -9,6 +9,8 @@ #include "matrix.h" #include "rotate.h" +#define EPSILON 1.0e-3f + /* Test the intersection between a ray starting from `origin` traveling in the direction `direction` and a triangle defined by the vertices `v0`, `v1`, and `v2`. If the ray intersects the triangle, set `distance` to the distance @@ -30,21 +32,21 @@ __device__ bool intersect_triangle(const float3 &origin, const float3 &direction (m.a02*m.a21 - m.a01*m.a22)*b.y + (m.a01*m.a12 - m.a02*m.a11)*b.z)/determinant; - if (u1 < 0.0f || u1 > 1.0f) + if (u1 < -EPSILON || u1 > 1.0f) return false; float u2 = ((m.a12*m.a20 - m.a10*m.a22)*b.x + (m.a00*m.a22 - m.a02*m.a20)*b.y + (m.a02*m.a10 - m.a00*m.a12)*b.z)/determinant; - if (u2 < 0.0f || u2 > 1.0f) + if (u2 < -EPSILON || u2 > 1.0f) return false; float u3 = ((m.a10*m.a21 - m.a11*m.a20)*b.x + (m.a01*m.a20 - m.a00*m.a21)*b.y + (m.a00*m.a11 - m.a01*m.a10)*b.z)/determinant; - if (u3 <= 0.0f || (1.0f-u1-u2) < 0.0f) + if (u3 <= 0.0f || (1.0f-u1-u2) < -EPSILON) return false; distance = u3; |