-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecm_move.cpp
More file actions
470 lines (431 loc) · 21.7 KB
/
ecm_move.cpp
File metadata and controls
470 lines (431 loc) · 21.7 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
FLAMEGPU_HOST_DEVICE_FUNCTION void boundPosition(int id, float &x, float &y, float &z,
uint8_t &cxpos, uint8_t &cxneg, uint8_t &cypos, uint8_t &cyneg, uint8_t &czpos, uint8_t &czneg,
const float bxpos, const float bxneg, const float bypos, const float byneg, const float bzpos, const float bzneg,
const int clamp_on_xpos, const int clamp_on_xneg, const int clamp_on_ypos, const int clamp_on_yneg, const int clamp_on_zpos, const int clamp_on_zneg, const float ecm_boundary_equilibrium_distance) {
//if (id == 9 || id = 10) {
// printf("Boundposition ANTES agent %d position %2.4f, %2.4f, %2.4f -> boundary pos: [%2.4f, %2.4f, %2.4f, %2.4f, %2.4f, %2.4f], clamping: [%d, %d, %d, %d, %d, %d] \n", id, x, y, z, bxpos, bxneg, bypos, byneg, bzpos, bzneg, cxpos, cxneg, cypos, cyneg, czpos, czneg);
//}
float EPSILON = 0.00000001;
if (cxpos == 1) {
x = bxpos - ecm_boundary_equilibrium_distance; // redundant. Could say "do nothing"
} else {
if (x > bxpos || fabsf(x - bxpos) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_xpos == 1) {
cxpos = 1;
x = bxpos - ecm_boundary_equilibrium_distance;
}
}
}
if (cxneg == 1) {
x = bxneg + ecm_boundary_equilibrium_distance;
} else {
if (x < bxneg || fabsf(x - bxneg) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_xneg == 1) {
cxneg = 1;
x = bxneg + ecm_boundary_equilibrium_distance;
}
}
}
if (cypos == 1) {
y = bypos - ecm_boundary_equilibrium_distance;
} else {
if (y > bypos || fabsf(y - bypos) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_ypos == 1) {
cypos = 1;
y = bypos - ecm_boundary_equilibrium_distance;
}
}
}
if (cyneg == 1) {
y = byneg + ecm_boundary_equilibrium_distance;
} else {
if (y < byneg || fabsf(y - byneg) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_yneg == 1) {
cyneg = 1;
y = byneg + ecm_boundary_equilibrium_distance;
}
}
}
if (czpos == 1) {
z = bzpos - ecm_boundary_equilibrium_distance;
} else {
if (z > bzpos || fabsf(z - bzpos) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_zpos == 1) {
czpos = 1;
z = bzpos - ecm_boundary_equilibrium_distance;
}
}
}
if (czneg == 1) {
z = bzneg + ecm_boundary_equilibrium_distance;
}
else {
if (z < bzneg || fabsf(z - bzneg) < ecm_boundary_equilibrium_distance + EPSILON) {
if (clamp_on_zneg == 1) {
czneg = 1;
z = bzneg + ecm_boundary_equilibrium_distance;
}
}
}
//if (id == 9 || id = 10) {
// printf("Boundposition DESPUES agent %d position %2.4f, %2.4f, %2.4f -> boundary pos: [%2.4f, %2.4f, %2.4f, %2.4f, %2.4f, %2.4f], clamping: [%d, %d, %d, %d, %d, %d] \n", id, x, y, z, bxpos, bxneg, bypos, byneg, bzpos, bzneg, cxpos, cxneg, cypos, cyneg, czpos, czneg);
//}
}
FLAMEGPU_AGENT_FUNCTION(ecm_move, flamegpu::MessageNone, flamegpu::MessageNone) {
int id = FLAMEGPU->getVariable<int>("id");
//Agent position vector
float agent_x = FLAMEGPU->getVariable<float>("x");
float agent_y = FLAMEGPU->getVariable<float>("y");
float agent_z = FLAMEGPU->getVariable<float>("z");
int DEBUG_PRINTING = FLAMEGPU->environment.getProperty<int>("DEBUG_PRINTING");
// Agent velocity
float agent_vx = FLAMEGPU->getVariable<float>("vx");
float agent_vy = FLAMEGPU->getVariable<float>("vy");
float agent_vz = FLAMEGPU->getVariable<float>("vz");
// Agent clamps
uint8_t clamped_bx_pos = FLAMEGPU->getVariable<uint8_t>("clamped_bx_pos");
uint8_t clamped_bx_neg = FLAMEGPU->getVariable<uint8_t>("clamped_bx_neg");
uint8_t clamped_by_pos = FLAMEGPU->getVariable<uint8_t>("clamped_by_pos");
uint8_t clamped_by_neg = FLAMEGPU->getVariable<uint8_t>("clamped_by_neg");
uint8_t clamped_bz_pos = FLAMEGPU->getVariable<uint8_t>("clamped_bz_pos");
uint8_t clamped_bz_neg = FLAMEGPU->getVariable<uint8_t>("clamped_bz_neg");
// Agent force transmitted to clamped or elastic boundaries
float f_bx_pos = 0.0;
float f_bx_neg = 0.0;
float f_by_pos = 0.0;
float f_by_neg = 0.0;
float f_bz_pos = 0.0;
float f_bz_neg = 0.0;
float f_bx_pos_y = 0.0;
float f_bx_pos_z = 0.0;
float f_bx_neg_y = 0.0;
float f_bx_neg_z = 0.0;
float f_by_pos_x = 0.0;
float f_by_pos_z = 0.0;
float f_by_neg_x = 0.0;
float f_by_neg_z = 0.0;
float f_bz_pos_x = 0.0;
float f_bz_pos_y = 0.0;
float f_bz_neg_x = 0.0;
float f_bz_neg_y = 0.0;
// Mass of the ecm agent
const float mass = FLAMEGPU->getVariable<float>("mass");
//Forces acting on the agent
float agent_fx = FLAMEGPU->getVariable<float>("fx");
float agent_fy = FLAMEGPU->getVariable<float>("fy");
float agent_fz = FLAMEGPU->getVariable<float>("fz");
float agent_boundary_fx = FLAMEGPU->getVariable<float>("boundary_fx");
float agent_boundary_fy = FLAMEGPU->getVariable<float>("boundary_fy");
float agent_boundary_fz = FLAMEGPU->getVariable<float>("boundary_fz");
//Add the force coming from the boundaries
agent_fx += agent_boundary_fx;
agent_fy += agent_boundary_fy;
agent_fz += agent_boundary_fz;
if (DEBUG_PRINTING == 1 && (id == 9 || id == 10 || id == 14 || id == 25 || id == 26 || id == 29 || id == 30)){
printf("ECM move ID: %d clamps before -> (%d, %d, %d, %d, %d, %d)\n", id, clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg);
printf("ECM move ID: %d pos -> (%2.6f, %2.6f, %2.6f)\n", id, agent_x, agent_y, agent_z);
printf("ECM move ID: %d vel -> (%2.6f, %2.6f, %2.6f)\n", id, agent_vx, agent_vy, agent_vz);
printf("ECM move ID: %d f -> (%2.6f, %2.6f, %2.6f)\n", id, agent_fx, agent_fy, agent_fz);
printf("ECM move ID: %d bf -> (%2.6f, %2.6f, %2.6f)\n", id, agent_boundary_fx, agent_boundary_fy, agent_boundary_fz);
printf("ECM move ID: %d f after -> (%2.6f, %2.6f, %2.6f)\n", id, agent_fx, agent_fy, agent_fz);
}
//Get the new position and velocity:
// a(t) = f(t) / m;
// v(t) = v(t-1) + a(t) * dt;
// x(t) = x(t-1) + v(t) * dt
const float DELTA_TIME = FLAMEGPU->environment.getProperty<float>("DELTA_TIME");
//Bound the position within the environment
const float COORD_BOUNDARY_X_POS = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",0);
const float COORD_BOUNDARY_X_NEG = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",1);
const float COORD_BOUNDARY_Y_POS = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",2);
const float COORD_BOUNDARY_Y_NEG = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",3);
const float COORD_BOUNDARY_Z_POS = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",4);
const float COORD_BOUNDARY_Z_NEG = FLAMEGPU->environment.getProperty<float>("COORDS_BOUNDARIES",5);
const float DISP_RATE_BOUNDARY_X_POS = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",0);
const float DISP_RATE_BOUNDARY_X_NEG = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",1);
const float DISP_RATE_BOUNDARY_Y_POS = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",2);
const float DISP_RATE_BOUNDARY_Y_NEG = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",3);
const float DISP_RATE_BOUNDARY_Z_POS = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",4);
const float DISP_RATE_BOUNDARY_Z_NEG = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES",5);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_X_POS = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 0);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_X_NEG = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 1);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_Y_POS = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 2);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_Y_NEG = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 3);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_Z_POS = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 4);
const int CLAMP_AGENT_TOUCHING_BOUNDARY_Z_NEG = FLAMEGPU->environment.getProperty<int>("CLAMP_AGENT_TOUCHING_BOUNDARY", 5);
const int ALLOW_AGENT_SLIDING_X_POS = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 0);
const int ALLOW_AGENT_SLIDING_X_NEG = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 1);
const int ALLOW_AGENT_SLIDING_Y_POS = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 2);
const int ALLOW_AGENT_SLIDING_Y_NEG = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 3);
const int ALLOW_AGENT_SLIDING_Z_POS = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 4);
const int ALLOW_AGENT_SLIDING_Z_NEG = FLAMEGPU->environment.getProperty<int>("ALLOW_AGENT_SLIDING", 5);
const float ECM_BOUNDARY_EQUILIBRIUM_DISTANCE = FLAMEGPU->environment.getProperty<float>("ECM_BOUNDARY_EQUILIBRIUM_DISTANCE");
const float DISP_RATE_BOUNDARY_PARALLEL_X_POS_Y = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 0);
const float DISP_RATE_BOUNDARY_PARALLEL_X_POS_Z = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 1);
const float DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Y = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 2);
const float DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Z = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 3);
const float DISP_RATE_BOUNDARY_PARALLEL_Y_POS_X = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 4);
const float DISP_RATE_BOUNDARY_PARALLEL_Y_POS_Z = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 5);
const float DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_X = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 6);
const float DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_Z = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 7);
const float DISP_RATE_BOUNDARY_PARALLEL_Z_POS_X = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 8);
const float DISP_RATE_BOUNDARY_PARALLEL_Z_POS_Y = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 9);
const float DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_X = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 10);
const float DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_Y = FLAMEGPU->environment.getProperty<float>("DISP_RATES_BOUNDARIES_PARALLEL", 11);
float prev_agent_x = agent_x;
float prev_agent_y = agent_y;
float prev_agent_z = agent_z;
if ((clamped_bx_pos == 0) && (clamped_bx_neg == 0)) {
agent_vx += (agent_fx / mass) * DELTA_TIME;
agent_x += agent_vx * DELTA_TIME;
}
if ((clamped_by_pos == 0) && (clamped_by_neg == 0)) {
agent_vy += (agent_fy / mass) * DELTA_TIME;
agent_y += agent_vy * DELTA_TIME;
}
if ((clamped_bz_pos == 0) && (clamped_bz_neg == 0)) {
agent_vz += (agent_fz / mass) * DELTA_TIME;
agent_z += agent_vz * DELTA_TIME;
}
//if (id == 9 || id == 10 || id == 13 || id == 14 || id == 25 || id == 26 || id == 29 || id == 30) {
if (DEBUG_PRINTING == 1 && (id == 11 || id == 12 || id == 18)) {
printf("agent %d position ANTES (%2.4f, %2.4f, %2.4f) -> boundary pos: [%2.4f, %2.4f, %2.4f, %2.4f, %2.4f, %2.4f], clamping: [%d, %d, %d, %d, %d, %d] \n",id, agent_x,agent_y,agent_z, COORD_BOUNDARY_X_POS, COORD_BOUNDARY_X_NEG, COORD_BOUNDARY_Y_POS, COORD_BOUNDARY_Y_NEG, COORD_BOUNDARY_Z_POS, COORD_BOUNDARY_Z_NEG, clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg);
}
if (clamped_bx_pos == 1){
agent_x = COORD_BOUNDARY_X_POS - ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vx = DISP_RATE_BOUNDARY_X_POS;
f_bx_pos = agent_fx;
if (ALLOW_AGENT_SLIDING_X_POS == 0) {
f_bx_pos_y = agent_fy;
f_bx_pos_z = agent_fz;
if ((clamped_by_pos == 0) && (clamped_by_neg == 0)) { // this must be checked to avoid overwriting when agent is clamped to multiple boundaries
agent_y = prev_agent_y;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_X_POS_Y) > 0.0) {
agent_vy = DISP_RATE_BOUNDARY_PARALLEL_X_POS_Y;
agent_y += agent_vy * DELTA_TIME;
} else {
agent_vy = 0.0;
}
}
if ((clamped_bz_pos == 0) && (clamped_bz_neg == 0)) {
agent_z = prev_agent_z;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_X_POS_Z) > 0.0) {
agent_vz = DISP_RATE_BOUNDARY_PARALLEL_X_POS_Z;
agent_z += agent_vz * DELTA_TIME;
} else {
agent_vz = 0.0;
}
}
}
}
if (clamped_bx_neg == 1){
agent_x = COORD_BOUNDARY_X_NEG + ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vx = DISP_RATE_BOUNDARY_X_NEG;
f_bx_neg = agent_fx;
if (ALLOW_AGENT_SLIDING_X_NEG == 0) {
f_bx_neg_y = agent_fy;
f_bx_neg_z = agent_fz;
if ((clamped_by_pos == 0) && (clamped_by_neg == 0)) {
agent_y = prev_agent_y;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Y) > 0.0) {
agent_vy = DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Y;
agent_y += agent_vy * DELTA_TIME;
}
else {
agent_vy = 0.0;
}
}
if ((clamped_bz_pos == 0) && (clamped_bz_neg == 0)) {
agent_z = prev_agent_z;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Z) > 0.0) {
agent_vz = DISP_RATE_BOUNDARY_PARALLEL_X_NEG_Z;
agent_z += agent_vz * DELTA_TIME;
}
else {
agent_vz = 0.0;
}
}
}
}
if (clamped_by_pos == 1){
agent_y = COORD_BOUNDARY_Y_POS - ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vy = DISP_RATE_BOUNDARY_Y_POS;
f_by_pos = agent_fy;
if (ALLOW_AGENT_SLIDING_Y_POS == 0) {
f_by_pos_x = agent_fx;
f_by_pos_z = agent_fz;
if ((clamped_bx_pos == 0) && (clamped_bx_neg == 0)) {
agent_x = prev_agent_x;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Y_POS_X) > 0.0) {
agent_vx = DISP_RATE_BOUNDARY_PARALLEL_Y_POS_X;
agent_x += agent_vx * DELTA_TIME;
}
else {
agent_vx = 0.0;
}
}
if ((clamped_bz_pos == 0) && (clamped_bz_neg == 0)) {
agent_z = prev_agent_z;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Y_POS_Z) > 0.0) {
agent_vz = DISP_RATE_BOUNDARY_PARALLEL_Y_POS_Z;
agent_z += agent_vz * DELTA_TIME;
}
else {
agent_vz = 0.0;
}
}
}
}
if (clamped_by_neg == 1){
agent_y = COORD_BOUNDARY_Y_NEG + ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vy = DISP_RATE_BOUNDARY_Y_NEG;
f_by_neg = agent_fy;
if (ALLOW_AGENT_SLIDING_Y_NEG == 0) {
f_by_neg_x = agent_fx;
f_by_neg_z = agent_fz;
if ((clamped_bx_pos == 0) && (clamped_bx_neg == 0)) {
agent_x = prev_agent_x;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_X) > 0.0) {
agent_vx = DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_X;
agent_x += agent_vx * DELTA_TIME;
}
else {
agent_vx = 0.0;
}
}
if ((clamped_bz_pos == 0) && (clamped_bz_neg == 0)) {
agent_z = prev_agent_z;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_Z) > 0.0) {
agent_vz = DISP_RATE_BOUNDARY_PARALLEL_Y_NEG_Z;
agent_z += agent_vz * DELTA_TIME;
}
else {
agent_vz = 0.0;
}
}
}
}
if (clamped_bz_pos == 1){
agent_z = COORD_BOUNDARY_Z_POS - ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vz = DISP_RATE_BOUNDARY_Z_POS;
f_bz_pos = agent_fz;
if (ALLOW_AGENT_SLIDING_Z_POS == 0) {
f_bz_pos_x = agent_fx;
f_bz_pos_y = agent_fy;
if ((clamped_bx_pos == 0) && (clamped_bx_neg == 0)) {
agent_x = prev_agent_x;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Z_POS_X) > 0.0) {
agent_vx = DISP_RATE_BOUNDARY_PARALLEL_Z_POS_X;
agent_x += agent_vx * DELTA_TIME;
}
else {
agent_vx = 0.0;
}
}
if ((clamped_by_pos == 0) && (clamped_by_neg == 0)) {
agent_y = prev_agent_y;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Z_POS_Y) > 0.0) {
agent_vy = DISP_RATE_BOUNDARY_PARALLEL_Z_POS_Y;
agent_y += agent_vy * DELTA_TIME;
}
else {
agent_vy = 0.0;
}
}
}
}
if (clamped_bz_neg == 1){
agent_z = COORD_BOUNDARY_Z_NEG + ECM_BOUNDARY_EQUILIBRIUM_DISTANCE;
agent_vz = DISP_RATE_BOUNDARY_Z_NEG;
f_bz_neg = agent_fz;
if (ALLOW_AGENT_SLIDING_Z_NEG == 0) {
f_bz_neg_x = agent_fx;
f_bz_neg_y = agent_fy;
if ((clamped_bx_pos == 0) && (clamped_bx_neg == 0)) {
agent_x = prev_agent_x;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_X) > 0.0) {
agent_vx = DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_X;
agent_x += agent_vx * DELTA_TIME;
}
else {
agent_vx = 0.0;
}
}
if ((clamped_by_pos == 0) && (clamped_by_neg == 0)) {
agent_y = prev_agent_y;
if (fabsf(DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_Y) > 0.0) {
agent_vy = DISP_RATE_BOUNDARY_PARALLEL_Z_NEG_Y;
agent_y += agent_vy * DELTA_TIME;
}
else {
agent_vy = 0.0;
}
}
}
}
// Add forces from elastic boundaries (therefore, not clamped)
if (fabsf(agent_x - COORD_BOUNDARY_X_POS) > fabsf(agent_x - COORD_BOUNDARY_X_NEG)) { //if closer to xpos
f_bx_pos += agent_boundary_fx;// agent_boundary_fx will be 0 except for agents closer to boundaries
}
else {
f_bx_neg += agent_boundary_fx;
}
if (fabsf(agent_y - COORD_BOUNDARY_Y_POS) > fabsf(agent_y - COORD_BOUNDARY_Y_NEG)) { //if closer to ypos
f_by_pos += agent_boundary_fy; // agent_boundary_fy will be 0 except for agents closer to boundaries
}
else {
f_by_neg += agent_boundary_fy;
}
if (fabsf(agent_z - COORD_BOUNDARY_Z_POS) > fabsf(agent_z - COORD_BOUNDARY_Z_NEG)) { //if closer to zpos
f_bz_pos += agent_boundary_fz; // agent_boundary_fz will be 0 except for agents closer to boundaries
}
else {
f_bz_neg += agent_boundary_fz;
}
//if (id == 9 || id == 10 || id == 13 || id == 14 || id == 25 || id == 26 || id == 29 || id == 30) {
if (DEBUG_PRINTING == 1 && (id == 11 || id == 12 || id == 18)) {
printf("agent %d position EN MEDIO (%2.4f, %2.4f, %2.4f) -> boundary pos: [%2.4f, %2.4f, %2.4f, %2.4f, %2.4f, %2.4f], clamping: [%d, %d, %d, %d, %d, %d] \n", id, agent_x, agent_y, agent_z, COORD_BOUNDARY_X_POS, COORD_BOUNDARY_X_NEG, COORD_BOUNDARY_Y_POS, COORD_BOUNDARY_Y_NEG, COORD_BOUNDARY_Z_POS, COORD_BOUNDARY_Z_NEG, clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg);
}
boundPosition(id,agent_x, agent_y, agent_z,
clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg,
COORD_BOUNDARY_X_POS, COORD_BOUNDARY_X_NEG, COORD_BOUNDARY_Y_POS, COORD_BOUNDARY_Y_NEG, COORD_BOUNDARY_Z_POS, COORD_BOUNDARY_Z_NEG,
CLAMP_AGENT_TOUCHING_BOUNDARY_X_POS, CLAMP_AGENT_TOUCHING_BOUNDARY_X_NEG, CLAMP_AGENT_TOUCHING_BOUNDARY_Y_POS, CLAMP_AGENT_TOUCHING_BOUNDARY_Y_NEG, CLAMP_AGENT_TOUCHING_BOUNDARY_Z_POS, CLAMP_AGENT_TOUCHING_BOUNDARY_Z_NEG,
ECM_BOUNDARY_EQUILIBRIUM_DISTANCE);
//if (id == 9 || id == 10 || id == 13 || id == 14 || id == 25 || id == 26 || id == 29 || id == 30) {
if (DEBUG_PRINTING == 1 && (id == 11 || id == 12 || id == 18)) {
printf("agent %d position DESPUES (%2.4f, %2.4f, %2.4f) -> boundary pos: [%2.4f, %2.4f, %2.4f, %2.4f, %2.4f, %2.4f], clamping: [%d, %d, %d, %d, %d, %d] \n", id, agent_x, agent_y, agent_z, COORD_BOUNDARY_X_POS, COORD_BOUNDARY_X_NEG, COORD_BOUNDARY_Y_POS, COORD_BOUNDARY_Y_NEG, COORD_BOUNDARY_Z_POS, COORD_BOUNDARY_Z_NEG, clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg);
}
//printf("ECM move ID: %d clamps after -> (%d, %d, %d, %d, %d, %d)\n", id, clamped_bx_pos, clamped_bx_neg, clamped_by_pos, clamped_by_neg, clamped_bz_pos, clamped_bz_neg);
//Update the agents position and velocity
FLAMEGPU->setVariable<float>("x",agent_x);
FLAMEGPU->setVariable<float>("y",agent_y);
FLAMEGPU->setVariable<float>("z",agent_z);
FLAMEGPU->setVariable<float>("vx",agent_vx);
FLAMEGPU->setVariable<float>("vy",agent_vy);
FLAMEGPU->setVariable<float>("vz",agent_vz);
FLAMEGPU->setVariable<uint8_t>("clamped_bx_pos", clamped_bx_pos);
FLAMEGPU->setVariable<uint8_t>("clamped_bx_neg", clamped_bx_neg);
FLAMEGPU->setVariable<uint8_t>("clamped_by_pos", clamped_by_pos);
FLAMEGPU->setVariable<uint8_t>("clamped_by_neg", clamped_by_neg);
FLAMEGPU->setVariable<uint8_t>("clamped_bz_pos", clamped_bz_pos);
FLAMEGPU->setVariable<uint8_t>("clamped_bz_neg", clamped_bz_neg);
FLAMEGPU->setVariable<float>("f_bx_pos", f_bx_pos);
FLAMEGPU->setVariable<float>("f_bx_neg", f_bx_neg);
FLAMEGPU->setVariable<float>("f_by_pos", f_by_pos);
FLAMEGPU->setVariable<float>("f_by_neg", f_by_neg);
FLAMEGPU->setVariable<float>("f_bz_pos", f_bz_pos);
FLAMEGPU->setVariable<float>("f_bz_neg", f_bz_neg);
FLAMEGPU->setVariable<float>("f_bx_pos_y", f_bx_pos_y);
FLAMEGPU->setVariable<float>("f_bx_pos_z", f_bx_pos_z);
FLAMEGPU->setVariable<float>("f_bx_neg_y", f_bx_neg_y);
FLAMEGPU->setVariable<float>("f_bx_neg_z", f_bx_neg_z);
FLAMEGPU->setVariable<float>("f_by_pos_x", f_by_pos_x);
FLAMEGPU->setVariable<float>("f_by_pos_z", f_by_pos_z);
FLAMEGPU->setVariable<float>("f_by_neg_x", f_by_neg_x);
FLAMEGPU->setVariable<float>("f_by_neg_z", f_by_neg_z);
FLAMEGPU->setVariable<float>("f_bz_pos_x", f_bz_pos_x);
FLAMEGPU->setVariable<float>("f_bz_pos_y", f_bz_pos_y);
FLAMEGPU->setVariable<float>("f_bz_neg_x", f_bz_neg_x);
FLAMEGPU->setVariable<float>("f_bz_neg_y", f_bz_neg_y);
return flamegpu::ALIVE;
}