Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
lightman.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "graphics/core/color.h"
27 #include "graphics/core/light.h"
28 #include "graphics/engine/engine.h"
29 
30 #include "math/vector.h"
31 
32 
33 // Graphics module namespace
34 namespace Gfx {
35 
41 {
43  float starting;
45  float ending;
47  float current;
49  float progress;
51  float speed;
52 
54  : starting(0.0f)
55  , ending(0.0f)
56  , current(0.0f)
57  , progress(0.0f)
58  , speed(0.0f)
59  {}
60 
62  void Init(float value);
63 
65  void Update(float rTime);
66 
68  void SetTarget(float value);
69 };
70 
76 {
80 };
81 
90 {
92  int rank;
93 
95  bool used;
97  bool enabled;
98 
101 
104 
113 
118 
119  DynamicLight()
120  : rank(0)
121  , used(false)
122  , enabled(false)
126  {}
127 };
128 
143 {
144 public:
146  CLightManager(CEngine* engine);
148  virtual ~CLightManager();
149 
151  void SetDevice(CDevice* device);
152 
154  void DebugDumpLights();
155 
157  void FlushLights();
159  int CreateLight(LightPriority priority = LIGHT_PRI_LOW);
161  bool DeleteLight(int lightRank);
163  bool SetLight(int lightRank, const Light &light);
165  bool GetLight(int lightRank, Light &light);
167  bool SetLightEnabled(int lightRank, bool enable);
169  bool SetLightPriority(int lightRank, LightPriority priority);
170 
172  bool SetLightIncludeType(int lightRank, EngineObjectType type);
174  bool SetLightExcludeType(int lightRank, EngineObjectType type);
175 
177  bool SetLightPos(int lightRank, const Math::Vector &pos);
179  Math::Vector GetLightPos(int lightRank);
180 
182  bool SetLightDir(int lightRank, const Math::Vector &dir);
184  Math::Vector GetLightDir(int lightRank);
185 
187  bool SetLightIntensity(int lightRank, float value);
189  float GetLightIntensity(int lightRank);
191  bool SetLightIntensitySpeed(int lightRank, float speed);
192 
194  void AdaptLightColor(const Color &color, float factor);
195 
197  bool SetLightColor(int lightRank, const Color &color);
199  Color GetLightColor(int lightRank);
201  bool SetLightColorSpeed(int lightRank, float speed);
202 
204  void UpdateProgression(float rTime);
206  void UpdateLights();
209 
210 protected:
212  {
213  public:
214  LightsComparator(Math::Vector eyePos, EngineObjectType objectType);
215 
216  bool operator()(const DynamicLight& left, const DynamicLight& right);
217 
218  private:
219  float GetLightWeight(const DynamicLight& dynLight);
220 
221  Math::Vector m_eyePos;
222  EngineObjectType m_objectType;
223  };
224 
225 protected:
226  CEngine* m_engine;
227  CDevice* m_device;
228 
230  float m_time;
232  std::vector<DynamicLight> m_dynLights;
234  std::vector<int> m_lightMap;
235 };
236 
237 }; // namespace Gfx
238 
CLightManager(CEngine *engine)
Constructor.
Definition: lightman.cpp:72
Color GetLightColor(int lightRank)
Returns current light color.
Definition: lightman.cpp:339
float starting
Starting value.
Definition: lightman.h:43
bool SetLightIncludeType(int lightRank, EngineObjectType type)
Sets what objects are included in given dynamic light.
Definition: lightman.cpp:238
float m_time
Current time.
Definition: lightman.h:230
void DebugDumpLights()
Prints debug info.
Definition: lightman.cpp:92
int CreateLight(LightPriority priority=LIGHT_PRI_LOW)
Creates a new dynamic light and returns its index (lightRank)
Definition: lightman.cpp:153
Main graphics engine - CEngine class.
virtual ~CLightManager()
Destructor.
Definition: lightman.cpp:80
Object doesn't exist.
Definition: engine.h:168
void SetDevice(CDevice *device)
Sets the device to be used.
Definition: lightman.cpp:86
LightProgression colorBlue
Progression of blue diffuse color.
Definition: lightman.h:112
bool GetLight(int lightRank, Light &light)
Returns the light parameters for given dynamic light.
Definition: lightman.cpp:211
bool SetLightPos(int lightRank, const Math::Vector &pos)
Sets the position of dynamic light.
Definition: lightman.cpp:256
EngineObjectType
Class of graphics engine object.
Definition: engine.h:165
bool SetLightColor(int lightRank, const Color &color)
Sets the destination color for dynamic light's color progression.
Definition: lightman.cpp:328
LightPriority priority
Priority in assignment.
Definition: lightman.h:100
bool SetLightIntensitySpeed(int lightRank, float speed)
Sets the rate of change for dynamic light intensity.
Definition: lightman.cpp:290
EngineObjectType includeType
Type of objects included in lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:115
LightPriority
Priority in light assignment.
Definition: lightman.h:75
EngineObjectType excludeType
Type of objects excluded from lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored.
Definition: lightman.h:117
Light light
Configuration of the light.
Definition: lightman.h:103
Manager for dynamic lights in 3D scene.
Definition: lightman.h:142
float speed
Speed of progression.
Definition: lightman.h:51
Light struct and related enums.
bool SetLight(int lightRank, const Light &light)
Sets the light parameters for dynamic light.
Definition: lightman.cpp:197
Math::Vector GetLightPos(int lightRank)
Returns the position of dynamic light.
Definition: lightman.cpp:265
int rank
Rank (index)
Definition: lightman.h:92
high weight
Definition: lightman.h:78
Dynamic light in 3D scene.
Definition: lightman.h:89
std::vector< int > m_lightMap
Map of current light allocation: graphics light -> dynamic light.
Definition: lightman.h:234
void FlushLights()
Clears and disables all lights.
Definition: lightman.cpp:147
Properties of light in 3D scene.
Definition: light.h:51
Definition: lightman.h:211
Color structs and related functions.
float progress
Progress from start to end.
Definition: lightman.h:49
void AdaptLightColor(const Color &color, float factor)
Adjusts the color of all dynamic lights.
Definition: lightman.cpp:351
always highest weight (always picked)
Definition: lightman.h:77
void SetTarget(float value)
Sets the new end value (starting is set to current)
Definition: lightman.cpp:64
LightProgression colorGreen
Progression of green diffuse color.
Definition: lightman.h:110
Describes the progression of light parameters change.
Definition: lightman.h:40
bool SetLightPriority(int lightRank, LightPriority priority)
Changes the light priority.
Definition: lightman.cpp:229
void UpdateDeviceLights(EngineObjectType type)
Enables or disables dynamic lights affecting the given object type.
Definition: lightman.cpp:442
LightProgression colorRed
Progression of red diffuse color.
Definition: lightman.h:108
LightProgression intensity
Progression of intensity [0, 1].
Definition: lightman.h:106
std::vector< DynamicLight > m_dynLights
List of dynamic lights.
Definition: lightman.h:232
void UpdateLights()
Updates (recalculates) all dynamic lights.
Definition: lightman.cpp:410
void UpdateProgression(float rTime)
Updates progression of dynamic lights.
Definition: lightman.cpp:375
float GetLightIntensity(int lightRank)
Returns the current light intensity.
Definition: lightman.cpp:308
bool SetLightColorSpeed(int lightRank, float speed)
Sets the rate of change for dynamic light colors (RGB)
Definition: lightman.cpp:317
Vector struct and related functions.
The graphics engine.
Definition: engine.h:681
bool used
Whether the light is used.
Definition: lightman.h:95
Math::Vector GetLightDir(int lightRank)
Returns the direction of dynamic light.
Definition: lightman.cpp:282
3D (3x1) vector
Definition: vector.h:49
bool DeleteLight(int lightRank)
Deletes and disables the given dynamic light.
Definition: lightman.cpp:188
bool SetLightIntensity(int lightRank, float value)
Sets the destination intensity for dynamic light's intensity progression.
Definition: lightman.cpp:299
void Update(float rTime)
Updates the progression.
Definition: lightman.cpp:45
bool SetLightEnabled(int lightRank, bool enable)
Enables/disables the given dynamic light.
Definition: lightman.cpp:220
RGBA color.
Definition: color.h:35
void Init(float value)
Initializes the progression.
Definition: lightman.cpp:36
float ending
Ending (destination) value.
Definition: lightman.h:45
bool SetLightDir(int lightRank, const Math::Vector &dir)
Sets the direction of dynamic light.
Definition: lightman.cpp:273
float current
Current value.
Definition: lightman.h:47
low weight
Definition: lightman.h:79
bool SetLightExcludeType(int lightRank, EngineObjectType type)
Sets what objects are excluded from given dynamic light.
Definition: lightman.cpp:247
bool enabled
Whether the light is turned on.
Definition: lightman.h:97
Abstract interface of graphics device.
Definition: device.h:235