-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuitbots.cpp
More file actions
131 lines (112 loc) · 2.94 KB
/
Suitbots.cpp
File metadata and controls
131 lines (112 loc) · 2.94 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
/* (c) oblong industries */
#include "Greenhouse.h"
#include <cmath>
#include <algorithm>
class Handler : public Thing {
private:
double max_size { -1.0 };
bool zoomed { false };
Node* currently_active { nullptr };
public:
Handler ()
{ TranslationAnimateAsymp (2.0);
SetTranslationHard (Vect { .0, .0, .0 });
}
void Add (const Str& nam_)
{ Str nam { nam_ }; // ug. Stupid mutable regexp.
if (nam . Match (".*\\.[Jj][Pp][eE]?[Gg]") ||
nam . Match (".*\\.[Pp][Nn][Gg]"))
AddImage (nam);
else
AddVideo (nam);
}
template <typename T>
void AdjustMaxSize (T* t)
{ if (0.0 > max_size) max_size = t -> Diagonal ();
else max_size = std::min (max_size, t -> Diagonal ());
}
void AddVideo (const Str& nam)
{ Video *v = new Video (nam);
v -> EnableLooping ();
v -> SetVolume (0.0);
v -> Play ();
AppendKid (v);
AdjustMaxSize (v);
}
void AddImage (const Str& nam)
{ Image *img = new Image (nam);
AppendKid (img);
AdjustMaxSize (img);
}
Vect KidLoc (const int i)
{ const int N = KidCount ();
const double RN = std::sqrt (N);
const double A = FeldAspect (Feld ());
const int COLS = RN * A;
const int x = i % COLS;
const int y = i / COLS;
const double Z = RN * max_size / 3.0;
return Vect { (x - COLS / 2) * max_size, (y - (N / COLS) / 2) * max_size, - Z };
}
void Rejigger ()
{ const int N = KidCount ();
for (int i = 0; i < N; ++i)
{ Node* n = NthKid (i);
n -> SetTranslation (KidLoc (i));
SetDiagonal (n);
}
}
void SetDiagonal (Node *n)
{ if (Image* i = dynamic_cast<Image*> (n))
i -> SetDiagonal (max_size);
else if (Video* v = dynamic_cast<Video*> (n))
v -> SetDiagonal (max_size);
}
void Activate (Node *n)
{ if (n) n -> Heartbeat ();
if (Video *v = dynamic_cast<Video*> (n))
{ if (n == currently_active)
v -> Rewind ();
v -> SetVolume (1.0);
}
}
void Deactivate (Node *n)
{ if (Video *v = dynamic_cast<Video*> (n))
{ v -> SetVolume (0.0);
}
}
bool HitAnAsset (PointingEvent *e)
{ const int N = KidCount ();
for (int i = 0; i < N; ++i)
{ Node *n = NthKid (i);
if (n -> HitCheck (e))
{ Deactivate (currently_active);
Activate (n);
currently_active = n;
SetTranslation (- KidLoc (i));
return true;
}
}
return false;
}
void PointingHarden (PointingEvent *e)
{ const bool hit = HitAnAsset (e);
if (zoomed && !hit)
{ SetTranslation (Vect { .0, .0, .0 });
zoomed = false;
if (nullptr != currently_active)
{ Deactivate (currently_active);
currently_active = nullptr;
}
}
else zoomed = hit;
}
};
void Setup ()
{ SetFeldsColor (Color {0.0, 0.0, 0.0, 0.0});
Handler *h = new Handler {};
h -> SlapOnFeld ();
for (auto arg : args)
h -> Add (arg);
h -> Rejigger ();
}