diff --git a/modules/skybrowser/include/screenspaceskybrowser.h b/modules/skybrowser/include/screenspaceskybrowser.h index f73e8e66cd..1699f968ae 100644 --- a/modules/skybrowser/include/screenspaceskybrowser.h +++ b/modules/skybrowser/include/screenspaceskybrowser.h @@ -52,8 +52,6 @@ namespace openspace { void setScale(float scalingFactor); void setWebpageBorderColor(glm::ivec3 color); - // Communication with the web page - void executeJavascript(std::string script); void sendIdToBrowser(); // Display @@ -82,6 +80,9 @@ namespace openspace { //void translate(glm::vec2 translation); private: + // Communication with the web page + void executeJavascript(std::string script); + // Properties properties::FloatProperty _verticalFov; properties::StringProperty _skyTargetId; diff --git a/modules/skybrowser/include/screenspaceskytarget.h b/modules/skybrowser/include/screenspaceskytarget.h index f1c6d0ec67..a064fd498d 100644 --- a/modules/skybrowser/include/screenspaceskytarget.h +++ b/modules/skybrowser/include/screenspaceskytarget.h @@ -79,7 +79,14 @@ namespace openspace { bool _lockAfterAnimation{ false }; // Shader - UniformCache(modelTransform, viewProj, showCrosshair, showRectangle, lineWidth, dimensions, lineColor) _uniformCache; + UniformCache( + modelTransform, + viewProj, + showCrosshair, + showRectangle, + lineWidth, + dimensions, + lineColor) _uniformCache; GLuint _vertexArray = 0; GLuint _vertexBuffer = 0; diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index cbd04b1d41..1e38c9bde5 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -274,16 +274,25 @@ SkyBrowserModule::SkyBrowserModule() if (button == MouseButton::Left) { _cameraIsRotating = false; _startMousePosition = _mousePosition; - _startDragPosition = _isBrowser ? _mouseOnPair->getBrowser()->screenSpacePosition() - : _mouseOnPair->getTarget()->screenSpacePosition(); + if (_isBrowser) { + _startDragPosition = _mouseOnPair->getBrowser()-> + screenSpacePosition(); + } + else { + _startDragPosition = _mouseOnPair->getTarget()-> + screenSpacePosition(); + } // If current object is browser, check for resizing if (_isBrowser) { // Resize browser if mouse is over resize button - _resizeDirection = _mouseOnPair->getBrowser()->isOnResizeArea(_mousePosition); + _resizeDirection = _mouseOnPair->getBrowser()->isOnResizeArea( + _mousePosition + ); if (_resizeDirection != glm::vec2{ 0 }) { _mouseOnPair->getBrowser()->saveResizeStartSize(); - _startBrowserSize = _mouseOnPair->getBrowser()->screenSpaceDimensions(); + _startBrowserSize = _mouseOnPair->getBrowser()-> + screenSpaceDimensions(); _isResizing = true; return true; } @@ -297,9 +306,10 @@ SkyBrowserModule::SkyBrowserModule() return true; } else if (_isBrowser && button == MouseButton::Right) { - // If you start dragging around on the browser, the target should unlock + // If you start dragging around on the browser, the target unlocks _mouseOnPair->unlock(); - // Change view (by moving target) within browser if right mouse click on browser + // Change view (by moving target) within browser if right mouse + // click on browser _startMousePosition = _mousePosition; _startDragPosition = _mouseOnPair->getTarget()->screenSpacePosition(); _fineTuneMode = true; @@ -339,28 +349,37 @@ SkyBrowserModule::SkyBrowserModule() if (_isDragging || _isResizing) { if (_isResizing) { // Calculate scaling factor - glm::vec2 mouseDragVector = (_mousePosition - _startMousePosition); + glm::vec2 mouseDragVector = (_mousePosition-_startMousePosition); glm::vec2 scaling = mouseDragVector * _resizeDirection; - glm::vec2 newSizeRelToOld = (_startBrowserSize + (scaling)) / _startBrowserSize; + glm::vec2 newSizeRelToOld = (_startBrowserSize + (scaling)) / + _startBrowserSize; // Scale the browser _mouseOnPair->getBrowser()->setScale(newSizeRelToOld); - // For dragging functionality, translate so it looks like the browser - // isn't moving. Make sure the browser doesn't move in directions it's - // not supposed to + // For dragging functionality, translate so it looks like the + // browser isn't moving. Make sure the browser doesn't move in + // directions it's not supposed to translation = mouseDragVector * abs(_resizeDirection) / 2.f; } // Translate if (_isBrowser) { - _mouseOnPair->getBrowser()->translate(translation, _startDragPosition); + _mouseOnPair->getBrowser()->translate( + translation, + _startDragPosition + ); } else { - _mouseOnPair->getTarget()->translate(translation, _startDragPosition); + _mouseOnPair->getTarget()->translate( + translation, + _startDragPosition + ); } } else if (_fineTuneMode) { - glm::vec2 fineTune = _mouseOnPair->getBrowser()->fineTuneVector(translation); + glm::vec2 fineTune = _mouseOnPair->getBrowser()->fineTuneVector( + translation + ); _mouseOnPair->getTarget()->translate(fineTune, _startDragPosition); } // If there is no dragging or resizing, look for new objects @@ -377,7 +396,9 @@ SkyBrowserModule::SkyBrowserModule() // If mouse is on browser or target, apply zoom if (_mouseOnPair) { - _mouseOnPair->getBrowser()->setVerticalFovWithScroll(static_cast(scroll)); + _mouseOnPair->getBrowser()->setVerticalFovWithScroll( + static_cast(scroll) + ); return true; } @@ -424,7 +445,7 @@ SkyBrowserModule::SkyBrowserModule() animateTargets(deltaTime); } if (_cameraIsRotating) { - rotateCamera(deltaTime); + incrementallyRotateCamera(deltaTime); } }); @@ -467,8 +488,12 @@ void SkyBrowserModule::setSelectedObject() // Find and save what mouse is currently hovering on auto it = std::find_if(std::begin(_targetsBrowsers), std::end(_targetsBrowsers), [&] (Pair &pair) { - bool onBrowser = pair.getBrowser()->coordIsInsideCornersScreenSpace(_mousePosition); - bool onTarget = pair.getTarget()->coordIsInsideCornersScreenSpace(_mousePosition); + bool onBrowser = pair.getBrowser()->coordIsInsideCornersScreenSpace( + _mousePosition + ); + bool onTarget = pair.getTarget()->coordIsInsideCornersScreenSpace( + _mousePosition + ); if (onBrowser) { _selectedBrowser = pair.getBrowser()->identifier(); } @@ -614,7 +639,9 @@ void SkyBrowserModule::selectImage2dBrowser(int i) // If the coordinate is not in view, rotate camera if (image.hasCelestialCoords) { if(!isInView) { - rotateCamera(skybrowser::equatorialToGalactic(image.equatorialCartesian)); + startRotatingCamera( + skybrowser::equatorialToGalactic(image.equatorialCartesian) + ); } } } @@ -638,7 +665,7 @@ void SkyBrowserModule::lookAtTarget(std::string id) { Pair* pair = getPair(id); if (pair) { - rotateCamera(pair->targetDirectionGalactic()); + startRotatingCamera(pair->targetDirectionGalactic()); } } @@ -717,14 +744,14 @@ void SkyBrowserModule::lookAt3dBrowser() { ); } -void SkyBrowserModule::rotateCamera(glm::dvec3 endAnimation) { +void SkyBrowserModule::startRotatingCamera(glm::dvec3 endAnimation) { // Save coordinates to rotate to in galactic world coordinates _endAnimation = endAnimation; _startAnimation = skybrowser::cameraDirectionGalactic(); _cameraIsRotating = true; } -void SkyBrowserModule::rotateCamera(double deltaTime) { +void SkyBrowserModule::incrementallyRotateCamera(double deltaTime) { // Find smallest angle between the two vectors double smallestAngle = skybrowser::angleVector(_startAnimation, _endAnimation); diff --git a/modules/skybrowser/skybrowsermodule.h b/modules/skybrowser/skybrowsermodule.h index 716b2fcafe..3ed58e7fae 100644 --- a/modules/skybrowser/skybrowsermodule.h +++ b/modules/skybrowser/skybrowsermodule.h @@ -76,7 +76,7 @@ public: // Rotation and animation void lookAtTarget(std::string id); - void rotateCamera(double deltaTime); + void incrementallyRotateCamera(double deltaTime); bool fadeBrowserTargetsToTransparent(double deltaTime); bool fadeBrowserTargetsToOpaque(double deltaTime); void animateTargets(double deltaTime); @@ -109,7 +109,7 @@ protected: private: - void rotateCamera(glm::dvec3 endAnimation); // Pass in galactic coordinate + void startRotatingCamera(glm::dvec3 endAnimation); // Pass in galactic coordinate // The browsers and targets std::vector _targetsBrowsers; Pair* _mouseOnPair{ nullptr }; @@ -142,7 +142,7 @@ private: // Animation of rotation of camera to look at coordinate galactic coordinates glm::dvec3 _startAnimation; glm::dvec3 _endAnimation; - double _stopAnimationThreshold{ 0.0005 }; + double _stopAnimationThreshold{ 0.05 }; double _speed{ 1.0 }; // Data handler for the image collections diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index 4d16cd934f..a2049272d0 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -116,8 +116,10 @@ namespace openspace::skybrowser::luascriptfunctions { LINFO("Connection established to WorldWide Telescope application in " + id); LINFO("Loading image collections to " + id); - // Load the collections here because here we know that the browser can execute javascript - std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/wwt-web-client/master/assets/webclient-explore-root.wtml"; + // Load the collections here because here we know that the browser can execute + // javascript + std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/" + "wwt-web-client/master/assets/webclient-explore-root.wtml"; SkyBrowserModule* module = global::moduleEngine->module(); @@ -238,8 +240,10 @@ namespace openspace::skybrowser::luascriptfunctions { // If no data has been loaded yet, download the data from the web! if (module->nLoadedImages() == 0) { - std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/wwt-web-client/master/assets/webclient-explore-root.wtml"; - //std::string hubble = "http://www.worldwidetelescope.org/wwtweb/catalog.aspx?W=hubble"; + std::string root = "https://raw.githubusercontent.com/WorldWideTelescope/" + "wwt-web-client/master/assets/webclient-explore-root.wtml"; + //std::string hubble = "http://www.worldwidetelescope.org/wwtweb/" + //"catalog.aspx?W=hubble"; std::string directory = absPath("${MODULE_SKYBROWSER}/WWTimagedata/"); // 3D images @@ -249,7 +253,10 @@ namespace openspace::skybrowser::luascriptfunctions { // Load speck files for 3D positions std::filesystem::path globularClusters = absPath(http + globular); std::filesystem::path openClusters = absPath(http + open); - std::vector specks = { openClusters, globularClusters }; + std::vector specks = { + openClusters, + globularClusters + }; module->loadImages(root, directory, specks); } @@ -259,11 +266,11 @@ namespace openspace::skybrowser::luascriptfunctions { for (int i = 0; i < module->nLoadedImages(); i++) { const ImageData& img = module->getWWTDataHandler()->getImage(i); - glm::dvec3 cartCoords = img.equatorialCartesian; + glm::dvec3 coords = img.equatorialCartesian; glm::dvec3 position = img.position3d; // Conversions for ghoul - std::vector cartCoordsVec = { cartCoords.x, cartCoords.y, cartCoords.z }; + std::vector cartCoordsVec = { coords.x, coords.y, coords.z }; std::vector position3d = { position.x, position.y, position.z }; // Index for current ImageData @@ -310,10 +317,10 @@ namespace openspace::skybrowser::luascriptfunctions { // Add the window data for OpenSpace ghoul::lua::push(L, "OpenSpace"); lua_newtable(L); - glm::dvec3 cartesianJ2000 = skybrowser::cameraDirectionEquatorial(); - glm::dvec2 sphericalJ2000 = skybrowser::cartesianToSpherical(cartesianJ2000); + glm::dvec3 cartesian = skybrowser::cameraDirectionEquatorial(); + glm::dvec2 spherical = skybrowser::cartesianToSpherical(cartesian); // Convert to vector so ghoul can read it - std::vector viewDirCelestVec = { cartesianJ2000.x, cartesianJ2000.y, cartesianJ2000.z }; + std::vector viewDirCelestVec = { cartesian.x, cartesian.y, cartesian.z }; // Calculate the smallest FOV of vertical and horizontal @@ -324,9 +331,9 @@ namespace openspace::skybrowser::luascriptfunctions { lua_settable(L, -3); ghoul::lua::push(L, "cartesianDirection", viewDirCelestVec); lua_settable(L, -3); - ghoul::lua::push(L, "ra", sphericalJ2000.x); + ghoul::lua::push(L, "ra", spherical.x); lua_settable(L, -3); - ghoul::lua::push(L, "dec", sphericalJ2000.y); + ghoul::lua::push(L, "dec", spherical.y); lua_settable(L, -3); ghoul::lua::push(L, "selectedBrowserId", module->selectedBrowserId()); lua_settable(L, -3); @@ -348,10 +355,14 @@ namespace openspace::skybrowser::luascriptfunctions { selectedImagesVector.push_back(i); }); - glm::dvec3 celestialCart = pair.targetDirectionEquatorial(); - glm::dvec2 celestialSpherical = skybrowser::cartesianToSpherical(celestialCart); + glm::dvec3 cartesian = pair.targetDirectionEquatorial(); + glm::dvec2 spherical = skybrowser::cartesianToSpherical(cartesian); - std::vector celestialCartVec = { celestialCart.x, celestialCart.y, celestialCart.z }; + std::vector cartesianVec = { + cartesian.x, + cartesian.y, + cartesian.z + }; // Convert color to vector so ghoul can read it glm::ivec3 color = pair.borderColor(); std::vector colorVec = { color.r, color.g, color.b }; @@ -367,11 +378,11 @@ namespace openspace::skybrowser::luascriptfunctions { lua_settable(L, -3); ghoul::lua::push(L, "selectedImages", selectedImagesVector); lua_settable(L, -3); - ghoul::lua::push(L, "cartesianDirection", celestialCartVec); + ghoul::lua::push(L, "cartesianDirection", cartesianVec); lua_settable(L, -3); - ghoul::lua::push(L, "ra", celestialSpherical.x); + ghoul::lua::push(L, "ra", spherical.x); lua_settable(L, -3); - ghoul::lua::push(L, "dec", celestialSpherical.y); + ghoul::lua::push(L, "dec", spherical.y); lua_settable(L, -3); ghoul::lua::push(L, "color", colorVec); lua_settable(L, -3); @@ -393,10 +404,14 @@ namespace openspace::skybrowser::luascriptfunctions { std::for_each(selectedImages.begin(), selectedImages.end(), [&](int index) { selectedImagesVector.push_back(index); }); - glm::dvec3 worldPosition = node->position(); - glm::dvec3 celestialCart = skybrowser::galacticToEquatorial(worldPosition); - glm::dvec2 celestialSpherical = skybrowser::cartesianToSpherical(celestialCart); - std::vector celestialCartVec = { celestialCart.x, celestialCart.y, celestialCart.z }; + glm::dvec3 position3dBrowser = node->position(); + glm::dvec3 cartesian = skybrowser::galacticToEquatorial(position3dBrowser); + glm::dvec2 spherical = skybrowser::cartesianToSpherical(cartesian); + std::vector celestialCartVec = { + cartesian.x, + cartesian.y, + cartesian.z + }; // Convert color to vector so ghoul can read it //glm::ivec3 color = browser->_borderColor.value(); std::vector colorVec = { 200, 200, 200 }; @@ -414,9 +429,9 @@ namespace openspace::skybrowser::luascriptfunctions { lua_settable(L, -3); ghoul::lua::push(L, "cartesianDirection", celestialCartVec); lua_settable(L, -3); - ghoul::lua::push(L, "ra", celestialSpherical.x); + ghoul::lua::push(L, "ra", spherical.x); lua_settable(L, -3); - ghoul::lua::push(L, "dec", celestialSpherical.y); + ghoul::lua::push(L, "dec", spherical.y); lua_settable(L, -3); ghoul::lua::push(L, "color", colorVec); lua_settable(L, -3); @@ -471,7 +486,10 @@ namespace openspace::skybrowser::luascriptfunctions { const int i = ghoul::lua::value(L, 2); double opacity = ghoul::lua::value(L, 3); SkyBrowserModule* module = global::moduleEngine->module(); - ghoul::Dictionary message = wwtmessage::setImageOpacity(std::to_string(i), opacity); + ghoul::Dictionary message = wwtmessage::setImageOpacity( + std::to_string(i), + opacity + ); if (module->getPair(id)) { module->getPair(id)->setImageOpacity(i, opacity); diff --git a/modules/skybrowser/src/renderableskybrowser.cpp b/modules/skybrowser/src/renderableskybrowser.cpp index 5654660a67..48a49b1d4c 100644 --- a/modules/skybrowser/src/renderableskybrowser.cpp +++ b/modules/skybrowser/src/renderableskybrowser.cpp @@ -178,7 +178,9 @@ namespace openspace { void RenderableSkyBrowser::executeJavascript(std::string script) const { //LINFOC(_loggerCat, "Executing javascript " + script); - if (_browserInstance && _browserInstance->getBrowser() && _browserInstance->getBrowser()->GetMainFrame()) { + bool isBrowserReady = _browserInstance && _browserInstance->getBrowser(); + bool isMainFrameReady = _browserInstance->getBrowser()->GetMainFrame(); + if (isBrowserReady && isMainFrameReady) { CefRefPtr frame = _browserInstance->getBrowser()->GetMainFrame(); frame->ExecuteJavaScript(script, frame->GetURL(), 0); } @@ -191,7 +193,12 @@ namespace openspace { } void RenderableSkyBrowser::displayImage(const ImageData& image, const int i) { - sendMessageToWwt(wwtmessage::moveCamera(image.equatorialSpherical, image.fov, 0.0)); + ghoul::Dictionary msg = wwtmessage::moveCamera( + image.equatorialSpherical, + image.fov, + 0.0 + ); + sendMessageToWwt(msg); _verticalFov = image.fov; // Add to selected images if there are no duplicates auto it = std::find(std::begin(_selectedImages), std::end(_selectedImages), i); @@ -232,8 +239,12 @@ namespace openspace { glm::dvec2 aim{ 0.0 }; // Send a message just to establish contact - ghoul::Dictionary message = wwtmessage::moveCamera(aim, _verticalFov, 0.0); - sendMessageToWwt(message); + ghoul::Dictionary msg = wwtmessage::moveCamera( + aim, + _verticalFov, + 0.0 + ); + sendMessageToWwt(msg); // Sleep so we don't bombard WWT with too many messages std::this_thread::sleep_for(std::chrono::milliseconds(500)); @@ -305,7 +316,11 @@ namespace openspace { void RenderableSkyBrowser::setImageLayerOrder(int i, int order) { // Remove from selected list - auto current = std::find(std::begin(_selectedImages), std::end(_selectedImages), i); + auto current = std::find( + std::begin(_selectedImages), + std::end(_selectedImages), + i + ); auto target = std::begin(_selectedImages) + order; // Make sure the image was found in the list diff --git a/modules/skybrowser/src/screenspaceskybrowser.cpp b/modules/skybrowser/src/screenspaceskybrowser.cpp index f8292ce6a6..e4376f0ae4 100644 --- a/modules/skybrowser/src/screenspaceskybrowser.cpp +++ b/modules/skybrowser/src/screenspaceskybrowser.cpp @@ -76,7 +76,12 @@ namespace openspace { ScreenSpaceSkyBrowser::ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary) : ScreenSpaceBrowser(dictionary) - , _browserDimensions(BrowserDimensionInfo, _dimensions, glm::ivec2(0), glm::ivec2(300)) + , _browserDimensions( + BrowserDimensionInfo, + _dimensions, + glm::ivec2(0), + glm::ivec2(300) + ) , _verticalFov(VerticalFovInfo, 10.f, 0.1f, 70.f) , _borderColor(BorderColorInfo, glm::ivec3(200), glm::ivec3(0), glm::ivec3(255)) , _skyTargetId(TargetIdInfo) @@ -221,13 +226,13 @@ namespace openspace { return _fovIsAnimated; } - void ScreenSpaceSkyBrowser::startAnimation(float fov) + void ScreenSpaceSkyBrowser::startFovAnimation(float fov) { _fovIsAnimated = true; _endVfov = fov; } - void ScreenSpaceSkyBrowser::animateToFov(float deltaTime) + void ScreenSpaceSkyBrowser::incrementallyAnimateToFov(float deltaTime) { // If distance is small enough, stop animating float diff = verticalFov() - _endVfov; @@ -334,26 +339,20 @@ namespace openspace { }); } - - // - //void ScreenSpaceSkyBrowser::translate(glm::vec2 translation) { - // glm::vec3 position = _cartesianPosition; - // _cartesianPosition =glm::translate(glm::mat4(1.f), glm::vec3(translation, 0.0f)) * glm::vec4(position, 1.0f); - //} - glm::vec2 ScreenSpaceSkyBrowser::isOnResizeArea(glm::vec2 screenSpaceCoord) { + glm::vec2 ScreenSpaceSkyBrowser::isOnResizeArea(glm::vec2 coord) { glm::vec2 resizePosition = glm::vec2{ 0 }; // Make sure coordinate is on browser - if (!coordIsInsideCornersScreenSpace(screenSpaceCoord)) return resizePosition; + if (!coordIsInsideCornersScreenSpace(coord)) return resizePosition; // TO DO: turn this into a vector and use prettier vector arithmetic float resizeAreaY = screenSpaceDimensions().y * _resizeAreaPercentage; float resizeAreaX = screenSpaceDimensions().x * _resizeAreaPercentage; - bool isOnTop = screenSpaceCoord.y > upperRightCornerScreenSpace().y - resizeAreaY; - bool isOnBottom = screenSpaceCoord.y < lowerLeftCornerScreenSpace().y + resizeAreaY; - bool isOnRight = screenSpaceCoord.x > upperRightCornerScreenSpace().x - resizeAreaX; - bool isOnLeft = screenSpaceCoord.x < lowerLeftCornerScreenSpace().x + resizeAreaX; + bool isOnTop = coord.y > upperRightCornerScreenSpace().y - resizeAreaY; + bool isOnBottom = coord.y < lowerLeftCornerScreenSpace().y + resizeAreaY; + bool isOnRight = coord.x > upperRightCornerScreenSpace().x - resizeAreaX; + bool isOnLeft = coord.x < lowerLeftCornerScreenSpace().x + resizeAreaX; resizePosition.x = isOnRight ? 1.f : isOnLeft ? -1.f : 0.f; resizePosition.y = isOnTop ? 1.f : isOnBottom ? -1.f : 0.f; @@ -379,8 +378,8 @@ namespace openspace { // browser covers: e.g. a browser that covers 0.25 of the // height of the window will have scale = 0.25 - float textureRatio = - static_cast(_texture->dimensions().x) / static_cast(_texture->dimensions().y); + float textureRatio = static_cast(_texture->dimensions().x) / + static_cast(_texture->dimensions().y); glm::mat4 scale = glm::scale( glm::mat4(1.f), diff --git a/modules/skybrowser/src/screenspaceskytarget.cpp b/modules/skybrowser/src/screenspaceskytarget.cpp index 78d8d25756..388308fdc7 100644 --- a/modules/skybrowser/src/screenspaceskytarget.cpp +++ b/modules/skybrowser/src/screenspaceskytarget.cpp @@ -314,7 +314,9 @@ namespace openspace { // Start a thread to enable user interactions while locking target _lockTarget = std::thread([&] { while (_isLocked) { - _cartesianPosition = skybrowser::equatorialToScreenSpace(_lockedCoordinates); + _cartesianPosition = skybrowser::equatorialToScreenSpace( + _lockedCoordinates + ); } }); }