But some posts before you were talking about code from MacOSX, you found something interesting?

The raytracer code that I ported from Mac OS (x-code) is what I'm working with now. It renders spheres ( built-in) scenes using ray_sphereIntersection. But in order to render a polygon mesh of vertices and triangles that it loads from txt file it uses ray_triangleIntersection. Somewhere in that function there is an error. It renders spheres but it won't render triangle meshes.

Rendering spheres and triangles is the core of the raytracer so it needs to work correctly.

salvo,

I have to fully understand the Moller-Trumbore Algorithm before I can re-write the core of the raytracer. Lots of Vector Math. Here is the algorithm:

bool rayTriangleIntersect(

const Vec3f &orig, const Vec3f &dir,

const Vec3f &v0, const Vec3f &v1, const Vec3f &v2,

float &t, float &u, float &v)

{

#ifdef MOLLER_TRUMBORE

Vec3f v0v1 = v1 - v0;

Vec3f v0v2 = v2 - v0;

Vec3f pvec = dir.crossProduct(v0v2);

float det = v0v1.dotProduct(pvec);

#ifdef CULLING

// if the determinant is negative the triangle is backfacing

// if the determinant is close to 0, the ray misses the triangle

if (det < kEpsilon) return false;

#else

// ray and triangle are parallel if det is close to 0

if (fabs(det) < kEpsilon) return false;

#endif

float invDet = 1 / det;

Vec3f tvec = orig - v0;

u = tvec.dotProduct(pvec) * invDet;

if (u < 0 || u > 1) return false;

Vec3f qvec = tvec.crossProduct(v0v1);

v = dir.dotProduct(qvec) * invDet;

if (v < 0 || u + v > 1) return false;

t = v0v2.dotProduct(qvec) * invDet;

return true;

#else

...

#endif

}