From ec226835681740b90fb93448de8ab9c9e731d60e Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Tue, 7 Jun 2016 22:47:05 -0400 Subject: [PATCH] Use spice ephemeris for renderable globe. Still not considering rotation in rendering. --- data/scene/debugglobe/debugglobe.mod | 54 ++++++++++++++++++- .../globebrowsing/globes/chunkedlodglobe.cpp | 10 ++++ .../globebrowsing/globes/chunkedlodglobe.h | 4 ++ .../globebrowsing/globes/renderableglobe.cpp | 13 +++++ .../globebrowsing/globes/renderableglobe.h | 3 +- .../globebrowsing/rendering/patchrenderer.cpp | 7 +-- 6 files changed, 86 insertions(+), 5 deletions(-) diff --git a/data/scene/debugglobe/debugglobe.mod b/data/scene/debugglobe/debugglobe.mod index 1ce3034d5d..562d07105e 100644 --- a/data/scene/debugglobe/debugglobe.mod +++ b/data/scene/debugglobe/debugglobe.mod @@ -1,10 +1,33 @@ return { - -- DebugGlobe module + -- Earth barycenter module + { + Name = "EarthBarycenter", + Parent = "Root", + Static = true, + --[[ + Ephemeris = { + Type = "Kepler", + Inclination = 0.00041, + AscendingNode = 349.2, + Perihelion = 102.8517, + SemiMajorAxis = 1.00002, + DailyMotion = 0.9855796, + Eccentricity = 0.0166967, + MeanLongitude = 328.40353 + } + --]] + Ephemeris = { + Type = "Static" + } + }, + -- RenderableGlobe module { Name = "DebugGlobe", Parent = "Root", Renderable = { Type = "RenderableGlobe", + Frame = "IAU_EARTH", + Body = "EARTH", Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii SegmentsPerPatch = 64, Textures = { @@ -54,6 +77,35 @@ return { }, }, }, + --[[ + Ephemeris = { + Type = "Spice", + Body = "EARTH", + Reference = "ECLIPJ2000", + Observer = "SUN", + Kernels = { + "${OPENSPACE_DATA}/spice/de430_1850-2150.bsp" + } + }, + --]] GuiName = "/Solar/Planets/DebugGlobe" }, + --[[ + -- EarthTrail module + { + Name = "EarthTrail", + Parent = "EarthBarycenter", + Renderable = { + Type = "RenderableTrail", + Body = "EARTH", + Frame = "GALACTIC", + Observer = "SUN", + RGB = { 0.5, 0.8, 1.0}, + TropicalOrbitPeriod = 365.242, + EarthOrbitRatio = 1, + DayLength = 24 + }, + GuiName = "/Solar/EarthTrail" + }, + --]] } diff --git a/modules/globebrowsing/globes/chunkedlodglobe.cpp b/modules/globebrowsing/globes/chunkedlodglobe.cpp index 1c425b685f..73e6e88a3f 100644 --- a/modules/globebrowsing/globes/chunkedlodglobe.cpp +++ b/modules/globebrowsing/globes/chunkedlodglobe.cpp @@ -127,6 +127,16 @@ namespace openspace { } + void ChunkedLodGlobe::setStateMatrix(const glm::dmat3& stateMatrix) + { + _stateMatrix = stateMatrix; + } + + const glm::dmat3& ChunkedLodGlobe::stateMatrix() + { + return _stateMatrix; + } + const Ellipsoid& ChunkedLodGlobe::ellipsoid() const { return _ellipsoid; diff --git a/modules/globebrowsing/globes/chunkedlodglobe.h b/modules/globebrowsing/globes/chunkedlodglobe.h index b2d118e492..20d05f7ae3 100644 --- a/modules/globebrowsing/globes/chunkedlodglobe.h +++ b/modules/globebrowsing/globes/chunkedlodglobe.h @@ -69,10 +69,13 @@ namespace openspace { void render(const RenderData& data) override; void update(const UpdateData& data) override; + void setStateMatrix(const glm::dmat3& stateMatrix); + double minDistToCamera; //Scalar globeRadius; const Ellipsoid& ellipsoid() const; + const glm::dmat3& stateMatrix(); const int minSplitDepth; const int maxSplitDepth; @@ -118,6 +121,7 @@ namespace openspace { static const ChunkIndex RIGHT_HEMISPHERE_INDEX; const Ellipsoid& _ellipsoid; + glm::dmat3 _stateMatrix; Camera* _savedCamera; diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index 1e81432d86..f08541e096 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -40,6 +40,7 @@ namespace { const std::string _loggerCat = "RenderableGlobe"; // Keys for the dictionary + const std::string keyFrame = "Frame"; const std::string keyRadii = "Radii"; const std::string keySegmentsPerPatch = "SegmentsPerPatch"; const std::string keyTextures = "Textures"; @@ -82,6 +83,8 @@ namespace openspace { doHorizonCulling.setValue(true); renderSmallChunksFirst.setValue(true); + dictionary.getValue(keyFrame, _frame); + // Read the radii in to its own dictionary Vec3 radii; dictionary.getValue(keyRadii, radii); @@ -161,6 +164,12 @@ 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); @@ -191,5 +200,9 @@ namespace openspace { return _ellipsoid.geodeticSurfaceProjection(position); } + std::shared_ptr RenderableGlobe::chunkedLodGlobe() { + return _chunkedLodGlobe; + } + } // namespace openspace diff --git a/modules/globebrowsing/globes/renderableglobe.h b/modules/globebrowsing/globes/renderableglobe.h index b1ebbafb28..49e6f66205 100644 --- a/modules/globebrowsing/globes/renderableglobe.h +++ b/modules/globebrowsing/globes/renderableglobe.h @@ -65,6 +65,7 @@ public: void update(const UpdateData& data) override; glm::dvec3 geodeticSurfaceProjection(glm::dvec3 position); + std::shared_ptr chunkedLodGlobe(); properties::BoolProperty doFrustumCulling; properties::BoolProperty doHorizonCulling; @@ -79,6 +80,7 @@ public: properties::BoolProperty blendColorMap; private: + std::string _frame; void addToggleLayerProperties( std::vector&, @@ -92,7 +94,6 @@ private: //std::vector _heightMapKeys; //std::vector _colorTextureKeys; - std::shared_ptr _tileProviderManager; std::shared_ptr _chunkedLodGlobe; diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index 35b87759fc..39789459ad 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -345,10 +345,11 @@ namespace openspace { auto patchSize = chunk.surfacePatch().size(); // TODO : Model transform should be fetched as a matrix directly. - mat4 modelTransform = translate(mat4(1), data.position.vec3()); - mat4 viewTransform = data.camera.combinedViewMatrix(); + dmat4 modelTransform = dmat4(chunk.owner()->stateMatrix()); // Rotation + modelTransform = translate(dmat4(1), data.position.dvec3()) * modelTransform; // Translation + dmat4 viewTransform = data.camera.combinedViewMatrix(); mat4 modelViewProjectionTransform = data.camera.projectionMatrix() - * viewTransform * modelTransform; + * mat4(viewTransform * modelTransform); // Upload the uniform variables programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);