diff --git a/data/assets/circle.png b/data/assets/circle.png new file mode 100644 index 0000000000..5f3a08e5c5 Binary files /dev/null and b/data/assets/circle.png differ diff --git a/data/assets/hoverCircle.asset b/data/assets/hoverCircle.asset new file mode 100644 index 0000000000..91b16db98c --- /dev/null +++ b/data/assets/hoverCircle.asset @@ -0,0 +1,12 @@ +local assetHelper = asset.require('util/asset_helper') + + local spec = { + Identifier = "HoverCircle", + Type = "ScreenSpaceImageLocal", + Name = "HoverCircle", + FaceCamera = false, + Scale= 0.015, + Enabled = false, + TexturePath = "D:/Ylvas/OpenSpace/data/assets/circle.png" + }; +assetHelper.registerScreenSpaceRenderables(asset, { spec }) diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index e7227f3494..f7ba805bc5 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -71,6 +71,22 @@ namespace openspace { "string or list of strings", "Add one or multiple exoplanet systems to the scene, as specified by the " "input. An input string should be the name of the system host star" + }, + { + "moveCircleToHoverImage", + &skybrowser::luascriptfunctions::moveCircleToHoverImage, + {}, + "string or list of strings", + "Add one or multiple exoplanet systems to the scene, as specified by the " + "input. An input string should be the name of the system host star" + }, + { + "disableHoverCircle", + &skybrowser::luascriptfunctions::disableHoverCircle, + {}, + "string or list of strings", + "Add one or multiple exoplanet systems to the scene, as specified by the " + "input. An input string should be the name of the system host star" }, { "move", diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index 2a03c411b5..bf8e4a0fb7 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,45 @@ namespace openspace::skybrowser::luascriptfunctions { browser->sendMessageToWWT(browser->createMessageForSettingForegroundOpacityWWT(100)); return 1; } + + int moveCircleToHoverImage(lua_State* L) { + // Load image + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::moveCircleToHoverImage"); + const int i = ghoul::lua::value(L, 1); + + ScreenSpaceImageLocal* hoverCircle = dynamic_cast(global::renderEngine->screenSpaceRenderable("HoverCircle")); + hoverCircle->property("Enabled")->set(true); + SkyBrowserModule* module = global::moduleEngine->module(); + const ImageData& resultImage = module->getWWTDataHandler()->getLoadedImages()[i]; + + if (resultImage.hasCoords) { + + glm::dvec3 imageCoordsGalactic = icrsToGalacticCartesian(resultImage.celestCoords.x, resultImage.celestCoords.y, 1.0); + // This is a duplicate of target function "lookAtGalacticCoord". Probably should rewrite this so there are no duplicates... + glm::dmat4 cameraInvRotMat = global::navigationHandler->camera()->viewRotationMatrix(); + glm::dvec3 viewDirectionLocal = cameraInvRotMat * glm::dvec4(imageCoordsGalactic, 1.f); + + glm::dvec2 angleCoordsLocal = glm::dvec2(atan(viewDirectionLocal.x / viewDirectionLocal.z), atan(viewDirectionLocal.y / viewDirectionLocal.z)); + double projPlaneDistance = -2.1f; + glm::dvec2 imageCoordsScreenSpace = glm::dvec2(projPlaneDistance * tan(angleCoordsLocal.x), projPlaneDistance * tan(angleCoordsLocal.y)); + // Translate target + hoverCircle->translate(glm::vec2(imageCoordsScreenSpace) - hoverCircle->getScreenSpacePosition(), hoverCircle->getScreenSpacePosition()); + } + + return 1; + } + + int disableHoverCircle(lua_State* L) { + // Load image + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::disableHoverCircle"); + LINFO("YO"); + ScreenSpaceImageLocal* hoverCircle = dynamic_cast(global::renderEngine->screenSpaceRenderable("HoverCircle")); + LINFO("YAH"); + hoverCircle->property("Enabled")->set(false); + LINFO("Yu"); + return 1; + } + int followCamera(lua_State* L) { // Load images from url diff --git a/modules/skybrowser/src/wwtdatahandler.cpp b/modules/skybrowser/src/wwtdatahandler.cpp index e00adc27c4..46e2af616a 100644 --- a/modules/skybrowser/src/wwtdatahandler.cpp +++ b/modules/skybrowser/src/wwtdatahandler.cpp @@ -6,10 +6,6 @@ namespace { constexpr const char* _loggerCat = "WWTDataHandler"; - - - - } //namespace namespace openspace {