From 5917ac598aecbaf2796f9f5378ea665b0cbd2132 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Fri, 8 Apr 2022 14:13:23 -0400 Subject: [PATCH] Feature/location measure (#1987) * wip commit for measuring * wip;fixing for codegene change * adding asset file * clean up comments * pr comment cleanup --- .../educational/scale/eiffeltower.asset | 77 +++++++++++++++++++ .../globebrowsing/globebrowsingmodule_lua.inl | 39 ++++++++-- modules/globebrowsing/src/globerotation.cpp | 5 ++ .../globebrowsing/src/globetranslation.cpp | 5 ++ 4 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 data/assets/educational/scale/eiffeltower.asset diff --git a/data/assets/educational/scale/eiffeltower.asset b/data/assets/educational/scale/eiffeltower.asset new file mode 100644 index 0000000000..dc91b4ed1d --- /dev/null +++ b/data/assets/educational/scale/eiffeltower.asset @@ -0,0 +1,77 @@ +local earthAsset = asset.require('scene/solarsystem/planets/earth/earth') +local sunAsset = asset.require('scene/solarsystem/sun/sun') + +local modelFolder = asset.syncedResource({ + Name = "Eiffel Tower Model", + Type = "HttpSynchronization", + Identifier = "eiffel_tower_model", + Version = 1 +}) + +local eiffelTower = { + Identifier = "eiffelTower", + Parent = earthAsset.Earth.Identifier, + --Note: Lat/Lon/Scale values comes from alignment with Esri World Imagery 2D layer + Transform = { + Translation = { + Type = "GlobeTranslation", + Globe = earthAsset.Earth.Identifier, + Longitude = 2.29448, + Latitude = 48.85824, + Altitude = 0.0, + UseHeightmap = true + }, + Rotation = { + Type = "GlobeRotation", + Globe = earthAsset.Earth.Identifier, + Longitude = 2.29448, + Latitude = 48.85824, + UseHeightmap = false + }, + Scale = { + Type = "StaticScale", + Scale = 4.38 + } + }, + Renderable = { + Type = "RenderableModel", + GeometryFile = modelFolder .. "eiffeltower.osmodel", + ModelScale = "Centimeter", + RotationVector = { 0.0, 45.0, 0.0 }, + LightSources = { sunAsset.LightSource } + }, + GUI = { + Name = "Eiffel Tower", + Path = "/Scale Objects" + } +} + +local updatePositionAction = { + Identifier = "os.drop_eiffel_tower", + Name = "Drop Eiffel Tower under camera", + Command = [[local lat, lon, alt = openspace.globebrowsing.getGeoPositionForCamera(); + local camera = openspace.navigation.getNavigationState(); + openspace.setParent('eiffelTower', camera.Anchor) + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Globe', camera.Anchor); + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Latitude', lat); + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Longitude', lon); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Globe', camera.Anchor); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Latitude', lat); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Longitude', lon); + ]], + Documentation = "Updates the Eiffel Tower position based on the globe location of the camera", + GuiPath = "/Scale Objects", + IsLocal = false +} + +asset.onInitialize(function() + openspace.addSceneGraphNode(eiffelTower) + openspace.action.registerAction(updatePositionAction) +end) + +asset.onDeinitialize(function() + openspace.action.removeAction(updatePositionAction) + openspace.removeSceneGraphNode(eiffelTower) +end) + +asset.export(eiffelTower) diff --git a/modules/globebrowsing/globebrowsingmodule_lua.inl b/modules/globebrowsing/globebrowsingmodule_lua.inl index 8c6a6cee94..3b85f60227 100644 --- a/modules/globebrowsing/globebrowsingmodule_lua.inl +++ b/modules/globebrowsing/globebrowsingmodule_lua.inl @@ -22,6 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include + namespace { /** @@ -370,33 +372,54 @@ getLocalPositionFromGeo(std::string globeIdentifier, double latitude, double lon /** * Get geographic coordinates of the camera position in latitude, longitude, and altitude - * (degrees and meters). + * (degrees and meters). If the optional bool paramater is specified, the camera + * eye postion will be used instead */ -[[codegen::luawrap]] std::tuple getGeoPositionForCamera() { +[[codegen::luawrap]] std::tuple +getGeoPositionForCamera(bool useEyePosition = false) +{ using namespace openspace; using namespace globebrowsing; GlobeBrowsingModule* module = global::moduleEngine->module(); - const RenderableGlobe* globe = module->castFocusNodeRenderableToGlobe(); + const RenderableGlobe* globe = module->castFocusNodeRenderableToGlobe();//focus vs anchor if (!globe) { throw ghoul::lua::LuaError("Focus node must be a RenderableGlobe"); } + Camera* camera = global::navigationHandler->camera(); + + glm::dvec3 cameraPosition = camera->positionVec3(); + - const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3(); const SceneGraphNode* anchor = global::navigationHandler->orbitalNavigator().anchorNode(); const glm::dmat4 inverseModelTransform = glm::inverse(anchor->modelTransform()); - const glm::dvec3 cameraPositionModelSpace = - glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0)); + + glm::dvec3 target; + + ///@TODO (04-08-2022, micahnyc) + //adjust this to use the camera lookat + //once we fix this calculation, then we just add true to the function call in the asset + if (useEyePosition) { + const glm::dvec3 anchorPos = anchor->worldPosition(); + const glm::dvec3 cameraDir = ghoul::viewDirection(camera->rotationQuaternion()); + const double anchorToCameraDistance = glm::distance(anchorPos, cameraPosition); + const double anchorToPosDistance = glm::distance(anchorPos + globe->boundingSphere(), cameraPosition); + target = cameraPosition + anchorToPosDistance * cameraDir; + } + else { + target = glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0)); + } + const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle( - cameraPositionModelSpace + target ); const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2( posHandle.centerToReferenceSurface ); const double altitude = glm::length( - cameraPositionModelSpace - posHandle.centerToReferenceSurface + target - posHandle.centerToReferenceSurface ); return { glm::degrees(geo2.lat), glm::degrees(geo2.lon), altitude }; diff --git a/modules/globebrowsing/src/globerotation.cpp b/modules/globebrowsing/src/globerotation.cpp index 2d3bf8c077..b254903d8c 100644 --- a/modules/globebrowsing/src/globerotation.cpp +++ b/modules/globebrowsing/src/globerotation.cpp @@ -110,6 +110,11 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(dictionary); _globe = p.globe; + _globe.onChange([this]() { + findGlobe(); + setUpdateVariables(); + }); + addProperty(_globe); _latitude = p.latitude.value_or(_latitude); _latitude.onChange([this]() { setUpdateVariables(); }); diff --git a/modules/globebrowsing/src/globetranslation.cpp b/modules/globebrowsing/src/globetranslation.cpp index e6e027fffb..c6b457e5b6 100644 --- a/modules/globebrowsing/src/globetranslation.cpp +++ b/modules/globebrowsing/src/globetranslation.cpp @@ -111,6 +111,11 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(dictionary); _globe = p.globe; + _globe.onChange([this]() { + fillAttachedNode(); + setUpdateVariables(); + }); + addProperty(_globe); _latitude = p.latitude.value_or(_latitude); _latitude.onChange([this]() { setUpdateVariables(); });