-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapDisplay.pde
227 lines (161 loc) · 5.56 KB
/
MapDisplay.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
public class MapDisplay{
public static final int MAX_HEIGHT = 1000;
public static final int ARRIVAL_STEPS = 20;
public static final int ROUND_UP_DISTANCE = 5;
public static final int TARGET_DISTANCE = 50;
public static final int MAX_RANDOMIZER = 30;
public boolean drawTarget, showBox = true;
public PVector origin, object, target, velocity, distance;
public int ogx, ogy,x, y, dx, dy;
public int diameter, smalldiameter = 20;
public int boxOffsetY = 20, boxSizeX = 150, boxSizeY = 100;
public int textBoxGap = 25, textBoxOffsetX = 10;
public int randomCounter, randomizer;
public int fontSize = 20;
public color mapColor = color(200),
originColor = color(20,200,200),
objectColor = color(200,100,50),
targetColor = color(20,200,50);
private PImage mapImage;
public float finalX = 0.00;
public float finalY = 0.00;
public float finalZ = 0.00;
public float finalVx = 0.00;
public float finalVy = 0.00;
public float finalVz = 0.00;
public MapDisplay(int ogx, int ogy, int dx, int dy){
this.ogx = ogx;
this.ogy = ogy;
this.dx = dx;
this.dy = dy;
this.x = ogx - dx / 2;
this.y = ogy -dy / 2;
this.diameter = (dx + dy) / 2 - 1;
origin = new PVector(ogx, ogy, 0);
object = new PVector(origin.x, origin.y, origin.z);
target = new PVector(origin.x, origin.y, origin.z);
velocity = new PVector(0, 0, 0);
mapImage = loadImage("map.png");
}
public void draw(){
update();
int tz = 1;
translate(0,0,tz);
stroke(200);
fill(backgroundColor);
image(mapImage, ogx - dx/2, ogy - dy/2, dx, dy );
textSize(fontSize);
if(drawTarget){
translate(0,0,tz);
fill(targetColor);
circle(target.x, target.y, smalldiameter);
}
translate(0,0,tz);
fill(originColor);
circle(origin.x, origin.y, smalldiameter);
translate(0,0,tz);
fill(objectColor);
circle(object.x, object.y, smalldiameter);
if(showBox){
fill(255);
translate(0,0,tz);
rect(object.x - boxSizeX / 2, object.y - (boxSizeY + boxOffsetY), boxSizeX, boxSizeY);
PVector dist = getDistanceAsVector();
fill(0);
translate(0,0,tz);
text("x: " + (int)dist.x + "m", object.x - boxSizeX / 2 + textBoxOffsetX, object.y - boxSizeY);
text("y: " + (int)dist.y + "m", object.x - boxSizeX / 2 + textBoxOffsetX, object.y - boxSizeY + textBoxGap * 1 );
text("z: " + (int)dist.z + "m", object.x - boxSizeX / 2 + textBoxOffsetX, object.y - boxSizeY + textBoxGap * 2 );
text("total: " + (int)getDistance() + "m", object.x - boxSizeX / 2 + textBoxOffsetX, object.y - boxSizeY + textBoxGap * 3 );
}
translate(0,0,-6*tz);
}
public void update(){
finalX = rocketDisplay.finalX4;
finalY = rocketDisplay.finalY1;
finalZ = rocketDisplay.finalZ4;
finalVx = rocketDisplay.finalVx4;
finalVy = rocketDisplay.finalVy1;
finalVz = rocketDisplay.finalVz4;
moveRandomly();
}
void moveRandomly(){
randomCounter++;
if(randomCounter > randomizer){
randomizer = (int)random(MAX_RANDOMIZER);
randomCounter = 0;
moveObject(true);
}
if(sameVector(target, object)){
moveObject(true);
}else{
if(PVector.dist(object, target) < ROUND_UP_DISTANCE){
object.set(target.x, target.y, target.z);
moveObject(true);
}
object.add(velocity);
}
}
public void moveObject(boolean around){
createNewTarget(around);
createNewVelocity();
if(around){
while(PVector.dist(target, origin) > diameter / 2){
createNewTarget(around);
createNewVelocity();
}
}
}
public void createNewTarget(boolean around){
float angle = random(360);
if(around){
target.x = ((cos(radians(angle))) * TARGET_DISTANCE) * random(1) + object.x;
target.y = ((sin(radians(angle))) * TARGET_DISTANCE) * random(1) + object.y;
target.z = random(MAX_HEIGHT);
}else{
target.x = ((cos(radians(angle))) * diameter / 2) * random(1) + ogx;
target.y = ((sin(radians(angle))) * diameter / 2) * random(1) + ogy;
target.z = random(MAX_HEIGHT);
}
}
public void createNewVelocity(){
velocity = new PVector((target.x - object.x) / ARRIVAL_STEPS,
(target.y - object.y) / ARRIVAL_STEPS,
(target.z - object.z) / ARRIVAL_STEPS
);
}
public boolean sameVector(PVector v1, PVector v2){
if(v1.x == v2.x){
if(v1.y == v2.y){
if(v1.z == v2.z){
return true;
}
}
}
return false;
}
public PVector generateRandomVector(int x, int xx, int y, int yy, int z, int zz){
return new PVector(
(int)(random(x, xx)),
(int)(random(y ,yy)),
(int)(random(z, zz))
);
}
public PVector getDistanceAsVector(){
return new PVector(
abs(origin.x - object.x),
abs(origin.y - object.y),
abs(origin.z - object.z)
);
}
public float getDistance(){
return PVector.dist(origin, object);
}
void mousePressed(){
if(mouseX > x && mouseX < x + dx){
if(mouseY > y && mouseY < y + dy){
showBox = !showBox;
}
}
}
}