forked from osuripple/oppai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curves.h
64 lines (52 loc) · 1.43 KB
/
curves.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "types.h"
#include "v2f.h"
#include <stdlib.h>
#include <vector>
// ported from osu-web
// gets a point on a line.
//
// p1, p2: the two points that define the line
// t: how far into the line we are (0.0 would be p1 and 1.0 would be p2)
v2f pt_on_line(const v2f& p1, const v2f& p2, f64 t);
// generic curve code that can be reused in all curves
class curve {
public:
// copies pts to the curve's points
void init(const v2f* pts, size_t npts);
// calculates a point on the curve.
// t: how far into the curve we are (0.0-1.0)
virtual v2f at(f64 t) const = 0;
// compute points for the entire curve at a fixed internal granularity.
// (calls .at to do this by default)
// dst: the vector that will store the points.
virtual void compute(std::vector<v2f>* dst) const;
protected:
std::vector<v2f> points;
};
struct circle {
v2f c; // center
f64 r; // radius
};
class circular_arc : public curve {
public:
// copies 3 points from pts to the curve's points and sets length.
// len is the length of the circular arc, in the same units and scale as the
// points.
void init(const v2f* pts, f64 len);
virtual v2f at(f64 t) const;
protected:
f64 len;
circle c;
};
class bezier : public curve {
public:
virtual v2f at(f64 t) const;
};
class catmull : public curve {
public:
virtual v2f at(f64 t) const;
virtual void compute(std::vector<v2f>* dst) const;
protected:
v2f compute_single_point(size_t i, f64 t) const;
};