From d495778d4a65a2d3d9520dd0d14564170b832602 Mon Sep 17 00:00:00 2001 From: Anton Arbring Date: Mon, 4 May 2015 19:30:57 -0400 Subject: [PATCH] Restored some changes lost in merge + "timedots" Added impact on trails from start/stoptime definitions in modfile. Added dots of equal time in trails, no progress on printing the time string. --- include/openspace/rendering/renderabletrail.h | 1 + src/rendering/renderabletrail.cpp | 64 +++++++++++++++---- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/include/openspace/rendering/renderabletrail.h b/include/openspace/rendering/renderabletrail.h index b5c0bb93ad..4aecd34b16 100644 --- a/include/openspace/rendering/renderabletrail.h +++ b/include/openspace/rendering/renderabletrail.h @@ -63,6 +63,7 @@ private: properties::Vec3Property _lineColor; properties::FloatProperty _lineFade; properties::FloatProperty _lineWidth; + properties::BoolProperty _showTimestamps; ghoul::opengl::ProgramObject* _programObject; bool _programIsDirty; diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 689d9eb55a..5d2c8f4b1e 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -52,6 +52,7 @@ namespace { const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod"; const std::string keyEarthOrbitRatio = "EarthOrbitRatio"; const std::string keyDayLength = "DayLength"; + const std::string keyStamps = "Timestamps"; } namespace openspace { @@ -68,6 +69,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) , _oldTime(std::numeric_limits::max()) , _successfullDictionaryFetch(true) , _needsSweep(true) + , _showTimestamps("timestamps", "Show Timestamps", false) { _successfullDictionaryFetch &= dictionary.getValue(keyBody, _target); _successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer); @@ -84,6 +86,10 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) dictionary.getValue(keyColor, color); _lineColor = color; + if (dictionary.hasKeyAndValue(keyStamps)) + dictionary.getValue(keyStamps, _showTimestamps); + addProperty(_showTimestamps); + _lineColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_lineColor); @@ -165,12 +171,18 @@ void RenderableTrail::render(const RenderData& data) { glLineWidth(1.f); + if (_showTimestamps){ + glPointSize(5.f); + glBindVertexArray(_vaoID); + glDrawArrays(GL_POINTS, 0, _vertexArray.size()); + glBindVertexArray(0); + } + _programObject->deactivate(); } void RenderableTrail::update(const UpdateData& data) { - _time = data.time; - if (data.isTimeJump) + if (data.isTimeJump) _needsSweep = true; if (_needsSweep) { @@ -185,7 +197,14 @@ void RenderableTrail::update(const UpdateData& data) { _programIsDirty = false; } double lightTime = 0.0; - psc pscPos, pscVel; + psc pscPos; + + bool intervalSet = hasTimeInterval(); + double start = DBL_MIN; + double end = DBL_MAX; + if (intervalSet) { + getInterval(start, end); + } // Points in the vertex array should always have a fixed distance. For this reason we // keep the first entry in the array floating and always pointing to the current date @@ -195,9 +214,13 @@ void RenderableTrail::update(const UpdateData& data) { int nValues = floor(deltaTime / _increment); // Update the floating current time - // Is 'CN+S' correct? It has to be chosen to be the same as in SpiceEphemeris, but - // unsure if it is correct ---abock - SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time, pscPos, pscVel, lightTime); + if (start > data.time) + SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", start, pscPos, lightTime); + else if (end < data.time) + SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", end, pscPos, lightTime); + else + SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", data.time, pscPos, lightTime); + pscPos[3] += 3; // KM to M _vertexArray[0] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] }; @@ -212,8 +235,12 @@ void RenderableTrail::update(const UpdateData& data) { for (int i = nValues; i > 0; --i) { double et = _oldTime + i * _increment; - SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", et, pscPos, pscVel, lightTime); - pscPos[3] += 3; + if (start > et) + et = start; + else if (end < et) + et = end; + SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", et, pscPos, lightTime); + pscPos[3] += 3; _vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] }; } @@ -241,15 +268,28 @@ void RenderableTrail::fullYearSweep(double time) { float planetYear = SecondsPerEarthYear * _ratio; int segments = static_cast(_tropic); + bool intervalSet = hasTimeInterval(); + double start = DBL_MIN; + double end = DBL_MAX; + if (intervalSet) { + getInterval(start, end); + } + _increment = planetYear / _tropic; _oldTime = time; - psc pscPos, pscVel; + psc pscPos; + bool validPosition = true; _vertexArray.resize(segments+2); - for (int i = 0; i < segments+2; i++){ - SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", time, pscPos, pscVel, lightTime); - pscPos[3] += 3; + for (int i = 0; i < segments+2; i++) { + if (start > time) + time = start; + else if (end < time) + time = end; + + SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", time, pscPos, lightTime); + pscPos[3] += 3; _vertexArray[i] = {pscPos[0], pscPos[1], pscPos[2], pscPos[3]}; time -= _increment;