[drape] model view angle interpolation

This commit is contained in:
ExMix 2015-05-14 13:29:50 +03:00 committed by r.kuznetsov
parent 7ee6104bc9
commit f7d97541ae
10 changed files with 74 additions and 9 deletions

View file

@ -6,10 +6,10 @@
namespace df
{
class BaseViewportAnimation : public BaseInterpolator
class BaseModeViewAnimation : public BaseInterpolator
{
public:
BaseViewportAnimation(double duration) : BaseInterpolator(duration) {}
BaseModeViewAnimation(double duration) : BaseInterpolator(duration) {}
virtual void Apply(Navigator & navigator) = 0;
};

View file

@ -1,12 +1,26 @@
#include "drape_frontend/animation/interpolations.hpp"
#include "geometry/angles.hpp"
namespace df
{
m2::PointD Interpolate(m2::PointD const & startPt, m2::PointD const & endPt, double t)
m2::PointD InterpolatePoint(m2::PointD const & startPt, m2::PointD const & endPt, double t)
{
m2::PointD diff = endPt - startPt;
return startPt + diff * t;
}
InerpolateAngle::InerpolateAngle(double startAngle, double endAngle)
{
m_startAngle = ang::AngleIn2PI(startAngle);
m_delta = ang::GetShortestDistance(m_startAngle, ang::AngleIn2PI(endAngle));
}
double InerpolateAngle::Interpolate(double t)
{
return m_startAngle + m_delta * t;
}
} // namespace df

View file

@ -4,5 +4,16 @@
namespace df
{
m2::PointD Interpolate(m2::PointD const & startPt, m2::PointD const & endPt, double t);
m2::PointD InterpolatePoint(m2::PointD const & startPt, m2::PointD const & endPt, double t);
class InerpolateAngle
{
public:
InerpolateAngle(double startAngle, double endAngle);
double Interpolate(double t);
private:
double m_startAngle;
double m_delta;
};
} // namespace df

View file

@ -0,0 +1,20 @@
#include "modelview_angle_animation.hpp"
namespace df
{
ModelViewAngleAnimation::ModelViewAngleAnimation(double startAngle, double endAngle, double duration)
: BaseViewportAnimation(duration)
, m_angle(startAngle, endAngle)
{
}
void ModelViewAngleAnimation::Apply(Navigator & navigator)
{
double resultAngle = m_angle.Interpolate(GetT());
m2::AnyRectD r = navigator.Screen().GlobalRect();
r.SetAngle(resultAngle);
navigator.SetFromRect(r);
}
}

View file

@ -0,0 +1,19 @@
#pragma once
#include "drape_frontend/animation/base_viewport_animation.hpp"
#include "drape_frontend/animation/interpolations.hpp"
namespace df
{
class ModelViewAngleAnimation : public BaseViewportAnimation
{
public:
ModelViewAngleAnimation(double startAngle, double endAngle, double duration);
void Apply(Navigator & navigator) override;
private:
InerpolateAngle m_angle;
};
}

View file

@ -7,7 +7,7 @@ namespace df
ModelViewCenterAnimation::ModelViewCenterAnimation(m2::PointD const & start,
m2::PointD const & end,
double duration)
: BaseViewportAnimation(duration)
: BaseModeViewAnimation(duration)
, m_startPt(start)
, m_endPt(end)
{
@ -15,7 +15,7 @@ ModelViewCenterAnimation::ModelViewCenterAnimation(m2::PointD const & start,
void ModelViewCenterAnimation::Apply(Navigator & navigator)
{
m2::PointD center = Interpolate(m_startPt, m_endPt, GetT());
m2::PointD center = InterpolatePoint(m_startPt, m_endPt, GetT());
navigator.CenterViewport(center);
}

View file

@ -5,7 +5,7 @@
namespace df
{
class ModelViewCenterAnimation : public BaseViewportAnimation
class ModelViewCenterAnimation : public BaseModeViewAnimation
{
public:
ModelViewCenterAnimation(m2::PointD const & start, m2::PointD const & end, double duration);

View file

@ -50,6 +50,7 @@ SOURCES += \
visual_params.cpp \
my_position.cpp \
user_event_stream.cpp \
animation/modelview_angle_animation.cpp
HEADERS += \
animation/base_viewport_animation.hpp \
@ -99,3 +100,4 @@ HEADERS += \
visual_params.hpp \
my_position.hpp \
user_event_stream.hpp \
animation/modelview_angle_animation.hpp

View file

@ -1,4 +1,3 @@
#include "drape_frontend/animation/modelview_center_animation.hpp"
#include "drape_frontend/user_event_stream.hpp"
#include "drape_frontend/visual_params.hpp"

View file

@ -45,5 +45,5 @@ void QtOGLContext::present()
void QtOGLContext::setDefaultFramebuffer()
{
GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, m_nativeContext->defaultFramebufferObject());
}