mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-01 17:20:09 -06:00
Some rudimentary cleanup
This commit is contained in:
@@ -21,17 +21,12 @@
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
#include <modules/space/rendering/renderablesatellites.h>
|
||||
|
||||
#include <modules/space/translation/keplertranslation.h>
|
||||
#include <modules/space/translation/TLEtranslation.h>
|
||||
#include <modules/space/translation/tletranslation.h>
|
||||
#include <modules/space/spacemodule.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
@@ -39,15 +34,15 @@
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/misc/csvreader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "RenderableSatellites";
|
||||
@@ -317,7 +312,7 @@ documentation::Documentation RenderableSatellites::Documentation() {
|
||||
new DoubleVector3Verifier,
|
||||
Optional::No,
|
||||
LineColorInfo.description
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -333,14 +328,11 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary)
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableSatellites"
|
||||
);
|
||||
);
|
||||
|
||||
_path =
|
||||
dictionary.value<std::string>(PathInfo.identifier);
|
||||
_nSegments =
|
||||
static_cast<int>(dictionary.value<double>(SegmentsInfo.identifier));
|
||||
_lineFade =
|
||||
static_cast<float>(dictionary.value<double>(FadeInfo.identifier));
|
||||
_path = dictionary.value<std::string>(PathInfo.identifier);
|
||||
_nSegments = static_cast<int>(dictionary.value<double>(SegmentsInfo.identifier));
|
||||
_lineFade = static_cast<float>(dictionary.value<double>(FadeInfo.identifier));
|
||||
|
||||
if (dictionary.hasKeyAndValue<glm::vec3>(LineColorInfo.identifier)) {
|
||||
_appearance.lineColor = dictionary.value<glm::vec3>(LineColorInfo.identifier);
|
||||
@@ -364,16 +356,15 @@ void RenderableSatellites::readTLEFile(const std::string& filename) {
|
||||
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
file.open(filename);
|
||||
|
||||
__int64 numberOfLines = std::count(std::istreambuf_iterator<char>(file),
|
||||
std::streamoff numberOfLines = std::count(std::istreambuf_iterator<char>(file),
|
||||
std::istreambuf_iterator<char>(), '\n' );
|
||||
file.seekg(std::ios_base::beg); // reset iterator to beginning of file
|
||||
|
||||
// 3 because a TLE has 3 lines per element/ object.
|
||||
__int64 numberOfObjects = numberOfLines/3;
|
||||
std::streamoff numberOfObjects = numberOfLines / 3;
|
||||
|
||||
std::string line = "-";
|
||||
for (__int64 i = 0; i < numberOfObjects; i++) {
|
||||
|
||||
for (std::streamoff i = 0; i < numberOfObjects; i++) {
|
||||
std::getline(file, line); // get rid of title
|
||||
|
||||
KeplerParameters keplerElements;
|
||||
@@ -470,14 +461,6 @@ void RenderableSatellites::readTLEFile(const std::string& filename) {
|
||||
file.close();
|
||||
}
|
||||
|
||||
void RenderableSatellites::initialize() {
|
||||
|
||||
}
|
||||
|
||||
void RenderableSatellites::deinitialize() {
|
||||
|
||||
}
|
||||
|
||||
void RenderableSatellites::initializeGL() {
|
||||
glGenVertexArrays(1, &_vertexArray);
|
||||
glGenBuffers(1, &_vertexBuffer);
|
||||
@@ -493,21 +476,19 @@ void RenderableSatellites::initializeGL() {
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelView = _programObject->uniformLocation("modelViewTransform");
|
||||
_uniformCache.projection = _programObject->uniformLocation("projectionTransform");
|
||||
_uniformCache.lineFade = _programObject->uniformLocation("lineFade");
|
||||
_uniformCache.inGameTime = _programObject->uniformLocation("inGameTime");
|
||||
_uniformCache.color = _programObject->uniformLocation("color");
|
||||
_uniformCache.opacity = _programObject->uniformLocation("opacity");
|
||||
_uniformCache.modelView = _programObject->uniformLocation("modelViewTransform");
|
||||
_uniformCache.projection = _programObject->uniformLocation("projectionTransform");
|
||||
_uniformCache.lineFade = _programObject->uniformLocation("lineFade");
|
||||
_uniformCache.inGameTime = _programObject->uniformLocation("inGameTime");
|
||||
_uniformCache.color = _programObject->uniformLocation("color");
|
||||
_uniformCache.opacity = _programObject->uniformLocation("opacity");
|
||||
|
||||
updateBuffers();
|
||||
|
||||
setRenderBin(Renderable::RenderBin::Overlay);
|
||||
}
|
||||
|
||||
void RenderableSatellites::deinitializeGL() {
|
||||
glDeleteBuffers(1, &_vertexBuffer);
|
||||
//glDeleteBuffers(1, &_indexBuffer);
|
||||
glDeleteVertexArrays(1, &_vertexArray);
|
||||
|
||||
SpaceModule::ProgramObjectManager.release(
|
||||
@@ -519,25 +500,17 @@ void RenderableSatellites::deinitializeGL() {
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool RenderableSatellites::isReady() const {
|
||||
_programObject->activate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableSatellites::update(const UpdateData& data) {
|
||||
return _programObject != nullptr;
|
||||
}
|
||||
|
||||
void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
|
||||
if (_TLEData.empty())
|
||||
return;
|
||||
_inGameTime = data.time.j2000Seconds();
|
||||
|
||||
_programObject->activate();
|
||||
|
||||
_programObject->setUniform(_uniformCache.opacity, _opacity);
|
||||
_programObject->setUniform(_uniformCache.inGameTime, _inGameTime);
|
||||
_programObject->setUniform(_uniformCache.inGameTime, data.time.j2000Seconds());
|
||||
|
||||
|
||||
glm::dmat4 modelTransform =
|
||||
|
||||
@@ -22,26 +22,47 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_BASE___RenderableSatellites___H__
|
||||
#define __OPENSPACE_MODULE_BASE___RenderableSatellites___H__
|
||||
#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__
|
||||
#define __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/base/rendering/renderabletrail.h>
|
||||
#include <modules/space/translation/keplertranslation.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/uintproperty.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/objectmanager.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableSatellites : public Renderable {
|
||||
public:
|
||||
RenderableSatellites(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
bool isReady() const override;
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
/**
|
||||
* Reads the provided TLE file and calls the KeplerTranslation::setKeplerElments
|
||||
* method with the correct values. If \p filename is a valid TLE file but contains
|
||||
* disallowed values (see KeplerTranslation::setKeplerElements), a
|
||||
* KeplerTranslation::RangeError is thrown.
|
||||
*
|
||||
* \param filename The path to the file that contains the TLE file.
|
||||
*
|
||||
* \throw ghoul::RuntimeError if the TLE file does not exist or there is a
|
||||
* problem with its format.
|
||||
* \pre The \p filename must exist
|
||||
*/
|
||||
void readTLEFile(const std::string& filename);
|
||||
|
||||
private:
|
||||
struct Vertex {
|
||||
glm::vec3 position;
|
||||
glm::vec3 color;
|
||||
@@ -60,82 +81,49 @@ namespace openspace {
|
||||
double period = 0.0;
|
||||
};
|
||||
|
||||
class RenderableSatellites : public Renderable {
|
||||
public:
|
||||
RenderableSatellites(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
/**
|
||||
* Reads the provided TLE file and calls the KeplerTranslation::setKeplerElments
|
||||
* method with the correct values. If \p filename is a valid TLE file but contains
|
||||
* disallowed values (see KeplerTranslation::setKeplerElements), a
|
||||
* KeplerTranslation::RangeError is thrown.
|
||||
*
|
||||
* \param filename The path to the file that contains the TLE file.
|
||||
*
|
||||
* \throw ghoul::RuntimeError if the TLE file does not exist or there is a
|
||||
* problem with its format.
|
||||
* \pre The \p filename must exist
|
||||
*/
|
||||
void readTLEFile(const std::string& filename);
|
||||
|
||||
private:
|
||||
/// The layout of the VBOs
|
||||
struct TrailVBOLayout {
|
||||
float x, y, z, time;
|
||||
double epoch, period;
|
||||
};
|
||||
// static_assert(sizeof(struct TrailVBOLayout)==4*sizeof(float)+2*sizeof(double),"Implementation error!");
|
||||
|
||||
KeplerTranslation _keplerTranslator;
|
||||
std::vector<KeplerParameters> _TLEData;
|
||||
|
||||
/// The backend storage for the vertex buffer object containing all points for this
|
||||
/// trail.
|
||||
std::vector<TrailVBOLayout> _vertexBufferData;
|
||||
|
||||
/// The index array that is potentially used in the draw call. If this is empty, no
|
||||
/// element draw call is used.
|
||||
std::vector<unsigned int> _indexBufferData;
|
||||
|
||||
GLuint _vertexArray;
|
||||
GLuint _vertexBuffer;
|
||||
GLuint _indexBuffer;
|
||||
|
||||
//GLuint _vaoTest; // vertexArrayObject
|
||||
//GLuint _vboTest; // vertextBufferObject
|
||||
//GLuint _eboTest; // elementBufferObject/ indexBufferObject
|
||||
|
||||
void updateBuffers();
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
|
||||
properties::StringProperty _path;
|
||||
properties::UIntProperty _nSegments;
|
||||
|
||||
properties::DoubleProperty _lineFade;
|
||||
|
||||
RenderableTrail::Appearance _appearance;
|
||||
|
||||
glm::vec3 _position;
|
||||
|
||||
double _inGameTime = 0.0;
|
||||
|
||||
UniformCache(modelView, projection, lineFade, inGameTime, color, opacity, numberOfSegments)
|
||||
_uniformCache;
|
||||
|
||||
/// The layout of the VBOs
|
||||
struct TrailVBOLayout {
|
||||
float x, y, z, time;
|
||||
double epoch, period;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __OPENSPACE_MODULE_BASE___RenderableSatellites___H__
|
||||
KeplerTranslation _keplerTranslator;
|
||||
std::vector<KeplerParameters> _TLEData;
|
||||
|
||||
/// The backend storage for the vertex buffer object containing all points for this
|
||||
/// trail.
|
||||
std::vector<TrailVBOLayout> _vertexBufferData;
|
||||
|
||||
/// The index array that is potentially used in the draw call. If this is empty, no
|
||||
/// element draw call is used.
|
||||
std::vector<unsigned int> _indexBufferData;
|
||||
|
||||
GLuint _vertexArray;
|
||||
GLuint _vertexBuffer;
|
||||
GLuint _indexBuffer;
|
||||
|
||||
//GLuint _vaoTest; // vertexArrayObject
|
||||
//GLuint _vboTest; // vertextBufferObject
|
||||
//GLuint _eboTest; // elementBufferObject/ indexBufferObject
|
||||
|
||||
void updateBuffers();
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
|
||||
properties::StringProperty _path;
|
||||
properties::UIntProperty _nSegments;
|
||||
|
||||
properties::DoubleProperty _lineFade;
|
||||
|
||||
RenderableTrail::Appearance _appearance;
|
||||
|
||||
glm::vec3 _position;
|
||||
|
||||
UniformCache(modelView, projection, lineFade, inGameTime, color, opacity,
|
||||
numberOfSegments) _uniformCache;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SPACE___RENDERABLESATELLITES___H__
|
||||
|
||||
|
||||
Reference in New Issue
Block a user