-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreset.pde
54 lines (45 loc) · 1.31 KB
/
Preset.pde
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
public class PresetPoint{
public float c1;
public float c2;
public float rotation;
public PresetPoint(float c1, float c2, float rotation){
this.c1 = c1;
this.c2 = c2;
this.rotation = rotation;
}
public JSONObject toJSON(){
JSONObject json = new JSONObject();
json.setFloat("c1", c1);
json.setFloat("c2", c2);
json.setFloat("rotation", rotation);
return json;
}
public PresetPoint lerpTo(PresetPoint next, float t){
return new PresetPoint(lerp(this.c1, next.c1, t),
lerp(this.c2, next.c2, t),
lerp(this.rotation, next.rotation, t));
}
public PresetPoint normalizedRotation(){
return new PresetPoint(this.c1, this.c2, this.rotation % (2*PI));
}
}
public class Preset{
PresetPoint start;
PresetPoint end;
public Preset(PresetPoint start, PresetPoint end){
this.start = start;
this.end = end;
}
public JSONObject toJSON(){
JSONObject json = new JSONObject();
json.setJSONObject("start", start.toJSON());
json.setJSONObject("end", end.toJSON());
return json;
}
public PresetPoint getPresetState(float t){
return start.lerpTo(end, t);
}
public PresetPoint transition(Preset next, float t){
return this.end.normalizedRotation().lerpTo(next.start.normalizedRotation(), t);
}
}