Archived

This topic is now archived and is closed to further replies.

Muller-Trumbore algorithm problem

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry for the double post, just realised this was more appropriate in this forum: I'm having trouble with the Moller-Trumbore ray/triangle alogirithm. It's not giving me correct results, so I thought I'd try it out in a simple demo with a single triangle, ( (-1, -1, 2 ), (1, -1, 2), (0, 1, 2) ) and a ray fired from the origin (0, 0, 0), up the z-axis (0, 0, 1). Well the results I'm getting tell me that the ray is parallel to the plane of the triangle (i.e. the determinant is 0). Can someone please tell me what the stupid mistake I'm making is!

// hat ^ is dot product

// star * is cross product


// triangle vertices

V3f v0( -1, -1, 2 );
V3f v1( 1, -1, 2 );
V3f v2( 0, 1, 2 );

V3f O( 0, 0, 0 ); // ray origin

V3f D( 0, 0, 1 ); // ray direction


V3f e1 = v1 - v0;
V3f e2 = v2 - v0;

V3f P = D * e2;

float det = e1 ^ P;

float t, u, v;

if ( det < 0.0000001 && det > -0.0000001 )
{
cout << "Ray is in plane of polygon" << endl;
return -1;
}

float invdet = 1/det;

V3f T = ( O - v0 );

u = (T^P) * invdet;
if ( u < 0.0 || u > 1.0 )
{
cout << "u is outof bounds" << endl;
return -2;
}


V3f Q = T*e1;
v = (D^Q) * invdet;
if ( v < 0.0 || u + v > 1.0 )
{
cout << "v is out of bounds." << endl;
return -3;
}


t = (e2^Q) * invdet;

cout << "Ray intersects triangle at t = " << t << endl;
[edited by - playmesumch00ns on March 26, 2004 6:39:29 AM]

Share this post


Link to post
Share on other sites