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-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.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 
28 #include "graphics/core/color.h"
29 #include "graphics/core/light.h"
30 #include "graphics/engine/engine.h"
31 
32 #include "math/vector.h"
33 
34 
35 // Graphics module namespace
36 namespace Gfx {
37 
43 {
45  float starting;
47  float ending;
49  float current;
51  float progress;
53  float speed;
54 
56  : starting(0.0f)
57  , ending(0.0f)
58  , current(0.0f)
59  , progress(0.0f)
60  , speed(0.0f)
61  {}
62 
64  void Init(float value);
65 
67  void Update(float rTime);
68 
70  void SetTarget(float value);
71 };
72 
78 {
82 };
83 
92 {
94  int rank;
95 
97  bool used;
99  bool enabled;
100 
103 
106 
115 
120 
121  DynamicLight()
122  : rank(0)
123  , used(false)
124  , enabled(false)
125  , priority(LIGHT_PRI_LOW)
126  , includeType(ENG_OBJTYPE_NULL)
127  , excludeType(ENG_OBJTYPE_NULL)
128  {}
129 };
130 
145 {
146 public:
148  CLightManager(CEngine* engine);
150  virtual ~CLightManager();
151 
153  void SetDevice(CDevice* device);
154 
156  void DebugDumpLights();
157 
159  void FlushLights();
161  int CreateLight(LightPriority priority = LIGHT_PRI_LOW);
163  bool DeleteLight(int lightRank);
165  bool SetLight(int lightRank, const Light &light);
167  bool GetLight(int lightRank, Light &light);
169  bool SetLightEnabled(int lightRank, bool enable);
171  bool SetLightPriority(int lightRank, LightPriority priority);
172 
174  bool SetLightIncludeType(int lightRank, EngineObjectType type);
176  bool SetLightExcludeType(int lightRank, EngineObjectType type);
177 
179  bool SetLightPos(int lightRank, const Math::Vector &pos);
181  Math::Vector GetLightPos(int lightRank);
182 
184  bool SetLightDir(int lightRank, const Math::Vector &dir);
186  Math::Vector GetLightDir(int lightRank);
187 
189  bool SetLightIntensity(int lightRank, float value);
191  float GetLightIntensity(int lightRank);
193  bool SetLightIntensitySpeed(int lightRank, float speed);
194 
196  void AdaptLightColor(const Color &color, float factor);
197 
199  bool SetLightColor(int lightRank, const Color &color);
201  Color GetLightColor(int lightRank);
203  bool SetLightColorSpeed(int lightRank, float speed);
204 
206  void UpdateProgression(float rTime);
208  void UpdateLights();
211 
212 protected:
214  {
215  public:
216  LightsComparator(Math::Vector eyePos, EngineObjectType objectType);
217 
218  bool operator()(const DynamicLight& left, const DynamicLight& right);
219 
220  private:
221  float GetLightWeight(const DynamicLight& dynLight);
222 
223  Math::Vector m_eyePos;
224  EngineObjectType m_objectType;
225  };
226 
227 protected:
228  CEngine* m_engine;
229  CDevice* m_device;
230 
232  float m_time;
234  std::vector<DynamicLight> m_dynLights;
236  std::vector<int> m_lightMap;
237 };
238 
239 }; // namespace Gfx
240 
CLightManager(CEngine *engine)
Constructor.
Definition: lightman.cpp:74
Color GetLightColor(int lightRank)
Returns current light color.
Definition: lightman.cpp:341
float starting
Starting value.
Definition: lightman.h:45
bool SetLightIncludeType(int lightRank, EngineObjectType type)
Sets what objects are included in given dynamic light.
Definition: lightman.cpp:240
float m_time
Current time.
Definition: lightman.h:232
void DebugDumpLights()
Prints debug info.
Definition: lightman.cpp:94
int CreateLight(LightPriority priority=LIGHT_PRI_LOW)
Creates a new dynamic light and returns its index (lightRank)
Definition: lightman.cpp:155
Main graphics engine - CEngine class.
virtual ~CLightManager()
Destructor.
Definition: lightman.cpp:82
Object doesn't exist.
Definition: engine.h:171
void SetDevice(CDevice *device)
Sets the device to be used.
Definition: lightman.cpp:88
LightProgression colorBlue
Progression of blue diffuse color.
Definition: lightman.h:114
bool GetLight(int lightRank, Light &light)
Returns the light parameters for given dynamic light.
Definition: lightman.cpp:213
bool SetLightPos(int lightRank, const Math::Vector &pos)
Sets the position of dynamic light.
Definition: lightman.cpp:258
EngineObjectType
Class of graphics engine object.
Definition: engine.h:168
bool SetLightColor(int lightRank, const Color &color)
Sets the destination color for dynamic light's color progression.
Definition: lightman.cpp:330
LightPriority priority
Priority in assignment.
Definition: lightman.h:102
bool SetLightIntensitySpeed(int lightRank, float speed)
Sets the rate of change for dynamic light intensity.
Definition: lightman.cpp:292
EngineObjectType includeType
Type of objects included in lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:117
LightPriority
Priority in light assignment.
Definition: lightman.h:77
EngineObjectType excludeType
Type of objects excluded from lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:119
Light light
Configuration of the light.
Definition: lightman.h:105
Manager for dynamic lights in 3D scene.
Definition: lightman.h:144
float speed
Speed of progression.
Definition: lightman.h:53
Light struct and related enums.
bool SetLight(int lightRank, const Light &light)
Sets the light parameters for dynamic light.
Definition: lightman.cpp:199
Math::Vector GetLightPos(int lightRank)
Returns the position of dynamic light.
Definition: lightman.cpp:267
int rank
Rank (index)
Definition: lightman.h:94
high weight
Definition: lightman.h:80
Dynamic light in 3D scene.
Definition: lightman.h:91
std::vector< int > m_lightMap
Map of current light allocation: graphics light -> dynamic light.
Definition: lightman.h:236
void FlushLights()
Clears and disables all lights.
Definition: lightman.cpp:149
Properties of light in 3D scene.
Definition: light.h:53
Definition: lightman.h:213
Color structs and related functions.
float progress
Progress from start to end.
Definition: lightman.h:51
void AdaptLightColor(const Color &color, float factor)
Adjusts the color of all dynamic lights.
Definition: lightman.cpp:353
always highest weight (always picked)
Definition: lightman.h:79
void SetTarget(float value)
Sets the new end value (starting is set to current)
Definition: lightman.cpp:66
LightProgression colorGreen
Progression of green diffuse color.
Definition: lightman.h:112
Describes the progression of light parameters change.
Definition: lightman.h:42
bool SetLightPriority(int lightRank, LightPriority priority)
Changes the light priority.
Definition: lightman.cpp:231
void UpdateDeviceLights(EngineObjectType type)
Enables or disables dynamic lights affecting the given object type.
Definition: lightman.cpp:444
LightProgression colorRed
Progression of red diffuse color.
Definition: lightman.h:110
LightProgression intensity
Progression of intensity [0, 1].
Definition: lightman.h:108
std::vector< DynamicLight > m_dynLights
List of dynamic lights.
Definition: lightman.h:234
void UpdateLights()
Updates (recalculates) all dynamic lights.
Definition: lightman.cpp:412
void UpdateProgression(float rTime)
Updates progression of dynamic lights.
Definition: lightman.cpp:377
float GetLightIntensity(int lightRank)
Returns the current light intensity.
Definition: lightman.cpp:310
Namespace for (new) graphics code.
Definition: app.h:49
bool SetLightColorSpeed(int lightRank, float speed)
Sets the rate of change for dynamic light colors (RGB)
Definition: lightman.cpp:319
Vector struct and related functions.
The graphics engine.
Definition: engine.h:684
bool used
Whether the light is used.
Definition: lightman.h:97
Math::Vector GetLightDir(int lightRank)
Returns the direction of dynamic light.
Definition: lightman.cpp:284
3D (3x1) vector
Definition: vector.h:52
bool DeleteLight(int lightRank)
Deletes and disables the given dynamic light.
Definition: lightman.cpp:190
bool SetLightIntensity(int lightRank, float value)
Sets the destination intensity for dynamic light's intensity progression.
Definition: lightman.cpp:301
void Update(float rTime)
Updates the progression.
Definition: lightman.cpp:47
bool SetLightEnabled(int lightRank, bool enable)
Enables/disables the given dynamic light.
Definition: lightman.cpp:222
RGBA color.
Definition: color.h:38
void Init(float value)
Initializes the progression.
Definition: lightman.cpp:38
float ending
Ending (destination) value.
Definition: lightman.h:47
bool SetLightDir(int lightRank, const Math::Vector &dir)
Sets the direction of dynamic light.
Definition: lightman.cpp:275
float current
Current value.
Definition: lightman.h:49
low weight
Definition: lightman.h:81
bool SetLightExcludeType(int lightRank, EngineObjectType type)
Sets what objects are excluded from given dynamic light.
Definition: lightman.cpp:249
bool enabled
Whether the light is turned on.
Definition: lightman.h:99
Abstract interface of graphics device.
Definition: device.h:251