MCPcopy Create free account
hub / github.com/assaultcube/AC / intersectsphere

Function intersectsphere

source/src/weapon.cpp:248–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248static inline bool intersectsphere(const vec &from, const vec &to, vec center, float radius, float &dist)
249{
250 vec ray(to);
251 ray.sub(from);
252 center.sub(from);
253 float v = center.dot(ray),
254 inside = radius*radius - center.squaredlen();
255 if(inside < 0 && v < 0) return false;
256 float raysq = ray.squaredlen(), d = inside*raysq + v*v;
257 if(d < 0) return false;
258 dist = (v - sqrtf(d)) / raysq;
259 return dist >= 0 && dist <= 1;
260}
261
262static inline bool intersectcylinder(const vec &from, const vec &to, const vec &start, const vec &end, float radius, float &dist)
263{

Callers 1

intersectFunction · 0.85

Calls 2

squaredlenMethod · 0.80
dotMethod · 0.45

Tested by

no test coverage detected