Colobot
lightman.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "graphics/core/light.h"
28 
29 #include "graphics/engine/engine.h"
30 
31 #include "math/vector.h"
32 
33 
34 // Graphics module namespace
35 namespace Gfx
36 {
37 
38 struct Color;
39 
45 {
47  float starting;
49  float ending;
51  float current;
53  float progress;
55  float speed;
56 
58  : starting(0.0f)
59  , ending(0.0f)
60  , current(0.0f)
61  , progress(0.0f)
62  , speed(0.0f)
63  {}
64 
66  void Init(float value);
67 
69  void Update(float rTime);
70 
72  void SetTarget(float value);
73 };
74 
80 {
84 };
85 
94 {
96  int rank;
97 
99  bool used;
101  bool enabled;
102 
105 
108 
117 
122 
123  DynamicLight()
124  : rank(0)
125  , used(false)
126  , enabled(false)
127  , priority(LIGHT_PRI_LOW)
128  , includeType(ENG_OBJTYPE_NULL)
129  , excludeType(ENG_OBJTYPE_NULL)
130  {}
131 };
132 
147 {
148 public:
150  CLightManager(CEngine* engine);
152  virtual ~CLightManager();
153 
155  void SetDevice(CDevice* device);
156 
158  void DebugDumpLights();
159 
161  void FlushLights();
163  int CreateLight(LightPriority priority = LIGHT_PRI_LOW);
165  bool DeleteLight(int lightRank);
167  bool SetLight(int lightRank, const Light &light);
169  bool GetLight(int lightRank, Light &light);
171  bool SetLightEnabled(int lightRank, bool enabled);
173  bool SetLightPriority(int lightRank, LightPriority priority);
174 
176  bool SetLightIncludeType(int lightRank, EngineObjectType type);
178  bool SetLightExcludeType(int lightRank, EngineObjectType type);
179 
181  bool SetLightPos(int lightRank, const Math::Vector &pos);
183  Math::Vector GetLightPos(int lightRank);
184 
186  bool SetLightDir(int lightRank, const Math::Vector &dir);
188  Math::Vector GetLightDir(int lightRank);
189 
191  bool SetLightIntensity(int lightRank, float value);
193  float GetLightIntensity(int lightRank);
195  bool SetLightIntensitySpeed(int lightRank, float speed);
196 
198  void AdaptLightColor(const Color &color, float factor);
199 
201  bool SetLightColor(int lightRank, const Color &color);
203  Color GetLightColor(int lightRank);
205  bool SetLightColorSpeed(int lightRank, float speed);
206 
208  void UpdateProgression(float rTime);
210  void UpdateLights();
212  void UpdateDeviceLights(EngineObjectType type);
213 
214 protected:
216  {
217  public:
218  CLightsComparator(Math::Vector eyePos, EngineObjectType objectType);
219 
220  bool operator()(const DynamicLight& left, const DynamicLight& right);
221 
222  private:
223  float GetLightWeight(const DynamicLight& dynLight);
224 
225  Math::Vector m_eyePos;
226  EngineObjectType m_objectType;
227  };
228 
229 protected:
230  CEngine* m_engine;
231  CDevice* m_device;
232 
234  float m_time;
236  std::vector<DynamicLight> m_dynLights;
238  std::vector<int> m_lightMap;
239 };
240 
241 } // namespace Gfx
242 
float starting
Starting value.
Definition: lightman.h:47
float m_time
Current time.
Definition: lightman.h:234
Main graphics engine - CEngine class.
Object doesn&#39;t exist.
Definition: engine.h:174
LightProgression colorBlue
Progression of blue diffuse color.
Definition: lightman.h:116
EngineObjectType
Class of graphics engine object.
Definition: engine.h:171
LightPriority priority
Priority in assignment.
Definition: lightman.h:104
EngineObjectType includeType
Type of objects included in lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:119
LightPriority
Priority in light assignment.
Definition: lightman.h:79
EngineObjectType excludeType
Type of objects excluded from lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:121
Light light
Configuration of the light.
Definition: lightman.h:107
Manager for dynamic lights in 3D scene.
Definition: lightman.h:146
float speed
Speed of progression.
Definition: lightman.h:55
Light struct and related enums.
int rank
Rank (index)
Definition: lightman.h:96
high weight
Definition: lightman.h:82
Dynamic light in 3D scene.
Definition: lightman.h:93
std::vector< int > m_lightMap
Map of current light allocation: graphics light -> dynamic light.
Definition: lightman.h:238
Properties of light in 3D scene.
Definition: light.h:54
float progress
Progress from start to end.
Definition: lightman.h:53
always highest weight (always picked)
Definition: lightman.h:81
void SetTarget(float value)
Sets the new end value (starting is set to current)
Definition: lightman.cpp:67
LightProgression colorGreen
Progression of green diffuse color.
Definition: lightman.h:114
Describes the progression of light parameters change.
Definition: lightman.h:44
LightProgression colorRed
Progression of red diffuse color.
Definition: lightman.h:112
LightProgression intensity
Progression of intensity [0, 1].
Definition: lightman.h:110
Definition: lightman.h:215
std::vector< DynamicLight > m_dynLights
List of dynamic lights.
Definition: lightman.h:236
Namespace for (new) graphics code.
Definition: app.h:49
Vector struct and related functions.
The graphics engine.
Definition: engine.h:585
bool used
Whether the light is used.
Definition: lightman.h:99
3D (3x1) vector
Definition: vector.h:53
void Update(float rTime)
Updates the progression.
Definition: lightman.cpp:48
RGBA color.
Definition: color.h:39
void Init(float value)
Initializes the progression.
Definition: lightman.cpp:39
float ending
Ending (destination) value.
Definition: lightman.h:49
float current
Current value.
Definition: lightman.h:51
low weight
Definition: lightman.h:83
bool enabled
Whether the light is turned on.
Definition: lightman.h:101
Abstract interface of graphics device.
Definition: device.h:323