Candle v1.0
2D lighting for SFML
candle::RadialLight Class Reference

LightSource that emits light from a single point. More...

#include <RadialLight.hpp>

+ Inheritance diagram for candle::RadialLight:

Public Member Functions

 RadialLight ()
 Constructor.
 
virtual ~RadialLight ()
 Destructor.
 
void castLight (const EdgeVector::iterator &begin, const EdgeVector::iterator &end) override
 Modify the polygon of the illuminated area with a raycasting algorithm. More...
 
void setBeamAngle (float angle)
 Set the range for which rays may be casted. More...
 
float getBeamAngle () const
 Get the range for which rays may be casted. More...
 
sf::FloatRect getLocalBounds () const
 Get the local bounding rectangle of the light. More...
 
sf::FloatRect getGlobalBounds () const
 Get the global bounding rectangle of the light. More...
 
- Public Member Functions inherited from candle::LightSource
 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

void draw (sf::RenderTarget &t, sf::RenderStates st) const override
 Draw the object to a target.
 

Detailed Description

LightSource that emits light from a single point.

A RadialLight is defined, mainly, by the position, the orientation, the range of the light and the beam angle. To manipulate the position and the orientation of the light, you can change the position and rotation of the object as you would do with any sf::Transformable. The range can be manipulated as with other LightSources, with LightSource::setRange, and the angle of the beam with setBeamAngle.


Variables schema

Demo example

Member Function Documentation

◆ castLight()

void candle::RadialLight::castLight ( const EdgeVector::iterator &  begin,
const EdgeVector::iterator &  end 
)
overridevirtual

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

Implements candle::LightSource.

◆ setBeamAngle()

void candle::RadialLight::setBeamAngle ( float  angle)

Set the range for which rays may be casted.

The angle shall be specified in degrees. The angle in which the rays will be casted will be [R - angle/2, R + angle/2], where R is the rotation of the object.

Parameters
angle
See also
getBeamAngle

◆ getBeamAngle()

float candle::RadialLight::getBeamAngle ( ) const

Get the range for which rays may be casted.

It defaults to 360ยบ.

See also
setBeamAngle

◆ getLocalBounds()

sf::FloatRect candle::RadialLight::getLocalBounds ( ) const

Get the local bounding rectangle of the light.

Returns
The local bounding rectangle in float.

◆ getGlobalBounds()

sf::FloatRect candle::RadialLight::getGlobalBounds ( ) const

Get the global bounding rectangle of the light.

Returns
The global bounding rectangle in float.