Skip to content

Commit

Permalink
Fixed passing degree values around
Browse files Browse the repository at this point in the history
  • Loading branch information
weegeekps committed Oct 6, 2023
1 parent d97f1c4 commit fd2cd0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/core/include/cesium/omniverse/OmniGlobeAnchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/core/src/GeospatialUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions src/core/src/OmniGlobeAnchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CesiumGeospatial::GlobeAnchor>(anchorToFixed);
}
Expand Down Expand Up @@ -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<double>(
glm::radians(ecefRotationVec.x), glm::radians(ecefRotationVec.y), glm::radians(ecefRotationVec.z));
auto rotation = glm::eulerAngleXYZ<double>(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) {
Expand Down

0 comments on commit fd2cd0f

Please sign in to comment.