mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
93 lines
4.2 KiB
C++
93 lines
4.2 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2016 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
#include <modules/base/rotation/spicerotation.h>
|
|
|
|
#include <openspace/util/spicemanager.h>
|
|
#include <openspace/util/time.h>
|
|
|
|
namespace {
|
|
const std::string _loggerCat = "SpiceRotation";
|
|
//const std::string keyGhosting = "EphmerisGhosting";
|
|
|
|
const std::string KeySourceFrame = "SourceFrame";
|
|
const std::string KeyDestinationFrame = "DestinationFrame";
|
|
const std::string KeyKernels = "Kernels";
|
|
}
|
|
|
|
namespace openspace {
|
|
|
|
SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
|
|
: _sourceFrame("")
|
|
, _destinationFrame("")
|
|
, _rotationMatrix(1.0)
|
|
, _kernelsLoadedSuccessfully(true)
|
|
{
|
|
const bool hasSourceFrame = dictionary.getValue(KeySourceFrame, _sourceFrame);
|
|
if (!hasSourceFrame)
|
|
LERROR("SpiceRotation does not contain the key '" << KeySourceFrame << "'");
|
|
|
|
const bool hasDestinationFrame = dictionary.getValue(KeyDestinationFrame, _destinationFrame);
|
|
if (!hasDestinationFrame)
|
|
LERROR("SpiceRotation does not contain the key '" << KeyDestinationFrame << "'");
|
|
|
|
ghoul::Dictionary kernels;
|
|
dictionary.getValue(KeyKernels, kernels);
|
|
for (size_t i = 1; i <= kernels.size(); ++i) {
|
|
std::string kernel;
|
|
bool success = kernels.getValue(std::to_string(i), kernel);
|
|
if (!success)
|
|
LERROR("'" << KeyKernels << "' has to be an array-style table");
|
|
|
|
try {
|
|
SpiceManager::ref().loadKernel(kernel);
|
|
_kernelsLoadedSuccessfully = true;
|
|
}
|
|
catch (const SpiceManager::SpiceException& e) {
|
|
LERROR("Could not load SPICE kernel: " << e.what());
|
|
_kernelsLoadedSuccessfully = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
const glm::dmat3& SpiceRotation::matrix() const {
|
|
return _rotationMatrix;
|
|
}
|
|
|
|
void SpiceRotation::update(const UpdateData& data) {
|
|
if (!_kernelsLoadedSuccessfully)
|
|
return;
|
|
try {
|
|
_rotationMatrix = SpiceManager::ref().positionTransformMatrix(
|
|
_sourceFrame,
|
|
_destinationFrame,
|
|
data.time);
|
|
}
|
|
catch (const ghoul::RuntimeError&) {
|
|
// In case of missing coverage
|
|
_rotationMatrix = glm::dmat3(1);
|
|
}
|
|
}
|
|
|
|
} // namespace openspace
|