20
20
#include < mbgl/style/transition_options.hpp>
21
21
#include < mbgl/util/chrono.hpp>
22
22
#include < mbgl/util/geo.hpp>
23
+ #include < mbgl/util/interpolate.hpp>
23
24
#include < mbgl/util/io.hpp>
24
25
#include < mbgl/util/logging.hpp>
25
26
#include < mbgl/util/platform.hpp>
@@ -206,6 +207,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption
206
207
printf (" - Press `U` to toggle pitch bounds\n " );
207
208
printf (" - Press `H` to take a snapshot of a current map.\n " );
208
209
printf (" - Press `J` to take a snapshot of a current map with an extrusions overlay.\n " );
210
+ printf (" - Press `Y` to start a camera fly-by demo\n " );
209
211
printf (" \n " );
210
212
printf (" - Press `1` through `6` to add increasing numbers of point annotations for testing\n " );
211
213
printf (" - Press `7` through `0` to add increasing numbers of shape annotations for testing\n " );
@@ -487,6 +489,11 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
487
489
case GLFW_KEY_G: {
488
490
view->toggleLocationIndicatorLayer ();
489
491
} break ;
492
+ case GLFW_KEY_Y: {
493
+ view->freeCameraDemoPhase = 0 ;
494
+ view->freeCameraDemoStartTime = mbgl::Clock::now ();
495
+ view->invalidate ();
496
+ } break ;
490
497
}
491
498
}
492
499
@@ -508,6 +515,52 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
508
515
}
509
516
}
510
517
518
+ namespace mbgl {
519
+ namespace util {
520
+
521
+ template <>
522
+ struct Interpolator <mbgl::LatLng> {
523
+ mbgl::LatLng operator ()(const mbgl::LatLng &a, const mbgl::LatLng &b, const double t) {
524
+ return {
525
+ interpolate<double >(a.latitude (), b.latitude (), t),
526
+ interpolate<double >(a.longitude (), b.longitude (), t),
527
+ };
528
+ }
529
+ };
530
+
531
+ } // namespace util
532
+ } // namespace mbgl
533
+
534
+ void GLFWView::updateFreeCameraDemo () {
535
+ const mbgl::LatLng trainStartPos = {60.171367 , 24.941359 };
536
+ const mbgl::LatLng trainEndPos = {60.185147 , 24.936668 };
537
+ const mbgl::LatLng cameraStartPos = {60.167443 , 24.927176 };
538
+ const mbgl::LatLng cameraEndPos = {60.185107 , 24.933366 };
539
+ const double cameraStartAlt = 1000.0 ;
540
+ const double cameraEndAlt = 150.0 ;
541
+ const double duration = 8.0 ;
542
+
543
+ // Interpolate between starting and ending points
544
+ std::chrono::duration<double > deltaTime = mbgl::Clock::now () - freeCameraDemoStartTime;
545
+ freeCameraDemoPhase = deltaTime.count () / duration;
546
+
547
+ auto trainPos = mbgl::util::interpolate (trainStartPos, trainEndPos, freeCameraDemoPhase);
548
+ auto cameraPos = mbgl::util::interpolate (cameraStartPos, cameraEndPos, freeCameraDemoPhase);
549
+ auto cameraAlt = mbgl::util::interpolate (cameraStartAlt, cameraEndAlt, freeCameraDemoPhase);
550
+
551
+ mbgl::FreeCameraOptions camera;
552
+
553
+ // Update camera position and focus point on the map with interpolated values
554
+ camera.setLocation ({cameraPos, cameraAlt});
555
+ camera.lookAtPoint (trainPos);
556
+
557
+ map->setFreeCameraOptions (camera);
558
+
559
+ if (freeCameraDemoPhase > 1.0 ) {
560
+ freeCameraDemoPhase = -1.0 ;
561
+ }
562
+ }
563
+
511
564
mbgl::Color GLFWView::makeRandomColor () const {
512
565
const float r = 1 .0f * float (std::rand ()) / float (RAND_MAX);
513
566
const float g = 1 .0f * float (std::rand ()) / float (RAND_MAX);
@@ -860,11 +913,14 @@ void GLFWView::run() {
860
913
861
914
rendererFrontend->render ();
862
915
916
+ if (freeCameraDemoPhase >= 0.0 ) {
917
+ updateFreeCameraDemo ();
918
+ }
919
+
863
920
report (1000 * (glfwGetTime () - started));
864
921
if (benchmark) {
865
922
invalidate ();
866
923
}
867
-
868
924
}
869
925
};
870
926
0 commit comments