diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index 580f22a52a..c0d18c084c 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -88,6 +88,7 @@ private: glm::mat4 _projectorMatrix; // spice + std::string _sequenceDir; std::string _instrumentID; std::string _projectorID; std::string _projecteeID; diff --git a/include/openspace/rendering/renderablefov.h b/include/openspace/rendering/renderablefov.h index 7b2da806d3..e79b5ddfc3 100644 --- a/include/openspace/rendering/renderablefov.h +++ b/include/openspace/rendering/renderablefov.h @@ -69,7 +69,8 @@ public: glm::dvec3 interpolate(glm::dvec3 p0, glm::dvec3 p1, float t); glm::dvec3 bisection(glm::dvec3 p1, glm::dvec3 p2, double tolerance); - double distanceBetweenPoints(psc p1, psc p2); + void computeColors(); + // instance variables int _nrInserted = 0; int _isteps; @@ -114,7 +115,10 @@ public: // time double _time = 0; double _oldTime = 0; - int _delta = 0; + + // capturetime + double _timeInterval; + double _nextCaptureTime; }; } #endif diff --git a/include/openspace/util/imagesequencer.h b/include/openspace/util/imagesequencer.h index d491f7f1d4..e360c86a49 100644 --- a/include/openspace/util/imagesequencer.h +++ b/include/openspace/util/imagesequencer.h @@ -45,14 +45,20 @@ public: static void deinitialize(); bool sequenceReset(); -public: - - void createImage(double t1, double t2, std::string path = "dummypath"); - bool getImagePath(double& _currentTime, std::string& path); - bool getImagePath(std::string _currentTime, std::string& path); - //double _previousTime; // not sure if i wanna use this yet. + bool getImagePath(double& _currentTime, std::string& path, bool closedInterval = false); + bool getImagePath(std::string _currentTime, std::string& path, bool closedInterval = false); + double getNextCaptureTime(); + double getIntervalLength(){ return _intervalLength; }; static ImageSequencer* _sequencer; + +private: + double nextCaptureTime(double _time); + + void createImage(double t1, double t2, std::string path = "dummypath"); + + double _nextCapture; + double _intervalLength; }; } // namespace openspace diff --git a/openspace-data b/openspace-data index 1b695abb94..d2897d1511 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 1b695abb9470c686184af5f67855e7d69d0807cb +Subproject commit d2897d1511b911057ed8e1ce310ffe1b7ffbea54 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index ef5c7c2cb5..91aa4ed000 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,5 +1,6 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') --openspace.time.setTime("2007-01-08T20:42:01.359") -- far +--openspace.time.setTime("2007-02-10T13:30:01.359") -- 4x4 openspace.time.setTime("2007-02-27T16:30:00.000") -- close --openspace.time.setDeltaTime(200000.0) diff --git a/shaders/projectiveTexture_fs.glsl b/shaders/projectiveTexture_fs.glsl index 1cbe020784..d7e7cda5c2 100644 --- a/shaders/projectiveTexture_fs.glsl +++ b/shaders/projectiveTexture_fs.glsl @@ -59,7 +59,7 @@ void main() //vec3 e = normalize(camdir); vec3 l_pos = vec3(0.0); // sun. vec3 l_dir = normalize(l_pos-objpos.xyz); - float terminatorBright = 0.8; + float terminatorBright = 0.4; float intensity = min(max(5*dot(n,l_dir), terminatorBright), 1); float shine = 0.0001; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 742ae4aadd..227571ce8e 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -499,7 +499,7 @@ void OpenSpaceEngine::preSynchronization() { _interactionHandler.update(dt); _interactionHandler.lockControls(); - Time::ref().advanceTime(dt); + // Time::ref().advanceTime(dt); } } diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index f9440a0818..8ec1def42e 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -53,6 +53,7 @@ namespace { const std::string keyInstrumentAspect = "Instrument.Aspect"; const std::string keyInstrumentNear = "Instrument.Near"; const std::string keyInstrumentFar = "Instrument.Far"; + const std::string keySequenceDir = "Projection.Sequence"; const std::string _mainFrame = "GALACTIC"; } @@ -129,10 +130,12 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& addProperty(_projectionTexturePath); _projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this)); - //std::string sPath = "C:/Users/michal/JupSequenceCrosshair"; std::string sPath = "F:/JupiterFullSequence"; - - openspace::ImageSequencer::ref().loadSequence(sPath); + bool found = dictionary.getValue(keySequenceDir, _sequenceDir); + if (found){ + bool loaded = openspace::ImageSequencer::ref().loadSequence(_sequenceDir); + if (!loaded) LDEBUG(name + " did not load sequence " + _sequenceDir + " check mod file path"); + } } RenderablePlanetProjection::~RenderablePlanetProjection(){ @@ -336,7 +339,7 @@ void RenderablePlanetProjection::render(const RenderData& data){ #ifdef GPU_PROJ if (_capture){ - attitudeParameters(_time[0]); + attitudeParameters(_time[1]); imageProjectGPU(); } #endif @@ -373,8 +376,9 @@ void RenderablePlanetProjection::update(const UpdateData& data){ _capture = false; bool _withinFOV; + /* -- TEMPORARY TARGETING SOLUTION -- FML */ std::string potential[5] = { "JUPITER", "IO", "EUROPA", "GANYMEDE", "CALLISTO" }; - std::string p2[5] = { "JUPITER BARYCENTER", "IO", "EUROPA", "GANYMEDE", "CALLISTO" }; + std::string p2[5] = { "JUPITER BARYCENTER", "IO", "EUROPA", "GANYMEDE", "CALLISTO" }; // "Barycenter" term messes it all up.. SPICE ambiguities! std::string _fovTarget = ""; for (int i = 0; i < 5; i++){ @@ -385,11 +389,9 @@ void RenderablePlanetProjection::update(const UpdateData& data){ } } if (_projecteeID == _fovTarget){ - std::cout << _fovTarget << " " << _projecteeID << std::endl; _next = _defaultProjImage; + if (_time[0] >= openspace::ImageSequencer::ref().getNextCaptureTime()) _capture = openspace::ImageSequencer::ref().getImagePath(_time[0], _next); - if (_next != _defaultProjImage) - std::cout << _next << std::endl; _projectionTexturePath = _next; } } diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index 47e8d10e4e..35da69d54e 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -50,13 +52,12 @@ namespace { //#define DEBUG namespace openspace{ // colors, move later - glm::vec4 origin(0); - glm::vec4 col_gray(0.3, 0.3, 0.3, 1); - glm::vec4 col_start(1.00, 0.89, 0.00, 1); - glm::vec4 col_end(1.00, 0.29, 0.00, 1); - glm::vec4 col_sq(1.00, 0.29, 0.00, 1); - - glm::vec4 col_proj(1, 1, 1, 1); + glm::vec4 col_sq; + glm::vec4 c_project; + glm::vec4 col_end; + glm::vec4 blue; + glm::vec4 col_gray; + glm::vec4 col_start; RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) : Renderable(dictionary) @@ -187,10 +188,6 @@ void RenderableFov::insertPoint(std::vector& arr, psc& p, glm::vec4& c){ } _nrInserted++; } -double RenderableFov::distanceBetweenPoints(psc p1, psc p2){ - PowerScaledScalar dist = (p1 - p2).length(); - return dist[0] * pow(10, dist[1]); -} psc RenderableFov::pscInterpolate(psc p0, psc p1, float t){ assert(t >= 0 && t <= 1); @@ -356,6 +353,31 @@ void RenderableFov::updateData(){ glBindVertexArray(0); } } +void RenderableFov::computeColors(){ + double t2 = openspace::ImageSequencer::ref().getNextCaptureTime(); + double diff = (t2 - _time); + double t = 0.0; + if (diff <= 7.0) t = 1.f - diff / 7.0; + + c_project = glm::vec4(0.0, 1.0, 0.00,1); + col_end = glm::vec4(1.00, 0.29, 0.00, 1); + blue = glm::vec4(0, 0.5, 0.7, 1); + col_gray = glm::vec4(0.3, 0.3, 0.3, 1); + col_start = glm::vec4(1.00, 0.89, 0.00, 1); + col_sq = glm::vec4(1.00, 0.29, 0.00, 1); + + col_end.x = c_project.x*t + col_end.x*(1 - t); + col_end.y = c_project.y*t + col_end.y*(1 - t); + col_end.z = c_project.z*t + col_end.z*(1 - t); + + blue.x = c_project.x*t + blue.x*(1 - t); + blue.y = c_project.y*t + blue.y*(1 - t); + blue.z = c_project.z*t + blue.z*(1 - t); + + col_sq.x = c_project.x*t + col_sq.x*(1 - t); + col_sq.y = c_project.y*t + col_sq.y*(1 - t); + col_sq.z = c_project.z*t + col_sq.z*(1 - t); +} void RenderableFov::render(const RenderData& data){ assert(_programObject); @@ -402,18 +424,21 @@ void RenderableFov::render(const RenderData& data){ } } - //somehow get target in there. - //_targetNode = sceneGraphNode(_fovTarget); - /*std::vector properties = _targetNode->subOwners(); - for (auto & element : properties) { - std::cout << element->name() << std::endl; - }*/ - //std::cout << _targetNode->renderable.hasProperty("PlanetGeometry") << std::endl; - + computeColors(); + double t2 = openspace::ImageSequencer::ref().getNextCaptureTime(); + double diff = (t2 - _time); + double t = 0.0; + if (diff <= 30.0) t = 1.f - diff / 30.0; + double targetEpoch; + /* openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID, + _frame, _method, _aberrationCorrection, + _time, targetEpoch, boresight, ipoint, ivec); + psc bsvec = PowerScaledCoordinate::CreatePowerScaledCoordinate(ivec[0], ivec[1], ivec[2]); + bsvec[3] += 3; + */ // for each FOV vector for (int i = 0; i < 4; i++){ - double targetEpoch; // compute surface intercept _interceptTag[i] = openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID, _frame, _method, _aberrationCorrection, @@ -421,13 +446,13 @@ void RenderableFov::render(const RenderData& data){ // if not found, use the orthogonal projected point if (!_interceptTag[i]) _projectionBounds[i] = orthogonalProjection(bounds[i]); - // VBO1 : draw vectors representing outer points of FOV. if (_interceptTag[i]){ _interceptVector = PowerScaledCoordinate::CreatePowerScaledCoordinate(ivec[0], ivec[1], ivec[2]); _interceptVector[3] += 3; + //_interceptVector = pscInterpolate(_interceptVector, bsvec, t); // INTERCEPTIONS - memcpy(&_varray1[indx], glm::value_ptr(origin), size); + memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size); indx += 4; memcpy(&_varray1[indx], glm::value_ptr(col_start), size); indx += 4; @@ -437,20 +462,20 @@ void RenderableFov::render(const RenderData& data){ indx += 4; } else if (_withinFOV){ - // FOV LARGER THAN OBJECT - memcpy(&_varray1[indx], glm::value_ptr(origin), size); + // FOV OUTSIDE OBJECT + memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size); indx += 4; memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0,0,1,1)), size); indx += 4; memcpy(&_varray1[indx], glm::value_ptr(_projectionBounds[i].vec4()), size); indx += 4; - memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0, 0.5, 0.7, 1)), size); + memcpy(&_varray1[indx], glm::value_ptr(blue), size); indx += 4; }else{ glm::vec4 corner(bounds[i][0], bounds[i][1], bounds[i][2], data.position[3]); corner = tmp*corner; // "INFINITE" FOV - memcpy(&_varray1[indx], glm::value_ptr(origin), size); + memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size); indx += 4; memcpy(&_varray1[indx], glm::value_ptr(col_gray), size); indx += 4; @@ -495,7 +520,6 @@ void RenderableFov::render(const RenderData& data){ void RenderableFov::update(const UpdateData& data){ double lightTime; _time = data.time; - _delta = data.delta; openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _frame, data.time, _stateMatrix); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 2b96a355f9..7fa342c231 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -414,20 +415,39 @@ void RenderEngine::render() // GUI PRINT // Using a macro to shorten line length and increase readability -#define PrintText(i, format, ...) Freetype::print(font, 10.f, static_cast(startY - font_size_mono * i * 2), format, __VA_ARGS__); +#define PrintText(i, format, size, ...) Freetype::print(font, size, static_cast(startY - font_size_mono * i * 2), format, __VA_ARGS__); +#define PrintColorText(i, format, size, color, ...) Freetype::print(font, size, static_cast(startY - font_size_mono * i * 2), color, format, __VA_ARGS__); + int i = 0; - PrintText(i++, "Date: %s", Time::ref().currentTimeUTC().c_str()); - PrintText(i++, "DateD: %f", Time::ref().currentTime()); - PrintText(i++, "Avg. Frametime: %.5f", sgct::Engine::instance()->getAvgDt()); - PrintText(i++, "Drawtime: %.5f", sgct::Engine::instance()->getDrawTime()); - PrintText(i++, "Frametime: %.5f", sgct::Engine::instance()->getDt()); - PrintText(i++, "Origin: (% .5f, % .5f, % .5f, % .5f)", origin[0], origin[1], origin[2], origin[3]); - PrintText(i++, "Cam pos: (% .5f, % .5f, % .5f, % .5f)", position[0], position[1], position[2], position[3]); - PrintText(i++, "View dir: (% .5f, % .5f, % .5f)", viewdirection[0], viewdirection[1], viewdirection[2]); - PrintText(i++, "Cam->origin: (% .15f, % .4f)", pssl[0], pssl[1]); - PrintText(i++, "Scaling: (% .5f, % .5f)", scaling[0], scaling[1]); + PrintText(i++, "Date: %s", 20, Time::ref().currentTimeUTC().c_str()); + PrintText(i++, "Avg. Frametime: %.5f", 10, sgct::Engine::instance()->getAvgDt()); + PrintText(i++, "Drawtime: %.5f", 10, sgct::Engine::instance()->getDrawTime()); + PrintText(i++, "Frametime: %.5f", 10, sgct::Engine::instance()->getDt()); + PrintText(i++, "Origin: (% .5f, % .5f, % .5f, % .5f)", 10, origin[0], origin[1], origin[2], origin[3]); + PrintText(i++, "Cam pos: (% .5f, % .5f, % .5f, % .5f)", 10, position[0], position[1], position[2], position[3]); + PrintText(i++, "View dir: (% .5f, % .5f, % .5f)", 10, viewdirection[0], viewdirection[1], viewdirection[2]); + PrintText(i++, "Cam->origin: (% .15f, % .4f)", 10, pssl[0], pssl[1]); + PrintText(i++, "Scaling: (% .5f, % .5f)", 10, scaling[0], scaling[1]); + + double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - Time::ref().currentTime(); + double t = 0.0; + t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength(); + std::string progress = "|"; + int g = ((t) * 20) + 1; + for (int i = 0; i < g; i++) progress.append("-"); progress.append(">"); + for (int i = 0; i < 21 - g; i++) progress.append(" "); + + progress.append("|"); + if (remaining > 0){ + glm::vec4 w(1); + glm::vec4 g1(0, t, 0, 1); + glm::vec4 g2(1-t); + PrintColorText(i++, "Next projection in | %.0f seconds", 10, g1+g2, remaining); + PrintColorText(i++, "%s %.1f %%", 10, g1 + g2, progress.c_str(), t * 100); + } + #undef PrintText } diff --git a/src/util/imagesequencer.cpp b/src/util/imagesequencer.cpp index 9414bcbc4b..3e2d5e425d 100644 --- a/src/util/imagesequencer.cpp +++ b/src/util/imagesequencer.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,11 @@ struct ImageParams{ std::string path; bool projected; }; + +auto cmp = [](const ImageParams &a, const ImageParams &b)->bool{ + return a.startTime < b.startTime; +}; + std::vector _timeStamps; ImageSequencer& ImageSequencer::ref() { @@ -71,25 +77,40 @@ void ImageSequencer::createImage(double t1, double t2, std::string path){ _timeStamps.push_back(image); // sort - auto cmp = [](const ImageParams &a, const ImageParams &b)->bool{ - return a.startTime < b.startTime; - }; - + std::sort(_timeStamps.begin(), _timeStamps.end(), cmp); } - -bool ImageSequencer::getImagePath(std::string _currentTime, std::string& path){ - double currentEt = 0; - openspace::SpiceManager::ref().getETfromDate(_currentTime, currentEt); - bool success = getImagePath(currentEt, path); - return success; +double ImageSequencer::getNextCaptureTime(){ + return _nextCapture; } -#define OPEN_INTERVAL // assign boolean value... -bool ImageSequencer::getImagePath(double& _currentTime, std::string& path){ - auto cmp = [](const ImageParams &a, const ImageParams &b)->bool{ - return a.startTime < b.startTime; +double ImageSequencer::nextCaptureTime(double _time){ + auto binary_find = [](std::vector::iterator begin, + std::vector::iterator end, + const ImageParams &val, + bool(*cmp)(const ImageParams &a, const ImageParams &b))->std::vector::iterator{ + // Finds the lower bound in at most log(last - first) + 1 comparisons + std::vector::iterator it = std::lower_bound(begin, end, val, cmp); + if (it != begin){ + return it; + } + return end; }; + auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { _time, 0, "", false }, cmp); + + std::cout << _nextCapture << std::endl; + if (_time < _nextCapture) return _nextCapture; + return it->startTime; +} + +bool ImageSequencer::getImagePath(std::string _currentTime, std::string& path, bool closedInterval){ + double currentEt = 0; + openspace::SpiceManager::ref().getETfromDate(_currentTime, currentEt); + bool success = getImagePath(currentEt, path, closedInterval); + return success; +} + +bool ImageSequencer::getImagePath(double& _currentTime, std::string& path, bool closedInterval){ auto binary_find = [](std::vector::iterator begin, std::vector::iterator end, const ImageParams &val, @@ -104,19 +125,21 @@ bool ImageSequencer::getImagePath(double& _currentTime, std::string& path){ auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { _currentTime, 0, "", false }, cmp); //check [start, stop] -#ifndef OPEN_INTERVAL - if (it == _timeStamps.end() || it->stopTime < _currentTime || it->projected){ + if (closedInterval && (it == _timeStamps.end() || it->stopTime < _currentTime || it->projected)){ + return false; + }else if (!closedInterval && (it == _timeStamps.end() || it->projected)){ return false; } -#else - //check [start,) - if (it == _timeStamps.end() || it->projected){ - return false; + double upcoming = nextCaptureTime(_currentTime); + if (_nextCapture != upcoming){ + _nextCapture = upcoming; + _intervalLength = upcoming - _currentTime; } -#endif + it->projected = true; path = it->path; _currentTime = it->startTime; + return true; } @@ -130,8 +153,6 @@ bool ImageSequencer::sequenceReset(){ bool ImageSequencer::loadSequence(const std::string dir){ ghoul::filesystem::Directory sequenceDir(dir, true); std::vector sequencePaths = sequenceDir.read(true, false); // check inputs - int count = 0; - for (auto path : sequencePaths){ if (size_t position = path.find_last_of(".") + 1){ if (position != std::string::npos){ @@ -145,19 +166,21 @@ bool ImageSequencer::loadSequence(const std::string dir){ // open up label files std::string line = ""; - std::string specsOfInterest[2] = { "START_TIME", "STOP_TIME" }; double timestamps[2] = { 0.0, 0.0 }; bool found = false; do { std::getline(file, line); + auto p = line.find("IO"); + bool print = false; + if (p != std::string::npos){ + print = true; + } for (int i = 0; i < 2; i++){ auto pos = line.find(specsOfInterest[i]); if (pos != std::string::npos){ std::string time = line.substr(line.find("=") + 2); time.erase(std::remove(time.begin(), time.end(), ' '), time.end()); - //if (i == 0) std::cout << "Creating image with startTime: " << time; - //if (i == 1) std::cout << " ---> " << time << std::endl; openspace::SpiceManager::ref().getETfromDate(time, timestamps[i]); } } @@ -169,13 +192,18 @@ bool ImageSequencer::loadSequence(const std::string dir){ if ( it != sequencePaths.end()){ createImage(timestamps[0], timestamps[1], path); } + + if (print){ + std::cout << "Found europa at time " << timestamps[0] << " " << path << std::endl; + } } } while (!file.eof() && found == false); } } } } - return true; + _nextCapture = nextCaptureTime(Time::ref().currentTime()); // this is not really working 100% + return !sequencePaths.empty(); }