MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / collision

Function collision

utilities/olcUTIL_Geometry2D.h:2322–2331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2320 // optionally returns collision point and collision normal of ray and a line segment, if it collides
2321 template<typename T1, typename T2>
2322 inline std::optional<std::pair<olc::v_2d<T2>, olc::v_2d<T2>>> collision(const ray<T1>& q, const line<T2>& l)
2323 {
2324 const auto vIntersection = intersects(q, l);
2325 if (vIntersection.size() > 0)
2326 {
2327 return { {vIntersection[0], l.vector().perp().norm() * l.side(q.origin)} };
2328 }
2329
2330 return std::nullopt;
2331 }
2332
2333 // reflect(q,l)
2334 // optionally returns a ray reflected off a line segement if collision occurs

Callers 1

reflectFunction · 0.85

Calls 8

intersectsFunction · 0.85
vectorMethod · 0.80
sizeMethod · 0.45
normMethod · 0.45
perpMethod · 0.45
sideMethod · 0.45
side_countMethod · 0.45
mag2Method · 0.45

Tested by

no test coverage detected