Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

What is your favourite ray-triangle intersection C++ code?

$
0
0

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 …

Viewing all articles
Browse latest Browse all 17560

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>