aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers/BezierCurve.hpp
blob: 1b9144a8f74b481e33c4545b0d0682af44a7c1ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include <vector>
#include <array>
#include <vector>
#include "math/Math.hpp"

constexpr int   BAKEDPOINTS    = 255;
constexpr float INVBAKEDPOINTS = 1.f / BAKEDPOINTS;

// an implementation of a cubic bezier curve
// might do better later
class CBezierCurve {
  public:
    // sets up the bezier curve.
    // this EXCLUDES the 0,0 and 1,1 points,
    void  setup(std::vector<Vector2D>* points);

    float getYForT(float const& t);
    float getXForT(float const& t);
    float getYForPoint(float const& x);

  private:
    // this INCLUDES the 0,0 and 1,1 points.
    std::vector<Vector2D>             m_vPoints;

    std::array<Vector2D, BAKEDPOINTS> m_aPointsBaked;
};