LCOV - code coverage report
Current view: top level - source/graphics - LightEnv.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 9 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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             :  * CLightEnv, a class describing the current lights
      20             :  */
      21             : 
      22             : #ifndef INCLUDED_LIGHTENV
      23             : #define INCLUDED_LIGHTENV
      24             : 
      25             : #include "graphics/Color.h"
      26             : #include "maths/MathUtil.h"
      27             : #include "maths/Vector3D.h"
      28             : 
      29             : class CMapWriter;
      30             : class CMapReader;
      31             : 
      32             : /**
      33             :  * Class CLightEnv: description of a lighting environment - contains all the
      34             :  * necessary parameters for representation of the lighting within a scenario
      35             :  */
      36             : class CLightEnv
      37             : {
      38             : public:
      39             :     RGBColor m_SunColor;
      40             :     RGBColor m_AmbientColor;
      41             :     RGBColor m_FogColor;
      42             : 
      43             :     float m_FogFactor;
      44             :     float m_FogMax;
      45             : 
      46             :     float m_Brightness, m_Contrast, m_Saturation, m_Bloom;
      47             : 
      48             :     CLightEnv();
      49             : 
      50           0 :     float GetElevation() const { return m_Elevation; }
      51           0 :     float GetRotation() const { return m_Rotation; }
      52           0 :     const CVector3D& GetSunDir() const { return m_SunDir; }
      53             : 
      54             :     void SetElevation(float f);
      55             :     void SetRotation(float f);
      56             : 
      57             :     /**
      58             :      * Calculate brightness of a point of a unit with the given normal vector,
      59             :      * for rendering with CPU lighting.
      60             :      * The resulting color contains both ambient and diffuse light.
      61             :      * To cope with sun overbrightness, the color is scaled by 0.5.
      62             :      *
      63             :      * @param normal normal vector (must have length 1)
      64             :      */
      65           0 :     RGBColor EvaluateUnitScaled(const CVector3D& normal) const
      66             :     {
      67           0 :         float dot = -normal.Dot(m_SunDir);
      68             : 
      69           0 :         RGBColor color = m_AmbientColor;
      70           0 :         if (dot > 0)
      71           0 :             color += m_SunColor * dot;
      72             : 
      73           0 :         return color * 0.5f;
      74             :     }
      75             : 
      76             :     // Comparison operators
      77             :     bool operator==(const CLightEnv& o) const
      78             :     {
      79             :         return m_Elevation == o.m_Elevation &&
      80             :             m_Rotation == o.m_Rotation &&
      81             :             m_SunColor == o.m_SunColor &&
      82             :             m_AmbientColor == o.m_AmbientColor &&
      83             :             m_FogColor == o.m_FogColor &&
      84             :             m_FogFactor == o.m_FogFactor &&
      85             :             m_FogMax == o.m_FogMax &&
      86             :             m_Brightness == o.m_Brightness &&
      87             :             m_Contrast == o.m_Contrast &&
      88             :             m_Saturation == o.m_Saturation &&
      89             :             m_Bloom == o.m_Bloom;
      90             :     }
      91             : 
      92             :     bool operator!=(const CLightEnv& o) const
      93             :     {
      94             :         return !(*this == o);
      95             :     }
      96             : 
      97             : private:
      98             :     friend class CMapWriter;
      99             :     friend class CMapReader;
     100             :     friend class CXMLReader;
     101             : 
     102             :     /**
     103             :     * Height of sun above the horizon, in radians.
     104             :     * For example, an elevation of M_PI/2 means the sun is straight up.
     105             :     */
     106             :     float m_Elevation;
     107             : 
     108             :     /**
     109             :     * Direction of sun on the compass, in radians.
     110             :     * For example, a rotation of zero means the sun is in the direction (0,0,-1)
     111             :     * and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking
     112             :     * elevation into account).
     113             :     */
     114             :     float m_Rotation;
     115             : 
     116             :     /**
     117             :     * Vector corresponding to m_Elevation and m_Rotation.
     118             :     * Updated by CalculateSunDirection.
     119             :     */
     120             :     CVector3D m_SunDir;
     121             : 
     122             :     void CalculateSunDirection();
     123             : };
     124             : 
     125             : #endif // INCLUDED_LIGHTENV

Generated by: LCOV version 1.13