I was poking around looking for an algorithm for finding closest point on a triangle.
Found this one on these forums:
http://www.gamedev.net/community/forums/topic.asp?topic_id=516608
I kind of recognized it so I tried it out and it doesn't work. :(
This paper describes the correct way to solve what the algorithm above tries to do:
http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf
However it's heavy on math and does not give the complete source code.
Here is the complete source code:
!--source>!--startscript-->
vector3 closesPointOnTriangle( const vector3 *triangle, const vector3 &sourcePosition ) { vector3 edge0 = triangle[1 …