diff --git a/include/openspace/rendering/renderablepath.h b/include/openspace/rendering/renderablepath.h index dec2ebe5f9..32b449df69 100644 --- a/include/openspace/rendering/renderablepath.h +++ b/include/openspace/rendering/renderablepath.h @@ -1,46 +1,48 @@ /***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2015 * - * * - * 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. * - ****************************************************************************************/ +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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 __RenderablePath_H__ -#define __RenderablePath_H__ +#ifndef __RENDERABLEPATH_H__ +#define __RENDERABLEPATH_H__ -// open space includes #include - #include -#include +#include -// ghoul includes -#include -#include -//#include +#include + +namespace ghoul { + namespace opengl { + class ProgramObject; + class Texture; + } +} namespace openspace { - class RenderablePath : public Renderable{ + + class RenderablePath : public Renderable { public: RenderablePath(const ghoul::Dictionary& dictionary); - ~RenderablePath(); bool initialize() override; bool deinitialize() override; @@ -49,45 +51,45 @@ namespace openspace { void render(const RenderData& data) override; void update(const UpdateData& data) override; - private: - ghoul::opengl::ProgramObject* _programObject; - void loadTexture(); - bool fullYearSweep(); - // modfile reads - // spice + void calculatePath(std::string observer); + private: + struct VertexInfo { + float x, y, z, e; + //float r, g, b, a; + }; + void sendToGPU(); + void addPosition(psc pos); + void addColor(glm::vec4 col); + + glm::vec3 _lineColor; + glm::vec4 _lastPosition; + properties::FloatProperty _lineFade; + properties::FloatProperty _lineWidth; + properties::BoolProperty _drawLine; + + ghoul::opengl::ProgramObject* _programObject; + bool _programIsDirty; + + bool _successfullDictionaryFetch; + std::string _target; std::string _observer; std::string _frame; - // color - glm::vec3 _c; - double _r, _g, _b; - // need to write robust method for vbo id selection - // (right now galactic grid has to be present) (why though?) solve later... GLuint _vaoID; GLuint _vBufferID; - GLuint _iBufferID; + + bool _needsSweep; - void nextIndex(); - - unsigned int _isize; - unsigned int _vsize; - unsigned int _vtotal; - unsigned int _stride; - - //Vertex* _varray; - std::vector _varray; - std::vector _iarray; - - //used for update of trail - psc _pscpos, _pscvel; - double _increment; - double _time = 0; - double _oldTime = 0; - - int _delta = 0; - int _dtprogress = 0; + std::vector _vertexArray; + + float _increment; + double _start; + double _stop; + float _distanceFade; }; -} -#endif \ No newline at end of file + +} // namespace openspace + +#endif // __RENDERABLEPATH_H__ diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index 19fdb57b85..75eaa06d73 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -5,8 +5,8 @@ openspace.setInvertRoll(true); --openspace.setInteractionSensitivity(10) -- This is the default value for the sensitivity (the higher, the more sensitive) ---openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons - +openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons +--openspace.time.setTime("2007 FEB 28 11:45:00") -- europa rise --TESTING ALICE --openspace.time.setTime("2015-07-13T00:00:00.00") @@ -22,7 +22,7 @@ dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keyb -- NH takes series of images from visible to dark side (across terminator) -- Sequence lasts ~10 mins, (recommended dt = 10) -openspace.time.setTime("2015-07-14T11:22:00.00") -- PLUTO +--openspace.time.setTime("2015-07-14T11:22:00.00") -- PLUTO --BEAUTIFUL SEQUENCE -- NH takes series of images (same as previous) -- Sequence ends at 2015 JUL 14T11:24:00:000, (recommended dt = 1) diff --git a/shaders/modules/trails/path_fs.glsl b/shaders/modules/trails/path_fs.glsl new file mode 100644 index 0000000000..0a5443713c --- /dev/null +++ b/shaders/modules/trails/path_fs.glsl @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ +layout(location = 0) in vec4 vs_point_position; +layout(location = 1) in flat int isHour; +layout(location = 2) in vec4 vs_point_color; +//in flat int isHour; +//uniform vec4 campos; +uniform vec3 color; + +#include "ABuffer/abufferStruct.hglsl" +#include "ABuffer/abufferAddToBuffer.hglsl" +#include "PowerScaling/powerScaling_fs.hglsl" + +void main() { + vec4 position = vs_point_position; + float depth = pscDepth(position); + + vec4 diffuse = vs_point_color; + + ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth); + addToBuffer(frag); +} + + diff --git a/shaders/modules/trails/path_gs.glsl b/shaders/modules/trails/path_gs.glsl new file mode 100644 index 0000000000..dbe54155d4 --- /dev/null +++ b/shaders/modules/trails/path_gs.glsl @@ -0,0 +1,107 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +const vec2 corners[4] = vec2[4]( + vec2(0.0, 1.0), + vec2(0.0, 0.0), + vec2(1.0, 1.0), + vec2(1.0, 0.0) +); + +#include "PowerScaling/powerScalingMath.hglsl" +#include <${SHADERS_GENERATED}/constants.hglsl>:notrack + +layout(points) in; +layout(points, max_vertices = 4) out; + +uniform mat4 ViewProjection; +layout(location = 0) in vec4 vs_point_position[]; + +//out flat int isHour; +layout(location = 1) in flat int isHour[]; +layout(location = 2) in vec4 vs_point_color[]; + +layout(location = 0) out vec4 gs_point_position; +layout(location = 1) out vec4 gs_point_color; + + +//out flat int isHour; + +//out float billboardSize; + +uniform mat4 projection; + +//uniform float scaleFactor; + +void main() { + + gs_point_color = vs_point_color[0]; + gs_point_position = vs_point_position[0]; + //gs_point_position = gl_in[0].gl_Position; + if (isHour[0] == 1) { + /*vec4 projPos[4]; + for (int i = 0; i < 4; ++i) { + vec4 p1 = gl_in[0].gl_Position; + p1.xy += vec2(99999999*(corners[i] - vec2(0.5))); + projPos[i] = ViewProjection * p1; + } + + // Calculate the positions of the lower left and upper right corners of the + // billboard in screen-space + const vec2 screenSize = vec2(SCREEN_WIDTH, SCREEN_HEIGHT); + vec2 ll = (((projPos[1].xy / projPos[1].w) + 1) / 2) * screenSize; + vec2 ur = (((projPos[2].xy / projPos[2].w) + 1) / 2) * screenSize; + + // The billboard is smaller than one pixel, we can discard it + vec2 distance = abs(ll - ur); + float sizeInPixels = length(distance); + //if (sizeInPixels < 3) + // return; + + for(int i = 0; i < 4; i++) { + gs_point_position = gl_in[0].gl_Position; + gl_Position = projPos[i]; + // billboardSize = sizeInPixels; + EmitVertex(); + } + + + for(int i = 0; i < 4; i++) { + gl_Position = gl_in[0].gl_Position;; + // billboardSize = sizeInPixels; + + }*/ + gl_Position = gl_in[0].gl_Position; + EmitVertex(); + EndPrimitive(); + } + else { + gl_Position = gl_in[0].gl_Position; + EmitVertex(); + EndPrimitive(); + return; + } +} diff --git a/shaders/modules/trails/path_vs.glsl b/shaders/modules/trails/path_vs.glsl new file mode 100644 index 0000000000..294179bca8 --- /dev/null +++ b/shaders/modules/trails/path_vs.glsl @@ -0,0 +1,118 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +uniform mat4 ViewProjection; +uniform mat4 ModelTransform; +uniform vec4 objectVelocity; +uniform vec4 lastPosition; + +//this function does not consider cases where w component is negative +float psc_distance(vec4 v1, vec4 v2) { + // reduce position numbers + /*while(v1.w > 1 && v2.w > 1) { + v1.w -= 1; + v2.w -= 1; + } */ + // get position in vec3 + while(v1.w > 1) { + v1.xyz *= 10; + v1.w -= 1; + } + while(v2.w > 1 ) { + v2.xyz *= 10; + v2.w -= 1; + } + // using native distance function + return distance(v1.xyz, v2.xyz); +} + +layout(location = 0) in vec4 in_point_position; +//layout(location = 1) in vec4 in_point_color; +uniform vec3 color; +//uniform vec4 campos; + +layout(location = 0) out vec4 vs_point_position; +layout(location = 1) out flat int isHour; +layout(location = 2) out vec4 vs_point_color; + +#include "PowerScaling/powerScaling_vs.hglsl" + +void main() { + + vec4 gray = { 0.6f, 0.6f, 0.6f, 0.8f}; + float cameraTooFar = 1 * pow(k, 10); + float bigPoint = 5.f; + float smallPoint = 2.f; + + vec4 tmp = in_point_position; + vec4 position = pscTransform(tmp, ModelTransform); + vs_point_position = tmp; + position = ViewProjection * position; + gl_Position = z_normalization(position); + + + int id = gl_VertexID; + float hour = mod(id, 4); + + vs_point_color.xyz = color; + vs_point_color[3] = 1.f; + + vec4 v1 = campos; + vec4 v2 = vs_point_position; + float cameraDistance = psc_distance(v1,v2); + + vec4 temp = in_point_position; + vec4 templast = lastPosition; + while(temp.w > 1) { + temp.xyz *= 10; + temp.w -= 1; + } + while(templast.w > 1) { + templast.xyz *= 10; + templast.w -= 1; + } + float observerDistance = length(temp.xyz); + float lastDistance = length(templast.xyz); + + if(hour > 0.1f) { + isHour = 0; + vs_point_color = gray; + gl_PointSize = bigPoint; + } + else { + isHour = 1; + gl_PointSize = bigPoint; + } + if (observerDistance > (lastDistance/20)) { + gl_PointSize = smallPoint; + //vs_point_color = gray; + } + /*if (cameraDistance > cameraTooFar ) { + vs_point_color[3] = 0.0f; + + }*/ + +} \ No newline at end of file diff --git a/src/rendering/model/wavefrontgeometry.cpp b/src/rendering/model/wavefrontgeometry.cpp index 0bb62699ed..16d97ec4d3 100644 --- a/src/rendering/model/wavefrontgeometry.cpp +++ b/src/rendering/model/wavefrontgeometry.cpp @@ -94,7 +94,7 @@ bool WavefrontGeometry::loadModel(const std::string& filename) { _vertices[j + currentPosition].location[0] = shapes[i].mesh.positions[3 * j + 0]; _vertices[j + currentPosition].location[1] = shapes[i].mesh.positions[3 * j + 1]; _vertices[j + currentPosition].location[2] = shapes[i].mesh.positions[3 * j + 2]; - _vertices[j + currentPosition].location[3] = 5; // Temp size for the power scale coordinate. + _vertices[j + currentPosition].location[3] = 4; // Temp size for the power scale coordinate. // Could be defined per object as a dictionary key. _vertices[j + currentPosition].normal[0] = shapes[i].mesh.normals[3 * j + 0]; diff --git a/src/rendering/renderablepath.cpp b/src/rendering/renderablepath.cpp index 3eb2dfe2f0..fcafade1d6 100644 --- a/src/rendering/renderablepath.cpp +++ b/src/rendering/renderablepath.cpp @@ -1,256 +1,269 @@ /***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2015 * - * * - * 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. * - ****************************************************************************************/ +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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. * +****************************************************************************************/ #include +#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include -#include -#include -#include - -#include -#include +/* TODO for this class: +* In order to add geometry shader (for pretty-draw), +* need to pack each consecutive point pair into a vec2 +* in order to draw quad between them. +*/ namespace { - const std::string _loggerCat = "RenderablePath"; + const std::string _loggerCat = "RenderableTrail"; //constants + const std::string keyName = "Name"; const std::string keyBody = "Body"; const std::string keyObserver = "Observer"; const std::string keyFrame = "Frame"; const std::string keyPathModule = "ModulePath"; const std::string keyColor = "RGB"; - + const std::string keyTimeSteps = "TimeSteps"; + const std::string keyDrawLine = "DrawLine"; } -#define DEBUG -namespace openspace{ + +namespace openspace { + RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary) : Renderable(dictionary) + , _lineFade("lineFade", "Line Fade", 0.75f, 0.f, 5.f) + , _lineWidth("lineWidth", "Line Width", 2.f, 1.f, 20.f) , _programObject(nullptr) + , _programIsDirty(true) , _vaoID(0) , _vBufferID(0) - , _iBufferID(0) + , _successfullDictionaryFetch(true) + , _needsSweep(true) + , _drawLine("drawline", "Draw Line", false) { + _successfullDictionaryFetch &= dictionary.getValue(keyBody, _target); + _successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer); + _successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame); + _successfullDictionaryFetch &= dictionary.getValue(keyTimeSteps, _increment); - dictionary.getValue(keyBody, _target); - dictionary.getValue(keyObserver, _observer); - dictionary.getValue(keyFrame, _frame); + glm::vec3 color(0.f); + if (dictionary.hasKeyAndValue(keyColor)) + dictionary.getValue(keyColor, color); + _lineColor = color; - // not used now, will be though. - // dictionary.getValue(keyTropicalOrbitPeriod, _tropic); - // dictionary.getValue(keyEarthOrbitRatio, _ratio); - // dictionary.getValue(keyDayLength, _day); - - // values in modfiles set from here - // http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html - - // white is default col - if (!dictionary.getValue(keyColor, _c)){ - _c = glm::vec3(0.0); - } - else{ - _r = 1 / _c[0]; - _g = 1 / _c[1]; - _b = 1 / _c[2]; - } -} -bool RenderablePath::fullYearSweep(){ - double lightTime = 0.0; - SpiceManager::ref().getETfromDate("2006 jan 20 19:00:00", _time); - - //std::cout << _time << std::endl; - - // -------------------------------------- ^ this has to be simulation start-time, not passed in here though -- - //SpiceManager::ref().getETfromDate("2008 apr 01 00:00:00", et2); - //psc nhpos, nhvel; - //SpiceManager::ref().getTargetState("NEW HORIZONS", "SUN", "J2000", "LT+S", et2, _pscpos, _pscvel, lightTime); - - double et = _time; - int segments = 200000; - _increment = 86400; - - _isize = (segments + 2); - _vsize = (segments + 2); - _iarray.clear(); - - int indx = 0; - for (int i = 0; i < segments + 1; i++){ - //std::cout << i << std::endl; - bool gotData = SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "LT+S", et, _pscpos, lightTime); - -#ifndef NDEBUG - if (!gotData) { - LERROR("Could not fetch data from spice!"); - return false; - } -#endif - - if (_pscpos[0] != 0 && _pscpos[1] != 0 && _pscpos[2] != 0 && _pscpos[3] != 1){ - _pscpos[3] += 3; - _varray.push_back(_pscpos[0]); - _varray.push_back(_pscpos[1]); - _varray.push_back(_pscpos[2]); - _varray.push_back(_pscpos[3]); - -#ifndef DEBUG - _varray.push_back(1.f - ((double)i / _tropic * _r)); - _varray.push_back(1.f - ((double)i / _tropic * _g)); - _varray.push_back(1.f - ((double)i / _tropic * _b)); - _varray.push_back(1.f - ((double)i / _tropic)); -#else - _varray.push_back(1.f); - _varray.push_back(1.f); - _varray.push_back(1.f); - _varray.push_back(0.5f); -#endif - indx++; - _iarray.push_back(indx); - } - else{ - std::string date; - SpiceManager::ref().getDateFromET(et, date); - std::cout << "STOPPED AT: " << date << std::endl; - break; - } - et += _increment; - } - _stride = 8; - _vsize = static_cast(_varray.size()); - _vtotal = static_cast(_vsize / _stride); - return true; + bool drawLine; + if (dictionary.hasKeyAndValue(keyDrawLine)) + dictionary.getValue(keyDrawLine, drawLine); + _drawLine = drawLine; + addProperty(_drawLine); + addProperty(_lineFade); + addProperty(_lineWidth); + _distanceFade = 1.0; } -RenderablePath::~RenderablePath(){ -} - -bool RenderablePath::isReady() const { - bool ready = true; - ready &= (_programObject != nullptr); - return ready; -} - - -bool RenderablePath::initialize(){ - - if (_target.empty() || _observer.empty() || _frame.empty()) { +bool RenderablePath::initialize() { + if (!_successfullDictionaryFetch) { LERROR("The following keys need to be set in the Dictionary. Cannot initialize!"); LERROR(keyBody << ": " << _target); LERROR(keyObserver << ": " << _observer); LERROR(keyFrame << ": " << _frame); return false; } - // Does checking if can fetch spice data (debug mode only) - if (!fullYearSweep()) - return false; - // If the programobject is fetched after the string checking, then - // the isReady function will properly reflect the state of this object - // -- jonasstrandstedt bool completeSuccess = true; - if (_programObject == nullptr) - completeSuccess - &= OsEng.ref().configurationManager()->getValue("EphemerisProgram", _programObject); + _programObject = ghoul::opengl::ProgramObject::Build("PathProgram", + "${SHADERS}/modules/trails/path_vs.glsl", + "${SHADERS}/modules/trails/path_fs.glsl" + //,"${SHADERS}/modules/trails/path_gs.glsl" + ); + if (!_programObject) + return false; + _programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; }); - // Initialize and upload to graphics card - glGenVertexArrays(1, &_vaoID); - glGenBuffers(1, &_vBufferID); - glGenBuffers(1, &_iBufferID); + bool intervalSet = hasTimeInterval(); + if (intervalSet) { + getInterval(_start, _stop); + std::string stop, start; + SpiceManager::ref().getDateFromET(_start, start); + SpiceManager::ref().getDateFromET(_stop, stop); - glBindVertexArray(_vaoID); - glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); - glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data. - glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]); + std::cout << "STARTS: " << start << " " << "ENDS :" << stop << std::endl; - GLsizei st = sizeof(GLfloat) * _stride; - - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*)0); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, st, (void*)(4 * sizeof(GLfloat))); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray.data(), GL_STATIC_DRAW); - - glBindVertexArray(0); + } return completeSuccess; } -bool RenderablePath::deinitialize(){ +bool RenderablePath::deinitialize() { glDeleteVertexArrays(1, &_vaoID); glDeleteBuffers(1, &_vBufferID); - glDeleteBuffers(1, &_iBufferID); return true; + deinitialize(); } -void RenderablePath::render(const RenderData& data){ +bool RenderablePath::isReady() const { + return (_programObject != nullptr) && _successfullDictionaryFetch; +} + +void RenderablePath::render(const RenderData& data) { + double time = openspace::Time::ref().currentTime(); + if (_start > time || _stop < time) + return; + + //const psc& position = data.camera.position(); + //const psc& origin = openspace::OpenSpaceEngine::ref().interactionHandler()->focusNode()->worldPosition(); + //const PowerScaledScalar& pssl = (position - origin).length(); + //double properLength = static_cast(pssl.lengthf()); + //const PowerScaledScalar corrected = PowerScaledScalar::CreatePSS(properLength); + //float exp = corrected[1]; + // + //if (exp > 11) + // return; + _programObject->activate(); - - // fetch data 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 - //_programObject->setUniform("objectVelocity", pscvel.vec4()); _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _programObject->setUniform("ModelTransform", transform); + _programObject->setUniform("color", _lineColor); + _programObject->setUniform("lastPosition", _lastPosition); setPscUniforms(_programObject, &data.camera, data.position); -/* glBindVertexArray(_vaoID); - glDrawArrays(GL_LINE_STRIP, 0, _vtotal); - glBindVertexArray(0); -*/ - glPointSize(2.f); + if (_drawLine) { + glLineWidth(_lineWidth); + glBindVertexArray(_vaoID); + glDrawArrays(GL_LINE_STRIP, 0, _vertexArray.size()); + glBindVertexArray(0); + glLineWidth(1.f); + } + + //float pointSize = std::min((11-exp),5.f); + //glPointSize(5); + glEnable(GL_PROGRAM_POINT_SIZE); + + //GLfloat distanceParams[] = { 1.0f, 5.0f, 10.f }; //a, b, c + //GLfloat fadeThreshold[] = { 0.1f }; + // + //glPointParameterf(GL_POINT_SIZE_MAX, 5.0f); + //glPointParameterf(GL_POINT_SIZE_MIN, 1.0f); + //glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, distanceParams); + ////=> size = clamp(size*sqrt(1/(a+b*d+c*d^2))); + //glPointParameterfv(GL_POINT_FADE_THRESHOLD_SIZE, fadeThreshold); glBindVertexArray(_vaoID); - glDrawArrays(GL_POINTS, 0, _vtotal); + glDrawArrays(GL_POINTS, 0, _vertexArray.size()); glBindVertexArray(0); _programObject->deactivate(); } -void RenderablePath::update(const UpdateData& data){ -#ifndef NDEBUG - if (_target.empty() || _observer.empty() || _frame.empty()) +void RenderablePath::update(const UpdateData& data) { + if (data.isTimeJump) + _needsSweep = true; + + if (_needsSweep) { + calculatePath(_observer); + sendToGPU(); + _needsSweep = false; return; -#endif - double lightTime; + } - _time = data.time; - _delta = static_cast(data.delta); - - SpiceManager::ref().getTargetPosition(_target, _observer, _frame, "NONE", data.time, _pscpos, lightTime); + if (_programIsDirty) { + _programObject->rebuildFromFile(); + _programIsDirty = false; + } } +void RenderablePath::calculatePath(std::string observer) { + + double interval = (_stop - _start); + int segments = static_cast(interval /_increment); + double lightTime; + bool correctPosition = true; -} \ No newline at end of file + psc pscPos; + double currentTime = _start; + _vertexArray.resize(segments); + + //float r, g, b; + //float g = _lineColor[1]; + //float b = _lineColor[2]; + float a = 1.f; + for (int i = 0; i < segments; i++) { + correctPosition = SpiceManager::ref().getTargetPosition(_target, observer, _frame, "NONE", currentTime, pscPos, lightTime); + pscPos[3] += 3; + + //if (!correctPosition) { + // r = 1.f; + // g = b = 0.5f; + //} + //else if ((i % 8) == 0) { + // r = _lineColor[0]; + // g = _lineColor[1]; + // b = _lineColor[2]; + //} + //else { + // r = g = b = 0.6f; + //} + //add position + _vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] }; + //add color for position + //_vertexArray[i + 1] = { r, g, b, a }; + currentTime += _increment; + } + _lastPosition = pscPos.dvec4(); + + glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); + glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]); +} + +void RenderablePath::sendToGPU() { + glGenVertexArrays(1, &_vaoID); + glGenBuffers(1, &_vBufferID); + + glBindVertexArray(_vaoID); + + glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); + glBufferData(GL_ARRAY_BUFFER, _vertexArray.size() * sizeof(VertexInfo), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data. + glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]); + + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); + //glEnableVertexAttribArray(1); + //glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(VertexInfo) * 2, (void*)(sizeof(VertexInfo))); + + glBindVertexArray(0); +} + +} // namespace openspace diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index d7285e9d65..d73a8d551c 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -52,7 +52,7 @@ namespace { const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod"; const std::string keyEarthOrbitRatio = "EarthOrbitRatio"; const std::string keyDayLength = "DayLength"; - const std::string keyStamps = "Timestamps"; + const std::string keyStamps = "TimeStamps"; } namespace openspace { @@ -86,8 +86,10 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) dictionary.getValue(keyColor, color); _lineColor = color; + bool timeStamps = false; if (dictionary.hasKeyAndValue(keyStamps)) - dictionary.getValue(keyStamps, _showTimestamps); + dictionary.getValue(keyStamps, timeStamps); + _showTimestamps = timeStamps; addProperty(_showTimestamps); _lineColor.setViewOption(properties::Property::ViewOptions::Color); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index f57d13486f..0b63d8bfd1 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -980,7 +981,9 @@ void RenderEngine::changeViewPoint(std::string origin) { SceneGraphNode* solarSystemBarycenterNode = scene()->sceneGraphNode("SolarSystemBarycenter"); SceneGraphNode* plutoBarycenterNode = scene()->sceneGraphNode("PlutoBarycenter"); SceneGraphNode* newHorizonsNode = scene()->sceneGraphNode("NewHorizons"); - SceneGraphNode* newHorizonsTrailNode = scene()->sceneGraphNode("NewHorizonsTrail"); + SceneGraphNode* newHorizonsPathNodeJ = scene()->sceneGraphNode("NewHorizonsPathJupiter"); + SceneGraphNode* newHorizonsPathNodeP = scene()->sceneGraphNode("NewHorizonsPathPluto"); + RenderablePath* nhPath; SceneGraphNode* jupiterBarycenterNode = scene()->sceneGraphNode("JupiterBarycenter"); @@ -998,6 +1001,13 @@ void RenderEngine::changeViewPoint(std::string origin) { } if (origin == "Pluto") { + if (newHorizonsPathNodeP) { + Renderable* R = newHorizonsPathNodeP->renderable(); + nhPath = static_cast(R); + nhPath->calculatePath("PLUTO BARYCENTER"); + newHorizonsPathNodeP->setParent(plutoBarycenterNode); + } + plutoBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem")); plutoBarycenterNode->setEphemeris(new StaticEphemeris); @@ -1156,6 +1166,13 @@ void RenderEngine::changeViewPoint(std::string origin) { return; } if (origin == "Jupiter") { + if (newHorizonsPathNodeJ) { + Renderable* R = newHorizonsPathNodeJ->renderable(); + nhPath = static_cast(R); + nhPath->calculatePath("JUPITER BARYCENTER"); + newHorizonsPathNodeJ->setParent(jupiterBarycenterNode); + } + jupiterBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem")); jupiterBarycenterNode->setEphemeris(new StaticEphemeris);