diff options
Diffstat (limited to 'src/collision/ColSphere.cpp')
-rw-r--r-- | src/collision/ColSphere.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/collision/ColSphere.cpp b/src/collision/ColSphere.cpp index 9aac01e0..65f02860 100644 --- a/src/collision/ColSphere.cpp +++ b/src/collision/ColSphere.cpp @@ -1,5 +1,6 @@ #include "common.h" #include "ColSphere.h" +#include "General.h" void CColSphere::Set(float radius, const CVector ¢er, uint8 surf, uint8 piece) @@ -8,4 +9,19 @@ CColSphere::Set(float radius, const CVector ¢er, uint8 surf, uint8 piece) this->center = center; this->surface = surf; this->piece = piece; +} + +bool +CColSphere::IntersectRay(CVector const& from, CVector const& dir, CVector &entry, CVector &exit) +{ + CVector distToCenter = from - center; + float distToTouchSqr = distToCenter.MagnitudeSqr() - sq(radius); + float root1, root2; + + if (!CGeneral::SolveQuadratic(1.0f, DotProduct(distToCenter, dir) * 2.f, distToTouchSqr, root1, root2)) + return false; + + entry = from + dir * root1; + exit = from + dir * root2; + return true; }
\ No newline at end of file |