Jump to content
  • Advertisement

Archived

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

AyaKoshigaya

Line and Triangle Intersection

This topic is 5553 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

Hi, does anyone know how I can find out if a Line interects a Triangle??? I''ve found the code on Gametutorials.com, and it worked very well, but it''s very very slow... so, does anyone know how I can test if a Triangle and Line intersection can be, before I use the slow method to find it out exactly??? I''ve thougt on something like using BoundingBoxes or something.. any idea? Au''revoir, Aya~

Share this post


Link to post
Share on other sites
Advertisement

bool NPhysics::LineFaceIntersectionTest(const NMath::Vector3f &_rLineStartPoint,const NMath::Vector3f &_rLineEndPoint,const NMath::Vector3f _aVertices[],const NMath::Vector3f &_rNormal)
{
float OriginDistance = -NMath::DotProduct(_aVertices[0],_rNormal);

if ((NMath::DotProduct(_rNormal,_rLineStartPoint) + OriginDistance) * (NMath::DotProduct(_rNormal,_rLineEndPoint) + OriginDistance) >= 0)
return false;

NMath::Vector3f Point;
NMath::Vector3f LineDirection = _rLineEndPoint - _rLineStartPoint;

LineDirection.Normalize();

float Numerator = -NMath::DotProduct(_rNormal,_rLineStartPoint) - OriginDistance;
float Denominator = NMath::DotProduct(_rNormal,LineDirection);

Denominator == 0.0f ? Point = _rLineStartPoint : Point = _rLineStartPoint + LineDirection * (Numerator / Denominator);

if (!PointInsideTriangle(Point,_aVertices))
return false;

return true;
}


Heh, thats mine.. based on the one found at gametutorials.com =(

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!