From dce4835bab7a5589be0b5ba5493c3af26e04c962 Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Thu, 19 Feb 2015 15:19:20 +0100 Subject: [PATCH 1/4] changing render function of openspaceengine and renderengine to take glm::mat4 matrices for Projection / ViewMatrix. --- include/openspace/engine/openspaceengine.h | 2 +- include/openspace/rendering/renderengine.h | 2 +- src/engine/openspaceengine.cpp | 6 ++-- src/main.cpp | 5 +++- src/rendering/renderengine.cpp | 34 +++++++++++++--------- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index e00adfc509..312fc885e3 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -75,7 +75,7 @@ public: bool initializeGL(); void preSynchronization(); void postSynchronizationPreDraw(); - void render(); + void render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix); void postDraw(); void keyboardCallback(int key, int action); void charCallback(unsigned int codepoint); diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 8a54994e96..9c1dca534d 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -60,7 +60,7 @@ public: bool initializeGL(); void postSynchronizationPreDraw(); void preSynchronization(); - void render(); + void render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix); void postDraw(); void takeScreenshot(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 96e5ca2b21..4b929c4782 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -567,8 +567,8 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { } } -void OpenSpaceEngine::render() { - _renderEngine->render(); +void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) { + _renderEngine->render(projectionMatrix, viewMatrix); if (sgct::Engine::instance()->isMaster()) { // If currently writing a command, render it to screen @@ -576,7 +576,7 @@ void OpenSpaceEngine::render() { if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering() && _console->isVisible()) { _console->render(); } - + if (_gui->isEnabled()) _gui->endFrame(); } diff --git a/src/main.cpp b/src/main.cpp index 8ca0a294bd..f457835a5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,7 +162,10 @@ void mainPostSyncPreDrawFunc() void mainRenderFunc() { - OsEng.render(); + glm::mat4 userMatrix = glm::translate(glm::mat4(1.f), -_sgctEngine->getUserPtr()->getPos()); + glm::mat4 viewMatrix = _sgctEngine->getActiveModelViewMatrix() * userMatrix; + glm::mat4 projectionMatrix = _sgctEngine->getActiveProjectionMatrix(); + OsEng.render(projectionMatrix, viewMatrix); } void mainPostDrawFunc() diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 66d3d131b5..233f7b1d6d 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -347,7 +347,7 @@ namespace openspace { } - void RenderEngine::render() + void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) { // We need the window pointer sgct::SGCTWindow* w = sgct::Engine::instance()->getActiveWindowPtr(); @@ -371,25 +371,31 @@ namespace openspace { const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr("")->getPos(); #else - const glm::vec3 eyePosition - = sgct_core::ClusterManager::instance()->getUserPtr()->getPos(); + //const glm::vec3 eyePosition + // = sgct_core::ClusterManager::instance()->getUserPtr()->getPos(); #endif //@CHECK does the dome disparity disappear if this line disappears? ---abock - const glm::mat4 view - = glm::translate(glm::mat4(1.0), - eyePosition); // make sure the eye is in the center - _mainCamera->setViewProjectionMatrix( - sgct::Engine::instance()->getActiveModelViewProjectionMatrix() * view); + //const glm::mat4 view + // = glm::translate(glm::mat4(1.0), + // eyePosition); // make sure the eye is in the center + //_mainCamera->setViewProjectionMatrix( + // sgct::Engine::instance()->getActiveModelViewProjectionMatrix() * view); - _mainCamera->setModelMatrix( - sgct::Engine::instance()->getModelMatrix()); + //_mainCamera->setModelMatrix( + // sgct::Engine::instance()->getModelMatrix()); - _mainCamera->setViewMatrix( - sgct::Engine::instance()->getActiveViewMatrix()* view); + //_mainCamera->setViewMatrix( + // sgct::Engine::instance()->getActiveViewMatrix()* view); - _mainCamera->setProjectionMatrix( - sgct::Engine::instance()->getActiveProjectionMatrix()); + //_mainCamera->setProjectionMatrix( + // sgct::Engine::instance()->getActiveProjectionMatrix()); + _mainCamera->setViewMatrix(viewMatrix); + _mainCamera->setProjectionMatrix(projectionMatrix); + + //is this really necessary? + _mainCamera->setViewProjectionMatrix(projectionMatrix * viewMatrix); + // render the scene starting from the root node if (!_visualizeABuffer) { From c94a287cd205ffe5d7bfdce521b87ede5e7a9a1c Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Thu, 19 Feb 2015 15:20:14 +0100 Subject: [PATCH 2/4] changed to relative path for playbook --- src/rendering/planets/renderableplanetprojection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index 25bed5b6c0..8321472426 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -144,8 +144,9 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& bool loaded = openspace::ImageSequencer::ref().loadSequence(_sequenceDir); if (!loaded) LDEBUG(name + " did not load sequence " + _sequenceDir + " check mod file path"); */ - openspace::ImageSequencer::ref().parsePlaybook("C:/Users/michal/playbook", "txt"); + //openspace::ImageSequencer::ref().parsePlaybook("C:/Users/michal/playbook", "txt"); //openspace::ImageSequencer::ref().parsePlaybook("C:/Users/joaki56/Desktop/ProjectionsOfInterest/playbook", "txt"); + openspace::ImageSequencer::ref().parsePlaybook(absPath("${OPENSPACE_DATA}/playbook.csv"), "csv"); } } From f87696f7622af8ee7874243f03e1ebd141280ab4 Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Thu, 19 Feb 2015 15:21:09 +0100 Subject: [PATCH 3/4] changed to relative path for placeholder image and removed directory searching for playbook file. function now accepts an actual playbook file --- src/util/imagesequencer.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/imagesequencer.cpp b/src/util/imagesequencer.cpp index c4180d101c..b84c03bb8b 100644 --- a/src/util/imagesequencer.cpp +++ b/src/util/imagesequencer.cpp @@ -158,9 +158,10 @@ bool replace(std::string& str, const std::string& from, const std::string& to) { } bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& type, std::string year){ - ghoul::filesystem::Directory playbookDir(dir, true); - std::vector dirlist = playbookDir.read(true, false); - for (auto path : dirlist){ + //ghoul::filesystem::Directory playbookDir(dir, true); + //std::vector dirlist = playbookDir.read(true, false); + //for (auto path : dirlist){ + std::string path = dir; if (size_t position = path.find_last_of(".") + 1){ if (position != std::string::npos){ ghoul::filesystem::File currentFile(path); @@ -185,7 +186,7 @@ bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& ty timestr = year + " " + timestr; openspace::SpiceManager::ref().getETfromDate(timestr, et); - std::string defaultImagePath = dir + "/placeholder.png"; + std::string defaultImagePath = absPath("${OPENSPACE_DATA}/placeholder.png"); createImage(et, et + shutter, defaultImagePath); } } while (!file.eof()); @@ -224,7 +225,7 @@ bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& ty openspace::SpiceManager::ref().getDateFromET(et, str); std::cout << str << std::endl; */ - std::string defaultImagePath = dir + "/placeholder.png"; + std::string defaultImagePath = absPath("${OPENSPACE_DATA}/placeholder.png"); createImage(et, et + shutter, defaultImagePath); } } while (!file.eof()); @@ -232,7 +233,7 @@ bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& ty } } - } + //} return true; // add check } From 26595edc903ee65065051e3759b5822f58e50f72 Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Thu, 19 Feb 2015 15:40:08 +0100 Subject: [PATCH 4/4] updates to matrix calculations --- src/main.cpp | 4 ++-- src/rendering/renderengine.cpp | 24 ++++++++---------------- src/rendering/stars/renderablestars.cpp | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f457835a5a..a985b7f210 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,8 +162,8 @@ void mainPostSyncPreDrawFunc() void mainRenderFunc() { - glm::mat4 userMatrix = glm::translate(glm::mat4(1.f), -_sgctEngine->getUserPtr()->getPos()); - glm::mat4 viewMatrix = _sgctEngine->getActiveModelViewMatrix() * userMatrix; + glm::mat4 userMatrix = glm::translate(glm::mat4(1.f), _sgctEngine->getUserPtr()->getPos()); + glm::mat4 viewMatrix = _sgctEngine->getActiveViewMatrix() * userMatrix; glm::mat4 projectionMatrix = _sgctEngine->getActiveProjectionMatrix(); OsEng.render(projectionMatrix, viewMatrix); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 233f7b1d6d..9df8cc8606 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -371,31 +371,23 @@ namespace openspace { const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr("")->getPos(); #else - //const glm::vec3 eyePosition - // = sgct_core::ClusterManager::instance()->getUserPtr()->getPos(); + const glm::vec3 eyePosition + = sgct_core::ClusterManager::instance()->getUserPtr()->getPos(); #endif //@CHECK does the dome disparity disappear if this line disappears? ---abock //const glm::mat4 view // = glm::translate(glm::mat4(1.0), // eyePosition); // make sure the eye is in the center - //_mainCamera->setViewProjectionMatrix( - // sgct::Engine::instance()->getActiveModelViewProjectionMatrix() * view); + // - //_mainCamera->setModelMatrix( - // sgct::Engine::instance()->getModelMatrix()); + _mainCamera->setViewMatrix( + viewMatrix ); - //_mainCamera->setViewMatrix( - // sgct::Engine::instance()->getActiveViewMatrix()* view); + _mainCamera->setProjectionMatrix( + projectionMatrix); - //_mainCamera->setProjectionMatrix( - // sgct::Engine::instance()->getActiveProjectionMatrix()); - - _mainCamera->setViewMatrix(viewMatrix); - _mainCamera->setProjectionMatrix(projectionMatrix); - - //is this really necessary? + //Is this really necessary to store? _mainCamera->setViewProjectionMatrix(projectionMatrix * viewMatrix); - // render the scene starting from the root node if (!_visualizeABuffer) { diff --git a/src/rendering/stars/renderablestars.cpp b/src/rendering/stars/renderablestars.cpp index ce2fbe8a72..d8dd150234 100644 --- a/src/rendering/stars/renderablestars.cpp +++ b/src/rendering/stars/renderablestars.cpp @@ -179,7 +179,7 @@ void RenderableStars::render(const RenderData& data) { // is done twice? ---abock glm::vec2 scaling = glm::vec2(1, -19); - glm::mat4 modelMatrix = data.camera.modelMatrix(); + glm::mat4 modelMatrix = glm::mat4(1.0); glm::mat4 viewMatrix = data.camera.viewMatrix(); glm::mat4 projectionMatrix = data.camera.projectionMatrix();