Candle v1.0
2D lighting for SFML
|
Interface for objects that emit light. More...
#include <LightSource.hpp>
Public Member Functions | |
LightSource () | |
Constructor. | |
void | setIntensity (float intensity) |
Set the light intensity. More... | |
float | getIntensity () const |
Get the intensity of the light. More... | |
void | setColor (const sf::Color &color) |
Set the light color. More... | |
sf::Color | getColor () const |
Get the plain color of the light. More... | |
virtual void | setFade (bool fade) |
Set the value of the fade flag. More... | |
virtual bool | getFade () const |
Check if the light fades or not. More... | |
void | setRange (float range) |
Set the range of the illuminated area. More... | |
float | getRange () const |
Get the range of the illuminated area. More... | |
virtual void | castLight (const EdgeVector::iterator &begin, const EdgeVector::iterator &end)=0 |
Modify the polygon of the illuminated area with a raycasting algorithm. More... | |
Private Member Functions | |
virtual void | draw (sf::RenderTarget &t, sf::RenderStates st) const =0 |
Draw the object to a target. | |
Interface for objects that emit light.
LightSources use raycasting algorithms to compute the polygon illuminated by the light. The main difference between the implementations, RadialLight and DirectedLight, is whether the constant is the origin or the direction of the rays.
LightSources manage their colour separating the alpha value from the RGB . This is convenient to manipulate color of the light (interpreted as the RGB value) and intensity (interpreted as the alpha value) separately.
By default, they use a sf::BlendAdd mode. This means that you can specify any other blend mode you want, except sf::BlendAlpha, that will be changed to the additive mode.
void candle::LightSource::setIntensity | ( | float | intensity | ) |
Set the light intensity.
The intensity
of the light determines two things: how much fog opacity it reduces when drawn in a LightingArea * in FOG mode, and how much presence its color has when drawn normally.
The default value is 1.
intensity | Value from 0 to 1. At 0 the light is invisible. |
float candle::LightSource::getIntensity | ( | ) | const |
void candle::LightSource::setColor | ( | const sf::Color & | color | ) |
Set the light color.
The light color refers only to the RGB values.
The default value is sf::Color::White
color | New color of the light. The alpha value is ignored. |
sf::Color candle::LightSource::getColor | ( | ) | const |
Get the plain color of the light.
The light color refers only to the RGB values.
|
virtual |
Set the value of the fade flag.
when the fade
flag is set, the light will lose intensity in the limits of its range. Otherwise, the intensity will remain constant.
The default value is true.
fade | Value to set the flag. |
|
virtual |
void candle::LightSource::setRange | ( | float | range | ) |
float candle::LightSource::getRange | ( | ) | const |
|
pure virtual |
Modify the polygon of the illuminated area with a raycasting algorithm.
The algorithm needs to know which edges to use to cast shadows. They are specified within a range of two iterators of a vector of edges of type sfu::Line.
begin | Iterator to the first sfu::Line of the vector to take into account. |
end | Iterator to the first sfu::Line of the vector not to be taken into account. |
Implemented in candle::DirectedLight, and candle::RadialLight.