added anim::SegmentInterpolation and MoveScreen animation tasks.

This commit is contained in:
rachytski 2012-09-28 20:37:21 +03:00 committed by Alex Zolotarev
parent 766d07bb94
commit 4f04b39a7a
9 changed files with 140 additions and 5 deletions

View file

@ -1,16 +1,11 @@
#pragma once
#include "task.hpp"
#include "../std/function.hpp"
namespace anim
{
class AngleInterpolation : public Task
{
public:
typedef function<void()> TCallback;
private:
double m_startAngle;

View file

@ -13,8 +13,10 @@ HEADERS += \
controller.hpp \
task.hpp \
angle_interpolation.hpp \
segment_interpolation.hpp \
SOURCES += \
controller.cpp \
task.cpp \
angle_interpolation.cpp \
segment_interpolation.cpp \

View file

@ -0,0 +1,48 @@
#include "segment_interpolation.hpp"
namespace anim
{
SegmentInterpolation::SegmentInterpolation(m2::PointD const & startPt,
m2::PointD const & endPt,
double interval,
m2::PointD & outPt)
: m_startPt(startPt),
m_endPt(endPt),
m_interval(interval),
m_outPt(outPt)
{
m_deltaPt = m_endPt - m_startPt;
}
void SegmentInterpolation::OnStart(double ts)
{
m_startTime = ts;
m_outPt = m_startPt;
Task::OnStart(ts);
}
void SegmentInterpolation::OnStep(double ts)
{
if (ts - m_startTime > m_interval)
{
End();
return;
}
if (!IsRunning())
return;
double elapsedSec = ts - m_startTime;
m_outPt = m_startPt + m_deltaPt * (elapsedSec / m_interval);
Task::OnStep(ts);
}
void SegmentInterpolation::OnEnd(double ts)
{
// ensuring that the final value was reached
m_outPt = m_endPt;
Task::OnEnd(ts);
}
}

View file

@ -0,0 +1,31 @@
#pragma once
#include "task.hpp"
#include "../geometry/point2d.hpp"
namespace anim
{
class SegmentInterpolation : public Task
{
private:
m2::PointD m_startPt;
m2::PointD m_endPt;
m2::PointD m_deltaPt;
m2::PointD & m_outPt;
double m_startTime;
double m_interval;
public:
SegmentInterpolation(m2::PointD const & startPt,
m2::PointD const & endPt,
double interval,
m2::PointD & outPt);
void OnStart(double ts);
void OnStep(double ts);
void OnEnd(double ts);
};
}

View file

@ -52,6 +52,7 @@ HEADERS += \
compass_arrow.hpp \
compass_filter.hpp \
animator.hpp \
move_screen_task.hpp
SOURCES += \
feature_vec_model.cpp \
@ -95,6 +96,7 @@ SOURCES += \
compass_arrow.cpp \
compass_filter.cpp \
animator.cpp \
move_screen_task.cpp
!iphone*:!bada*:!android* {
HEADERS += qgl_render_context.hpp
@ -113,3 +115,5 @@ SOURCES += \

26
map/move_screen_task.cpp Normal file
View file

@ -0,0 +1,26 @@
#include "move_screen_task.hpp"
#include "framework.hpp"
MoveScreenTask::MoveScreenTask(Framework * framework,
m2::PointD const & startPt,
m2::PointD const & endPt,
double interval)
: anim::SegmentInterpolation(startPt,
endPt,
interval,
m_outPt),
m_framework(framework)
{}
void MoveScreenTask::OnStep(double ts)
{
anim::SegmentInterpolation::OnStep(ts);
m_framework->GetNavigator().SetOrg(m_outPt);
}
void MoveScreenTask::OnEnd(double ts)
{
anim::SegmentInterpolation::OnEnd(ts);
m_framework->GetNavigator().SetOrg(m_outPt);
}

23
map/move_screen_task.hpp Normal file
View file

@ -0,0 +1,23 @@
#pragma once
#include "../anim/segment_interpolation.hpp"
class Framework;
class MoveScreenTask : public anim::SegmentInterpolation
{
private:
Framework * m_framework;
m2::PointD m_outPt;
public:
MoveScreenTask(Framework * framework,
m2::PointD const & startPt,
m2::PointD const & endPt,
double interval);
void OnStep(double ts);
void OnEnd(double ts);
};

View file

@ -588,6 +588,11 @@ void Navigator::SetAngle(double angle)
m_Screen.SetAngle(angle);
}
void Navigator::SetOrg(m2::PointD const & org)
{
m_Screen.SetOrg(org);
}
void Navigator::Move(double azDir, double factor)
{
m2::RectD const r = m_Screen.ClipRect();

View file

@ -48,6 +48,7 @@ public:
void Scale(double scale);
void Rotate(double angle);
void SetAngle(double angle);
void SetOrg(m2::PointD const & org);
void Move(double azDir, double factor);