Candle v1.0
2D lighting for SFML
Line.hpp File Reference

This file contains the Line struct and main raycast algorithm. More...

#include <limits>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Rect.hpp>
#include "Candle/geometry/Vector2.hpp"
#include "Candle/Constants.hpp"

Classes

struct  sfu::Line
 2D Line defined by an origin point and a direction vector. More...
 

Functions

template<typename Iterator >
sf::Vector2f sfu::castRay (const Iterator &begin, const Iterator &end, Line ray, float maxRange=std::numeric_limits< float >::infinity())
 Cast a ray against a set of segments. More...
 

Detailed Description

This file contains the Line struct and main raycast algorithm.

Author
Miguel Mejía Jiménez

Function Documentation

◆ castRay()

template<typename Iterator >
sf::Vector2f sfu::castRay ( const Iterator &  begin,
const Iterator &  end,
Line  ray,
float  maxRange = std::numeric_limits<float>::infinity() 
)

Cast a ray against a set of segments.

Use a line as a ray, casted from its origin in its direction. It is intersected with * a set of segments, represented as [Lines](sfu::Line) too, and the one closest to the cast point is returned.

Segments are interpreted to be delimited by the ray.m_origin and ray.point(1).

Parameters
beginIterator to the first ray.
endIterator to the last ray.
ray
maxRangeOptional argument to indicate the max distance allowed for a ray to hit a segment.