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
|
#include "animation_constants.hpp"
#include "screen_animations.hpp"
#include "screen_operations.hpp"
#include "animation/follow_animation.hpp"
#include "animation/linear_animation.hpp"
#include "animation/scale_animation.hpp"
#include "animation/sequence_animation.hpp"
namespace df
{
string const kPrettyMoveAnim = "PrettyMove";
string const kPrettyFollowAnim = "PrettyFollow";
string const kParallelFollowAnim = "ParallelFollow";
string const kParallelLinearAnim = "ParallelLinear";
drape_ptr<SequenceAnimation> GetPrettyMoveAnimation(ScreenBase const & startScreen, ScreenBase const & endScreen)
{
return GetPrettyMoveAnimation(startScreen, startScreen.GetScale(), endScreen.GetScale(),
startScreen.GetOrg(), endScreen.GetOrg());
}
drape_ptr<SequenceAnimation> GetPrettyMoveAnimation(ScreenBase const & screen,
m2::AnyRectD const & startRect, m2::AnyRectD const & endRect)
{
double const startScale = CalculateScale(screen.PixelRect(), startRect.GetLocalRect());
double const endScale = CalculateScale(screen.PixelRect(), endRect.GetLocalRect());
return GetPrettyMoveAnimation(screen, startScale, endScale, startRect.GlobalCenter(), endRect.GlobalCenter());
}
drape_ptr<SequenceAnimation> GetPrettyMoveAnimation(ScreenBase const & screen, double startScale, double endScale,
m2::PointD const & startPt, m2::PointD const & endPt)
{
double const moveDuration = PositionInterpolator::GetMoveDuration(startPt, endPt, screen.PixelRectIn3d(), startScale);
ASSERT_GREATER(moveDuration, 0.0, ());
double const scaleFactor = moveDuration / kMaxAnimationTimeSec * 2.0;
auto sequenceAnim = make_unique_dp<SequenceAnimation>();
sequenceAnim->SetCustomType(kPrettyMoveAnim);
auto zoomOutAnim = make_unique_dp<MapLinearAnimation>();
zoomOutAnim->SetScale(startScale, startScale * scaleFactor);
zoomOutAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5);
//TODO (in future): Pass fixed duration instead of screen.
auto moveAnim = make_unique_dp<MapLinearAnimation>();
moveAnim->SetMove(startPt, endPt, screen);
moveAnim->SetMaxDuration(kMaxAnimationTimeSec);
auto zoomInAnim = make_unique_dp<MapLinearAnimation>();
zoomInAnim->SetScale(startScale * scaleFactor, endScale);
zoomInAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5);
sequenceAnim->AddAnimation(move(zoomOutAnim));
sequenceAnim->AddAnimation(move(moveAnim));
sequenceAnim->AddAnimation(move(zoomInAnim));
return sequenceAnim;
}
drape_ptr<SequenceAnimation> GetPrettyFollowAnimation(ScreenBase const & startScreen, m2::PointD const & userPos, double targetScale,
double targetAngle, m2::PointD const & endPixelPos)
{
auto sequenceAnim = make_unique_dp<SequenceAnimation>();
sequenceAnim->SetCustomType(kPrettyFollowAnim);
m2::RectD const viewportRect = startScreen.PixelRectIn3d();
ScreenBase tmp = startScreen;
tmp.SetAngle(targetAngle);
tmp.MatchGandP3d(userPos, viewportRect.Center());
double const moveDuration = PositionInterpolator::GetMoveDuration(startScreen.GetOrg(), tmp.GetOrg(), startScreen);
ASSERT_GREATER(moveDuration, 0.0, ());
double const scaleFactor = moveDuration / kMaxAnimationTimeSec * 2.0;
tmp = startScreen;
if (moveDuration > 0.0)
{
tmp.SetScale(startScreen.GetScale() * scaleFactor);
auto zoomOutAnim = make_unique_dp<MapLinearAnimation>();
zoomOutAnim->SetScale(startScreen.GetScale(), tmp.GetScale());
zoomOutAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5);
sequenceAnim->AddAnimation(move(zoomOutAnim));
tmp.MatchGandP3d(userPos, viewportRect.Center());
auto moveAnim = make_unique_dp<MapLinearAnimation>();
moveAnim->SetMove(startScreen.GetOrg(), tmp.GetOrg(), viewportRect, tmp.GetScale());
moveAnim->SetMaxDuration(kMaxAnimationTimeSec);
sequenceAnim->AddAnimation(move(moveAnim));
}
auto followAnim = make_unique_dp<MapFollowAnimation>(tmp, userPos, endPixelPos,
targetScale, targetAngle,
false /* isAutoZoom */);
followAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5);
sequenceAnim->AddAnimation(move(followAnim));
return sequenceAnim;
}
drape_ptr<MapLinearAnimation> GetRectAnimation(ScreenBase const & startScreen, ScreenBase const & endScreen)
{
auto anim = make_unique_dp<MapLinearAnimation>();
anim->SetRotate(startScreen.GetAngle(), endScreen.GetAngle());
anim->SetMove(startScreen.GetOrg(), endScreen.GetOrg(),
startScreen.PixelRectIn3d(), (startScreen.GetScale() + endScreen.GetScale()) / 2.0);
anim->SetScale(startScreen.GetScale(), endScreen.GetScale());
anim->SetMaxScaleDuration(kMaxAnimationTimeSec);
return anim;
}
drape_ptr<MapLinearAnimation> GetSetRectAnimation(ScreenBase const & screen,
m2::AnyRectD const & startRect, m2::AnyRectD const & endRect)
{
auto anim = make_unique_dp<MapLinearAnimation>();
double const startScale = CalculateScale(screen.PixelRect(), startRect.GetLocalRect());
double const endScale = CalculateScale(screen.PixelRect(), endRect.GetLocalRect());
anim->SetRotate(startRect.Angle().val(), endRect.Angle().val());
anim->SetMove(startRect.GlobalCenter(), endRect.GlobalCenter(), screen);
anim->SetScale(startScale, endScale);
anim->SetMaxScaleDuration(kMaxAnimationTimeSec);
return anim;
}
drape_ptr<MapFollowAnimation> GetFollowAnimation(ScreenBase const & startScreen, m2::PointD const & userPos,
double targetScale, double targetAngle, m2::PointD const & endPixelPos,
bool isAutoZoom)
{
auto anim = make_unique_dp<MapFollowAnimation>(startScreen, userPos, endPixelPos, targetScale, targetAngle, isAutoZoom);
anim->SetMaxDuration(kMaxAnimationTimeSec);
return anim;
}
drape_ptr<MapScaleAnimation> GetScaleAnimation(ScreenBase const & startScreen, m2::PointD pxScaleCenter,
m2::PointD glbScaleCenter, double factor)
{
ScreenBase endScreen = startScreen;
ApplyScale(pxScaleCenter, factor, endScreen);
auto anim = make_unique_dp<MapScaleAnimation>(startScreen.GetScale(), endScreen.GetScale(),
glbScaleCenter, pxScaleCenter);
anim->SetMaxDuration(kMaxAnimationTimeSec);
return anim;
}
} // namespace df
|