File: LightEnv.h

package info (click to toggle)
0ad 0.0.26-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 130,460 kB
  • sloc: cpp: 261,824; ansic: 198,392; javascript: 19,067; python: 14,557; sh: 7,629; perl: 4,072; xml: 849; makefile: 741; java: 533; ruby: 229; php: 190; pascal: 30; sql: 21; tcl: 4
file content (125 lines) | stat: -rw-r--r-- 3,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* Copyright (C) 2021 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * 0 A.D. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * CLightEnv, a class describing the current lights
 */

#ifndef INCLUDED_LIGHTENV
#define INCLUDED_LIGHTENV

#include "graphics/Color.h"
#include "maths/MathUtil.h"
#include "maths/Vector3D.h"

class CMapWriter;
class CMapReader;

/**
 * Class CLightEnv: description of a lighting environment - contains all the
 * necessary parameters for representation of the lighting within a scenario
 */
class CLightEnv
{
public:
	RGBColor m_SunColor;
	RGBColor m_AmbientColor;
	RGBColor m_FogColor;

	float m_FogFactor;
	float m_FogMax;

	float m_Brightness, m_Contrast, m_Saturation, m_Bloom;

	CLightEnv();

	float GetElevation() const { return m_Elevation; }
	float GetRotation() const { return m_Rotation; }
	const CVector3D& GetSunDir() const { return m_SunDir; }

	void SetElevation(float f);
	void SetRotation(float f);

	/**
	 * Calculate brightness of a point of a unit with the given normal vector,
	 * for rendering with CPU lighting.
	 * The resulting color contains both ambient and diffuse light.
	 * To cope with sun overbrightness, the color is scaled by 0.5.
	 *
	 * @param normal normal vector (must have length 1)
	 */
	RGBColor EvaluateUnitScaled(const CVector3D& normal) const
	{
		float dot = -normal.Dot(m_SunDir);

		RGBColor color = m_AmbientColor;
		if (dot > 0)
			color += m_SunColor * dot;

		return color * 0.5f;
	}

	// Comparison operators
	bool operator==(const CLightEnv& o) const
	{
		return m_Elevation == o.m_Elevation &&
			m_Rotation == o.m_Rotation &&
			m_SunColor == o.m_SunColor &&
			m_AmbientColor == o.m_AmbientColor &&
			m_FogColor == o.m_FogColor &&
			m_FogFactor == o.m_FogFactor &&
			m_FogMax == o.m_FogMax &&
			m_Brightness == o.m_Brightness &&
			m_Contrast == o.m_Contrast &&
			m_Saturation == o.m_Saturation &&
			m_Bloom == o.m_Bloom;
	}

	bool operator!=(const CLightEnv& o) const
	{
		return !(*this == o);
	}

private:
	friend class CMapWriter;
	friend class CMapReader;
	friend class CXMLReader;

	/**
	* Height of sun above the horizon, in radians.
	* For example, an elevation of M_PI/2 means the sun is straight up.
	*/
	float m_Elevation;

	/**
	* Direction of sun on the compass, in radians.
	* For example, a rotation of zero means the sun is in the direction (0,0,-1)
	* and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking
	* elevation into account).
	*/
	float m_Rotation;

	/**
	* Vector corresponding to m_Elevation and m_Rotation.
	* Updated by CalculateSunDirection.
	*/
	CVector3D m_SunDir;

	void CalculateSunDirection();
};

#endif // INCLUDED_LIGHTENV