-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransformable.pde
86 lines (66 loc) · 1.76 KB
/
Transformable.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Transformable {
// attaributes
PVector _position;
float _rotation;
float _scale;
// constructor (without arguments)
public Transformable() {
_position = new PVector(0, 0);
_rotation = 0;
_scale = 1.0;
}
// constructor (with arguments)
public Transformable(int x, int y) {
_position = new PVector(x, y);
_rotation = 0;
_scale = 1.0;
}
/////////////////////////////////
// (absolute) transforms
public void rotate_to(float r) {
_rotation = r;
}
public void translate_to(float x, float y) {
_position.x = x;
_position.y = y;
}
public void scale_to(float s) {
_scale = s;
}
///////////////////////////////////
// (incremental) transforms
public void rotate_increment(float r) {
_rotation += r;
}
public void translate_increment(float x, float y) {
_position.x += x;
_position.y += y;
}
public void scale_increment(float s) {
_scale += s;
}
///////////////////////////////////
// display method
// + applies transformations
// + draws shape of the subclass
public void display() {
pushMatrix();
translate(_position.x, _position.y);
rotate(_rotation);
scale(_scale);
draw_shape();
popMatrix();
}
///////////////////////////////////
// helper method - distance_from
// + computes distance from other position
public float distance_from(int x, int y) {
return dist(_position.x, _position.y, x, y);
}
///////////////////////////////////
// ** METHODS FOR SUBCLASSES **
// draws a (subclass) shape (in own coordinates)
public void draw_shape(){}
// evaluates if mx and my are inside the (subclass) shape
public boolean inside(int mx, int my){return false;}
};