diff --git a/data/scene/lodearth/lodearth.mod b/data/scene/lodearth/lodearth.mod index 7046aaf924..4df2ff724a 100644 --- a/data/scene/lodearth/lodearth.mod +++ b/data/scene/lodearth/lodearth.mod @@ -3,6 +3,20 @@ return { { Name = "EarthBarycenter", Parent = "SolarSystemBarycenter", + Transform = { + Translation = { + Type = "StaticEphemeris", + Position = {0,0,0}, + }, + Rotation = { + Type = "StaticRotation", + EulerAngles = {0,0,0}, + }, + Scale = { + Type = "StaticScale", + Scale = 1, + }, + }, }, -- EarthTrail module { @@ -46,8 +60,6 @@ return { }, Renderable = { Type = "RenderableGlobe", - Frame = "IAU_EARTH", - Body = "EARTH", Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii CameraMinHeight = 300, InteractionDepthBelowEllipsoid = 0, -- Useful when having negative height map values diff --git a/data/scene/osirisrex.scene b/data/scene/osirisrex.scene index 316e3db8e5..a8ef1810a1 100644 --- a/data/scene/osirisrex.scene +++ b/data/scene/osirisrex.scene @@ -13,6 +13,7 @@ function preInitialization() dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load Spice Kernels + openspace.spice.loadKernel("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp") -- background -- SCLK kernels needs to be loaded before CK kernels (and generally first) diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h index 7dd777d765..991841cdd8 100644 --- a/include/openspace/util/updatestructures.h +++ b/include/openspace/util/updatestructures.h @@ -38,6 +38,8 @@ struct InitializeData { struct UpdateData { glm::dvec3 position; + glm::dmat3 rotation; + double scale; double time; bool isTimeJump; double delta; diff --git a/modules/base/rotation/spicerotation.cpp b/modules/base/rotation/spicerotation.cpp index 7f8b00bb14..709292554d 100644 --- a/modules/base/rotation/spicerotation.cpp +++ b/modules/base/rotation/spicerotation.cpp @@ -78,31 +78,15 @@ const glm::dmat3& SpiceRotation::matrix() const { void SpiceRotation::update(const UpdateData& data) { if (!_kernelsLoadedSuccessfully) return; - - // TODO : Need to be checking for real if the frame is fixed since fixed frames - // do not have CK coverage. - bool sourceFrameIsFixed = _sourceFrame == "GALACTIC"; - bool destinationFrameIsFixed = _destinationFrame == "GALACTIC"; - - bool sourceHasCoverage = - !_sourceFrame.empty() && - SpiceManager::ref().hasFrameId(_sourceFrame) && - (SpiceManager::ref().hasCkCoverage(_sourceFrame, data.time) || - sourceFrameIsFixed); - bool destinationHasCoverage = - !_destinationFrame.empty() && - SpiceManager::ref().hasFrameId(_destinationFrame) && - (SpiceManager::ref().hasCkCoverage(_destinationFrame, data.time) || - destinationFrameIsFixed); - - if (sourceHasCoverage && destinationHasCoverage) { + try { _rotationMatrix = SpiceManager::ref().positionTransformMatrix( _sourceFrame, _destinationFrame, data.time); } - else { - _rotationMatrix = glm::dmat3(1.0); + catch (const ghoul::RuntimeError&) { + // In case of missing coverage + _rotationMatrix = glm::dmat3(1); } } diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.cpp b/modules/globebrowsing/chunk/chunkedlodglobe.cpp index bb02d1bfe2..e0c8c3c6b5 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.cpp +++ b/modules/globebrowsing/chunk/chunkedlodglobe.cpp @@ -155,15 +155,6 @@ namespace openspace { stats.startNewRecord(); int j2000s = Time::now().unsyncedJ2000Seconds(); - /* - int lastJ2000s = stats.i.previous("time"); - if (j2000s == lastJ2000s) { - stats.disable(); - } - else { - stats.enable(); - } - */ auto duration = std::chrono::system_clock::now().time_since_epoch(); auto millis = std::chrono::duration_cast(duration).count(); @@ -197,11 +188,9 @@ namespace openspace { _leftRoot->reverseBreadthFirst(renderJob); _rightRoot->reverseBreadthFirst(renderJob); - if (_savedCamera != nullptr) { DebugRenderer::ref().renderCameraFrustum(data, *_savedCamera); } - //LDEBUG("min distnace to camera: " << minDistToCamera); @@ -242,24 +231,16 @@ namespace openspace { } void ChunkedLodGlobe::update(const UpdateData& data) { - _modelTransform = - translate(dmat4(1), data.position) * // Translation - dmat4(stateMatrix()); // Rotation + glm::dmat4 translation = glm::translate(glm::dmat4(1.0), data.position); + glm::dmat4 rotation = glm::dmat4(data.rotation); + glm::dmat4 scaling = glm::scale(glm::dmat4(1.0), glm::dvec3(data.scale, data.scale, data.scale)); + + _modelTransform = translation * rotation * scaling; _inverseModelTransform = glm::inverse(_modelTransform); _renderer->update(); } - void ChunkedLodGlobe::setStateMatrix(const glm::dmat3& stateMatrix) - { - _stateMatrix = stateMatrix; - } - - const glm::dmat3& ChunkedLodGlobe::stateMatrix() - { - return _stateMatrix; - } - const glm::dmat4& ChunkedLodGlobe::modelTransform() { return _modelTransform; } diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.h b/modules/globebrowsing/chunk/chunkedlodglobe.h index 0a11a56825..3d30d01f3b 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.h +++ b/modules/globebrowsing/chunk/chunkedlodglobe.h @@ -76,16 +76,12 @@ namespace openspace { const ChunkNode& findChunkNode(const Geodetic2 location) const; ChunkNode& findChunkNode(const Geodetic2 location); - void setStateMatrix(const glm::dmat3& stateMatrix); - bool testIfCullable(const Chunk& chunk, const RenderData& renderData) const; int getDesiredLevel(const Chunk& chunk, const RenderData& renderData) const; double minDistToCamera; - //Scalar globeRadius; const Ellipsoid& ellipsoid() const; - const glm::dmat3& stateMatrix(); const glm::dmat4& modelTransform(); const glm::dmat4& inverseModelTransform(); @@ -145,7 +141,6 @@ namespace openspace { std::unique_ptr _chunkEvaluatorByDistance; const Ellipsoid& _ellipsoid; - glm::dmat3 _stateMatrix; glm::dmat4 _modelTransform; glm::dmat4 _inverseModelTransform; diff --git a/modules/globebrowsing/chunk/chunkrenderer.cpp b/modules/globebrowsing/chunk/chunkrenderer.cpp index cec1d6a1a0..5ff49de520 100644 --- a/modules/globebrowsing/chunk/chunkrenderer.cpp +++ b/modules/globebrowsing/chunk/chunkrenderer.cpp @@ -370,7 +370,6 @@ namespace openspace { Geodetic2 swCorner = chunk.surfacePatch().getCorner(Quad::SOUTH_WEST); auto patchSize = chunk.surfacePatch().size(); - // TODO : Model transform should be fetched as a matrix directly. dmat4 modelTransform = chunk.owner()->modelTransform(); dmat4 viewTransform = data.camera.combinedViewMatrix(); mat4 modelViewTransform = mat4(viewTransform * modelTransform); diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index 00dc07daa3..0033c6701f 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -178,13 +178,6 @@ namespace openspace { } void RenderableGlobe::update(const UpdateData& data) { - - // set spice-orientation in accordance to timestamp - _chunkedLodGlobe->setStateMatrix( - SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time)); - // We currently do not consider rotation anywhere in the rendering. - // @TODO Consider rotation everywhere in the rendering (culling, splitting, camera, etc) - //_chunkedLodGlobe->setStateMatrix(glm::dmat3(1.0)); _time = data.time; _distanceSwitch.update(data); @@ -207,10 +200,6 @@ namespace openspace { return _ellipsoid; } - const glm::dmat3& RenderableGlobe::stateMatrix() { - return _chunkedLodGlobe->stateMatrix(); - } - float RenderableGlobe::getHeight(glm::dvec3 position) { // Get the tile provider for the height map const auto& heightMapProviders = _tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps).getActiveTileProviders(); diff --git a/modules/globebrowsing/globes/renderableglobe.h b/modules/globebrowsing/globes/renderableglobe.h index c574d5f6cc..9fd3447ec0 100644 --- a/modules/globebrowsing/globes/renderableglobe.h +++ b/modules/globebrowsing/globes/renderableglobe.h @@ -112,13 +112,11 @@ public: glm::dvec3 projectOnEllipsoid(glm::dvec3 position); const Ellipsoid& ellipsoid(); - const glm::dmat3& stateMatrix(); float getHeight(glm::dvec3 position); float cameraMinHeight(); double interactionDepthBelowEllipsoid(); std::shared_ptr chunkedLodGlobe(); - // Properties properties::BoolProperty _isEnabled; properties::FloatProperty lodScaleFactor; @@ -128,9 +126,6 @@ public: properties::BoolProperty _saveOrThrowCamera; properties::BoolProperty _resetTileProviders; - - - private: double _interactionDepthBelowEllipsoid; @@ -142,7 +137,6 @@ private: std::shared_ptr _tileProviderManager; std::shared_ptr _chunkedLodGlobe; - DistanceSwitch _distanceSwitch; properties::FloatProperty _cameraMinHeight; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 2b42a22e4e..1dd56b5736 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -367,6 +367,8 @@ void RenderEngine::postSynchronizationPreDraw() { // update and evaluate the scene starting from the root node _sceneGraph->update({ glm::dvec3(0), + glm::dmat3(1), + 1, Time::ref().currentTime(), Time::ref().timeJumped(), Time::ref().deltaTime(), diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index b54fce3e80..9cffc86a82 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -209,7 +209,11 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) { // TODO need to check this; unnecessary? (ab) for (SceneGraphNode* node : _graph.nodes()) { try { - node->update({glm::dvec3(0), Time::ref().currentTime() }); + node->update({ + glm::dvec3(0), + glm::dmat3(1), + 1, + Time::ref().currentTime() }); } catch (const ghoul::RuntimeError& e) { LERRORC(e.component, e.message); diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 82e1e6f7fe..3120bd739d 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -193,6 +193,18 @@ bool SceneGraphNode::deinitialize() { delete _renderable; _renderable = nullptr; } + if (_ephemeris) { + delete _ephemeris; + _ephemeris = nullptr; + } + if (_rotation) { + delete _rotation; + _rotation = nullptr; + } + if (_scale) { + delete _scale; + _scale = nullptr; + } //delete _ephemeris; //_ephemeris = nullptr; @@ -213,21 +225,19 @@ bool SceneGraphNode::deinitialize() { } void SceneGraphNode::update(const UpdateData& data) { - UpdateData newUpdateData = data; - if (_ephemeris) { if (data.doPerformanceMeasurement) { glFinish(); auto start = std::chrono::high_resolution_clock::now(); - _ephemeris->update(newUpdateData); + _ephemeris->update(data); glFinish(); auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeEphemeris = (end - start).count(); } else - _ephemeris->update(newUpdateData); + _ephemeris->update(data); } if (_rotation) { @@ -235,14 +245,14 @@ void SceneGraphNode::update(const UpdateData& data) { glFinish(); auto start = std::chrono::high_resolution_clock::now(); - _rotation->update(newUpdateData); + _rotation->update(data); glFinish(); auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeEphemeris = (end - start).count(); } else - _rotation->update(newUpdateData); + _rotation->update(data); } if (_scale) { @@ -250,23 +260,25 @@ void SceneGraphNode::update(const UpdateData& data) { glFinish(); auto start = std::chrono::high_resolution_clock::now(); - _scale->update(newUpdateData); + _scale->update(data); glFinish(); auto end = std::chrono::high_resolution_clock::now(); _performanceRecord.updateTimeEphemeris = (end - start).count(); } else - _scale->update(newUpdateData); + _scale->update(data); } + UpdateData newUpdateData = data; _worldRotationCached = calculateWorldRotation(); _worldScaleCached = calculateWorldScale(); - // Assumes _worldRotationCached and _worldScaleCached have been calculated for parent _worldPositionCached = calculateWorldPosition(); newUpdateData.position = worldPosition(); + newUpdateData.rotation = worldRotationMatrix(); + newUpdateData.scale = worldScale(); if (_renderable && _renderable->isReady()) { if (data.doPerformanceMeasurement) {