Skip to content

Commit

Permalink
Add CesiumGeometry::Transforms::getUpAxisTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 16, 2024
1 parent 14034e0 commit e5640ae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CesiumGeometry/include/CesiumGeometry/Transforms.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Axis.h"
#include "Library.h"

#include <glm/fwd.hpp>
Expand Down Expand Up @@ -83,6 +84,17 @@ struct CESIUMGEOMETRY_API Transforms final {
glm::dvec3* pTranslation,
glm::dquat* pRotation,
glm::dvec3* pScale);

/**
* @brief Gets a transform that converts from one up axis to another.
*
* @param from The up axis to convert from.
* @param to The up axis to convert to.
*
* @returns The up axis transform.
*/
static glm::dmat4
getUpAxisTransform(CesiumGeometry::Axis from, CesiumGeometry::Axis to);
};

} // namespace CesiumGeometry
37 changes: 37 additions & 0 deletions CesiumGeometry/src/Transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,41 @@ void Transforms::computeTranslationRotationScaleFromMatrix(
*pTranslation = glm::dvec3(matrix[3]);
}

glm::dmat4 Transforms::getUpAxisTransform(Axis from, Axis to) {
switch (from) {
case Axis::X:
switch (to) {
case Axis::X:
return glm::dmat4(1.0);
case Axis::Y:
return X_UP_TO_Y_UP;
case Axis::Z:
return X_UP_TO_Z_UP;
}
break;
case Axis::Y:
switch (to) {
case Axis::X:
return Y_UP_TO_X_UP;
case Axis::Y:
return glm::dmat4(1.0);
case Axis::Z:
return Y_UP_TO_Z_UP;
}
break;
case Axis::Z:
switch (to) {
case Axis::X:
return Z_UP_TO_X_UP;
case Axis::Y:
return Z_UP_TO_Y_UP;
case Axis::Z:
return glm::dmat4(1.0);
}
break;
}

return glm::dmat4(1.0);
}

} // namespace CesiumGeometry

0 comments on commit e5640ae

Please sign in to comment.