TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Math::BezierCurve Class Reference

Classes

struct  Section
 

Public Member Functions

 BezierCurve (void)
 
 ~BezierCurve (void)
 
bool IsClosedLoop (void) const
 
void MakeLinesBySteps (std::vector< tbMath::Vector3 > &points, const size_t &stepsPerSection=25) const
 
void GetPositionsByDistance (std::vector< tbMath::Vector3 > &points, const float maxLineLength, const size_t stepsPerSection) const
 
void GetTangentsByDistance (std::vector< tbMath::Vector3 > &points, const float maxLineLength, const size_t stepsPerSection) const
 
void GetInformationByDistance (std::vector< tbMath::Vector3 > &points, std::vector< tbMath::Vector3 > &tangents, std::vector< float > &tValues, const float maxLineLength, const size_t stepsPerSection) const
 
tbMath::Vector3 GetClosestPoint (const tbMath::Vector3 &position, float &distance, const size_t &stepsPerSection=25) const
 
void GetOriginalPoints (std::vector< tbMath::Vector3 > &points) const
 
void GetTangents (std::vector< tbMath::Vector3 > &points, const size_t &stepsPerSection=25) const
 
float CalculateLength (const size_t stepsPerSection=25) const
 
tbMath::Vector3 GetPosition (float t) const
 
tbMath::Vector3 GetTangent (float t) const
 
tbMath::Vector3 GetPositionAt (float lengthFromStart, const size_t &stepsPerSection=25) const
 
size_t NumberOfSections (void) const
 

Static Public Member Functions

static BezierCurve FromCatMullRom (const std::vector< tbMath::Vector3 > &points, bool isLoop)
 
static BezierCurve FromCatMullRomBeau (const std::vector< tbMath::Vector3 > &points, bool isLoop)
 

Public Attributes

std::vector< SectionmSections
 
size_t mEstimatedLengthSteps
 
float mEstimatedLength
 
bool mIsLoop
 

Constructor & Destructor Documentation

◆ BezierCurve()

TurtleBrains::Math::BezierCurve::BezierCurve ( void  )
explicit

Constructs an empty curve object.

◆ ~BezierCurve()

TurtleBrains::Math::BezierCurve::~BezierCurve ( void  )

Cleans up any resources used by the BezierCurve.

Member Function Documentation

◆ CalculateLength()

float TurtleBrains::Math::BezierCurve::CalculateLength ( const size_t  stepsPerSection = 25) const

Estimates the length of the entire curve, the more steps the more accurate. This will cache the result of previous estimations and return the value. If stepsPerSection is larger than a previous result a new calculation will take place.

Note
In the case of the Live for Speed track known as Fern Bay 1, back when this was created for the AIRS project, the centerline measured 1,602 meters using 25 steps, and using 250 steps the length was 1692 meters, adding a whole 90m. More steps is more accurate but more expensive.

◆ FromCatMullRom()

static BezierCurve TurtleBrains::Math::BezierCurve::FromCatMullRom ( const std::vector< tbMath::Vector3 > &  points,
bool  isLoop 
)
static

Sets up a BezierCurve object from a set of points that lay along the curve using the catmullrom algorithm.

Parameters
pointsPoints that lay on the desired curve. Must contain at least 2 points for a not looping curve, or at least 5 for a loop.
isLoopTrue if the curved path should use the last and first points to create a continuous loop.

◆ FromCatMullRomBeau()

static BezierCurve TurtleBrains::Math::BezierCurve::FromCatMullRomBeau ( const std::vector< tbMath::Vector3 > &  points,
bool  isLoop 
)
static

Sets up a BezierCurve object from a set of points that lay along the curve using the catmullrom algorithm with a slightly different control points for at the start and end of the curve to reduce the kink in the spline.

Parameters
pointsPoints that lay on the desired curve. Must contain at least 2 points for a not looping curve, or at least 5 for a loop.
isLoopTrue if the curved path should use the last and first points to create a continuous loop.
Note
Behaves identical to FromCatMullRom for looping curves.

◆ GetPositionsByDistance()

void TurtleBrains::Math::BezierCurve::GetPositionsByDistance ( std::vector< tbMath::Vector3 > &  points,
const float  maxLineLength,
const size_t  stepsPerSection 
) const

Takes a curve object and breaks it back into lines. This variant will make each line approximately the length specified by maxLineLength independent of the actual curve sections. Shorter line lenghts will increase accurracy whereas a longer line may skip over portions of the curve. Do not, the lineLength is not a guaranteed that the points given back will actually be that length!

Note
Not yet implemented

◆ IsClosedLoop()

bool TurtleBrains::Math::BezierCurve::IsClosedLoop ( void  ) const
inline

Returns true if the curve completes a loop sharing the start and final point.

◆ MakeLinesBySteps()

void TurtleBrains::Math::BezierCurve::MakeLinesBySteps ( std::vector< tbMath::Vector3 > &  points,
const size_t &  stepsPerSection = 25 
) const

Takes a curve object and breaks it back into lines. This variant will split each curve section into several small lines. If the curve section is shorter, the amount of lines will remain the same as a longer curve section. Obviously, the more steps per section, the more lines will be created, so carefully increase.