curvedraw

view src/curve.h @ 2:ce7aa9a0594c

improved curve editing
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 17 Dec 2015 05:13:25 +0200
parents 8e524989c904
children 9f75208b81cd
line source
1 #ifndef CURVE_H_
2 #define CURVE_H_
4 #include <vector>
5 #include <vmath/vmath.h>
7 enum CurveType {
8 CURVE_LINEAR,
9 CURVE_HERMITE,
10 CURVE_BSPLINE
11 };
13 class Curve {
14 private:
15 std::vector<Vector3> cp;
16 CurveType type;
18 public:
19 Curve(CurveType type = CURVE_HERMITE);
21 void set_type(CurveType type);
22 CurveType get_type() const;
24 void add_point(const Vector2 &p, float weight = 1.0f);
25 bool remove_point(int idx);
27 int nearest_point(const Vector2 &p);
29 bool empty() const;
30 int size() const;
31 Vector3 &operator [](int idx);
32 const Vector3 &operator [](int idx) const;
34 const Vector3 &get_homo_point(int idx) const; // homogeneous point
35 Vector2 get_point(int idx) const;
36 float get_weight(int idx) const;
38 bool set_point(int idx, const Vector2 &p, float weight = 1.0f);
39 bool set_weight(int idx, float weight);
40 // move point without changing its weight
41 bool move_point(int idx, const Vector2 &p);
43 Vector2 interpolate(float t, CurveType type) const;
44 Vector2 interpolate(float t) const;
45 Vector2 operator ()(float t) const;
47 void draw(int res = -1) const;
48 void draw_cp(float sz = -1.0f) const;
49 };
51 #endif // CURVE_H_