LCOV - code coverage report
Current view: top level - source/graphics - Frustum.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 2 100.0 %
Date: 2021-02-02 11:00:08 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2009 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             : /*
      19             :  * CFrustum is a collection of planes which define a viewing space.
      20             :  */
      21             : 
      22             : /*
      23             : Usually associated with the camera, there are 6 planes which define the
      24             : view pyramid. But we allow more planes per frustum which may be used for
      25             : portal rendering, where a portal may have 3 or more edges.
      26             : */
      27             : 
      28             : #ifndef INCLUDED_FRUSTUM
      29             : #define INCLUDED_FRUSTUM
      30             : 
      31             : #include "maths/Plane.h"
      32             : 
      33             : //10 planes should be enough
      34             : #define MAX_NUM_FRUSTUM_PLANES      (10)
      35             : 
      36             : class CBoundingBoxAligned;
      37             : class CMatrix3D;
      38             : 
      39             : class CFrustum
      40             : {
      41             : public:
      42             :     CFrustum ();
      43             :     ~CFrustum ();
      44             : 
      45             :     //Set the number of planes to use for
      46             :     //calculations. This is clipped to
      47             :     //[0,MAX_NUM_FRUSTUM_PLANES]
      48             :     void SetNumPlanes (size_t num);
      49             : 
      50          16 :     size_t GetNumPlanes() const { return m_NumPlanes; }
      51             : 
      52             :     void AddPlane (const CPlane& plane);
      53             : 
      54             :     void Transform(CMatrix3D& m);
      55             : 
      56             :     //The following methods return true if the shape is
      57             :     //partially or completely in front of the frustum planes
      58             :     bool IsPointVisible(const CVector3D& point) const;
      59             :     bool DoesSegmentIntersect(const CVector3D& start, const CVector3D& end) const;
      60             :     bool IsSphereVisible(const CVector3D& center, float radius) const;
      61             :     bool IsBoxVisible(const CVector3D& position, const CBoundingBoxAligned& bounds) const;
      62             :     bool IsBoxVisible(const CBoundingBoxAligned& bounds) const;
      63             : 
      64             :     CPlane& operator[](size_t idx) { return m_aPlanes[idx]; }
      65          14 :     const CPlane& operator[](size_t idx) const { return m_aPlanes[idx]; }
      66             : 
      67             : public:
      68             :     //make the planes public for ease of use
      69             :     CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
      70             : 
      71             : private:
      72             :     size_t m_NumPlanes;
      73             : };
      74             : 
      75             : #endif

Generated by: LCOV version 1.13