-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVictory.cc
64 lines (57 loc) · 1.48 KB
/
Victory.cc
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
#include "Victory.h"
#include "Puzzle.h"
#include "Camera.h"
static CameraCoords cam_p0;
static double cam_R0;
static PuzzleCoords puz_p0;
VictoryAnimation::VictoryAnimation(Puzzle &puzzle, Camera &camera)
: puzzle(puzzle), camera(camera), t(0.0)
{
const int W = puzzle.W, H = puzzle.H;
cam_p0 = camera.center;
cam_R0 = camera.R;
puz_p0 = puzzle.N > 0 ? puzzle.pos[0]+P2d(W*0.5, H*0.5) : P2d(0,0);
puzzle.kill_animations();
}
static inline double S(double t) { assert(t >= 0.0 && t <= 1.0); return 0.5-0.5*cos(t*M_PI); }
void VictoryAnimation::run(double dt)
{
t += dt*4.0;
const int W = puzzle.W, H = puzzle.H;
const int w = camera.screen_w(), h = camera.screen_h();
double R = 1.125 * std::max(W*puzzle.sx*h, H*puzzle.sy*w) * 0.5 / std::max(w, h); // see Camera::view_box(...)
PuzzleCoords c(W*0.5, H*0.5);
if (t < 1.0)
{
double tt = S(t);
camera.set_R((1.0-tt)*cam_R0 + tt*R);
camera.center = cam_p0*(1.0-tt);
c += puz_p0*(1.0-tt);
}
else
{
camera.set_R(R);
camera.center.clear();
}
for (int y = 0; y < H; ++y)
{
for (int x = 0; x < W; ++x)
{
PuzzleCoords &p = puzzle.pos[W*y+x];
p.set(x-c.x, y-c.y);
#if 1
if (t < 1.0) { p.x *= 1.0+S(t); }
else if (t < 2.0) { p.x *= 2.0; p.y *= 1.0+S(t-1.0); }
else if (t < 3.0) { p *= 4.0-t; }
#else
if (t < 1.0) { p.x *= 1.0+t; }
else if (t < 2.0) { p.x *= 2.0; p.y *= t; }
else if (t < 3.0) { p *= 4.0-t; }
#endif
}
}
}
bool VictoryAnimation::done() const
{
return t >= 3.0;
}