From a06d4d0a0d8f2be097500a1b983ef98fc6f2c5fc Mon Sep 17 00:00:00 2001 From: Elon Date: Fri, 5 Apr 2019 18:53:04 -0600 Subject: [PATCH] started adding on calculatePosition. Does not complie yet --- .../earth/satellites/satellites_shared.asset | 21 +-- data/assets/spaceDebris.scene | 10 +- modules/space/rendering/elonstest.cpp | 170 ++++++++++++------ modules/space/rendering/elonstest.h | 45 ++++- modules/space/translation/keplertranslation.h | 6 +- 5 files changed, 183 insertions(+), 69 deletions(-) diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/satellites_shared.asset b/data/assets/scene/solarsystem/planets/earth/satellites/satellites_shared.asset index 5d7a65d60e..d60413b0d7 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/satellites_shared.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/satellites_shared.asset @@ -63,16 +63,17 @@ local addSatelliteGroupObjects = function(group, tleFolder, shouldAddDuplicates) -- File = file -- }, - PathInfo = "bubbis", - SegmentsInfo = 1, - EccentricityColumnInfo = "bubbis", - SemiMajorAxisColumnInfo = "bubbis", - SemiMajorAxisUnitInfo = 1, - InclinationColumnInfo = "bubbis", - AscendingNodeColumnInfo = "bubbis", - ArgumentOfPeriapsisColumnInfo = "bubbis", - MeanAnomalyAtEpochColumnInfo = "bubbis", - EpochColumnInfo = "bubbis", + Path = file, + + Segments = 160, + EccentricityColumn = "bubbis", + SemiMajorAxisColumn = "bubbis", + SemiMajorAxisUnit = 1, + InclinationColumn = "bubbis", + AscendingNodeColumn = "bubbis", + ArgumentOfPeriapsisColumn = "bubbis", + MeanAnomalyAtEpochColumn = "bubbis", + EpochColumn = "bubbis", }, GUI = { diff --git a/data/assets/spaceDebris.scene b/data/assets/spaceDebris.scene index 39e3d32b4e..94c957c32b 100644 --- a/data/assets/spaceDebris.scene +++ b/data/assets/spaceDebris.scene @@ -4,15 +4,15 @@ local propertyHelper = asset.require('util/property_helper') -- Specifying which other assets should be loaded in this scene asset.require('spice/base') -assetHelper.requestAll(asset, 'scene/solarsystem/sun') +--assetHelper.requestAll(asset, 'scene/solarsystem/sun') asset.require('scene/solarsystem/planets/earth/earth') -assetHelper.requestAll(asset, 'scene/digitaluniverse') +--assetHelper.requestAll(asset, 'scene/digitaluniverse') -- Load default key bindings applicable to most scenes asset.require('util/default_keybindings') -asset.require('util/default_dashboard') -asset.require('util/default_joystick') +--asset.require('util/default_dashboard') +--asset.require('util/default_joystick') -asset.require('util/webgui') +--asset.require('util/webgui') --asset.request('customization/globebrowsing') diff --git a/modules/space/rendering/elonstest.cpp b/modules/space/rendering/elonstest.cpp index 6c20404261..6f40b147e5 100644 --- a/modules/space/rendering/elonstest.cpp +++ b/modules/space/rendering/elonstest.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include @@ -102,7 +104,7 @@ namespace { "The header of the column where the epoch is stored" }; - constexpr const char* KeyFile = "File"; + constexpr const char* KeyFile = "Path"; constexpr const char* KeyLineNumber = "LineNumber"; @@ -118,6 +120,7 @@ namespace openspace { 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, 2048, 2052, 2056 }; + // Count the number of full days since the beginning of 2000 to the beginning of // the parameter 'year' @@ -302,7 +305,7 @@ namespace openspace { // We need the semi major axis in km instead of m return semiMajorAxis / 1000.0; } - + documentation::Documentation ElonsTest::Documentation() { using namespace documentation; return { @@ -416,6 +419,7 @@ namespace openspace { addProperty(_path); addProperty(_nSegments); // addProperty(_semiMajorAxisUnit); + // addPropertySubOwner(_appearance); const std::string& file = dictionary.value(KeyFile); @@ -431,20 +435,6 @@ namespace openspace { std::ifstream file; file.exceptions(std::ofstream::failbit | std::ofstream::badbit); file.open(filename); - - // All of the Kepler element information - struct KeplerParameters{ - double inclination = 0.0; - double semiMajorAxis = 0.0; - double ascendingNode = 0.0; - double eccentricity = 0.0; - double argumentOfPeriapsis = 0.0; - double meanAnomaly = 0.0; - double meanMotion = 0.0; - double epoch = 0.0; - }; - - std::vector TLEData; // int numberOfLines = std::count(std::istreambuf_iterator(file), // std::istreambuf_iterator(), '\n' ); @@ -452,17 +442,13 @@ namespace openspace { // int numberOfObjects = numberOfLines/3; // LINFO("Number of data elements: " + numberOfObjects); - // for(int i=0 ; i std::unique_ptr { @@ -593,17 +575,21 @@ namespace openspace { } - void ElonsTest::deinitializeGL() { - - + void ElonsTest::deinitializeGL() { + // todo. release object + glDeleteBuffers(1, &_vertexBuffer); + glDeleteBuffers(1, &_indexBuffer); + glDeleteVertexArrays(1, &_vertexArray); } void ElonsTest::render(const RenderData& data, RendererTasks& rendererTask) { _programObject->activate(); - LINFO("render data: ", data); + // LINFO("render data: "); + + _programObject->deactivate(); } void ElonsTest::update(const UpdateData& data) { @@ -614,4 +600,86 @@ namespace openspace { return true; } + + void ElonsTest::updateBuffers(){ + + const size_t nVerticesPerOrbit = _nSegments + 1; + _vertexBufferData.resize(_TLEData.size() * nVerticesPerOrbit); + _indexBufferData.resize(_TLEData.size() * _nSegments * 2); + + size_t orbitIndex = 0; + size_t elementIndex = 0; + + for (const auto& orbit : _TLEData) { + // Converting the mean motion (revolutions per day) to period (seconds per revolution) + using namespace std::chrono; + double period = seconds(hours(24)).count() / orbit.meanMotion; + + // // KeplerTranslation setKeplerElements(orbit); + // _keplerTranslator.setKeplerElements( + // orbit.eccentricity, + // orbit.semiMajorAxis, + // orbit.inclination, + // orbit.ascendingNode, + // orbit.argumentOfPeriapsis, + // orbit.meanAnomaly, + // period, + // orbit.epoch + // ); + // // KeplerTranslation keplerTranslation(orbit); + // const double period = orbit.period(); + for (size_t i = 0; i <= _nSegments; ++i) { + size_t index = orbitIndex * nVerticesPerOrbit + i; + + double timeOffset = period * + static_cast(i) / static_cast(_nSegments); + + // positionAtTime.time = Time(orbit.epoch + timeOffset); + + glm::vec3 position = calculatePosition(Time(orbit.epoch + timeOffset), orbit.epoch); + + _vertexBufferData[index].x = position.x; + _vertexBufferData[index].y = position.y; + _vertexBufferData[index].z = position.z; + _vertexBufferData[index].time = timeOffset; + if (i > 0) { + _indexBufferData[elementIndex++] = static_cast(index) - 1; + _indexBufferData[elementIndex++] = static_cast(index); + } + } + ++orbitIndex; + } + + // glBindVertexArray(_vertexArray); + + // glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); + // glBufferData(GL_ARRAY_BUFFER, + // _vertexBufferData.size() * sizeof(TrailVBOLayout), + // _vertexBufferData.data(), + // GL_STATIC_DRAW + // ); + + + // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer); + // glBufferData(GL_ELEMENT_ARRAY_BUFFER, + // _indexBufferData.size() * sizeof(int), + // _indexBufferData.data(), + // GL_STATIC_DRAW + // ); + + // glBindVertexArray(0); + + + } + + glm::dvec3 ElonsTest::calculatePosition(const Time& time, double epoch) const { + if (_orbitPlaneDirty) { + _keplerTranslator.computeOrbitPlane(); + _orbitPlaneDirty = false; + } + const double t = time.j2000Seconds() - epoch; + + + } + } diff --git a/modules/space/rendering/elonstest.h b/modules/space/rendering/elonstest.h index 59de3aa610..d4371f8e84 100644 --- a/modules/space/rendering/elonstest.h +++ b/modules/space/rendering/elonstest.h @@ -32,12 +32,33 @@ #include #include +#include +#include +#include + + + namespace ghoul::opengl { class ProgramObject; class Texture; } // namespace ghoul::opengl namespace openspace { + // The layout of the VBOs + struct TrailVBOLayout { + float x, y, z, time; + }; + // All of the Kepler element information + struct KeplerParameters{ + double inclination = 0.0; + double semiMajorAxis = 0.0; + double ascendingNode = 0.0; + double eccentricity = 0.0; + double argumentOfPeriapsis = 0.0; + double meanAnomaly = 0.0; + double meanMotion = 0.0; + double epoch = 0.0; + }; namespace documentation { struct Documentation; } @@ -62,12 +83,28 @@ public: protected: private: - TLETranslation _tleTranslator; + + + // TLETranslation _tleTranslator; // std::vector _orbits; ghoul::opengl::ProgramObject* _programObject; KeplerTranslation _keplerTranslator; + std::vector _TLEData; + + + /// The backend storage for the vertex buffer object containing all points for this + /// trail. + std::vector _vertexBufferData; + /// The index array that is potentially used in the draw call. If this is empty, no + /// element draw call is used. + std::vector _indexBufferData; + + GLuint _vertexArray; + GLuint _vertexBuffer; + GLuint _indexBuffer; + properties::StringProperty _path; properties::UIntProperty _nSegments; @@ -80,7 +117,13 @@ private: properties::StringProperty _meanAnomalyAtEpochColumnName; properties::StringProperty _epochColumnName; + void readTLEFile(const std::string& filename); + void updateBuffers(); + + /// Dirty flag for the _orbitPlaneRotation parameters + mutable bool _orbitPlaneDirty = true; + glm::dvec3 calculatePosition(const Time& time, double epoch) const; }; diff --git a/modules/space/translation/keplertranslation.h b/modules/space/translation/keplertranslation.h index 4742b78877..b37507ad38 100644 --- a/modules/space/translation/keplertranslation.h +++ b/modules/space/translation/keplertranslation.h @@ -143,12 +143,14 @@ public: /// Default construct that initializes all the properties and member variables KeplerTranslation(); + /// Recombutes the rotation matrix used in the update method + void computeOrbitPlane() const; + protected: private: - /// Recombutes the rotation matrix used in the update method - void computeOrbitPlane() const; + /** * This method computes the eccentric anomaly (location of the space craft taking the