MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Intersects

Method Intersects

TombEngine/Physics/Objects/CollisionMesh.cpp:64–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 }
63
64 bool LocalCollisionTriangle::Intersects(const Ray& ray, float& dist, const std::vector<Vector3>& vertices) const
65 {
66 // Get vertices.
67 const auto& vertex0 = GetVertex0(vertices);
68 const auto& vertex1 = GetVertex1(vertices);
69 const auto& vertex2 = GetVertex2(vertices);
70
71 // Calculate edges.
72 auto edge1 = vertex1 - vertex0;
73 auto edge2 = vertex2 - vertex0;
74
75 // Calculate determinant.
76 auto rayEdgeCross = ray.direction.Cross(edge2);
77 float det = edge1.Dot(rayEdgeCross);
78
79 // Ignore back side.
80 if (det < EPSILON)
81 return false;
82
83 float invDet = 1.0f / det;
84
85 // Calculate barycentric coordinate U.
86 auto rayToVertex = ray.position - vertex0;
87 float barycentricU = rayToVertex.Dot(rayEdgeCross) * invDet;
88 if (barycentricU < 0.0f || barycentricU > 1.0f)
89 return false;
90
91 // Calculate barycentric coordinate V.
92 auto cross = rayToVertex.Cross(edge1);
93 float barycentricV = ray.direction.Dot(cross) * invDet;
94 if (barycentricV < 0.0f || (barycentricU + barycentricV) > 1.0f)
95 return false;
96
97 // Calculate intersection distance.
98 float intersectDist = edge2.Dot(cross) * invDet;
99 if (intersectDist < 0.0f)
100 return false;
101
102 dist = intersectDist;
103 return true;
104 }
105
106 void LocalCollisionTriangle::DrawDebug(const Matrix& transformMatrix, const Matrix& rotMatrix, const std::vector<Vector3>& vertices) const
107 {

Callers 15

SphereBoxIntersectionMethod · 0.80
CollectLightsForRoomMethod · 0.80
GetCellKeysMethod · 0.80
GetBoundedObjectIdsMethod · 0.80
AssignSectorsMethod · 0.80
DeassignSectorsMethod · 0.80
CollideLaserBarrierFunction · 0.80
ElectricityWiresControlFunction · 0.80
FireRopeCollisionFunction · 0.80
TestBoundsCollideCameraFunction · 0.80
GetTargetOnLOSFunction · 0.80
DoRayBoxFunction · 0.80

Calls 2

CrossMethod · 0.45
DotMethod · 0.45

Tested by 5

TestBoundsCollideCameraFunction · 0.64
TestVolumeContainmentFunction · 0.64
TestLaraPoleCollisionFunction · 0.64
TestForObjectOnLedgeFunction · 0.64
TestMethod · 0.64