-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.pde
156 lines (144 loc) · 3.89 KB
/
Rectangle.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
class Rectangle implements Shape {
float x, y, z;
int wid, len;
color fill, stroke;
float buildingHeight;
PImage texture;
float[] terrainHeights = new float[4];
Rectangle(float x, float y, float z, int wid, int len, PImage text) {
this(x, y, z, wid, len, color(55), color(55), text);
}
Rectangle(float x, float y, float z, int wid, int len, color fill) {
this(x, y, z, wid, len, fill, color(55), null);
}
Rectangle(float x, float y, float z, int wid, int len, color fill, color stroke, PImage texture) {
// generate random shapes
this.x = x;
this.y = y;
this.z = z;
this.wid = wid;
this.len = len;
this.fill = fill;
this.stroke = stroke;
this.texture = texture;
this.terrainHeights[0] = cMap.getHeightAt(x, y);
this.terrainHeights[1] = cMap.getHeightAt(x, y+len);
this.terrainHeights[2] = cMap.getHeightAt(x+wid, y);
this.terrainHeights[3] = cMap.getHeightAt(x+wid, y+len);
this.z = max(terrainHeights);
}
void display2D() {
fill(fill);
//stroke(stroke);
// println(x, map(x, 0, GRID_WIDTH, 0, width), width*(this.wid/(float)GRID_WIDTH));
rect(x, y, wid,len);
}
void display() {
// make top
fill(55);
//stroke(stroke);
beginShape();
vertex(x, y, this.z+this.buildingHeight);
vertex(x, y+len, this.z+this.buildingHeight);
vertex(x+wid, y+len, this.z+this.buildingHeight);
vertex(x+wid, y, this.z+this.buildingHeight);
endShape();
fill(fill);
// make front
beginShape();
if(texture != null){
texture(texture);
}
vertex(x, y, this.z, 0, 0);
vertex(x, y, this.z+this.buildingHeight, 0, 1);
vertex(x+wid, y, this.z+this.buildingHeight, 1, 1);
vertex(x+wid, y, this.z, 1, 0);
endShape();
// make back
beginShape();
if(texture != null){
texture(texture);
}
vertex(x+wid, y+len, this.z, 0, 0);
vertex(x+wid, y+len, this.z+this.buildingHeight, 0, 1);
vertex(x, y+len, this.z+this.buildingHeight, 1, 1);
vertex(x, y+len, this.z, 1, 0);
endShape();
// make right
beginShape();
if(texture != null){
texture(texture);
}
vertex(x, y, this.z, 0, 0);
vertex(x, y, this.z+this.buildingHeight, 0, 1);
vertex(x, y+len, this.z+this.buildingHeight, 1, 1);
vertex(x, y+len, this.z, 1, 0);
endShape();
// make left
beginShape();
if(texture != null){
texture(texture);
}
vertex(x+wid, y, this.z, 0, 0);
vertex(x+wid, y, this.z+this.buildingHeight, 0, 1);
vertex(x+wid, y+len, this.z+this.buildingHeight, 1, 1);
vertex(x+wid, y+len, this.z, 1, 0);
endShape();
drawBase();
}
void drawBase() {
fill(100);
// make front
beginShape();
vertex(x, y, this.z);
vertex(x, y, terrainHeights[0]);
vertex(x+wid, y, terrainHeights[2]);
vertex(x+wid, y, this.z);
endShape();
// make back
beginShape();
vertex(x+wid, y+len, this.z);
vertex(x+wid, y+len, terrainHeights[3]);
vertex(x, y+len, terrainHeights[1]);
vertex(x, y+len, this.z);
endShape();
// make right
beginShape();
vertex(x, y, this.z);
vertex(x, y, terrainHeights[0]);
vertex(x, y+len, terrainHeights[1]);
vertex(x, y+len, this.z);
endShape();
// make left
beginShape();
vertex(x+wid, y, this.z);
vertex(x+wid, y, terrainHeights[2]);
vertex(x+wid, y+len, terrainHeights[3]);
vertex(x+wid, y+len, this.z);
endShape();
}
boolean containsPoint(int x1, int y1) {
return (x1 >= x && x1 <= x+wid && y1 >= y && y1 <= y+len);
}
float getArea() {
return wid*len;
}
color getFill() {
return fill;
}
color getStroke() {
return stroke;
}
void setFill(color fill) {
this.fill = fill;
}
void setStroke(color stroke) {
this.stroke = stroke;
}
float getHeight() {
return this.buildingHeight;
}
void setHeight(float h) {
this.buildingHeight = h;
}
}