8 public static class pb_Geometry
15 public static bool RayIntersectsTriangle(
21 out
float OutDistance,
29 float det, inv_det, u, v;
33 e1 = InTriangleB - InTriangleA;
34 e2 = InTriangleC - InTriangleA;
37 P =
Vector3.Cross(InRay.direction, e2);
43 if( (cull ==
Culling.Front && det < Mathf.Epsilon) || (det > -Mathf.Epsilon && det < Mathf.Epsilon) )
49 T = InRay.origin - InTriangleA;
52 u =
Vector3.Dot(T, P) * inv_det;
62 v =
Vector3.Dot(InRay.direction, Q) * inv_det;
65 if(v < 0f || u + v > 1f)
68 t =
Vector3.Dot(e2, Q) * inv_det;
75 OutPoint.x = (u * InTriangleB.x + v * InTriangleC.x + (1-(u+v)) * InTriangleA.x);
76 OutPoint.y = (u * InTriangleB.y + v * InTriangleC.y + (1-(u+v)) * InTriangleA.y);
77 OutPoint.z = (u * InTriangleB.z + v * InTriangleC.z + (1-(u+v)) * InTriangleA.z);