2
\$\begingroup\$

I have a line (the direction vector of the player) and a triangle representing the face of a model (so composed of 3 points).

I can't find the mathematical operation to check if that vector is intersecting with this triangle, and how far from the player...

\$\endgroup\$
  • \$\begingroup\$ Have you Googled "ray triangle intersection"? Ray will likely get more hits than vector, and there are lots of articles and sample code out there. \$\endgroup\$ – Will Jan 21 '14 at 14:37
  • \$\begingroup\$ realtimerendering.com/intersections.html has a bunch of intersection tests. \$\endgroup\$ – Exilyth Jan 27 '14 at 9:13
3
\$\begingroup\$

In general, lines are a poor approximation of a user's movement because they don't account for the size of the player.

You want "sweep sphere triangle intersection", also called "capsule triangle intersection". http://xania.org/Games has a good overview of this.

\$\endgroup\$
  • 1
    \$\begingroup\$ "lines are a poor approximation of a user's movement" -- unless the player is well-approximated by a point. (While this is helpful, it doesn't answer the question.) \$\endgroup\$ – Anko Jan 21 '14 at 15:06
  • \$\begingroup\$ @Anko kind of true, but on the other hand, cameras are not well approximated by a point if you want to avoid front plane clipping glitches; if you're doing true 3D movement in a 3D world, you end up having to do approximate something bigger than a point eventually. \$\endgroup\$ – Will Jan 21 '14 at 19:02
  • 1
    \$\begingroup\$ Good point -- I was neglecting the third dimension. \$\endgroup\$ – Anko Jan 23 '14 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.