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:
Micah Acinapura
2022-04-08 14:13:23 -04:00
committed by GitHub
parent eafa8bf467
commit 5917ac598a
4 changed files with 118 additions and 8 deletions

View File

@@ -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 };