From 7359adf400d11b78e77847218fd59b213738efe2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 26 Sep 2014 13:29:01 +0200 Subject: [PATCH] Replaced RuntimeData with separate, temporary structs that are passed around --- include/openspace/engine/openspaceengine.h | 4 ++ .../rendering/planets/renderableplanet.h | 8 ++-- include/openspace/rendering/renderable.h | 7 ++- .../rendering/renderablefieldlines.h | 5 ++- .../rendering/renderablesphericalgrid.h | 5 ++- .../openspace/rendering/renderablevolumegl.h | 5 +-- include/openspace/rendering/renderengine.h | 3 -- .../rendering/stars/renderablestars.h | 7 ++- include/openspace/scenegraph/ephemeris.h | 9 +--- include/openspace/scenegraph/scenegraph.h | 10 ++--- include/openspace/scenegraph/scenegraphnode.h | 9 ++-- include/openspace/scenegraph/spiceephemeris.h | 10 ++--- .../openspace/scenegraph/staticephemeris.h | 2 +- include/openspace/util/runtimedata.h | 39 ---------------- include/openspace/util/updatestructures.h | 45 +++++++++++++++++++ src/engine/openspaceengine.cpp | 10 ----- src/rendering/planets/renderableplanet.cpp | 21 +++++---- src/rendering/renderable.cpp | 2 +- src/rendering/renderablefieldlines.cpp | 20 ++++----- src/rendering/renderablesphericalgrid.cpp | 14 +++--- src/rendering/renderablevolumegl.cpp | 14 +++--- src/rendering/renderengine.cpp | 19 ++------ src/rendering/stars/renderablestars.cpp | 18 ++++---- src/scenegraph/ephemeris.cpp | 2 +- src/scenegraph/scenegraph.cpp | 19 ++++---- src/scenegraph/scenegraphnode.cpp | 22 ++++----- src/scenegraph/spiceephemeris.cpp | 6 +-- src/scenegraph/staticephemeris.cpp | 2 +- 28 files changed, 154 insertions(+), 183 deletions(-) delete mode 100644 include/openspace/util/runtimedata.h create mode 100644 include/openspace/util/updatestructures.h diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 80ea8a7626..1e0d41a50b 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -25,6 +25,10 @@ #ifndef __OPENSPACEENGINE_H__ #define __OPENSPACEENGINE_H__ +// sgct header has to be included before all others due to Windows header +#define SGCT_WINDOWS_INCLUDE +#include "sgct.h" + #include #include #include diff --git a/include/openspace/rendering/planets/renderableplanet.h b/include/openspace/rendering/planets/renderableplanet.h index 9ecc4aa2f1..668f16e10f 100644 --- a/include/openspace/rendering/planets/renderableplanet.h +++ b/include/openspace/rendering/planets/renderableplanet.h @@ -29,11 +29,11 @@ #include #include +#include // ghoul includes #include #include -#include namespace openspace { @@ -49,8 +49,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; protected: void loadTexture(); @@ -62,6 +62,8 @@ private: ghoul::opengl::Texture* _texture; planetgeometry::PlanetGeometry* _geometry; + glm::dmat3 _stateMatrix; + std::string _target; }; diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index c72ad8290e..d42afe13a6 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include namespace openspace { @@ -51,8 +51,8 @@ public: void setBoundingSphere(const PowerScaledScalar& boundingSphere); const PowerScaledScalar& getBoundingSphere(); - virtual void render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) = 0; - virtual void update(); + virtual void render(const RenderData& data) = 0; + virtual void update(const UpdateData& data); bool isVisible() const; @@ -63,7 +63,6 @@ private: properties::BoolProperty _enabled; PowerScaledScalar boundingSphere_; - RuntimeData* _runtimeData; std::string _relativePath; }; diff --git a/include/openspace/rendering/renderablefieldlines.h b/include/openspace/rendering/renderablefieldlines.h index b730345076..c0b54c0f16 100644 --- a/include/openspace/rendering/renderablefieldlines.h +++ b/include/openspace/rendering/renderablefieldlines.h @@ -27,6 +27,7 @@ // open space includes #include +#include // ghoul includes #include @@ -43,8 +44,8 @@ public: bool initialize(); bool deinitialize(); - virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); - virtual void update(); + void render(const RenderData& data) override; + void update(const UpdateData& data) override; private: std::vector > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary); diff --git a/include/openspace/rendering/renderablesphericalgrid.h b/include/openspace/rendering/renderablesphericalgrid.h index 29f5622131..d2de735960 100644 --- a/include/openspace/rendering/renderablesphericalgrid.h +++ b/include/openspace/rendering/renderablesphericalgrid.h @@ -30,6 +30,7 @@ // open space includes #include #include + // ghoul includes #include #include @@ -43,8 +44,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& position, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; private: protected: typedef struct { diff --git a/include/openspace/rendering/renderablevolumegl.h b/include/openspace/rendering/renderablevolumegl.h index b67b7e52f2..d7885b1aa0 100644 --- a/include/openspace/rendering/renderablevolumegl.h +++ b/include/openspace/rendering/renderablevolumegl.h @@ -44,8 +44,8 @@ public: bool initialize(); bool deinitialize(); - virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); - virtual void update(); + virtual void render(const RenderData& data) override; + virtual void update(const UpdateData& data) override; private: ghoul::Dictionary _hintsDictionary; @@ -69,7 +69,6 @@ private: float _w; GLint _MVPLocation, _modelTransformLocation, _typeLocation; - RuntimeData* _runtimeData; bool _updateTransferfunction; int _id; }; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 4eda44fb85..6ae5056338 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -26,7 +26,6 @@ #define __RENDERENGINE_H__ #include -#include #include #include @@ -44,7 +43,6 @@ public: bool initialize(); - void setRuntimeData(RuntimeData* runtimeData); void setSceneGraph(SceneGraph* sceneGraph); SceneGraph* sceneGraph(); @@ -63,7 +61,6 @@ public: private: Camera* _mainCamera; SceneGraph* _sceneGraph; - RuntimeData* _runtimeData; ABuffer* _abuffer; }; diff --git a/include/openspace/rendering/stars/renderablestars.h b/include/openspace/rendering/stars/renderablestars.h index 75878f01a3..dc63c335d8 100644 --- a/include/openspace/rendering/stars/renderablestars.h +++ b/include/openspace/rendering/stars/renderablestars.h @@ -28,6 +28,7 @@ // open space includes #include #include + // ghoul includes #include #include @@ -43,8 +44,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& position, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; protected: void loadTexture(); @@ -72,8 +73,6 @@ private: int v_size; int v_stride; int v_total; - - RuntimeData* _runtimeData; }; } // namespace openspace diff --git a/include/openspace/scenegraph/ephemeris.h b/include/openspace/scenegraph/ephemeris.h index 9a8baef1e8..28483e6a31 100644 --- a/include/openspace/scenegraph/ephemeris.h +++ b/include/openspace/scenegraph/ephemeris.h @@ -27,8 +27,7 @@ #include #include -#include - +#include namespace openspace { @@ -40,14 +39,10 @@ public: virtual ~Ephemeris(); virtual bool initialize(); virtual const psc& position() const = 0; - virtual void update(RuntimeData* runtimeData) = 0; - virtual void update(); + virtual void update(const UpdateData& data); protected: Ephemeris(); - -private: - RuntimeData* _runtimeData; }; } // namespace openspace diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h index 15d105b6b4..07544bbd99 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -30,13 +30,12 @@ #include #include - +#include #include // ghoul includes #include #include -#include namespace openspace { @@ -49,8 +48,6 @@ public: SceneGraph(); ~SceneGraph(); - void setRuntimeData(RuntimeData* runtimeData); - /** * Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory */ @@ -72,7 +69,7 @@ public: /* * Updates all SceneGraphNodes relative positions */ - void update(); + void update(const UpdateData& data); /* * Evaluates if the SceneGraphNodes are visible to the provided camera @@ -82,7 +79,7 @@ public: /* * Render visible SceneGraphNodes using the provided camera */ - void render(Camera* camera); + void render(const RenderData& data); /* * Prints the SceneGraph tree. For debugging purposes @@ -119,7 +116,6 @@ private: SceneGraphNode* _root; std::vector _nodes; std::map _allNodes; - RuntimeData* _runtimeData; std::string _sceneGraphToLoad; }; diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h index f7f4dfba0c..2dade38bb6 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -32,7 +32,7 @@ #include #include -#include +#include // std includes #include @@ -52,13 +52,13 @@ public: static SceneGraphNode* createFromDictionary(const ghoul::Dictionary& dictionary); - bool initialize(RuntimeData* runtimeData); + bool initialize(); bool deinitialize(); // essential - void update(); + void update(const UpdateData& data); void evaluate(const Camera* camera, const psc& parentPosition = psc()); - void render(const Camera* camera, const psc& parentPosition = psc()); + void render(const RenderData& data); // set & get void addNode(SceneGraphNode* child); @@ -88,7 +88,6 @@ private: std::vector _children; SceneGraphNode* _parent; Ephemeris* _ephemeris; - RuntimeData* _runtimeData; // renderable Renderable* _renderable; diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scenegraph/spiceephemeris.h index 80780a66de..1d454cbc01 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scenegraph/spiceephemeris.h @@ -34,10 +34,10 @@ namespace openspace { class SpiceEphemeris : public Ephemeris { public: SpiceEphemeris(const ghoul::Dictionary& dictionary); - virtual ~SpiceEphemeris(); - virtual bool initialize(); - virtual const psc& position() const; - virtual void update(RuntimeData* runtimeData); + ~SpiceEphemeris(); + bool initialize(); + const psc& position() const; + void update(const UpdateData& data) override; private: std::string _targetName; @@ -45,8 +45,6 @@ private: int _target; int _origin; psc _position; - double _currentEphemerisTime = -1; - }; } // namespace openspace diff --git a/include/openspace/scenegraph/staticephemeris.h b/include/openspace/scenegraph/staticephemeris.h index 401fd1a329..82ed4f5710 100644 --- a/include/openspace/scenegraph/staticephemeris.h +++ b/include/openspace/scenegraph/staticephemeris.h @@ -35,7 +35,7 @@ public: = ghoul::Dictionary()); virtual ~StaticEphemeris(); virtual const psc& position() const; - virtual void update(RuntimeData* runtimeData); + virtual void update(const UpdateData& data) override; private: psc _position; }; diff --git a/include/openspace/util/runtimedata.h b/include/openspace/util/runtimedata.h deleted file mode 100644 index 099b4424e0..0000000000 --- a/include/openspace/util/runtimedata.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __RUNTIMEDATA_H__ -#define __RUNTIMEDATA_H__ - -enum increment{ - YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND -}; - -struct RuntimeData{ -public: - RuntimeData() :_openspaceTime(0.0){ - }; - void setTime(double time) { _openspaceTime = time; } - double getTime() { return _openspaceTime; } - - // cant come up with proper user friendly-method, this will do. - void advanceTimeBy(double nr, increment incr){ - switch (incr){ - case YEAR: _openspaceTime += (nr * year); break; - case MONTH: _openspaceTime += (nr * month); break; - case DAY: _openspaceTime += (nr * day); break; - case HOUR: _openspaceTime += (nr * hour); break; - case MINUTE: _openspaceTime += (nr * minute); break; - case MILLISECOND: _openspaceTime += (nr * millisec); break; - default : _openspaceTime += (nr); - } - } - -private: - double _openspaceTime; - - double year = 3.154*pow(10, 7); - double month = 2.628*pow(10, 6); - double day = 86400; - double hour = 3600; - double minute = 60; - double millisec = 0.001; -}; - -#endif // __RUNTIMEDATA_H__ diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h new file mode 100644 index 0000000000..11590154d2 --- /dev/null +++ b/include/openspace/util/updatestructures.h @@ -0,0 +1,45 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* 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 __UPDATESTRUCTURES_H__ +#define __UPDATESTRUCTURES_H__ + +#include +#include + +namespace openspace { + +struct UpdateData { + double time; +}; + +struct RenderData { + const Camera& camera; + psc position; + +}; + +} + +#endif // __UPDATESTRUCTURES_H__ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index e25432c594..494b95039b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -24,10 +24,6 @@ #include -// sgct header has to be included before all others due to Windows header -#define SGCT_WINDOWS_INCLUDE -#include "sgct.h" - #include #include #include @@ -37,7 +33,6 @@ #include #include #include -#include #include #include @@ -329,9 +324,6 @@ bool OpenSpaceEngine::initialize() Spice::init(); Spice::ref().loadDefaultKernels(); // changeto: instantiate spicemanager, load kernels. - RuntimeData* initialData = new RuntimeData; - initialData->setTime(Time::ref().currentTime()); - SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"), "SPK_EARTH"); SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/MAR063.bsp") , "SPK_MARS"); SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/pck00010.tpc") , "PCK"); @@ -355,8 +347,6 @@ bool OpenSpaceEngine::initialize() // initialize the RenderEngine, needs ${SCENEPATH} to be set _renderEngine->initialize(); - _renderEngine->setRuntimeData(initialData); - sceneGraph->setRuntimeData(initialData); sceneGraph->initialize(); std::string sceneDescriptionPath; diff --git a/src/rendering/planets/renderableplanet.cpp b/src/rendering/planets/renderableplanet.cpp index 8399e0f835..f38dc71213 100644 --- a/src/rendering/planets/renderableplanet.cpp +++ b/src/rendering/planets/renderableplanet.cpp @@ -113,7 +113,7 @@ bool RenderablePlanet::deinitialize() return true; } -void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) +void RenderablePlanet::render(const RenderData& data) { if (!_programObject) return; @@ -124,9 +124,9 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run _programObject->activate(); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); // PowerScaledScalar scaling = camera->scaling(); PowerScaledScalar scaling = glm::vec2(1, -6); @@ -134,23 +134,19 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run // scale the planet to appropriate size since the planet is a unit sphere glm::mat4 transform = glm::mat4(1); - // set spice-orientation in accordance to timestamp - glm::dmat3 stateMatrix; - openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", runtimeData->getTime(), stateMatrix); - //earth needs to be rotated for that to work. glm::mat4 rot = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0)); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ - transform[i][j] = stateMatrix[i][j]; + transform[i][j] = _stateMatrix[i][j]; } } transform = transform* rot; // setup the data to the shader - _programObject->setUniform("ViewProjection", camera->viewProjectionMatrix()); + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _programObject->setUniform("ModelTransform", transform); _programObject->setUniform("campos", campos.vec4()); _programObject->setUniform("objpos", currentPosition.vec4()); @@ -171,8 +167,11 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run } -void RenderablePlanet::update() +void RenderablePlanet::update(const UpdateData& data) { + // set spice-orientation in accordance to timestamp + openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", data.time, _stateMatrix); + } void RenderablePlanet::loadTexture() diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 7c497be81c..d525f29df3 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -88,7 +88,7 @@ const PowerScaledScalar& Renderable::getBoundingSphere() return boundingSphere_; } -void Renderable::update() +void Renderable::update(const UpdateData&) { } diff --git a/src/rendering/renderablefieldlines.cpp b/src/rendering/renderablefieldlines.cpp index 98b44a3e30..d301eaa65f 100644 --- a/src/rendering/renderablefieldlines.cpp +++ b/src/rendering/renderablefieldlines.cpp @@ -211,29 +211,29 @@ bool RenderableFieldlines::deinitialize() { return true; } -void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) { +void RenderableFieldlines::render(const RenderData& data) { if(_update) { _update = false; safeShaderCompilation(); } - glm::mat4 transform = camera->viewProjectionMatrix(); - glm::mat4 camTransform = camera->viewRotationMatrix(); - psc relative = thisPosition-camera->position(); + glm::mat4 transform = data.camera.viewProjectionMatrix(); + glm::mat4 camTransform = data.camera.viewRotationMatrix(); + psc relative = data.position - data.camera.position(); transform = transform*camTransform; transform = glm::mat4(1.0); transform = glm::scale(transform, glm::vec3(0.01)); - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); - PowerScaledScalar scaling = camera->scaling(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); + PowerScaledScalar scaling = data.camera.scaling(); // Activate shader _fieldlinesProgram->activate(); - _fieldlinesProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix()); + _fieldlinesProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix()); _fieldlinesProgram->setUniform("modelTransform", transform); _fieldlinesProgram->setUniform("campos", campos.vec4()); _fieldlinesProgram->setUniform("objpos", currentPosition.vec4()); @@ -253,7 +253,7 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, _fieldlinesProgram->deactivate(); } -void RenderableFieldlines::update() { +void RenderableFieldlines::update(const UpdateData& data) { } void RenderableFieldlines::safeShaderCompilation() { diff --git a/src/rendering/renderablesphericalgrid.cpp b/src/rendering/renderablesphericalgrid.cpp index 318119c88c..eaa4460274 100644 --- a/src/rendering/renderablesphericalgrid.cpp +++ b/src/rendering/renderablesphericalgrid.cpp @@ -181,21 +181,21 @@ bool RenderableSphericalGrid::initialize(){ return completeSuccess; } -void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){ +void RenderableSphericalGrid::render(const RenderData& data){ assert(_gridProgram); _gridProgram->activate(); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); // PowerScaledScalar scaling = camera->scaling(); PowerScaledScalar scaling = glm::vec2(1, -6); glm::mat4 transform = glm::mat4(1); // setup the data to the shader - _gridProgram->setUniform("ViewProjection", camera->viewProjectionMatrix()); + _gridProgram->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _gridProgram->setUniform("ModelTransform", transform); _gridProgram->setUniform("campos", campos.vec4()); _gridProgram->setUniform("objpos", currentPosition.vec4()); @@ -216,7 +216,7 @@ void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPositi _gridProgram->deactivate(); } -void RenderableSphericalGrid::update(){ - +void RenderableSphericalGrid::update(const UpdateData& data){ } + } \ No newline at end of file diff --git a/src/rendering/renderablevolumegl.cpp b/src/rendering/renderablevolumegl.cpp index 0b735da7e6..b9c227f986 100644 --- a/src/rendering/renderablevolumegl.cpp +++ b/src/rendering/renderablevolumegl.cpp @@ -228,7 +228,7 @@ bool RenderableVolumeGL::deinitialize() { return true; } -void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) { +void RenderableVolumeGL::render(const RenderData& data) { if(_updateTransferfunction) { _updateTransferfunction = false; ghoul::opengl::Texture* transferFunction = loadTransferFunction(_transferFunctionPath); @@ -248,10 +248,10 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R transform = glm::scale(transform, _boxScaling); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); - PowerScaledScalar scaling = camera->scaling(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); + PowerScaledScalar scaling = data.camera.scaling(); // psc addon(-1.1,0.0,0.0,0.0); // currentPosition += addon; @@ -262,7 +262,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R _boxProgram->activate(); _boxProgram->setUniform(_typeLocation, _id); - _boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix()); + _boxProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix()); _boxProgram->setUniform("modelTransform", transform); _boxProgram->setUniform("campos", campos.vec4()); _boxProgram->setUniform("objpos", currentPosition.vec4()); @@ -284,7 +284,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R _boxProgram->deactivate(); } -void RenderableVolumeGL::update() { +void RenderableVolumeGL::update(const UpdateData& data) { } } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 18e8c5d53f..c352f2dac9 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -51,7 +51,6 @@ namespace openspace { RenderEngine::RenderEngine() : _mainCamera(nullptr) , _sceneGraph(nullptr) - , _runtimeData(nullptr) , _abuffer(nullptr) { } @@ -82,10 +81,6 @@ bool RenderEngine::initialize() return true; } -void RenderEngine::setRuntimeData(RuntimeData* runtimeData){ - _runtimeData = runtimeData; -} - bool RenderEngine::initializeGL() { // LDEBUG("RenderEngine::initializeGL()"); @@ -177,7 +172,7 @@ void RenderEngine::postSynchronizationPreDraw() _mainCamera->compileViewRotationMatrix(); // update and evaluate the scene starting from the root node - _sceneGraph->update(); + _sceneGraph->update({Time::ref().currentTime()}); _mainCamera->setCameraDirection(glm::vec3(0, 0, -1)); _sceneGraph->evaluate(_mainCamera); } @@ -212,7 +207,7 @@ void RenderEngine::render() // render the scene starting from the root node _abuffer->clear(); _abuffer->preRender(); - _sceneGraph->render(_mainCamera); + _sceneGraph->render({*_mainCamera, psc()}); _abuffer->postRender(); _abuffer->resolve(); @@ -227,21 +222,15 @@ void RenderEngine::render() #endif - std::string timeGUI = SpiceManager::ref().ephemerisTimeToString(_runtimeData->getTime()); - - if (timeGUI == "") _runtimeData->setTime(0); // if time ends -> reset time to julian date 0. - const glm::vec2 scaling = _mainCamera->scaling(); const glm::vec3 viewdirection = _mainCamera->viewDirection(); const psc position = _mainCamera->position(); const psc origin = OsEng.interactionHandler().getOrigin(); const PowerScaledScalar pssl = (position - origin).length(); + /* GUI PRINT */ - Freetype::print( - sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE), - FONT_SIZE, FONT_SIZE * 20, "OpenSpace Time: (%s)", timeGUI.c_str()); - const std::string time = Time::ref().currentTimeUTC().c_str(); + std::string&& time = Time::ref().currentTimeUTC().c_str(); Freetype::print( sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE), FONT_SIZE, FONT_SIZE * 18, "Date: %s", time.c_str() diff --git a/src/rendering/stars/renderablestars.cpp b/src/rendering/stars/renderablestars.cpp index b80c66d1c9..5436bbe320 100644 --- a/src/rendering/stars/renderablestars.cpp +++ b/src/rendering/stars/renderablestars.cpp @@ -306,17 +306,17 @@ bool RenderableStars::deinitialize(){ } //#define TMAT -void RenderableStars::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){ +void RenderableStars::render(const RenderData& data){ assert(_haloProgram); printOpenGLError(); // activate shader _haloProgram->activate(); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); - PowerScaledScalar scaling = camera->scaling(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); + PowerScaledScalar scaling = data.camera.scaling(); glm::mat4 transform = glm::mat4(1); //scaling = glm::vec2(1, -22); scaling = glm::vec2(1, -19); @@ -332,9 +332,9 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); #ifdef GLSPRITES - glm::mat4 modelMatrix = camera->modelMatrix(); - glm::mat4 viewMatrix = camera->viewMatrix(); - glm::mat4 projectionMatrix = camera->projectionMatrix(); + glm::mat4 modelMatrix = data.camera.modelMatrix(); + glm::mat4 viewMatrix = data.camera.viewMatrix(); + glm::mat4 projectionMatrix = data.camera.projectionMatrix(); // ---------------------- RENDER HALOS ----------------------------- _haloProgram->setUniform("model", modelMatrix); @@ -404,7 +404,7 @@ void RenderableStars::loadTexture(){ } } -void RenderableStars::update() +void RenderableStars::update(const UpdateData& data) { } diff --git a/src/scenegraph/ephemeris.cpp b/src/scenegraph/ephemeris.cpp index ae2d5080d8..b764190cf7 100644 --- a/src/scenegraph/ephemeris.cpp +++ b/src/scenegraph/ephemeris.cpp @@ -68,6 +68,6 @@ bool Ephemeris::initialize() { return true; } -void Ephemeris::update() {} +void Ephemeris::update(const UpdateData& data) {} } // namespace openspace \ No newline at end of file diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 7015e44c36..0142f19b83 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // ghoul includes #include "ghoul/opengl/programobject.h" @@ -196,7 +197,6 @@ SceneGraph::SceneGraph() : _focus(SceneGraphNode::RootNodeName) , _position(SceneGraphNode::RootNodeName) , _root(nullptr) - , _runtimeData(nullptr) { } @@ -205,10 +205,6 @@ SceneGraph::~SceneGraph() deinitialize(); } -void SceneGraph::setRuntimeData(RuntimeData* runtimeData){ - _runtimeData = runtimeData; -} - bool SceneGraph::initialize() { LDEBUG("Initializing SceneGraph"); @@ -457,7 +453,7 @@ bool SceneGraph::deinitialize() return true; } -void SceneGraph::update() +void SceneGraph::update(const UpdateData& data) { if (!_sceneGraphToLoad.empty()) { OsEng.renderEngine().sceneGraph()->clearSceneGraph(); @@ -468,7 +464,7 @@ void SceneGraph::update() } for (auto node : _nodes) - node->update(); + node->update(data); } void SceneGraph::evaluate(Camera* camera) @@ -477,10 +473,10 @@ void SceneGraph::evaluate(Camera* camera) _root->evaluate(camera); } -void SceneGraph::render(Camera* camera) +void SceneGraph::render(const RenderData& data) { if (_root) - _root->render(camera); + _root->render(data); } void SceneGraph::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { @@ -588,7 +584,7 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) // Initialize all nodes for (auto node : _nodes) { - bool success = node->initialize(_runtimeData); + bool success = node->initialize(); if (success) LDEBUG(node->name() << " initialized successfully!"); else @@ -596,8 +592,9 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) } // update the position of all nodes + // TODO need to check this; unnecessary? (ab) for (auto node : _nodes) - node->update(); + node->update({Time::ref().currentTime()}); // Calculate the bounding sphere for the scenegraph _root->calculateBoundingSphere(); diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index afdb3bf5d2..6966db4035 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -128,7 +128,6 @@ SceneGraphNode::SceneGraphNode() , _renderable(nullptr) , _renderableVisible(false) , _boundingSphereVisible(false) - , _runtimeData(nullptr) { } @@ -137,7 +136,7 @@ SceneGraphNode::~SceneGraphNode() deinitialize(); } -bool SceneGraphNode::initialize(RuntimeData* runtimeData) +bool SceneGraphNode::initialize() { if (_renderable != nullptr) _renderable->initialize(); @@ -145,7 +144,6 @@ bool SceneGraphNode::initialize(RuntimeData* runtimeData) if (_ephemeris != nullptr) _ephemeris->initialize(); - _runtimeData = runtimeData; return true; } @@ -173,9 +171,12 @@ bool SceneGraphNode::deinitialize() } // essential -void SceneGraphNode::update() +void SceneGraphNode::update(const UpdateData& data) { - _ephemeris->update(_runtimeData); + if (_ephemeris) + _ephemeris->update(data); + if (_renderable) + _renderable->update(data); } void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) @@ -220,9 +221,11 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) } } -void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) +void SceneGraphNode::render(const RenderData& data) { - const psc thisPosition = parentPosition + _ephemeris->position(); + const psc thisPosition = data.position + _ephemeris->position(); + + RenderData newData = {data.camera, thisPosition}; // check if camera is outside the node boundingsphere /*if (!_boundingSphereVisible) { @@ -231,13 +234,13 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) if (_renderableVisible && _renderable->isVisible()) { // LDEBUG("Render"); - _renderable->render(camera, thisPosition, _runtimeData); + _renderable->render(newData); } // evaluate all the children, tail-recursive function(?) for (auto& child : _children) { - child->render(camera, thisPosition); + child->render(newData); } } @@ -317,7 +320,6 @@ PowerScaledScalar SceneGraphNode::boundingSphere() const{ // renderable void SceneGraphNode::setRenderable(Renderable* renderable) { _renderable = renderable; - update(); } const Renderable* SceneGraphNode::renderable() const diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 816a11be18..4a3100488b 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -78,15 +78,13 @@ const psc& SpiceEphemeris::position() const { return _position; } -void SpiceEphemeris::update(RuntimeData* runtimeData) { +void SpiceEphemeris::update(const UpdateData& data) { double state[3]; - _currentEphemerisTime = runtimeData->getTime(); - glm::dvec3 position(0,0,0); double lightTime = 0.0; - SpiceManager::ref().getTargetPosition(_targetName, _currentEphemerisTime, "GALACTIC", "LT+S", _originName, position, lightTime); + SpiceManager::ref().getTargetPosition(_targetName, data.time, "GALACTIC", "LT+S", _originName, position, lightTime); /* std::cout << _targetName << " ("; diff --git a/src/scenegraph/staticephemeris.cpp b/src/scenegraph/staticephemeris.cpp index 2c7bee2345..a38ab47c3b 100644 --- a/src/scenegraph/staticephemeris.cpp +++ b/src/scenegraph/staticephemeris.cpp @@ -47,7 +47,7 @@ const psc& StaticEphemeris::position() const { return _position; } -void StaticEphemeris::update(RuntimeData* runtimeData) { +void StaticEphemeris::update(const UpdateData&) { }