2
// This file is part of the Marble Virtual Globe.
4
// This program is free software licensed under the GNU LGPL. You can
5
// find a copy of this license in LICENSE.txt in the top directory of
8
// Copyright 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
11
#include "PlaybackFlyToItem.h"
13
#include "GeoDataTypes.h"
14
#include "GeoDataLookAt.h"
15
#include "GeoDataCamera.h"
16
#include "Quaternion.h"
22
PlaybackFlyToItem::PlaybackFlyToItem( const GeoDataFlyTo* flyTo ):
26
m_duration( flyTo->duration() ),
32
const GeoDataFlyTo* PlaybackFlyToItem::flyTo() const
37
double PlaybackFlyToItem::duration() const
39
return m_flyTo->duration();
42
void PlaybackFlyToItem::play()
48
if ( !( m_start.isValid() ) ){
49
m_start = QDateTime::currentDateTime();
50
Q_ASSERT( m_start.isValid() );
52
m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) );
58
void PlaybackFlyToItem::playNext()
60
if( !m_start.isValid() ){
63
double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
64
Q_ASSERT( progress >= 0.0 );
65
double const t = progress / m_duration;
69
emit progressChanged( progress );
70
QTimer::singleShot( 5, this, SLOT( playNext() ) );
79
void PlaybackFlyToItem::pause()
82
m_pause = QDateTime::currentDateTime();
85
void PlaybackFlyToItem::seek( double t )
87
m_start = QDateTime::currentDateTime().addMSecs( -t * m_duration * 1000 );
88
m_pause = QDateTime::currentDateTime();
92
void PlaybackFlyToItem::stop()
95
m_start = QDateTime();
96
m_pause = QDateTime();
99
void PlaybackFlyToItem::center( double t )
101
Q_ASSERT( t >= 0.0 && t <= 1.0 );
102
Q_ASSERT( m_before );
103
if ( m_flyTo->flyToMode() == GeoDataFlyTo::Bounce || !m_before->m_before || !m_next ) {
104
GeoDataCoordinates const a = m_before->m_flyTo->view()->coordinates();
105
GeoDataCoordinates const b = m_flyTo->view()->coordinates();
106
emit centerOn( a.interpolate( b, t ) );
108
Q_ASSERT( m_flyTo->flyToMode() == GeoDataFlyTo::Smooth );
109
GeoDataCoordinates const a = m_before->m_before->m_flyTo->view()->coordinates();
110
GeoDataCoordinates const b = m_before->m_flyTo->view()->coordinates();
111
GeoDataCoordinates const c = m_flyTo->view()->coordinates();
112
GeoDataCoordinates const d = m_next->m_flyTo->view()->coordinates();
113
emit centerOn( b.interpolate( a, c, d, t ) );
117
void PlaybackFlyToItem::setBefore( PlaybackFlyToItem *before )
122
void PlaybackFlyToItem::setNext( PlaybackFlyToItem *next )
129
#include "PlaybackFlyToItem.moc"