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

Function intersectbox

source/src/weapon.cpp:214–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214static inline bool intersectbox(const vec &o, const vec &rad, const vec &from, const vec &to, vec *end) // if lineseg hits entity bounding box
215{
216 const vec *p;
217 vec v = to, w = o;
218 v.sub(from);
219 w.sub(from);
220 float c1 = w.dot(v);
221
222 if(c1<=0) p = &from;
223 else
224 {
225 float c2 = v.squaredlen();
226 if(c2<=c1) p = &to;
227 else
228 {
229 float f = c1/c2;
230 v.mul(f).add(from);
231 p = &v;
232 }
233 }
234
235 if(p->x <= o.x+rad.x
236 && p->x >= o.x-rad.x
237 && p->y <= o.y+rad.y
238 && p->y >= o.y-rad.y
239 && p->z <= o.z+rad.z
240 && p->z >= o.z-rad.z)
241 {
242 if(end) *end = *p;
243 return true;
244 }
245 return false;
246}
247
248static inline bool intersectsphere(const vec &from, const vec &to, vec center, float radius, float &dist)
249{

Callers 1

intersectFunction · 0.85

Calls 4

squaredlenMethod · 0.80
mulMethod · 0.80
dotMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected