diff --git a/include/openspace/scene/rotation.h b/include/openspace/scene/rotation.h index 2ada96c6ab..c76cf1ef85 100644 --- a/include/openspace/scene/rotation.h +++ b/include/openspace/scene/rotation.h @@ -34,7 +34,7 @@ namespace ghoul { class Dictionary; } namespace openspace { -class Time; +struct UpdateData; namespace documentation { struct Documentation; } @@ -49,8 +49,8 @@ public: virtual bool initialize(); const glm::dmat3& matrix() const; - virtual glm::dmat3 matrix(const Time& time) const = 0; - void update(const Time& time); + virtual glm::dmat3 matrix(const UpdateData& time) const = 0; + void update(const UpdateData& data); static documentation::Documentation Documentation(); diff --git a/include/openspace/scene/scale.h b/include/openspace/scene/scale.h index 4f8faccd46..20a9c81fce 100644 --- a/include/openspace/scene/scale.h +++ b/include/openspace/scene/scale.h @@ -34,7 +34,7 @@ namespace ghoul { class Dictionary; } namespace openspace { -class Time; +struct UpdateData; namespace documentation { struct Documentation; } @@ -49,8 +49,8 @@ public: virtual bool initialize(); double scaleValue() const; - virtual double scaleValue(const Time& time) const = 0; - virtual void update(const Time& time); + virtual double scaleValue(const UpdateData& data) const = 0; + virtual void update(const UpdateData& data); static documentation::Documentation Documentation(); diff --git a/include/openspace/scene/translation.h b/include/openspace/scene/translation.h index d7f1045d0e..93a2f0f30e 100644 --- a/include/openspace/scene/translation.h +++ b/include/openspace/scene/translation.h @@ -36,7 +36,7 @@ namespace ghoul { class Dictionary; } namespace openspace { -class Time; +struct UpdateData; namespace documentation { struct Documentation; } @@ -50,9 +50,9 @@ public: virtual bool initialize(); glm::dvec3 position() const; - void update(const Time& time); + void update(const UpdateData& data); - virtual glm::dvec3 position(const Time& time) const = 0; + virtual glm::dvec3 position(const UpdateData& data) const = 0; // Registers a callback that gets called when a significant change has been made that // invalidates potentially stored points, for example in trails diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 4f1b8f8705..f59393c8c8 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -53,6 +53,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.h ${CMAKE_CURRENT_SOURCE_DIR}/translation/luatranslation.h ${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/constantrotation.h ${CMAKE_CURRENT_SOURCE_DIR}/rotation/fixedrotation.h ${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.h ${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.h @@ -92,6 +93,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.cpp ${CMAKE_CURRENT_SOURCE_DIR}/translation/luatranslation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/constantrotation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rotation/fixedrotation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index fa67a68d29..e67c069e9f 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { auto fRotation = FactoryManager::ref().factory(); ghoul_assert(fRotation, "Rotation factory was not created"); + fRotation->registerClass("ConstantRotation"); fRotation->registerClass("FixedRotation"); fRotation->registerClass("LuaRotation"); fRotation->registerClass("StaticRotation"); diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index 99667a751f..2cc3283946 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -197,7 +197,12 @@ void RenderableTrailOrbit::update(const UpdateData& data) { // 2 // Write the current location into the floating position - const glm::vec3 p = _translation->position(data.time.j2000Seconds()); + const glm::vec3 p = _translation->position({ + {}, + data.time.j2000Seconds(), + 0.0, + false + }); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; glBindVertexArray(_primaryRenderInformation._vaoID); @@ -371,7 +376,12 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails( // Get the new permanent point and write it into the (previously) floating // location - const glm::vec3 p = _translation->position(_lastPointTime); + const glm::vec3 p = _translation->position({ + {}, + _lastPointTime, + 0.0, + false + }); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; // Move the current pointer back one step to be used as the new floating @@ -406,7 +416,12 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails( // Get the new permanent point and write it into the (previously) floating // location - const glm::vec3 p = _translation->position(_firstPointTime); + const glm::vec3 p = _translation->position({ + {}, + _firstPointTime, + 0.0, + false + }); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; // if we are on the upper bounds of the array, we start at 0 @@ -447,7 +462,7 @@ void RenderableTrailOrbit::fullSweep(double time) { const double secondsPerPoint = _period / (_resolution - 1); // starting at 1 because the first position is a floating current one for (int i = 1; i < _resolution; ++i) { - const glm::vec3 p = _translation->position(time); + const glm::vec3 p = _translation->position({ {}, time, 0.0, false }); _vertexArray[i] = { p.x, p.y, p.z }; time -= secondsPerPoint; diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index 4c8a47b3c2..2c6091b55e 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -224,7 +224,12 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { // ... fill all of the values for (int i = 0; i < nValues; ++i) { - const glm::vec3 p = _translation->position(_start + i * totalSampleInterval); + const glm::vec3 p = _translation->position({ + {}, + _start + i * totalSampleInterval, + 0.0, + false + }); _vertexArray[i] = { p.x, p.y, p.z }; } @@ -283,7 +288,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { ); // And get the current location of the object - const glm::dvec3 p = _translation->position(data.time.j2000Seconds()); + const glm::dvec3 p = _translation->position(data); const glm::dvec3 v1 = { p.x, p.y, p.z }; // Comptue the difference between the points in double precision diff --git a/modules/base/rotation/constantrotation.cpp b/modules/base/rotation/constantrotation.cpp new file mode 100644 index 0000000000..5562fd2cf9 --- /dev/null +++ b/modules/base/rotation/constantrotation.cpp @@ -0,0 +1,125 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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 + +#include +#include +#include +#include + +namespace { + constexpr openspace::properties::Property::PropertyInfo RotationInfo = { + "RotationAxis", + "Rotation Axis", + "This value is the rotation axis around which the object will rotate." + }; + + constexpr openspace::properties::Property::PropertyInfo RotationRateInfo = { + "RotationRate", + "Rotation Rate", + "This value determines the number of revolutions per in-game second" + }; +} // namespace + +namespace openspace { + +documentation::Documentation ConstantRotation::Documentation() { + using namespace openspace::documentation; + return { + "Static Rotation", + "base_transform_rotation_constant", + { + { + "Type", + new StringEqualVerifier("ConstantRotation"), + Optional::No + }, + { + RotationInfo.identifier, + new DoubleVector3Verifier(), + Optional::Yes, + RotationInfo.description + }, + { + RotationRateInfo.identifier, + new DoubleVerifier(), + Optional::Yes, + RotationRateInfo.description + } + } + }; +} + +ConstantRotation::ConstantRotation(const ghoul::Dictionary& dictionary) + : _rotationAxis( + RotationInfo, + glm::dvec3(0.0, 0.0, 1.0), + glm::dvec3(-1.0), + glm::dvec3(1.0) + ) + , _rotationRate(RotationRateInfo, 1.f, -1000.f, 1000.f) +{ + addProperty(_rotationAxis); + addProperty(_rotationRate); + + if (dictionary.hasKeyAndValue(RotationInfo.identifier)) { + _rotationAxis = dictionary.value(RotationInfo.identifier); + } + + if (dictionary.hasKeyAndValue(RotationRateInfo.identifier)) { + _rotationRate = static_cast( + dictionary.value(RotationRateInfo.identifier) + ); + } +} + +glm::dmat3 ConstantRotation::matrix(const UpdateData& data) const { + if (data.time.j2000Seconds() == data.previousFrameTime.j2000Seconds()) { + return glm::dmat3(); + } + + const double rotPerSec = _rotationRate; + const double secPerFrame = data.time.j2000Seconds() - + data.previousFrameTime.j2000Seconds(); + + const double rotPerFrame = rotPerSec * secPerFrame; + const double radPerFrame = rotPerFrame * glm::tau(); + + _accumulatedRotation += radPerFrame; + // Renormalize the rotation to prevent potential overflow (which probably will never + // happen, but whatever) + if (_accumulatedRotation > glm::tau()) { + _accumulatedRotation -= glm::tau(); + } + if (_accumulatedRotation < -glm::tau()) { + _accumulatedRotation += glm::tau(); + } + + const glm::dvec3 axis = _rotationAxis; + glm::dquat q = glm::angleAxis(_accumulatedRotation, _rotationAxis.value()); + return glm::toMat3(q); +} + +} // namespace openspace diff --git a/modules/base/rotation/constantrotation.h b/modules/base/rotation/constantrotation.h new file mode 100644 index 0000000000..d9c74e8098 --- /dev/null +++ b/modules/base/rotation/constantrotation.h @@ -0,0 +1,54 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___CONSTANTROTATION___H__ +#define __OPENSPACE_MODULE_BASE___CONSTANTROTATION___H__ + +#include + +#include +#include + +namespace openspace { + +namespace documentation { struct Documentation; } + +class ConstantRotation : public Rotation { +public: + ConstantRotation(const ghoul::Dictionary& dictionary); + + glm::dmat3 matrix(const UpdateData& data) const override; + + static documentation::Documentation Documentation(); + +private: + properties::DVec3Property _rotationAxis; + properties::FloatProperty _rotationRate; + + mutable double _accumulatedRotation = 0.0; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___CONSTANTROTATION___H__ diff --git a/modules/base/rotation/fixedrotation.cpp b/modules/base/rotation/fixedrotation.cpp index 772d3785b4..2b98839b4d 100644 --- a/modules/base/rotation/fixedrotation.cpp +++ b/modules/base/rotation/fixedrotation.cpp @@ -526,7 +526,7 @@ bool FixedRotation::initialize() { return res; } -glm::dmat3 FixedRotation::matrix(const Time&) const { +glm::dmat3 FixedRotation::matrix(const UpdateData&) const { if (!_enabled) { return glm::dmat3(); } diff --git a/modules/base/rotation/fixedrotation.h b/modules/base/rotation/fixedrotation.h index f245069aa8..51e49eea00 100644 --- a/modules/base/rotation/fixedrotation.h +++ b/modules/base/rotation/fixedrotation.h @@ -48,7 +48,7 @@ public: static documentation::Documentation Documentation(); - glm::dmat3 matrix(const Time& time) const override; + glm::dmat3 matrix(const UpdateData& data) const override; private: glm::vec3 xAxis() const; diff --git a/modules/base/rotation/luarotation.cpp b/modules/base/rotation/luarotation.cpp index d075ce1e66..01249b7389 100644 --- a/modules/base/rotation/luarotation.cpp +++ b/modules/base/rotation/luarotation.cpp @@ -95,7 +95,7 @@ LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary) : LuaRotation() { _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); } -glm::dmat3 LuaRotation::matrix(const Time& time) const { +glm::dmat3 LuaRotation::matrix(const UpdateData& data) const { ghoul::lua::runScriptFile(_state, _luaScriptFile); // Get the scaling function @@ -110,9 +110,12 @@ glm::dmat3 LuaRotation::matrix(const Time& time) const { } // First argument is the number of seconds past the J2000 epoch in ingame time - ghoul::lua::push(_state, time.j2000Seconds()); + ghoul::lua::push(_state, data.time.j2000Seconds()); - // Second argument is the number of milliseconds past the J2000 epoch in wallclock + // Second argument is the number of seconds past the J2000 epoch of the last frame + ghoul::lua::push(_state, data.previousFrameTime.j2000Seconds()); + + // Third argument is the number of milliseconds past the J2000 epoch in wallclock using namespace std::chrono; auto now = high_resolution_clock::now(); ghoul::lua::push(_state, duration_cast(now.time_since_epoch()).count()); diff --git a/modules/base/rotation/luarotation.h b/modules/base/rotation/luarotation.h index 388a4cf6af..5fa1ac7967 100644 --- a/modules/base/rotation/luarotation.h +++ b/modules/base/rotation/luarotation.h @@ -42,7 +42,7 @@ public: LuaRotation(); LuaRotation(const ghoul::Dictionary& dictionary); - glm::dmat3 matrix(const Time& time) const override; + glm::dmat3 matrix(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/rotation/staticrotation.cpp b/modules/base/rotation/staticrotation.cpp index 4b553cc55b..cd9678f248 100644 --- a/modules/base/rotation/staticrotation.cpp +++ b/modules/base/rotation/staticrotation.cpp @@ -89,7 +89,7 @@ StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary) : StaticRota } } -glm::dmat3 StaticRotation::matrix(const Time&) const { +glm::dmat3 StaticRotation::matrix(const UpdateData&) const { return _rotationMatrix; } diff --git a/modules/base/rotation/staticrotation.h b/modules/base/rotation/staticrotation.h index 56bde89aab..9174508f16 100644 --- a/modules/base/rotation/staticrotation.h +++ b/modules/base/rotation/staticrotation.h @@ -38,7 +38,7 @@ public: StaticRotation(); StaticRotation(const ghoul::Dictionary& dictionary); - glm::dmat3 matrix(const Time& time) const override; + glm::dmat3 matrix(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/scale/luascale.cpp b/modules/base/scale/luascale.cpp index 50735113d2..33cd1affd1 100644 --- a/modules/base/scale/luascale.cpp +++ b/modules/base/scale/luascale.cpp @@ -86,7 +86,7 @@ LuaScale::LuaScale(const ghoul::Dictionary& dictionary) : LuaScale() { _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); } -double LuaScale::scaleValue(const Time& time) const { +double LuaScale::scaleValue(const UpdateData& data) const { ghoul::lua::runScriptFile(_state, _luaScriptFile); // Get the scaling function @@ -101,7 +101,10 @@ double LuaScale::scaleValue(const Time& time) const { } // First argument is the number of seconds past the J2000 epoch in ingame time - ghoul::lua::push(_state, time.j2000Seconds()); + ghoul::lua::push(_state, data.time.j2000Seconds()); + + // Second argument is the number of seconds past the J2000 epoch of last frame + ghoul::lua::push(_state, data.previousFrameTime.j2000Seconds()); // Second argument is the number of milliseconds past the J2000 epoch in wallclock using namespace std::chrono; diff --git a/modules/base/scale/luascale.h b/modules/base/scale/luascale.h index 853e04dff0..e434b924e5 100644 --- a/modules/base/scale/luascale.h +++ b/modules/base/scale/luascale.h @@ -41,7 +41,7 @@ public: LuaScale(); LuaScale(const ghoul::Dictionary& dictionary); - double scaleValue(const Time& time) const override; + double scaleValue(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/scale/staticscale.cpp b/modules/base/scale/staticscale.cpp index 34f4255722..2250909aa8 100644 --- a/modules/base/scale/staticscale.cpp +++ b/modules/base/scale/staticscale.cpp @@ -54,7 +54,7 @@ documentation::Documentation StaticScale::Documentation() { }; } -double StaticScale::scaleValue(const Time&) const { +double StaticScale::scaleValue(const UpdateData&) const { return _scaleValue; } diff --git a/modules/base/scale/staticscale.h b/modules/base/scale/staticscale.h index f38abe645c..6d56351ed9 100644 --- a/modules/base/scale/staticscale.h +++ b/modules/base/scale/staticscale.h @@ -37,7 +37,7 @@ class StaticScale : public Scale { public: StaticScale(); StaticScale(const ghoul::Dictionary& dictionary); - double scaleValue(const Time& time) const override; + double scaleValue(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/translation/luatranslation.cpp b/modules/base/translation/luatranslation.cpp index d844f175c7..5d64991066 100644 --- a/modules/base/translation/luatranslation.cpp +++ b/modules/base/translation/luatranslation.cpp @@ -98,7 +98,7 @@ LuaTranslation::LuaTranslation(const ghoul::Dictionary& dictionary) : LuaTransla _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); } -glm::dvec3 LuaTranslation::position(const Time& time) const { +glm::dvec3 LuaTranslation::position(const UpdateData& data) const { ghoul::lua::runScriptFile(_state, _luaScriptFile); // Get the scaling function @@ -116,9 +116,12 @@ glm::dvec3 LuaTranslation::position(const Time& time) const { } // First argument is the number of seconds past the J2000 epoch in ingame time - ghoul::lua::push(_state, time.j2000Seconds()); + ghoul::lua::push(_state, data.time.j2000Seconds()); - // Second argument is the number of milliseconds past the J2000 epoch in wallclock + // Second argument is the number of seconds past the J2000 epoch of the last frame + ghoul::lua::push(_state, data.previousFrameTime.j2000Seconds()); + + // Third argument is the number of milliseconds past the J2000 epoch in wallclock using namespace std::chrono; const auto now = high_resolution_clock::now(); ghoul::lua::push(_state, duration_cast(now.time_since_epoch()).count()); diff --git a/modules/base/translation/luatranslation.h b/modules/base/translation/luatranslation.h index 76556dc806..dfdf019fdb 100644 --- a/modules/base/translation/luatranslation.h +++ b/modules/base/translation/luatranslation.h @@ -42,7 +42,7 @@ public: LuaTranslation(); LuaTranslation(const ghoul::Dictionary& dictionary); - glm::dvec3 position(const Time& time) const override; + glm::dvec3 position(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/translation/statictranslation.cpp b/modules/base/translation/statictranslation.cpp index 64598e89bd..e6673914c2 100644 --- a/modules/base/translation/statictranslation.cpp +++ b/modules/base/translation/statictranslation.cpp @@ -88,7 +88,7 @@ StaticTranslation::StaticTranslation(const ghoul::Dictionary& dictionary) _position = dictionary.value(PositionInfo.identifier); } -glm::dvec3 StaticTranslation::position(const Time&) const { +glm::dvec3 StaticTranslation::position(const UpdateData&) const { return _position; } diff --git a/modules/base/translation/statictranslation.h b/modules/base/translation/statictranslation.h index d975af3604..a1df192ae7 100644 --- a/modules/base/translation/statictranslation.h +++ b/modules/base/translation/statictranslation.h @@ -31,6 +31,8 @@ namespace openspace { +struct UpdateData; + namespace documentation { struct Documentation; } class StaticTranslation : public Translation { @@ -38,7 +40,7 @@ public: StaticTranslation(); StaticTranslation(const ghoul::Dictionary& dictionary); - glm::dvec3 position(const Time& time) const override; + glm::dvec3 position(const UpdateData& data) const override; static documentation::Documentation Documentation(); private: diff --git a/modules/space/rotation/spicerotation.cpp b/modules/space/rotation/spicerotation.cpp index a8683747ca..3c5d67802e 100644 --- a/modules/space/rotation/spicerotation.cpp +++ b/modules/space/rotation/spicerotation.cpp @@ -123,11 +123,11 @@ SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary) _destinationFrame.onChange([this]() { requireUpdate(); }); } -glm::dmat3 SpiceRotation::matrix(const Time& time) const { +glm::dmat3 SpiceRotation::matrix(const UpdateData& data) const { return SpiceManager::ref().positionTransformMatrix( _sourceFrame, _destinationFrame, - time.j2000Seconds() + data.time.j2000Seconds() ); } diff --git a/modules/space/rotation/spicerotation.h b/modules/space/rotation/spicerotation.h index 77f4f29c7a..34595ce633 100644 --- a/modules/space/rotation/spicerotation.h +++ b/modules/space/rotation/spicerotation.h @@ -38,7 +38,7 @@ public: SpiceRotation(const ghoul::Dictionary& dictionary); const glm::dmat3& matrix() const; - glm::dmat3 matrix(const Time& time) const override; + glm::dmat3 matrix(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/space/translation/keplertranslation.cpp b/modules/space/translation/keplertranslation.cpp index c7129e1122..75037dc8d7 100644 --- a/modules/space/translation/keplertranslation.cpp +++ b/modules/space/translation/keplertranslation.cpp @@ -284,13 +284,13 @@ double KeplerTranslation::eccentricAnomaly(double meanAnomaly) const { } } -glm::dvec3 KeplerTranslation::position(const Time& time) const { +glm::dvec3 KeplerTranslation::position(const UpdateData& data) const { if (_orbitPlaneDirty) { computeOrbitPlane(); _orbitPlaneDirty = false; } - const double t = time.j2000Seconds() - _epoch; + const double t = data.time.j2000Seconds() - _epoch; const double meanMotion = glm::two_pi() / _period; const double meanAnomaly = glm::radians(_meanAnomalyAtEpoch.value()) + t * meanMotion; const double e = eccentricAnomaly(meanAnomaly); diff --git a/modules/space/translation/keplertranslation.h b/modules/space/translation/keplertranslation.h index 4615e8ccf6..5c9407eabc 100644 --- a/modules/space/translation/keplertranslation.h +++ b/modules/space/translation/keplertranslation.h @@ -66,7 +66,7 @@ public: * * \param time The time to use when doing the position lookup */ - glm::dvec3 position(const Time& time) const override; + glm::dvec3 position(const UpdateData& data) const override; /** * Method returning the openspace::Documentation that describes the ghoul::Dictinoary diff --git a/modules/space/translation/spicetranslation.cpp b/modules/space/translation/spicetranslation.cpp index 7461513731..bffc86ea80 100644 --- a/modules/space/translation/spicetranslation.cpp +++ b/modules/space/translation/spicetranslation.cpp @@ -174,14 +174,14 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary) addProperty(_frame); } -glm::dvec3 SpiceTranslation::position(const Time& time) const { +glm::dvec3 SpiceTranslation::position(const UpdateData& data) const { double lightTime = 0.0; return SpiceManager::ref().targetPosition( _target, _observer, _frame, {}, - time.j2000Seconds(), + data.time.j2000Seconds(), lightTime ) * glm::pow(10.0, 3.0); } diff --git a/modules/space/translation/spicetranslation.h b/modules/space/translation/spicetranslation.h index 96a7743fa0..28011b6f5e 100644 --- a/modules/space/translation/spicetranslation.h +++ b/modules/space/translation/spicetranslation.h @@ -35,7 +35,7 @@ class SpiceTranslation : public Translation { public: SpiceTranslation(const ghoul::Dictionary& dictionary); - glm::dvec3 position(const Time& time) const override; + glm::dvec3 position(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/src/scene/rotation.cpp b/src/scene/rotation.cpp index 4063fe65aa..c6809fb180 100644 --- a/src/scene/rotation.cpp +++ b/src/scene/rotation.cpp @@ -28,7 +28,7 @@ #include #include #include - +#include #include #include #include @@ -88,12 +88,12 @@ const glm::dmat3& Rotation::matrix() const { return _cachedMatrix; } -void Rotation::update(const Time& time) { - if (!_needsUpdate && (time.j2000Seconds() == _cachedTime)) { +void Rotation::update(const UpdateData& data) { + if (!_needsUpdate && (data.time.j2000Seconds() == _cachedTime)) { return; } - _cachedMatrix = matrix(time); - _cachedTime = time.j2000Seconds(); + _cachedMatrix = matrix(data); + _cachedTime = data.time.j2000Seconds(); _needsUpdate = false; } diff --git a/src/scene/scale.cpp b/src/scene/scale.cpp index 75183e5f74..4f6acb8d75 100644 --- a/src/scene/scale.cpp +++ b/src/scene/scale.cpp @@ -83,12 +83,12 @@ double Scale::scaleValue() const { return _cachedScale; } -void Scale::update(const Time& time) { - if (!_needsUpdate && time.j2000Seconds() == _cachedTime) { +void Scale::update(const UpdateData& data) { + if (!_needsUpdate && data.time.j2000Seconds() == _cachedTime) { return; } - _cachedScale = scaleValue(time); - _cachedTime = time.j2000Seconds(); + _cachedScale = scaleValue(data); + _cachedTime = data.time.j2000Seconds(); _needsUpdate = false; } diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 4682a80930..3a44095df0 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -290,14 +290,14 @@ void SceneGraphNode::update(const UpdateData& data) { glFinish(); const auto start = std::chrono::high_resolution_clock::now(); - _transform.translation->update(data.time); + _transform.translation->update(data); glFinish(); const auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeTranslation = (end - start).count(); } else { - _transform.translation->update(data.time); + _transform.translation->update(data); } } @@ -306,14 +306,14 @@ void SceneGraphNode::update(const UpdateData& data) { glFinish(); const auto start = std::chrono::high_resolution_clock::now(); - _transform.rotation->update(data.time); + _transform.rotation->update(data); glFinish(); const auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeRotation = (end - start).count(); } else { - _transform.rotation->update(data.time); + _transform.rotation->update(data); } } @@ -322,14 +322,14 @@ void SceneGraphNode::update(const UpdateData& data) { glFinish(); const auto start = std::chrono::high_resolution_clock::now(); - _transform.scale->update(data.time); + _transform.scale->update(data); glFinish(); const auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeScaling = (end - start).count(); } else { - _transform.scale->update(data.time); + _transform.scale->update(data); } } UpdateData newUpdateData = data; diff --git a/src/scene/translation.cpp b/src/scene/translation.cpp index c23d36de44..9b7228abab 100644 --- a/src/scene/translation.cpp +++ b/src/scene/translation.cpp @@ -77,13 +77,13 @@ bool Translation::initialize() { return true; } -void Translation::update(const Time& time) { - if (!_needsUpdate && time.j2000Seconds() == _cachedTime) { +void Translation::update(const UpdateData& data) { + if (!_needsUpdate && data.time.j2000Seconds() == _cachedTime) { return; } const glm::dvec3 oldPosition = _cachedPosition; - _cachedPosition = position(time); - _cachedTime = time.j2000Seconds(); + _cachedPosition = position(data); + _cachedTime = data.time.j2000Seconds(); _needsUpdate = false; if (oldPosition != _cachedPosition) {