Candle v1.0
2D lighting for SFML
candle::LightSource Class Referenceabstract

Interface for objects that emit light. More...

#include <LightSource.hpp>

+ Inheritance diagram for candle::LightSource:

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.
 

Detailed Description

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.

Member Function Documentation

◆ setIntensity()

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.

Parameters
intensityValue from 0 to 1. At 0 the light is invisible.
See also
getIntensity

◆ getIntensity()

float candle::LightSource::getIntensity ( ) const

Get the intensity of the light.

Returns
The light intensity.
See also
setIntensity

◆ setColor()

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

Parameters
colorNew color of the light. The alpha value is ignored.
See also
getColor

◆ getColor()

sf::Color candle::LightSource::getColor ( ) const

Get the plain color of the light.

The light color refers only to the RGB values.

Returns
The light color.
See also
setColor

◆ setFade()

virtual void candle::LightSource::setFade ( bool  fade)
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.

Parameters
fadeValue to set the flag.
See also
getFade

◆ getFade()

virtual bool candle::LightSource::getFade ( ) const
virtual

Check if the light fades or not.

Returns
The value of the fade flag.
See also
setFade

◆ setRange()

void candle::LightSource::setRange ( float  range)

Set the range of the illuminated area.

The range of the light indicates the how far a light ray may hit from its origin.

Parameters
rangeRange of the illuminated area.
See also
getRange, setFade

◆ getRange()

float candle::LightSource::getRange ( ) const

Get the range of the illuminated area.

Returns
The range of the illuminated area.
See also
setRange

◆ castLight()

virtual void candle::LightSource::castLight ( const EdgeVector::iterator &  begin,
const EdgeVector::iterator &  end 
)
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.

Parameters
beginIterator to the first sfu::Line of the vector to take into account.
endIterator to the first sfu::Line of the vector not to be taken into account.
See also
setRange, EdgeVector

Implemented in candle::DirectedLight, and candle::RadialLight.