• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
PlaybackFlyToItem.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
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
6 // the source code.
7 //
8 // Copyright 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
9 //
10 
11 #include "PlaybackFlyToItem.h"
12 
13 #include "GeoDataTypes.h"
14 #include "GeoDataLookAt.h"
15 #include "GeoDataCamera.h"
16 #include "Quaternion.h"
17 
18 #include <QTimer>
19 
20 namespace Marble
21 {
22 PlaybackFlyToItem::PlaybackFlyToItem( const GeoDataFlyTo* flyTo ):
23  m_flyTo( flyTo ),
24  m_before( 0 ),
25  m_next( 0 ),
26  m_duration( flyTo->duration() ),
27  m_isPlaying( false )
28 {
29  //do nothing
30 }
31 
32 const GeoDataFlyTo* PlaybackFlyToItem::flyTo() const
33 {
34  return m_flyTo;
35 }
36 
37 double PlaybackFlyToItem::duration() const
38 {
39  return m_flyTo->duration();
40 }
41 
42 void PlaybackFlyToItem::play()
43 {
44  if( m_isPlaying ){
45  return;
46  } else {
47  m_isPlaying = true;
48  if ( !( m_start.isValid() ) ){
49  m_start = QDateTime::currentDateTime();
50  Q_ASSERT( m_start.isValid() );
51  } else {
52  m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) );
53  }
54  playNext();
55  }
56 }
57 
58 void PlaybackFlyToItem::playNext()
59 {
60  if( !m_start.isValid() ){
61  return;
62  }
63  double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
64  Q_ASSERT( progress >= 0.0 );
65  double const t = progress / m_duration;
66  if( t <= 1 ){
67  if( m_isPlaying ){
68  center( t );
69  emit progressChanged( progress );
70  QTimer::singleShot( 5, this, SLOT( playNext() ) );
71  }
72  } else {
73  center( 1.0 );
74  emit finished();
75  stop();
76  }
77 }
78 
79 void PlaybackFlyToItem::pause()
80 {
81  m_isPlaying = false;
82  m_pause = QDateTime::currentDateTime();
83 }
84 
85 void PlaybackFlyToItem::seek( double t )
86 {
87  m_start = QDateTime::currentDateTime().addMSecs( -t * m_duration * 1000 );
88  m_pause = QDateTime::currentDateTime();
89  center( t );
90 }
91 
92 void PlaybackFlyToItem::stop()
93 {
94  m_isPlaying = false;
95  m_start = QDateTime();
96  m_pause = QDateTime();
97 }
98 
99 void PlaybackFlyToItem::center( double t )
100 {
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 ) );
107  } else {
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 ) );
114  }
115 }
116 
117 void PlaybackFlyToItem::setBefore( PlaybackFlyToItem *before )
118 {
119  m_before = before;
120 }
121 
122 void PlaybackFlyToItem::setNext( PlaybackFlyToItem *next )
123 {
124  m_next = next;
125 }
126 
127 }
128 
129 #include "PlaybackFlyToItem.moc"
Quaternion.h
Marble::GeoDataAbstractView::coordinates
GeoDataCoordinates coordinates() const
Definition: GeoDataAbstractView.cpp:63
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::PlaybackFlyToItem::flyTo
const GeoDataFlyTo * flyTo() const
Definition: PlaybackFlyToItem.cpp:32
Marble::PlaybackItem::finished
void finished()
Marble::PlaybackFlyToItem::pause
void pause()
Definition: PlaybackFlyToItem.cpp:79
Marble::PlaybackFlyToItem::play
void play()
Definition: PlaybackFlyToItem.cpp:42
Marble::PlaybackFlyToItem::setNext
void setNext(PlaybackFlyToItem *next)
Definition: PlaybackFlyToItem.cpp:122
GeoDataCamera.h
Marble::PlaybackFlyToItem
Definition: PlaybackFlyToItem.h:20
GeoDataLookAt.h
Marble::PlaybackItem::progressChanged
void progressChanged(double seconds)
Marble::PlaybackItem::centerOn
void centerOn(const GeoDataCoordinates &coordinates)
Marble::PlaybackFlyToItem::setBefore
void setBefore(PlaybackFlyToItem *before)
Definition: PlaybackFlyToItem.cpp:117
Marble::GeoDataFlyTo
Definition: GeoDataFlyTo.h:23
Marble::PlaybackFlyToItem::PlaybackFlyToItem
PlaybackFlyToItem(const GeoDataFlyTo *flyTo)
Definition: PlaybackFlyToItem.cpp:22
Marble::PlaybackFlyToItem::stop
void stop()
Definition: PlaybackFlyToItem.cpp:92
Marble::GeoDataFlyTo::Smooth
Definition: GeoDataFlyTo.h:28
PlaybackFlyToItem.h
Marble::GeoDataFlyTo::flyToMode
FlyToMode flyToMode() const
Definition: GeoDataFlyTo.cpp:135
Marble::PlaybackFlyToItem::seek
void seek(double position)
Definition: PlaybackFlyToItem.cpp:85
Marble::GeoDataFlyTo::Bounce
Definition: GeoDataFlyTo.h:27
QDateTime::isValid
bool isValid() const
QDateTime::currentDateTime
QDateTime currentDateTime()
Marble::GeoDataFlyTo::duration
double duration() const
Definition: GeoDataFlyTo.cpp:125
GeoDataTypes.h
Marble::GeoDataCoordinates::interpolate
GeoDataCoordinates interpolate(const GeoDataCoordinates &target, double t) const
slerp (spherical linear) interpolation between this coordinate and the given target coordinate ...
Definition: GeoDataCoordinates.cpp:1241
Marble::GeoDataFlyTo::view
const GeoDataAbstractView * view() const
Definition: GeoDataFlyTo.cpp:110
QDateTime
QDateTime::msecsTo
qint64 msecsTo(const QDateTime &other) const
Marble::PlaybackFlyToItem::center
void center(double t)
Definition: PlaybackFlyToItem.cpp:99
QTimer::singleShot
singleShot
QDateTime::addMSecs
QDateTime addMSecs(qint64 msecs) const
Marble::PlaybackFlyToItem::duration
double duration() const
Definition: PlaybackFlyToItem.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal