diff --git a/src/osgEarth/EarthManipulator.cpp b/src/osgEarth/EarthManipulator.cpp index 35217ab0e4..366dbe403e 100644 --- a/src/osgEarth/EarthManipulator.cpp +++ b/src/osgEarth/EarthManipulator.cpp @@ -289,9 +289,9 @@ _min_distance ( 1.0 ), _max_distance ( DBL_MAX ), _tether_mode ( TETHER_CENTER ), _arc_viewpoints ( true ), -_auto_vp_duration ( false ), -_min_vp_duration_s ( 3.0 ), -_max_vp_duration_s ( 8.0 ), +_auto_vp_duration ( true ), +_min_vp_duration_s ( 1.0 ), +_max_vp_duration_s ( 3.0 ), _orthoTracksPerspective ( true ), _terrainAvoidanceEnabled ( true ), _terrainAvoidanceMinDistance ( 1.0 ), @@ -539,8 +539,8 @@ EarthManipulator::Settings::setAutoViewpointDurationEnabled( bool value ) void EarthManipulator::Settings::setAutoViewpointDurationLimits( double minSeconds, double maxSeconds ) { - _min_vp_duration_s = osg::clampAbove( minSeconds, 0.0 ); - _max_vp_duration_s = osg::clampAbove( maxSeconds, _min_vp_duration_s ); + _min_vp_duration_s = std::max( minSeconds, 0.0 ); + _max_vp_duration_s = std::max( maxSeconds, _min_vp_duration_s ); dirty(); } @@ -1036,7 +1036,7 @@ EarthManipulator::setViewpoint(const Viewpoint& vp, double duration_seconds) _setVP1->focalPoint() = _setVP0->focalPoint().get(); } - _setVPDuration.set( osg::maximum(duration_seconds, 0.0), Units::SECONDS ); + _setVPDuration.set( std::max(duration_seconds, 0.0), Units::SECONDS ); OE_DEBUG << LC << "setViewpoint:\n" << " from " << _setVP0->toString() << "\n" @@ -1168,7 +1168,7 @@ EarthManipulator::setViewpointFrame(double time_s) // Remaining time is the full duration minus the time since initiation: double elapsed = time_s - _setVPStartTime->as(Units::SECONDS); double duration = _setVPDuration.as(Units::SECONDS); - double t = osg::minimum(1.0, duration > 0.0 ? elapsed/duration : 1.0); + double t = std::min(1.0, duration > 0.0 ? elapsed/duration : 1.0); double tp = t; if ( _setVPArcHeight > 0.0 ) diff --git a/src/osgEarth/ImGui/ImGui b/src/osgEarth/ImGui/ImGui index bee8829f81..e8e29c1b7e 100644 --- a/src/osgEarth/ImGui/ImGui +++ b/src/osgEarth/ImGui/ImGui @@ -277,6 +277,32 @@ namespace ImGuiLTable return ImGui::SliderFloat(s.c_str(), v, v_min, v_max, format, flags); } + static bool SliderDouble(const char* label, double* v, double v_min, double v_max, const char* format = nullptr) + { + ImGui::TableNextColumn(); + ImGui::Text(label); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(-1); + std::string s("##" + std::string(label)); + float temp = *v; + bool ok = ImGui::SliderFloat(s.c_str(), &temp, (float)v_min, (float)v_max, format); + if (ok) *v = (double)temp; + return ok; + } + + static bool SliderDouble(const char* label, double* v, double v_min, double v_max, const char* format, ImGuiSliderFlags flags) + { + ImGui::TableNextColumn(); + ImGui::Text(label); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(-1); + std::string s("##" + std::string(label)); + float temp = *v; + bool ok = ImGui::SliderFloat(s.c_str(), &temp, (float)v_min, (float)v_max, format, flags); + if (ok) *v = (double)temp; + return ok; + } + static bool SliderInt(const char* label, int* v, int v_min, int v_max) { ImGui::TableNextColumn(); diff --git a/src/osgEarth/ImGui/ViewpointsGUI b/src/osgEarth/ImGui/ViewpointsGUI index 0d4e5b52e2..a0a07063ce 100644 --- a/src/osgEarth/ImGui/ViewpointsGUI +++ b/src/osgEarth/ImGui/ViewpointsGUI @@ -19,6 +19,7 @@ #ifndef OSGEARTH_IMGUI_VIEWPOINTS_GUI #define OSGEARTH_IMGUI_VIEWPOINTS_GUI +#include "ImGui" #include #include #include @@ -61,10 +62,11 @@ namespace osgEarth { { _duration = i.value("time", 1.0f); auto key = 0; - for(auto& j : i.children("viewpoint")) + for (auto& j : i.children("viewpoint")) { _viewpoints.push_back(Viewpoint(j)); +#if 0 // works, but conflicts with the ViewpointsExtension :) if (key < 9) { EventRouter::get(view(ri)).onKeyPress( @@ -76,6 +78,7 @@ namespace osgEarth { }); key++; } +#endif } } } @@ -83,52 +86,69 @@ namespace osgEarth { _initialized = true; } - ImGui::Begin(name(), visible()); + if (ImGui::Begin(name(), visible())) { OE_SOFT_ASSERT_AND_RETURN(view(ri), void()); auto manip = dynamic_cast(view(ri)->getCameraManipulator()); - - if (!manip) - ImGui::TextColored(ImVec4(1,.9,.9,1), "(Viewpoints not active)"); - - if (_viewpoints.empty()) - ImGui::TextColored(ImVec4(1, .9, .9, 1), "No viewpoints"); - - for (auto& vp : _viewpoints) + if (manip) { - ImGui::PushID(&vp); - bool selected = false; - std::string name = vp.name().get(); - if (name.empty()) - { - name = ""; - } - if (manip) + if (_viewpoints.empty()) + ImGui::TextColored(ImVec4(1, .9, .9, 1), "No viewpoints"); + + for (auto& vp : _viewpoints) { - ImGui::Selectable(name.c_str(), &selected); - if (selected) - manip->setViewpoint(vp, _duration); + ImGui::PushID(&vp); + bool selected = false; + std::string name = vp.name().get(); + if (name.empty()) + { + name = ""; + } + if (manip) + { + ImGui::Selectable(name.c_str(), &selected); + if (selected) + manip->setViewpoint(vp, _duration); + } + else + { + ImGui::TextColored(ImVec4(.5, .5, .5, 1), name.c_str()); + } + ImGui::PopID(); + ImGui::Separator(); } - else + + ImGui::Separator(); + + ImGuiLTable::Begin("viewpoints-settings"); { - ImGui::TextColored(ImVec4(.5,.5,.5,1), name.c_str()); + double xmin, xmax; + manip->getSettings()->getAutoViewpointDurationLimits(xmin, xmax); + if (ImGuiLTable::SliderDouble("Min fly time (s)", &xmin, 0.0, 4.0, "%.1lf")) + manip->getSettings()->setAutoViewpointDurationLimits(xmin, xmax); + if (ImGuiLTable::SliderDouble("Max fly time (s)", &xmax, xmin, 10.0, "%.1lf")) + manip->getSettings()->setAutoViewpointDurationLimits(xmin, xmax); } - ImGui::PopID(); - ImGui::Separator(); - } + ImGuiLTable::End(); - if (ImGui::Button("Print current viewpoint as XML")) - { - auto manip = dynamic_cast(view(ri)->getCameraManipulator()); - if (manip) + static bool show_xml = false; + ImGui::Checkbox("XML dump", &show_xml); + if (show_xml) { + std::stringstream buf; Util::XmlDocument xml(manip->getViewpoint().getConfig()); - xml.store(std::cout); - std::cout << std::endl; + xml.store(buf); + std::string xml_str = buf.str(); + xml_str = xml_str.substr(xml_str.find("")); + ImGui::InputTextMultiline("##vp_xml", (char*)xml_str.c_str(), xml_str.size(), ImVec2(-1, -1), ImGuiInputTextFlags_ReadOnly); } } + else + { + ImGui::TextColored(ImVec4(1, .9, .9, 1), "(Viewpoints not active)"); + } + ImGui::End(); } - ImGui::End(); } }; } diff --git a/tests/viewpoints.xml b/tests/viewpoints.xml index e6dec5879f..474882212f 100644 --- a/tests/viewpoints.xml +++ b/tests/viewpoints.xml @@ -1,32 +1,23 @@ - - - 8.806974516644791 - 4465.397310772911 - 37.55814749233749 - -122.334535784141 - San Francisco, California - -34.79540299384382 - 78142.53643278375 + + + 38.7144 + -16.5932 + 27784.4m + -122.1783922007742 + 46.26669980080434 + 1103.579998404719 + +proj=longlat +datum=WGS84 +no_defs 17.33521725357022 2462.60273069609 46.82181702111031 -121.7814936386096 - Mt Rainier, Washington + Mt Rainier -21.29241356548601 23926.75258864516 - - -10.1722 - -30.6795 - 10034.5m - -118.2936168720471 - 36.57474451155277 - 4234.804840335622 - +proj=longlat +datum=WGS84 +no_defs - -72.70835146844568 6334.845537136309 @@ -37,7 +28,7 @@ 13611.24948464565 - Grand Canyon, US + Grand Canyon -0.8051 -21.5398 28203.1m @@ -47,16 +38,16 @@ +proj=longlat +datum=WGS84 +no_defs - -121.443 - -11.05 - 131.491m - 12.87702838363237 - 25.33350237523004 - 666.3695949940011 - +proj=longlat +datum=WGS84 +no_defs + -121.37 + -11.2494 + 14568m + 12.85790518927135 + 25.30076063533988 + 643.3327136170119 + +proj=longlat +datum=WGS84 +no_defs - Hallstatt, Austria + Hallstatt -21.36 -35.0965 14786m @@ -65,60 +56,33 @@ 502.9998890347779 - Castel Gandolfo, Italy - 99.4295 - -21.0981 - 2140.85m - 12.66202808744844 - 41.75146324723777 - 340.4633435951546 - +proj=longlat +datum=WGS84 +no_defs + Castel Gandolfo + 111.96 + -13.0742 + 4296.89m + 12.66116827312502 + 41.75440141710527 + 340.4608940472826 + +proj=longlat +datum=WGS84 +no_defs - Sion, Switzerland - 77.5248 - -13.3381 - 1333.35m - 7.275357552703459 - 46.19243759376418 - 683.0508383652195 - +proj=longlat +datum=WGS84 +no_defs - - - 49.7937 - -26.6006 - 57.9473m - -77.755348526353 - 38.04641758070872 - 42.46923910733312 - +proj=longlat +datum=WGS84 +no_defs - - - 34.4312 - -16.2989 - 66.1984m - -121.6193310135399 - 46.66096138267813 - 357.5176040958613 - +proj=longlat +datum=WGS84 +no_defs - - - -65.3262 - -32.1928 - 84.6626m - -75.76722964595007 - 36.2183042666146 - -40.40036714822054 - +proj=longlat +datum=WGS84 +no_defs + Sion + 56.9871 + -11.165 + 4136.16m + 7.285408955688748 + 46.20564340401928 + 533.4425292843953 + +proj=longlat +datum=WGS84 +no_defs - 44.2873 - -27.5639 - 1731.74m - -78.90770900060492 - -0.861917594231788 - 3529.603598460555 - +proj=longlat +datum=WGS84 +no_defs + 59.7275 + -15.6577 + 13806.2m + -78.88765976722279 + -0.8457417820864883 + 3530.116631868295 + +proj=longlat +datum=WGS84 +no_defs -19.7694 @@ -138,31 +102,13 @@ 2686.409382589161 +proj=longlat +datum=WGS84 +no_defs - - 169.243 - -28.2287 - 345.368m - -78.66579949472357 - 38.94076285334965 - 822.951564357616 - +proj=longlat +datum=WGS84 +no_defs - - - -1.18119 - -53.6318 - 1985.36m - 131.0341405855624 - -25.34910343183637 - 614.0726152313873 - +proj=longlat +datum=WGS84 +no_defs - - - -5.97814e-06 - -88.9999 - 4185.64m - -117.3492928130499 - 33.34190250682511 - 73.99633575323969 + + 25.0068 + -22.0497 + 6946.77m + 131.0325742056094 + -25.34751837532118 + 723.1286411993206 +proj=longlat +datum=WGS84 +no_defs