MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / SphereContainsBox

Method SphereContainsBox

Engine/lib/opcode/OPC_SphereCollider.cpp:310–325  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * Checks the sphere completely contains the box. In which case we can end the query sooner. * \param bc [in] box center * \param be [in] box extents * \return true if the sphere contains the whole bo

Source from the content-addressed store, hash-verified

308 */
309///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
310inline_ BOOL SphereCollider::SphereContainsBox(const Point& bc, const Point& be)
311{
312 // I assume if all 8 box vertices are inside the sphere, so does the whole box.
313 // Sounds ok but maybe there's a better way?
314 Point p;
315 p.x=bc.x+be.x; p.y=bc.y+be.y; p.z=bc.z+be.z; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
316 p.x=bc.x-be.x; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
317 p.x=bc.x+be.x; p.y=bc.y-be.y; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
318 p.x=bc.x-be.x; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
319 p.x=bc.x+be.x; p.y=bc.y+be.y; p.z=bc.z-be.z; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
320 p.x=bc.x-be.x; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
321 p.x=bc.x+be.x; p.y=bc.y-be.y; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
322 p.x=bc.x-be.x; if(mCenter.SquareDistance(p)>=mRadius2) return FALSE;
323
324 return TRUE;
325}
326
327#define TEST_BOX_IN_SPHERE(center, extents) \
328 if(SphereContainsBox(center, extents)) \

Callers

nothing calls this directly

Calls 1

SquareDistanceMethod · 0.45

Tested by

no test coverage detected