Sign in to follow this  
john13to

Perform intersection between a ray and a triangle

Recommended Posts

john13to    151
Here is another problem that has showed up in short time. I am trying to find where a rline is intersecting a triangle side that is a part of the 3D prism in XNA that I have mentioned about in previous threads. I am using this algorithm which I found in a blog, since the previous intersecting algorithm I used before might not worked correctly:

http://dzindzinovic.blogspot.com/2010/05/xna-ray-intersect-triangle.html

This is how I use the RayIntersectTriangle-function during the update call:

curr3DPos += 0.005f * line3DDir;
pointPreList.SetValue(new VertexPositionColor(line3DStartPos + curr3DPos, Color.Brown), 0);
pointPreList.SetValue(new VertexPositionColor(line3DEndPos + curr3DPos, Color.Brown), 1);


if (RayIntersectTriangle(line3DEndPos + curr3DPos, line3DDir, prismData[0].Position,
prismData[1].Position, prismData[2].Position, ref pickDistance,
ref barycentricU, ref barycentricV))
{
Console.WriteLine("Intersected");
}

where line3DEndPos + curr3DPos is the current end position of the line, line3DDir is the ray direction and prismData[0,1,2].Position are the positions of the triangle sides vertices. The problem is that it won´t detect the intersection when the end of the line is hitting the triangle.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this