Skip to content

Commit

Permalink
Perspective animation.
Browse files Browse the repository at this point in the history
Conflicts:
	drape_frontend/drape_engine.hpp
	drape_frontend/frontend_renderer.cpp
	drape_frontend/message.hpp
	drape_frontend/message_subclasses.hpp

Conflicts:
	drape_frontend/message.hpp
  • Loading branch information
darina committed Dec 29, 2015
1 parent fa15cdf commit 45f3a71
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 135 deletions.
31 changes: 31 additions & 0 deletions drape_frontend/animation/perspective_animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "perspective_animation.hpp"
#include "drape_frontend/animation/interpolations.hpp"

namespace df
{

double PerspectiveAnimation::GetRotateDuration(double startAngle, double endAngle)
{
return 0.5 * fabs(endAngle - startAngle) / math::pi4;
}

PerspectiveAnimation::PerspectiveAnimation(double duration, double startRotationAngle, double endRotationAngle)
: PerspectiveAnimation(duration, 0.0, startRotationAngle, endRotationAngle)
{
}

PerspectiveAnimation::PerspectiveAnimation(double duration, double delay, double startRotationAngle, double endRotationAngle)
: BaseInterpolator(duration, delay)
, m_startRotationAngle(startRotationAngle)
, m_endRotationAngle(endRotationAngle)
, m_rotationAngle(startRotationAngle)
{
}

void PerspectiveAnimation::Advance(double elapsedSeconds)
{
TBase::Advance(elapsedSeconds);
m_rotationAngle = InterpolateDouble(m_startRotationAngle, m_endRotationAngle, GetT());
}

} // namespace df
28 changes: 28 additions & 0 deletions drape_frontend/animation/perspective_animation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "drape_frontend/animation/base_interpolator.hpp"

namespace df
{

class PerspectiveAnimation : public BaseInterpolator
{
using TBase = BaseInterpolator;

public:
static double GetRotateDuration(double startAngle, double endAngle);

PerspectiveAnimation(double duration, double startRotationAngle, double endRotationAngle);
PerspectiveAnimation(double duration, double delay, double startRotationAngle, double endRotationAngle);

void Advance(double elapsedSeconds) override;
double GetRotationAngle() const { return m_rotationAngle; }

private:
double m_startRotationAngle;
double m_endRotationAngle;
double m_rotationAngle;
};

} // namespace df

17 changes: 5 additions & 12 deletions drape_frontend/drape_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ void DrapeEngine::MyPositionNextMode()
MessagePriority::High);
}

void DrapeEngine::FollowRoute(int preferredZoomLevel)
void DrapeEngine::FollowRoute(int preferredZoomLevel, int preferredZoomLevel3d, double rotationAngle, double angleFOV)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<ChangeMyPositionModeMessage>(ChangeMyPositionModeMessage::TYPE_NEXT,
preferredZoomLevel),
make_unique_dp<FollowRouteMessage>(preferredZoomLevel, preferredZoomLevel3d,
rotationAngle, angleFOV),
MessagePriority::High);
}

Expand Down Expand Up @@ -429,17 +429,10 @@ gui::TWidgetsSizeInfo const & DrapeEngine::GetWidgetSizes()
return m_widgetSizes;
}

void DrapeEngine::Enable3dMode(float rotationAngle, float angleFOV)
void DrapeEngine::Enable3dMode(bool enable)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<Enable3dModeMessage>(rotationAngle, angleFOV),
MessagePriority::Normal);
}

void DrapeEngine::Disable3dMode()
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<Disable3dModeMessage>(),
make_unique_dp<Enable3dModeMessage>(enable),
MessagePriority::Normal);
}

Expand Down
5 changes: 2 additions & 3 deletions drape_frontend/drape_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ class DrapeEngine

void AddRoute(m2::PolylineD const & routePolyline, vector<double> const & turns, dp::Color const & color);
void RemoveRoute(bool deactivateFollowing);
void FollowRoute(int preferredZoomLevel);
void FollowRoute(int preferredZoomLevel, int preferredZoomLevel3d, double rotationAngle, double angleFOV);
void DeactivateRouteFollowing();
void SetRoutePoint(m2::PointD const & position, bool isStart, bool isValid);

void SetWidgetLayout(gui::TWidgetsLayoutInfo && info);
gui::TWidgetsSizeInfo const & GetWidgetSizes();

void Enable3dMode(float rotationAngle, float angleFOV);
void Disable3dMode();
void Enable3dMode(bool enable);

private:
void AddUserEvent(UserEvent const & e);
Expand Down
2 changes: 2 additions & 0 deletions drape_frontend/drape_frontend.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SOURCES += \
animation/interpolations.cpp \
animation/model_view_animation.cpp \
animation/opacity_animation.cpp \
animation/perspective_animation.cpp \
animation/show_hide_animation.cpp \
gui/button.cpp \
gui/compass.cpp \
Expand Down Expand Up @@ -96,6 +97,7 @@ HEADERS += \
animation/interpolations.hpp \
animation/model_view_animation.hpp \
animation/opacity_animation.hpp \
animation/perspective_animation.hpp \
animation/show_hide_animation.hpp \
animation/value_mapping.hpp \
gui/button.hpp \
Expand Down
74 changes: 38 additions & 36 deletions drape_frontend/frontend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ FrontendRenderer::FrontendRenderer(Params const & params)
, m_gpuProgramManager(new dp::GpuProgramManager())
, m_routeRenderer(new RouteRenderer())
, m_overlayTree(new dp::OverlayTree())
, m_useFramebuffer(false)
, m_enable3dInNavigation(false)
, m_isBillboardRenderPass(false)
, m_3dModeChanged(true)
, m_framebuffer(new Framebuffer())
, m_renderer3d(new Renderer3d())
, m_viewport(params.m_viewport)
Expand Down Expand Up @@ -140,7 +139,8 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
ref_ptr<dp::GpuProgram> program = m_gpuProgramManager->GetProgram(state.GetProgramIndex());
ref_ptr<dp::GpuProgram> program3d = m_gpuProgramManager->GetProgram(state.GetProgram3dIndex());
program->Bind();
bucket->GetBuffer()->Build(m_useFramebuffer ? program3d : program);
bucket->GetBuffer()->Build(m_userEventStream.GetCurrentScreen().isPerspective() ? program3d
: program);
if (!IsUserMarkLayer(key))
{
if (CheckTileGenerations(key))
Expand Down Expand Up @@ -387,7 +387,20 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
ref_ptr<RemoveRouteMessage> msg = message;
m_routeRenderer->Clear();
if (msg->NeedDeactivateFollowing())
{
m_myPositionController->DeactivateRouting();
if (m_enable3dInNavigation)
AddUserEvent(Disable3dModeEvent());
}
break;
}

case Message::FollowRoute:
{
ref_ptr<FollowRouteMessage> msg = message;
m_myPositionController->NextMode(msg->GetPreferredZoomLevel());
if (m_enable3dInNavigation)
AddUserEvent(Enable3dModeEvent(msg->GetRotationAngle(), msg->GetAngleFOV()));
break;
}

Expand Down Expand Up @@ -468,26 +481,11 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)

break;
}
case Message::Enable3dMode:
{
if (!m_useFramebuffer)
{
ref_ptr<Enable3dModeMessage> const msg = message;
AddUserEvent(Enable3dModeEvent(msg->GetRotationAngle(), msg->GetAngleFOV()));
m_useFramebuffer = true;
m_3dModeChanged = true;
}
break;
}

case Message::Disable3dMode:
case Message::Enable3dMode:
{
if (m_useFramebuffer)
{
m_useFramebuffer = false;
m_3dModeChanged = true;
AddUserEvent(Disable3dMode());
}
ref_ptr<Enable3dModeMessage> const msg = message;
m_enable3dInNavigation = msg->Enable();
break;
}

Expand Down Expand Up @@ -516,17 +514,18 @@ void FrontendRenderer::OnResize(ScreenBase const & screen)
m_contextFactory->getDrawContext()->resize(viewportRect.SizeX(), viewportRect.SizeY());
RefreshProjection();

if (m_useFramebuffer)
if (screen.isPerspective())
{
int width = screen.GetWidth();
int height = screen.GetHeight();
int const maxSide = max(width, height);
if (maxSide > m_framebuffer->GetMaxSize())
int const maxTextureSize = m_framebuffer->GetMaxSize();
if (maxSide > maxTextureSize)
{
width = width * m_framebuffer->GetMaxSize() / maxSide;
height = height * m_framebuffer->GetMaxSize() / maxSide;
LOG(LINFO, ("Max texture size:", m_framebuffer->GetMaxSize(), ", expanded screen size:", maxSide,
", scale:", m_framebuffer->GetMaxSize() / (double)maxSide));
width = width * maxTextureSize / maxSide;
height = height * maxTextureSize / maxSide;
LOG(LINFO, ("Max texture size:", maxTextureSize, ", expanded screen size:", maxSide,
", scale:", maxTextureSize / (double)maxSide));
}

m_viewport.SetViewport(0, 0, width, height);
Expand Down Expand Up @@ -691,7 +690,8 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
BeforeDrawFrame();
#endif

if (m_useFramebuffer)
bool const isPerspective = modelView.isPerspective();
if (isPerspective)
{
m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext());
m_framebuffer->Enable();
Expand Down Expand Up @@ -784,7 +784,7 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)

m_routeRenderer->RenderRoute(modelView, make_ref(m_gpuProgramManager), m_generalUniforms);

if (!m_useFramebuffer)
if (!isPerspective)
{
for (drape_ptr<UserMarkRenderGroup> const & group : m_userMarkRenderGroups)
{
Expand All @@ -799,10 +799,10 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
m_myPositionController->Render(MyPositionController::RenderMyPosition,
modelView, make_ref(m_gpuProgramManager), m_generalUniforms);

if (!m_useFramebuffer && m_guiRenderer != nullptr)
if (!isPerspective && m_guiRenderer != nullptr)
m_guiRenderer->Render(make_ref(m_gpuProgramManager), modelView);

if (m_useFramebuffer)
if (isPerspective)
{
m_framebuffer->Disable();
m_renderer3d->Render(modelView, m_framebuffer->GetTextureId(), make_ref(m_gpuProgramManager));
Expand Down Expand Up @@ -842,6 +842,11 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
#endif
}

bool FrontendRenderer::IsPerspective() const
{
return m_userEventStream.GetCurrentScreen().isPerspective();
}

bool FrontendRenderer::IsBillboardProgram(int programIndex) const
{
return programIndex == gpu::TEXTURING_BILLBOARD_PROGRAM
Expand All @@ -852,7 +857,7 @@ bool FrontendRenderer::IsBillboardProgram(int programIndex) const

void FrontendRenderer::RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group)
{
if (m_useFramebuffer &&
if (modelView.isPerspective() &&
(m_isBillboardRenderPass != IsBillboardProgram(group->GetState().GetProgram3dIndex())))
return;

Expand Down Expand Up @@ -885,7 +890,7 @@ void FrontendRenderer::RefreshModelView(ScreenBase const & screen)

void FrontendRenderer::RefreshPivotTransform(ScreenBase const & screen)
{
if (m_useFramebuffer)
if (screen.isPerspective())
{
math::Matrix<float, 4, 4> const transform(screen.PTo3dMatrix());
m_generalUniforms.SetMatrix4x4Value("pivotTransform", transform.m_data);
Expand Down Expand Up @@ -1228,9 +1233,6 @@ ScreenBase const & FrontendRenderer::ProcessEvents(bool & modelViewChanged, bool
ScreenBase const & modelView = m_userEventStream.ProcessEvents(modelViewChanged, viewportChanged);
gui::DrapeGui::Instance().SetInUserAction(m_userEventStream.IsInUserAction());

viewportChanged = viewportChanged || m_3dModeChanged;
m_3dModeChanged = false;

return modelView;
}

Expand Down
4 changes: 2 additions & 2 deletions drape_frontend/frontend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class FrontendRenderer : public BaseRenderer
FeatureID GetVisiblePOI(m2::RectD const & pixelRect) const;

bool IsBillboardProgram(int programIndex) const;
bool IsPerspective() const;

private:
drape_ptr<dp::GpuProgramManager> m_gpuProgramManager;
Expand All @@ -229,9 +230,8 @@ class FrontendRenderer : public BaseRenderer

dp::UniformValuesStorage m_generalUniforms;

bool m_useFramebuffer;
bool m_enable3dInNavigation;
bool m_isBillboardRenderPass;
bool m_3dModeChanged;
drape_ptr<Framebuffer> m_framebuffer;
drape_ptr<Renderer3d> m_renderer3d;

Expand Down
4 changes: 2 additions & 2 deletions drape_frontend/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class Message
RemoveRoute,
FlushRoute,
FlushRouteSign,
FollowRoute,
DeactivateRouteFollowing,
UpdateMapStyle,
InvalidateTextures,
Invalidate,
Enable3dMode,
Disable3dMode
Enable3dMode
};

virtual ~Message() {}
Expand Down
44 changes: 27 additions & 17 deletions drape_frontend/message_subclasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,29 @@ class UpdateMapStyleMessage : public BaseBlockingMessage
Type GetType() const override { return Message::UpdateMapStyle; }
};

class FollowRouteMessage : public Message
{
public:
FollowRouteMessage(int preferredZoomLevel, int preferredZoomLevelIn3d, double rotationAngle, double angleFOV)
: m_preferredZoomLevel(preferredZoomLevel)
, m_preferredZoomLevelIn3d(preferredZoomLevelIn3d)
, m_rotationAngle(rotationAngle)
, m_angleFOV(angleFOV)
{}

Type GetType() const override { return Message::FollowRoute; }
int GetPreferredZoomLevel() const { return m_preferredZoomLevel; }
int GetPreferredZoomLevelIn3d() const { return m_preferredZoomLevelIn3d; }
double GetRotationAngle() const { return m_rotationAngle; }
double GetAngleFOV() const { return m_angleFOV; }

private:
int m_preferredZoomLevel;
int m_preferredZoomLevelIn3d;
double m_rotationAngle;
double m_angleFOV;
};

class InvalidateTexturesMessage : public BaseBlockingMessage
{
public:
Expand Down Expand Up @@ -633,28 +656,15 @@ class DeactivateRouteFollowingMessage : public Message
class Enable3dModeMessage : public Message
{
public:
Enable3dModeMessage(float rotationAngle, float angleFOV)
: m_angleFOV(angleFOV)
, m_rotationAngle(rotationAngle)
Enable3dModeMessage(bool enable)
: m_enable(enable)
{}

Type GetType() const override { return Message::Enable3dMode; }

float GetAngleFOV() const { return m_angleFOV; }
float GetRotationAngle() const { return m_rotationAngle; }
bool Enable() const { return m_enable; }

private:
float m_angleFOV;
float m_rotationAngle;
};

class Disable3dModeMessage : public Message
{
public:
Disable3dModeMessage()
{}

Type GetType() const override { return Message::Disable3dMode; }
bool m_enable;
};

} // namespace df
Loading

0 comments on commit 45f3a71

Please sign in to comment.