mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-09 05:00:42 -06:00
Feature/location measure (#1987)
* wip commit for measuring * wip;fixing for codegene change * adding asset file * clean up comments * pr comment cleanup
This commit is contained in:
77
data/assets/educational/scale/eiffeltower.asset
Normal file
77
data/assets/educational/scale/eiffeltower.asset
Normal file
@@ -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)
|
||||
@@ -22,6 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/util/collisionhelper.h>
|
||||
|
||||
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<double, double, double> getGeoPositionForCamera() {
|
||||
[[codegen::luawrap]] std::tuple<double, double, double>
|
||||
getGeoPositionForCamera(bool useEyePosition = false)
|
||||
{
|
||||
using namespace openspace;
|
||||
using namespace globebrowsing;
|
||||
|
||||
GlobeBrowsingModule* module = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
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 };
|
||||
|
||||
@@ -110,6 +110,11 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary)
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
_globe = p.globe;
|
||||
_globe.onChange([this]() {
|
||||
findGlobe();
|
||||
setUpdateVariables();
|
||||
});
|
||||
addProperty(_globe);
|
||||
|
||||
_latitude = p.latitude.value_or(_latitude);
|
||||
_latitude.onChange([this]() { setUpdateVariables(); });
|
||||
|
||||
@@ -111,6 +111,11 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary)
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
_globe = p.globe;
|
||||
_globe.onChange([this]() {
|
||||
fillAttachedNode();
|
||||
setUpdateVariables();
|
||||
});
|
||||
addProperty(_globe);
|
||||
|
||||
_latitude = p.latitude.value_or(_latitude);
|
||||
_latitude.onChange([this]() { setUpdateVariables(); });
|
||||
|
||||
Reference in New Issue
Block a user