diff --git a/modules/skybrowser/include/screenspaceskybrowser.h b/modules/skybrowser/include/screenspaceskybrowser.h index 21a30fad9a..a56bce98db 100644 --- a/modules/skybrowser/include/screenspaceskybrowser.h +++ b/modules/skybrowser/include/screenspaceskybrowser.h @@ -51,7 +51,7 @@ public: // Animation bool isAnimated() const; - void startFovAnimation(float fov); + void startFovAnimation(double fov); void incrementallyAnimateToFov(float deltaTime); float opacity() const; @@ -86,7 +86,7 @@ private: bool _sizeIsDirty = false; // Animation of fieldOfView - float _endVfov = 0.f; + double _endVfov = 0.0; glm::vec2 _size = glm::vec2(0.5f); }; } // namespace openspace diff --git a/modules/skybrowser/include/targetbrowserpair.h b/modules/skybrowser/include/targetbrowserpair.h index b70d2d104d..5a3cf718f4 100644 --- a/modules/skybrowser/include/targetbrowserpair.h +++ b/modules/skybrowser/include/targetbrowserpair.h @@ -50,7 +50,7 @@ public: void removeHighlight(const glm::ivec3& color); void highlight(const glm::ivec3& color); // Animation - void startAnimation(glm::dvec3 coordsEnd, float fovEnd, bool shouldLockAfter = true); + void startAnimation(glm::dvec3 coordsEnd, double fovEnd, bool shouldLockAfter = true); void incrementallyAnimateToCoordinate(double deltaTime); void incrementallyFade(float goalState, float fadeTime, float deltaTime); // Mouse interaction @@ -76,13 +76,13 @@ public: void setEnabled(bool enable); void setIsSyncedWithWwt(bool isSynced); - void setVerticalFov(float vfov); + void setVerticalFov(double vfov); void setEquatorialAim(const glm::dvec2& aim); void setBorderColor(const glm::ivec3& color); void setScreenSpaceSize(const glm::vec2& dimensions); void setVerticalFovWithScroll(float scroll); - float verticalFov() const; + double verticalFov() const; glm::ivec3 borderColor() const; glm::dvec2 targetDirectionEquatorial() const; glm::dvec3 targetDirectionGalactic() const; diff --git a/modules/skybrowser/include/utility.h b/modules/skybrowser/include/utility.h index cd81f72197..346a157a6b 100644 --- a/modules/skybrowser/include/utility.h +++ b/modules/skybrowser/include/utility.h @@ -124,7 +124,7 @@ glm::dvec3 localCameraToEquatorial(const glm::dvec3& coords); * \return Angle in degrees between the OpenSpace camera's up direction vector and the * equatorial North Pole direction. */ -double cameraRoll(); +double targetRoll(const glm::dvec3& up, const glm::dvec3& forward); /** * Returns the view direction of the OpenSpace camera in galactic coordinates. * \return View direction of the OpenSpace camera in Cartesian galactic coordinates. diff --git a/modules/skybrowser/include/wwtcommunicator.h b/modules/skybrowser/include/wwtcommunicator.h index 29a9ffed32..76b1f63c9e 100644 --- a/modules/skybrowser/include/wwtcommunicator.h +++ b/modules/skybrowser/include/wwtcommunicator.h @@ -55,17 +55,18 @@ public: void hideChromeInterface(bool shouldHide); bool hasLoadedImages() const; - float verticalFov() const; + double verticalFov() const; glm::ivec3 borderColor() const; glm::dvec2 equatorialAim() const; glm::dvec2 fieldsOfView() const; const std::deque& getSelectedImages() const; void setHasLoadedImages(bool isLoaded); - void setVerticalFov(float vfov); + void setVerticalFov(double vfov); void setIsSyncedWithWwt(bool isSynced); void setEquatorialAim(glm::dvec2 equatorial); void setBorderColor(glm::ivec3 color); + void setTargetRoll(double roll); void highlight(const glm::ivec3& addition); // The removal parameter decides what will be removed from the border color @@ -76,9 +77,10 @@ public: protected: void setIdInBrowser(const std::string& id); - float _verticalFov = 10.f; + double _verticalFov = 10.0f; glm::ivec3 _borderColor = glm::ivec3(70); glm::dvec2 _equatorialAim = glm::dvec2(0.0); + double _targetRoll = 0.0; bool _hasLoadedImages = false; std::deque _selectedImages; diff --git a/modules/skybrowser/src/screenspaceskybrowser.cpp b/modules/skybrowser/src/screenspaceskybrowser.cpp index 99ffabe324..d51d20b4d4 100644 --- a/modules/skybrowser/src/screenspaceskybrowser.cpp +++ b/modules/skybrowser/src/screenspaceskybrowser.cpp @@ -219,19 +219,19 @@ bool ScreenSpaceSkyBrowser::isAnimated() const{ return _isFovAnimated; } -void ScreenSpaceSkyBrowser::startFovAnimation(float fov) { +void ScreenSpaceSkyBrowser::startFovAnimation(double fov) { _isFovAnimated = true; _endVfov = fov; } void ScreenSpaceSkyBrowser::incrementallyAnimateToFov(float deltaTime) { // If distance too large, keep animating. Else, stop animation - float diff = _endVfov - verticalFov(); + double diff = _endVfov - verticalFov(); bool shouldAnimate = abs(diff) > FovThreshold; if (shouldAnimate) { - float delta = _animationSpeed * (diff * deltaTime); - _verticalFov = std::clamp(_verticalFov + delta, 0.0001f, 70.0f); + double delta = _animationSpeed * (diff * static_cast(deltaTime)); + _verticalFov = std::clamp(_verticalFov + delta, 0.0, 70.0); } else { _isFovAnimated = false; @@ -295,10 +295,10 @@ void ScreenSpaceSkyBrowser::update() { void ScreenSpaceSkyBrowser::setVerticalFovWithScroll(float scroll) { // Make scroll more sensitive the smaller the FOV - float x = _verticalFov; - float zoomFactor = atan(x / 50.f) + exp(x / 40.f) - 0.999999f; - float zoom = scroll > 0.f ? -zoomFactor : zoomFactor; - _verticalFov = std::clamp(_verticalFov + zoom, 0.000001f, 70.0f); + double x = _verticalFov; + double zoomFactor = atan(x / 50.0) + exp(x / 40.0) - 0.99999999999999999999999999999; + double zoom = scroll > 0.0 ? -zoomFactor : zoomFactor; + _verticalFov = std::clamp(_verticalFov + zoom, 0.0, 70.0); } void ScreenSpaceSkyBrowser::bindTexture() { diff --git a/modules/skybrowser/src/targetbrowserpair.cpp b/modules/skybrowser/src/targetbrowserpair.cpp index c401e90f4d..d96c039db3 100644 --- a/modules/skybrowser/src/targetbrowserpair.cpp +++ b/modules/skybrowser/src/targetbrowserpair.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -144,6 +146,11 @@ void TargetBrowserPair::synchronizeAim() { // target, send the locked coordinates to wwt glm::dvec2 aim = targetDirectionEquatorial(); _browser->setEquatorialAim(aim); + glm::dvec3 direction = _targetNode->worldPosition() - + global::navigationHandler->camera()->positionVec3(); + glm::dvec3 normalized = glm::normalize(direction); + glm::dvec3 up = global::navigationHandler->camera()->lookUpVectorWorldSpace(); + _browser->setTargetRoll(skybrowser::targetRoll(up, normalized)); _targetRenderable->setVerticalFov(_browser->verticalFov()); } } @@ -201,7 +208,7 @@ glm::vec2 TargetBrowserPair::size() const { return _browser->size(); } -float TargetBrowserPair::verticalFov() const { +double TargetBrowserPair::verticalFov() const { return _browser->verticalFov(); } @@ -251,7 +258,7 @@ void TargetBrowserPair::setIsSyncedWithWwt(bool isSynced) { _browser->setIsSyncedWithWwt(isSynced); } -void TargetBrowserPair::setVerticalFov(float vfov) { +void TargetBrowserPair::setVerticalFov(double vfov) { _browser->setVerticalFov(vfov); _targetRenderable->setVerticalFov(vfov); } @@ -290,7 +297,7 @@ void TargetBrowserPair::incrementallyAnimateToCoordinate(double deltaTime) { } } -void TargetBrowserPair::startAnimation(glm::dvec3 galacticCoords, float fovEnd, +void TargetBrowserPair::startAnimation(glm::dvec3 galacticCoords, double fovEnd, bool shouldLockAfter) { _browser->startFovAnimation(fovEnd); diff --git a/modules/skybrowser/src/utility.cpp b/modules/skybrowser/src/utility.cpp index adb0290b9e..2b7f7ed23a 100644 --- a/modules/skybrowser/src/utility.cpp +++ b/modules/skybrowser/src/utility.cpp @@ -118,17 +118,13 @@ glm::dvec3 galacticToLocalCamera(const glm::dvec3& coords) { return glm::normalize(viewDirectionLocal); } -double cameraRoll() { - openspace::Camera* camera = global::navigationHandler->camera(); - glm::dvec3 upWorld = camera->lookUpVectorWorldSpace(); - glm::dvec3 forwardWorld = camera->viewDirectionWorldSpace(); +double targetRoll(const glm::dvec3& up, const glm::dvec3& forward) { + glm::dvec3 upJ2000 = skybrowser::galacticToEquatorial(up); + glm::dvec3 forwardJ2000 = skybrowser::galacticToEquatorial(forward); - glm::dvec3 camUpJ2000 = skybrowser::galacticToEquatorial(upWorld); - glm::dvec3 camForwardJ2000 = skybrowser::galacticToEquatorial(forwardWorld); - - glm::dvec3 crossUpNorth = glm::cross(camUpJ2000, skybrowser::NorthPole); - double dotNorthUp = glm::dot(skybrowser::NorthPole, camUpJ2000); - double dotCrossUpNorthForward = glm::dot(crossUpNorth, camForwardJ2000); + glm::dvec3 crossUpNorth = glm::cross(upJ2000, NorthPole); + double dotNorthUp = glm::dot(NorthPole, upJ2000); + double dotCrossUpNorthForward = glm::dot(upJ2000, forwardJ2000); return glm::degrees(atan2(dotCrossUpNorthForward, dotNorthUp)); } diff --git a/modules/skybrowser/src/wwtcommunicator.cpp b/modules/skybrowser/src/wwtcommunicator.cpp index 6237f7e63b..afd4f9fba8 100644 --- a/modules/skybrowser/src/wwtcommunicator.cpp +++ b/modules/skybrowser/src/wwtcommunicator.cpp @@ -72,7 +72,12 @@ const std::deque& WwtCommunicator::getSelectedImages() const { return _selectedImages; } -void WwtCommunicator::setVerticalFov(float vfov) { +void WwtCommunicator::setTargetRoll(double roll) +{ + _targetRoll = roll; +} + +void WwtCommunicator::setVerticalFov(double vfov) { _verticalFov = vfov; _equatorialAimIsDirty = true; } @@ -112,12 +117,11 @@ void WwtCommunicator::updateBorderColor() { } void WwtCommunicator::updateAim() { - double roll = _isSyncedWithWwt ? skybrowser::cameraRoll() : 0.0; // Message WorldWide Telescope current view ghoul::Dictionary message = moveCameraMessage( _equatorialAim, _verticalFov, - roll + _targetRoll ); sendMessageToWwt(message); } @@ -215,7 +219,7 @@ glm::ivec3 WwtCommunicator::borderColor() const { return _borderColor; } -float WwtCommunicator::verticalFov() const { +double WwtCommunicator::verticalFov() const { return _verticalFov; }