LCOV - code coverage report
Current view: top level - source/maths - BoundingSphere.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 5 6 83.3 %
Date: 2023-01-19 00:18:29 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* Copyright (C) 2019 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_BOUNDINGSPHERE
      19             : #define INCLUDED_BOUNDINGSPHERE
      20             : 
      21             : #include "maths/Vector3D.h"
      22             : 
      23             : class CBoundingBoxAligned;
      24             : 
      25             : class CBoundingSphere
      26             : {
      27             : public:
      28           0 :     CBoundingSphere() : m_Radius(0.0f) { }
      29             : 
      30          11 :     CBoundingSphere(const CVector3D& center, float radius) : m_Center(center), m_Radius(radius) { }
      31             : 
      32           2 :     const CVector3D& GetCenter() const
      33             :     {
      34           2 :         return m_Center;
      35             :     }
      36             : 
      37           2 :     float GetRadius() const
      38             :     {
      39           2 :         return m_Radius;
      40             :     }
      41             : 
      42             :     /**
      43             :      * Construct a bounding sphere that encompasses a bounding box
      44             :      * swept through all possible rotations around the origin.
      45             :      */
      46             :     static CBoundingSphere FromSweptBox(const CBoundingBoxAligned& bbox);
      47             : 
      48             :     /**
      49             :      * Check if the ray, defined by an origin point and a direction unit vector
      50             :      * interesects with the sphere. The direction should be normalized.
      51             :      */
      52             :     bool RayIntersect(const CVector3D& origin, const CVector3D& dir) const;
      53             : 
      54             : private:
      55             :     CVector3D m_Center;
      56             :     float m_Radius;
      57             : };
      58             : 
      59             : #endif // INCLUDED_BOUNDINGSPHERE

Generated by: LCOV version 1.13