mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-09 21:21:19 -06:00
Move calculation of camera geo position from DashboardItemGlobeLocation to a function in GlobeBrowsingModule
This commit is contained in:
@@ -421,6 +421,46 @@ glm::vec3 GlobeBrowsingModule::cartesianCoordinatesFromGeo(
|
||||
return glm::vec3(globe.ellipsoid().cartesianPosition(pos));
|
||||
}
|
||||
|
||||
glm::dvec3 GlobeBrowsingModule::geoPosition() const {
|
||||
using namespace globebrowsing;
|
||||
|
||||
const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode();
|
||||
if (!n) {
|
||||
return glm::dvec3(0);
|
||||
}
|
||||
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
|
||||
if (!globe) {
|
||||
return glm::dvec3(0);
|
||||
}
|
||||
|
||||
const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
|
||||
const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform());
|
||||
const glm::dvec3 cameraPositionModelSpace =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
|
||||
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(
|
||||
cameraPositionModelSpace
|
||||
);
|
||||
|
||||
const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2(
|
||||
posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
double lat = glm::degrees(geo2.lat);
|
||||
double lon = glm::degrees(geo2.lon);
|
||||
|
||||
double altitude = glm::length(
|
||||
cameraPositionModelSpace - posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
if (glm::length(cameraPositionModelSpace) <
|
||||
glm::length(posHandle.centerToReferenceSurface))
|
||||
{
|
||||
altitude = -altitude;
|
||||
}
|
||||
|
||||
return glm::dvec3(lat, lon, altitude);
|
||||
}
|
||||
|
||||
void GlobeBrowsingModule::goToChunk(const globebrowsing::RenderableGlobe& globe,
|
||||
const globebrowsing::TileIndex& ti,
|
||||
glm::vec2 uv, bool doResetCameraDirection)
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
glm::vec3 cartesianCoordinatesFromGeo(const globebrowsing::RenderableGlobe& globe,
|
||||
double latitude, double longitude, double altitude);
|
||||
|
||||
glm::dvec3 geoPosition() const;
|
||||
|
||||
globebrowsing::cache::MemoryAwareTileCache* tileCache();
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
|
||||
#include <modules/globebrowsing/src/dashboarditemglobelocation.h>
|
||||
|
||||
#include <modules/globebrowsing/globebrowsingmodule.h>
|
||||
#include <modules/globebrowsing/src/basictypes.h>
|
||||
#include <modules/globebrowsing/src/renderableglobe.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/navigation/navigationhandler.h>
|
||||
#include <openspace/navigation/orbitalnavigator.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
@@ -171,42 +173,13 @@ DashboardItemGlobeLocation::DashboardItemGlobeLocation(
|
||||
|
||||
void DashboardItemGlobeLocation::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
GlobeBrowsingModule* module = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
|
||||
using namespace globebrowsing;
|
||||
|
||||
const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode();
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
|
||||
const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
|
||||
const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform());
|
||||
const glm::dvec3 cameraPositionModelSpace =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
|
||||
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(
|
||||
cameraPositionModelSpace
|
||||
);
|
||||
|
||||
const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2(
|
||||
posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
double lat = glm::degrees(geo2.lat);
|
||||
double lon = glm::degrees(geo2.lon);
|
||||
|
||||
double altitude = glm::length(
|
||||
cameraPositionModelSpace - posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
if (glm::length(cameraPositionModelSpace) <
|
||||
glm::length(posHandle.centerToReferenceSurface))
|
||||
{
|
||||
altitude = -altitude;
|
||||
}
|
||||
glm::dvec3 position = module->geoPosition();
|
||||
double lat = position.x;
|
||||
double lon = position.y;
|
||||
double altitude = position.z;
|
||||
|
||||
std::pair<double, std::string> dist = simplifyDistance(altitude);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user