-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulation.pde
More file actions
76 lines (57 loc) · 1.98 KB
/
Copy pathSimulation.pde
File metadata and controls
76 lines (57 loc) · 1.98 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
public static PVector robotPos;
public static int currentSegment = 0;
public static float t = 0.0;
public static float speed = 0.02;
public static boolean isSimulating = false;
public static float robotWidth_mm = 287;
public static float robotHeight_mm = 284;
public static float robotHitbox_mm = 400;
public static float robotSpeed_mm_per_sec = 600.0; // vitesse constante
public static float frameRateSim = 60.0; // fréquence cible
PImage robotImg;
void updateSimulation() {
if (!isSimulating || StrategyEditor.points.size() < 2) return;
if (currentSegment >= StrategyEditor.points.size() - 1) {
isSimulating = false;
println("[SIM] End of path");
return;
}
StrategyPoint p1 = StrategyEditor.points.get(currentSegment);
StrategyPoint p2 = StrategyEditor.points.get(currentSegment + 1);
float dx = p2.x_mm - p1.x_mm;
float dy = p2.y_mm - p1.y_mm;
float dist_mm = dist(p1.x_mm, p1.y_mm, p2.x_mm, p2.y_mm);
float duration_sec = dist_mm / robotSpeed_mm_per_sec;
float totalFrames = duration_sec * frameRateSim;
float deltaT = 1.0 / totalFrames;
float easedT = easeInOut(t);
float x = lerp(p1.x_mm, p2.x_mm, easedT);
float y = lerp(p1.y_mm, p2.y_mm, easedT);
robotPos.set(x, y);
t += deltaT;
if (t >= 1.0) {
t = 0.0;
currentSegment++;
}
}
void drawRobot(PGraphics pg, float scale) {
if (!isSimulating || robotPos == null) return;
float robotWidth_px = robotWidth_mm * StrategyEditor.mmToPx;
float robotHeight_px = robotHeight_mm * StrategyEditor.mmToPx;
float hitbox_px = robotHitbox_mm * StrategyEditor.mmToPx;
float px = robotPos.x * scale;
float py = robotPos.y * scale;
pg.pushMatrix();
pg.pushStyle();
pg.translate(px, py);
pg.imageMode(CENTER);
pg.fill(255, 0, 0, 127);
pg.stroke(255, 0, 0);
pg.ellipse(0, 0, hitbox_px, hitbox_px);
pg.image(robotImg, 0, 0, robotWidth_px, robotHeight_px);
pg.popStyle();
pg.popMatrix();
}
float easeInOut(float t) {
return t * t * (3 - 2 * t); // interpolation douce entre 0 et 1
}