/// [groupSyntax] bool Triangle::Intersects(const LineSegment &l, float *d, float3 *intersectionPoint) const { /** The Triangle-Line/LineSegment/Ray intersection tests are based on Möller-Trumbore method: "T. Möller, B. Trumbore. Fast, Minimum Storage Ray/Triangle Intersection. 2005." http://jgt.akpeters.com/papers/MollerTrumbore97/. */ float u, v; float t = IntersectLineTri(l.a, l.Dir(), a, b, c, u, v); bool success = (t >= 0 && t != FLOAT_INF); if (!success) return false; float length = l.LengthSq(); if (t < 0.f || t*t >= length) return false; length = Sqrt(length); if (d) { float len = t / length; *d = len; if (intersectionPoint) *intersectionPoint = l.GetPoint(len); } else if (intersectionPoint) *intersectionPoint = l.GetPoint(t / length); return true; }
bool AABB::Intersects(const LineSegment &lineSegment, float *dNear, float *dFar) const { float tNear, tFar; bool success = IntersectLineAABB(lineSegment.a, lineSegment.Dir(), *this, tNear, tFar); success = (tNear >= 0.f && tNear*tNear <= lineSegment.LengthSq()); if (dNear) *dNear = tNear / lineSegment.Length(); if (dFar) *dFar = tFar / lineSegment.Length(); return success; }