Do you have a favourite ray-triangle intersection C++ code?
For instance, my favourite is listed below. The one problem is that it doesn't report the location of the intersection. Any ideas on going about calculating the location?
// https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection
bool rayTriangleIntersect(const vertex_3 orig, const vertex_3 dir, const vertex_3 v0, const vertex_3 v1, const vertex_3 v2)
{
vertex_3 v0v1 = v1 - v0;
vertex_3 v0v2 = v2 - v0;
vertex_3 pvec = dir.cross(v0v2);
float det = v0v1.dot(pvec);
if (det < 0.000001)
return false;
float invDet = 1.0 / det;
vertex_3 tvec = orig - v0;
float u = tvec.dot(pvec) * invDet;
if (u < 0 || u > 1)
return false;
vertex_3 qvec = tvec.cross(v0v1);
float v = dir.dot(qvec) * invDet;
if (v < 0 || u + v > 1)
return false;
float t = v0v2.dot(qvec) * invDet;
return true;
}