← API Reference Class

asge::math::CatmullRomSpline

A piecewise Catmull-Rom spline through a list of waypoints, with each segment pre-sampled into an arc-length table so points and tangents can be looked up either by a normalized [0, 1] curve parameter or by actual distance travelled along the curve.

#include <CatmullRomSpline.hpp>

Private Attributes

#std::vector< Float2 > m_Waypoints {}private
#std::vector< Segment > m_Segments {}private
#float m_TotalLength {0.0f}private

Private Member Functions

#std::pair< std::size_t, float > LocateSegment(float inTime) constprivate

Maps a normalized spline parameter inTime in [0, 1] to the segment it falls in and the local Hermite parameter within it.

#std::pair< std::size_t, float > LocateByDistance(float inDistance) const noexceptprivate

Maps inDistance (clamped to [0, Length()]) to the segment it falls in and the local Hermite parameter within it, via that segment's arc-length table — the distance-based counterpart to LocateSegment().

Shared by PointAtDistance() and TimeAtDistance().

Public Member Functions

#CatmullRomSpline()=default
#explicit CatmullRomSpline(std::vector< Float2 > inWp, std::size_t inResolution=32)

Builds the spline through inWp, precomputing each segment's arc-length table with inResolution samples.

Splines with fewer than two waypoints have no segments and evaluate to a zero point.

#CatmullRomSpline(CatmullRomSpline const &)=default
#CatmullRomSpline(CatmullRomSpline &&)=default
#CatmullRomSpline & operator=(CatmullRomSpline const &)=default
#CatmullRomSpline & operator=(CatmullRomSpline &&)=default
#~CatmullRomSpline()=default
#std::vector< Segment > const & Segments() const noexcept

Returns the spline's precomputed segments, in order.

#std::vector< Float2 > const & Waypoints() const noexcept

Returns the waypoints the spline was constructed from.

#bool HasSegments() const noexcept

Check if the spline has segments in it.

#float Length() const noexcept

Returns the total arc length of the spline.

#Float2 PointAt(float inTime) const noexcept

Returns the point at normalized parameter inTime, clamped to [0, 1] and distributed evenly across segments (not arc-length corrected).

#Float2 PointAtDistance(float inDistance) const noexcept

Returns the point at inDistance travelled along the curve, clamped to [0, Length()], using each segment's arc-length table.

#Float2 TangentAt(float inTime) const noexcept

Returns the normalized tangent direction at normalized parameter inTime.

#float TimeAtDistance(float inDistance) const noexcept

Returns the normalized [0, 1] parameter TangentAt()/PointAt() expect for the point inDistance (clamped to [0, Length()]) along the curve — the inverse of the distribution PointAt() walks, so PointAt(TimeAtDistance(d)) matches PointAtDistance(d).

Returns 0 for a spline with no segments.