/
lolshielddemo.cpp
199 lines (158 loc) · 3.68 KB
/
lolshielddemo.cpp
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
#include <WProgram.h>
#include <Charliplexing.h>
#include "tgl.h"
#include "settings.h"
extern "C" void __cxa_pure_virtual(void);
void __cxa_pure_virtual(void) {}
int frame = 0;
float cube[16][4] = {
{-1, -1, -1},
{ 1, -1, -1},
{ 1, 1, -1},
{-1, 1, -1},
{-1, -1, 1},
{ 1, -1, 1},
{ 1, 1, 1},
{-1, 1, 1}
};
int cubestrip1[] = {7,4,5,6,7,3,2,6};
int cubestrip2[] = {0,1,2,3,0,4,5,1};
#define N_SCENES 3
unsigned int timeline[] = {5000, 2500, 15000};
unsigned int timeline_cumsum[N_SCENES];
int scene = 0;
int scene_time = 0;
void initGL()
{
tglInit();
tglViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
tglMatrixMode(TGL_PROJECTION);
float aspect = (float)SCREEN_HEIGHT / (float)SCREEN_WIDTH;
tglFrustum(-1.0, 1.0, -aspect, aspect, 1.0, 5.0);
}
void setup()
{
LedSign::Init();
initGL();
unsigned int cumsum = 0;
for (int var = 0; var < N_SCENES; ++var) {
cumsum += timeline[var];
timeline_cumsum[var] = cumsum;
}
}
// DNA
inline void scene0(float scene_time) {
float offset = 3.14/2.0;
for(int i=0;i<14;++i) {
int high = (int)round((1.0+sin((float)(i+frame)/2))*4.5);
LedSign::Set(i,high,0);
}
for(int i=0;i<14;++i) {
int high = (int)round((1.0+sin(offset+(float)(i+frame)/2))*4.5);
LedSign::Set(i,high,0);
}
frame++;
for(int i=0;i<14;++i) {
int high = (int)round((1.0+sin((float)(i+frame)/2))*4.5);
LedSign::Set(i,high,1);
}
for(int i=0;i<14;++i) {
int high = (int)round((1.0+sin(offset+(float)(i+frame)/2))*4.5);
LedSign::Set(i,high,1);
}
delay(40);
}
// Zoom into the cube
inline void scene1(float scene_time)
{
tglClear(TGL_COLOR_BUFFER_BIT);
float min_zoom = -10;
float max_zoom = -2.5;
float zoom = min_zoom + (max_zoom-min_zoom) * (float)scene_time/timeline[scene];
tglMatrixMode(TGL_MODELVIEW);
tglLoadIdentity();
tglTranslatef(0, 0, zoom);
tglBegin(TGL_LINES);
for(int p=0; p<8; ++p) {
tglVertex3fv(cube[cubestrip1[p]]);
}
tglEnd();
tglBegin(TGL_LINES);
for(int p=0; p<8; ++p) {
tglVertex3fv(cube[cubestrip2[p]]);
}
tglEnd();
tglSwap();
delay(50);
}
// Spinning Cube!
inline void scene2(float scene_time)
{
int i = scene_time / 25;
tglClear(TGL_COLOR_BUFFER_BIT);
float zoom = 0;
if(scene_time > 5000)
zoom = 0.5*sin((float)(i-20)/10.0);
float rot_speed = 1.0;
if(scene_time > 12000)
rot_speed += (float)(scene_time - 12000) / 1500.0;
tglMatrixMode(TGL_MODELVIEW);
tglLoadIdentity();
tglTranslatef(0, 0, -2.5+zoom);
tglRotatef((float)(i % 360) * rot_speed, 0, 1, 0);
tglRotatef((float)(i % 360) * rot_speed, 1, 1, 0);
tglBegin(TGL_LINES);
for(int p=0; p<8; ++p) {
tglVertex3fv(cube[cubestrip1[p]]);
}
tglEnd();
tglBegin(TGL_LINES);
for(int p=0; p<8; ++p) {
tglVertex3fv(cube[cubestrip2[p]]);
}
tglEnd();
tglSwap();
}
void loop()
{
unsigned int abstime = millis() % timeline_cumsum[N_SCENES-1];
for (int var = 0; var < N_SCENES; ++var) {
if(timeline_cumsum[var] > abstime) {
scene = var;
break;
}
}
if(scene == 0)
scene_time = abstime;
else
scene_time = abstime - timeline_cumsum[scene-1];
/*
// Debug: Show Scene
LedSign::Set(0,0,0);
LedSign::Set(1,0,0);
LedSign::Set(2,0,0);
LedSign::Set(scene,0,1);
*/
switch(scene) {
case 0: {
scene0(scene_time);
break;
}
case 1: {
scene1(scene_time);
break;
}
case 2: {
scene2(scene_time);
break;
}
}
}
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}