TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_curve.hpp
1 
10 #ifndef TurtleBrains_Curve_hpp
11 #define TurtleBrains_Curve_hpp
12 
13 #include <turtle_brains/math/tb_vector.hpp>
14 
15 #include <vector>
16 
17 namespace TurtleBrains
18 {
19  namespace Math
20  {
21 
23  {
24  public:
32  static BezierCurve FromCatMullRom(const std::vector<tbMath::Vector3>& points, bool isLoop);
33 
45  static BezierCurve FromCatMullRomBeau(const std::vector<tbMath::Vector3>& points, bool isLoop);
46 
50  explicit BezierCurve(void);
51 
55  ~BezierCurve(void);
56 
60  inline bool IsClosedLoop(void) const { return mIsLoop; }
61 
67  void MakeLinesBySteps(std::vector<tbMath::Vector3>& points, const size_t& stepsPerSection = 25) const;
68 
77  void GetPositionsByDistance(std::vector<tbMath::Vector3>& points, const float maxLineLength, const size_t stepsPerSection) const;
78  void GetTangentsByDistance(std::vector<tbMath::Vector3>& points, const float maxLineLength, const size_t stepsPerSection) const;
79 
81  void GetInformationByDistance(std::vector<tbMath::Vector3>& points, std::vector<tbMath::Vector3>& tangents, std::vector<float>& tValues,
82  const float maxLineLength, const size_t stepsPerSection) const;
83 
84 
88  tbMath::Vector3 GetClosestPoint(const tbMath::Vector3& position, float& distance, const size_t& stepsPerSection = 25) const;
89 
90  void GetOriginalPoints(std::vector<tbMath::Vector3>& points) const;
91 
92  //Temporary code will need to reorganize once a better way to handle curves and sections are added.
93  void GetTangents(std::vector<tbMath::Vector3>& points, const size_t& stepsPerSection = 25) const;
94  //void GetNormals(std::vector<tbMath::Vector3>& points, const size_t& stepsPerSection = 25) const;
95 
105  float CalculateLength(const size_t stepsPerSection = 25) const;
106 
107  //t is a value from 0 <= t <= numberOfSections
108  // sectionIndex + percentage value into a single t value.
109  tbMath::Vector3 GetPosition(float t) const;
110  tbMath::Vector3 GetTangent(float t) const;
111 
112  tbMath::Vector3 GetPositionAt(float lengthFromStart, const size_t& stepsPerSection = 25) const;
113 
114  size_t NumberOfSections(void) const { return mSections.size(); }
115 
116  //for testing do not commit...
117  //private:
118  struct Section
119  {
120  tbMath::Vector3 a, b, c, d; //a = start, d = end, b and c are control points.
121  };
122 
123  std::vector<Section> mSections;
124  mutable size_t mEstimatedLengthSteps;
125  mutable float mEstimatedLength;
126  bool mIsLoop;
127  };
128 
129  }; //namespace Math
130 }; //namespace TurtleBrains
131 
132 namespace tbMath = TurtleBrains::Math;
133 
134 #endif /* TurtleBrains_Curve_hpp */
Definition: tb_curve.hpp:23
float CalculateLength(const size_t stepsPerSection=25) const
static BezierCurve FromCatMullRomBeau(const std::vector< tbMath::Vector3 > &points, bool isLoop)
void MakeLinesBySteps(std::vector< tbMath::Vector3 > &points, const size_t &stepsPerSection=25) const
static BezierCurve FromCatMullRom(const std::vector< tbMath::Vector3 > &points, bool isLoop)
bool IsClosedLoop(void) const
Definition: tb_curve.hpp:60
void GetPositionsByDistance(std::vector< tbMath::Vector3 > &points, const float maxLineLength, const size_t stepsPerSection) const
Definition: tb_vector.hpp:472
Contains objects and functions for dealing with Vector and Matrix math.
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:22
Definition: tb_curve.hpp:119