From fd2cd0f9ac3979cc7a2b4c32966435e253444489 Mon Sep 17 00:00:00 2001 From: "Adam N. Morris" Date: Fri, 6 Oct 2023 15:00:06 -0500 Subject: [PATCH] Fixed passing degree values around --- .../include/cesium/omniverse/OmniGlobeAnchor.h | 6 +++--- src/core/src/GeospatialUtil.cpp | 5 +++-- src/core/src/OmniGlobeAnchor.cpp | 18 ++++++------------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/core/include/cesium/omniverse/OmniGlobeAnchor.h b/src/core/include/cesium/omniverse/OmniGlobeAnchor.h index 225603101..c3a79c471 100644 --- a/src/core/include/cesium/omniverse/OmniGlobeAnchor.h +++ b/src/core/include/cesium/omniverse/OmniGlobeAnchor.h @@ -18,7 +18,7 @@ struct OmniGlobeAnchorValueCache { class OmniGlobeAnchor { public: - OmniGlobeAnchor(pxr::SdfPath anchorPrimPath, const glm::dmat4 anchorToFixed); + OmniGlobeAnchor(pxr::SdfPath anchorPrimPath, const glm::dmat4& anchorToFixed); [[nodiscard]] const pxr::GfMatrix4d& getCachedTransformation() const; [[nodiscard]] const pxr::GfVec3d& getCachedGeographicCoordinate() const; @@ -36,10 +36,10 @@ class OmniGlobeAnchor { [[nodiscard]] const pxr::SdfPath& getPrimPath() const; void updateByFixedTransform( const glm::dvec3& ecefPositionVec, - const glm::dvec3& ecefRotationVec, + const glm::dvec3& ecefRotationRadVec, const glm::dvec3& ecefScaleVec, bool shouldReorient); - void updateByGeographicCoordinates(double latitude, double longitude, double height, bool shouldReorient); + void updateByGeographicCoordinates(CesiumGeospatial::Cartographic& cartographic, bool shouldReorient); void updateByUsdTransform(const CesiumGeospatial::Cartographic& origin, bool shouldReorient); private: diff --git a/src/core/src/GeospatialUtil.cpp b/src/core/src/GeospatialUtil.cpp index a52cfef4d..a41fb9f0a 100644 --- a/src/core/src/GeospatialUtil.cpp +++ b/src/core/src/GeospatialUtil.cpp @@ -133,7 +133,8 @@ void updateAnchorByLatLongHeight( bool shouldReorient; anchorApi.GetAdjustOrientationForGlobeWhenMovingAttr().Get(&shouldReorient); - globeAnchor->updateByGeographicCoordinates(usdLatitude, usdLongitude, usdHeight, shouldReorient); + auto cartographic = CesiumGeospatial::Cartographic::fromDegrees(usdLongitude, usdLatitude, usdHeight); + globeAnchor->updateByGeographicCoordinates(cartographic, shouldReorient); auto localTransform = globeAnchor->getAnchorToLocalTransform(origin); UsdUtil::addOrUpdateTransformOpForAnchor(anchorApi.GetPath(), localTransform); @@ -188,7 +189,7 @@ void updateAnchorByFixedTransform( bool shouldReorient; anchorApi.GetAdjustOrientationForGlobeWhenMovingAttr().Get(&shouldReorient); - globeAnchor->updateByFixedTransform(ecefPositionVec, ecefRotationVec, ecefScaleVec, shouldReorient); + globeAnchor->updateByFixedTransform(ecefPositionVec, glm::radians(ecefRotationVec), ecefScaleVec, shouldReorient); auto localTransform = globeAnchor->getAnchorToLocalTransform(origin); UsdUtil::addOrUpdateTransformOpForAnchor(anchorApi.GetPath(), localTransform); diff --git a/src/core/src/OmniGlobeAnchor.cpp b/src/core/src/OmniGlobeAnchor.cpp index 340d405e6..431f46b9b 100644 --- a/src/core/src/OmniGlobeAnchor.cpp +++ b/src/core/src/OmniGlobeAnchor.cpp @@ -57,7 +57,7 @@ void OmniGlobeAnchor::updateCachedValues() { } } -OmniGlobeAnchor::OmniGlobeAnchor(pxr::SdfPath anchorPrimPath, const glm::dmat4 anchorToFixed) +OmniGlobeAnchor::OmniGlobeAnchor(pxr::SdfPath anchorPrimPath, const glm::dmat4& anchorToFixed) : _anchorPrimPath{std::move(anchorPrimPath)} { _anchor = std::make_shared(anchorToFixed); } @@ -89,30 +89,24 @@ const pxr::SdfPath& OmniGlobeAnchor::getPrimPath() const { void OmniGlobeAnchor::updateByFixedTransform( const glm::dvec3& ecefPositionVec, - const glm::dvec3& ecefRotationVec, + const glm::dvec3& ecefRotationRadVec, const glm::dvec3& ecefScaleVec, bool shouldReorient) { auto translation = glm::translate(glm::dmat4(1.0), ecefPositionVec); - auto rotation = glm::eulerAngleXYZ( - glm::radians(ecefRotationVec.x), glm::radians(ecefRotationVec.y), glm::radians(ecefRotationVec.z)); + auto rotation = glm::eulerAngleXYZ(ecefRotationRadVec.x, ecefRotationRadVec.y, ecefRotationRadVec.z); auto scale = glm::scale(glm::dmat4(1.0), ecefScaleVec); auto newAnchorToFixed = translation * rotation * scale; _anchor->setAnchorToFixedTransform(newAnchorToFixed, shouldReorient); } -void OmniGlobeAnchor::updateByGeographicCoordinates( - double latitude, - double longitude, - double height, - bool shouldReorient) { - auto cartographic = CesiumGeospatial::Cartographic::fromDegrees(longitude, latitude, height); +void OmniGlobeAnchor::updateByGeographicCoordinates(CesiumGeospatial::Cartographic& cartographic, bool shouldReorient) { auto newEcefPositionVec = CesiumGeospatial::Ellipsoid::WGS84.cartographicToCartesian(cartographic); - auto ecefRotationVec = UsdUtil::usdToGlmVector(_valueCache.ecefRotation); + auto ecefRotationDegVec = UsdUtil::usdToGlmVector(_valueCache.ecefRotation); auto ecefScaleVec = UsdUtil::usdToGlmVector(_valueCache.ecefScale); - updateByFixedTransform(newEcefPositionVec, ecefRotationVec, ecefScaleVec, shouldReorient); + updateByFixedTransform(newEcefPositionVec, glm::radians(ecefRotationDegVec), ecefScaleVec, shouldReorient); } void OmniGlobeAnchor::updateByUsdTransform(const CesiumGeospatial::Cartographic& origin, bool shouldReorient) {