Cleanup for Spheres and PSC (#827)

* Fade fixes
  * Clean up RenderableSphere. Add orientation properties.
  * Sane defaults for Digital Universe
  * Clean up New Horizons related code
  * Add basic scene
  * Add ability to initialize rotation as quaternion and mat3
  * Adapt legacy code to new Renderable interface
This commit is contained in:
Emil Axelsson
2019-04-24 13:34:49 +02:00
committed by Alexander Bock
parent e78121febc
commit 50ff2d96d2
77 changed files with 667 additions and 2848 deletions

View File

@@ -34,6 +34,27 @@ namespace {
"This value is the used as a 3x3 rotation matrix that is applied to the scene "
"graph node that this transformation is attached to relative to its parent."
};
// Conversion from rotation matrix to euler angles,
// given that the rotation is a pure rotation matrix.
// Inspired by:
// https://www.learnopencv.com/rotation-matrix-to-euler-angles/
glm::dvec3 rotationMatrixToEulerAngles(glm::dmat4 mat) {
double sy = glm::sqrt(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
bool singular = sy < 1e-6;
double x, y, z;
if (singular) {
x = glm::atan(-mat[2][1], mat[1][1]);
y = glm::atan(-mat[0][2], sy);
z = 0;
} else {
x = glm::atan(mat[1][2], mat[2][2]);
y = glm::atan(-mat[0][2], sy);
z = glm::atan(mat[0][1], mat[0][0]);
}
return glm::dvec3(x, y, z);
}
} // namespace
namespace openspace {
@@ -53,21 +74,27 @@ documentation::Documentation StaticRotation::Documentation() {
RotationInfo.identifier,
new OrVerifier({
new DoubleVector3Verifier(),
new DoubleVector4Verifier(),
new DoubleMatrix3Verifier()
}),
Optional::No,
"Stores the static rotation as either a vector containing Euler angles "
"or by specifiying the 3x3 rotation matrix directly"
"Stores the static rotation as a vector containing Euler angles, "
" a quaternion or a rotation matrix."
}
}
};
}
StaticRotation::StaticRotation()
: _rotationMatrix(RotationInfo, glm::dmat3(1.0), glm::dmat3(-1.0), glm::dmat3(1.0))
: _eulerRotation(
RotationInfo,
glm::vec3(0.f),
glm::vec3(-glm::pi<float>()),
glm::vec3(glm::pi<float>())
)
{
addProperty(_rotationMatrix);
_rotationMatrix.onChange([this]() { requireUpdate(); });
addProperty(_eulerRotation);
_eulerRotation.onChange([this]() { requireUpdate(); });
}
StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary) : StaticRotation() {
@@ -77,20 +104,35 @@ StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary) : StaticRota
"StaticRotation"
);
if (dictionary.hasKeyAndValue<glm::dvec3>(RotationInfo.identifier)) {
_rotationMatrix = glm::mat3_cast(
glm::dquat(dictionary.value<glm::dvec3>(RotationInfo.identifier))
_eulerRotation = static_cast<glm::vec3>(
dictionary.value<glm::dvec3>(RotationInfo.identifier)
);
_matrixIsDirty = true;
} else if (dictionary.hasKeyAndValue<glm::dvec4>(RotationInfo.identifier)) {
glm::dvec4 data = dictionary.value<glm::dvec4>(RotationInfo.identifier);
_eulerRotation = rotationMatrixToEulerAngles(
glm::mat3_cast(glm::dquat(data.w, data.x, data.y, data.z))
);
_matrixIsDirty = true;
} else if (dictionary.hasKeyAndValue<glm::dmat3>(RotationInfo.identifier)) {
_eulerRotation = rotationMatrixToEulerAngles(
dictionary.value<glm::dmat3>(RotationInfo.identifier)
);
_matrixIsDirty = true;
}
else {
// Must be glm::dmat3 due to specification restriction
_rotationMatrix = dictionary.value<glm::dmat3>(RotationInfo.identifier);
}
_eulerRotation.onChange([this]() {
_matrixIsDirty = true;
});
}
glm::dmat3 StaticRotation::matrix(const UpdateData&) const {
return _rotationMatrix;
if (_matrixIsDirty) {
_cachedMatrix = glm::mat3_cast(glm::quat(_eulerRotation.value()));
_matrixIsDirty = false;
}
return _cachedMatrix;
}
} // namespace openspace