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

LightSource that emits light in a single direction. More...

#include <DirectedLight.hpp>

+ Inheritance diagram for candle::DirectedLight:

Public Member Functions

void castLight (const EdgeVector::iterator &begin, const EdgeVector::iterator &end) override
 Modify the polygon of the illuminated area with a raycasting algorithm. More...
 
void setBeamWidth (float width)
 Set the width of the beam. More...
 
float getBeamWidth () const
 Get the width of the beam. 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 in a single direction.

A DirectedLight is defined, mainly, by the direction of the rays, the position of the source, the beam width and the range of the light. You can manipulate the first two changing the rotation and position as you would with any sf::Transformable. The range can be manipulated as with other LightSources, with LightSource::setRange, and the beam width with setBeamWidth.


Variables diagram

Demo example

Member Function Documentation

◆ castLight()

void candle::DirectedLight::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.

◆ setBeamWidth()

void candle::DirectedLight::setBeamWidth ( float  width)

Set the width of the beam.

The width specifies the maximum distance allowed from the center of the segment to cast a ray, along a segment normal to the light direction.

Parameters
widthWidth of the beam.
See also
getBeamWidth

◆ getBeamWidth()

float candle::DirectedLight::getBeamWidth ( ) const

Get the width of the beam.

Returns
Width of the beam
See also
setBeamWidth