1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [MATH_BEGIN_NAMESPACE]19 20 float TriangleMesh::IntersectRay_CPP(const [Ray] &ray) const21 float TriangleMesh::IntersectRay_TriangleIndex_CPP(const [Ray] &ray, int &outIndex) const22 float [TriangleMesh::IntersectRay_TriangleIndex_UV_CPP](const [Ray] &ray, int &outIndex, float &outU, float &outV) const23 {24 25 float TriangleMesh::IntersectLineTriSSE(const [float3] &linePos, const [float3] &lineDir,26 const [float3] &v0, const [float3] &v1, const [float3] &v2,27 float &u, float &v)28 {29 [float3] vE1, vE2;30 [float3] vT, vP, vQ;31 32 const float [epsilon] = 1[e]-6f;33 34 35 vE1 = v1 - v0;36 vE2 = v2 - v0;37 38 39 vP.[x] = lineDir.[y] * vE2.[z] - lineDir.[z] * vE2.[y];40 vP.[y] = lineDir.[z] * vE2.[x] - lineDir.[x] * vE2.[z];41 vP.[z] = lineDir.[x] * vE2.[y] - lineDir.[y] * vE2.[x];42 43 44 const float det = vE1.[x] * vP.[x] + vE1.[y] * vP.[y] + vE1.[z] * vP.[z];45 46 47 if (fabs(det) <= epsilon)48 return [FLOAT_INF];49 const float recipDet = 1.f / det;50 51 52 vT = linePos - v0;53 54 55 u = (vT.[x] * vP.[x] + vT.[y] * vP.[y] + vT.[z] * vP.[z]) * recipDet;56 if (u < 0.f || u > 1.f)57 return [FLOAT_INF]; 58 59 60 vQ.[x] = vT.[y] * vE1.[z] - vT.[z] * vE1.[y];61 vQ.[y] = vT.[z] * vE1.[x] - vT.[x] * vE1.[z];62 vQ.[z] = vT.[x] * vE1.[y] - vT.[y] * vE1.[x];63 64 65 v = (lineDir.[x] * vQ.[x] + lineDir.[y] * vQ.[y] + lineDir.[z] * vQ.[z]) * recipDet;66 if (v < 0.f || u + v > 1.f) 67 return [FLOAT_INF];68 69 70 71 72 return (vE2.[x] * vQ.[x] + vE2.[y] * vQ.[y] + vE2.[z] * vQ.[z]) * recipDet;73 }74 75 [MATH_END_NAMESPACE] Go back to previous page