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 : #include "precompiled.h"
19 :
20 : #include "graphics/LightEnv.h"
21 :
22 : #include "maths/MathUtil.h"
23 :
24 :
25 1 : CLightEnv::CLightEnv()
26 : : m_Elevation(DEGTORAD(45)),
27 : m_Rotation(DEGTORAD(315)),
28 : m_SunColor(1.5, 1.5, 1.5),
29 : m_AmbientColor(0x50/255.f, 0x60/255.f, 0x85/255.f),
30 : m_FogColor(0xCC/255.f, 0xCC/255.f, 0xE5/255.f),
31 : m_FogFactor(0.000f),
32 : m_FogMax(0.5f),
33 1 : m_Brightness(0.0f), m_Contrast(1.0f), m_Saturation(0.99f), m_Bloom(0.1999f)
34 : {
35 1 : CalculateSunDirection();
36 1 : }
37 :
38 0 : void CLightEnv::SetElevation(float f)
39 : {
40 0 : m_Elevation = f;
41 0 : CalculateSunDirection();
42 0 : }
43 :
44 0 : void CLightEnv::SetRotation(float f)
45 : {
46 0 : m_Rotation = f;
47 0 : CalculateSunDirection();
48 0 : }
49 :
50 1 : void CLightEnv::CalculateSunDirection()
51 : {
52 1 : m_SunDir.Y = -sinf(m_Elevation);
53 1 : float scale = 1 + m_SunDir.Y;
54 1 : m_SunDir.X = scale * sinf(m_Rotation);
55 1 : m_SunDir.Z = scale * cosf(m_Rotation);
56 1 : m_SunDir.Normalize();
57 4 : }
|