mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 10:59:47 -05:00
Renderableehpemeris still as it is, will be repurposed though.
Renderable trail now acts like planet ephemeris, not yet finished. Need to work on objectloader
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLETRAIL_H__
|
||||
#define __RENDERABLETRAIL_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
//#include <openspace/util/runtimedata.h>
|
||||
|
||||
namespace openspace {
|
||||
class RenderableTrail : public Renderable{
|
||||
public:
|
||||
RenderableTrail(const ghoul::Dictionary& dictionary);
|
||||
~RenderableTrail();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
private:
|
||||
properties::StringProperty _colorTexturePath; // not used now, will be later though.
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
void loadTexture();
|
||||
|
||||
/* typedef struct {
|
||||
GLfloat location[4];
|
||||
GLfloat velocity[4];
|
||||
GLubyte padding[32]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
*/
|
||||
// need to write robust method for vbo id selection
|
||||
// (right now galactic grid has to be present) (why though?) solve later...
|
||||
GLuint _vaoID = 6;
|
||||
GLuint _vBufferID = 7;
|
||||
GLuint _iBufferID = 8;
|
||||
|
||||
void nextIndex();
|
||||
|
||||
GLenum _mode;
|
||||
unsigned int _isize;
|
||||
unsigned int _vsize;
|
||||
unsigned int _vtotal;
|
||||
unsigned int _stride;
|
||||
|
||||
|
||||
|
||||
//Vertex* _varray;
|
||||
std::vector<float> _varray;
|
||||
int* _iarray;
|
||||
|
||||
bool* _updated;
|
||||
|
||||
psc _pscpos, _pscvel;
|
||||
|
||||
std::vector<std::pair<int, double>> _intervals;
|
||||
double _increment;
|
||||
// etc...
|
||||
double _time = 0;
|
||||
double _oldTime = 0;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
|
||||
openspace.time.setTime("2005-11-01T00:00:00")
|
||||
openspace.time.setDeltaTime(86400.0)
|
||||
openspace.time.setDeltaTime(20000000.0)
|
||||
|
||||
print(openspace.time.currentTimeUTC())
|
||||
|
||||
@@ -452,7 +452,7 @@ void OpenSpaceEngine::preSynchronization()
|
||||
_interactionHandler->update(dt);
|
||||
_interactionHandler->lockControls();
|
||||
|
||||
Time::ref().advanceTime(dt);
|
||||
//Time::ref().advanceTime(dt);
|
||||
}
|
||||
#ifdef FLARE_ONLY
|
||||
_flare->preSync();
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <iomanip>
|
||||
#include <utility> // std::move
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableEphemeris";
|
||||
@@ -73,7 +75,7 @@ RenderableEphemeris::RenderableEphemeris(const ghoul::Dictionary& dictionary)
|
||||
SM.getTargetPscState("EARTH", et, "GALACTIC", "LT+S", "SUN", pscpos, pscvel, lightTime);
|
||||
|
||||
memcpy(_varray[indx].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
|
||||
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(1, 0, 1, 1)), 4 * sizeof(double));
|
||||
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(1, 1, 0, 1)), 4 * sizeof(double));
|
||||
|
||||
_intervals.push_back(std::pair<int, double>(indx, et));
|
||||
|
||||
@@ -89,7 +91,7 @@ RenderableEphemeris::RenderableEphemeris(const ghoul::Dictionary& dictionary)
|
||||
break;
|
||||
}
|
||||
memcpy(_varray[indx].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
|
||||
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(0, 0, 0, 1)), 4 * sizeof(double));
|
||||
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(1, 1, 0, 1)), 4 * sizeof(double));
|
||||
|
||||
_intervals.push_back(std::pair<int, double>(indx, et));
|
||||
|
||||
@@ -99,6 +101,27 @@ RenderableEphemeris::RenderableEphemeris(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
}
|
||||
_delta = _vsize;
|
||||
|
||||
/// testing std::move()
|
||||
int array1[10] = { 10, 9, 8 , 7, 6, 5, 4, 3, 2 , 1 };
|
||||
|
||||
int size = sizeof(array1)/(sizeof(int));
|
||||
std::cout << "before : ";
|
||||
for (int i = 0; i < 10; i++){
|
||||
std::cout << array1[i] << " ";
|
||||
}
|
||||
for (int i = size-1; i != 0; i--){
|
||||
array1[i] = std::move(array1[i-1]);
|
||||
if (i == 1){
|
||||
array1[0] = 11;
|
||||
}
|
||||
}
|
||||
std::cout << "after : ";
|
||||
for (int i = 0; i < 10; i++){
|
||||
std::cout << array1[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
}
|
||||
|
||||
RenderableEphemeris::~RenderableEphemeris(){
|
||||
@@ -205,7 +228,7 @@ void RenderableEphemeris::render(const RenderData& data){
|
||||
_varray[i].velocity[1] -= 0.00006;
|
||||
_varray[i].velocity[2] -= 0.00004;
|
||||
}
|
||||
/*
|
||||
|
||||
if (_delta > 0){
|
||||
int i = _index[0];
|
||||
int j = _index[1];
|
||||
@@ -226,10 +249,11 @@ void RenderableEphemeris::render(const RenderData& data){
|
||||
}
|
||||
i = (i - 2 < 0) ? _vsize - 1 : i - 2;
|
||||
j = (j - 1 < 0) ? _vsize - 1 : j - 2;
|
||||
|
||||
std::cout << i << " " << j << std::endl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if (_updated[_index[1]] == false && _updated[_index[0]] == false){
|
||||
|
||||
_updated[_index[0]] = true;
|
||||
@@ -241,20 +265,21 @@ void RenderableEphemeris::render(const RenderData& data){
|
||||
memcpy(_varray[_index[0]].location, glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
|
||||
memcpy(_varray[_index[1]].location, glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
|
||||
|
||||
memcpy(_varray[_index[0]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
|
||||
memcpy(_varray[_index[1]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
|
||||
// memcpy(_varray[_index[0]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
|
||||
// memcpy(_varray[_index[1]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
|
||||
|
||||
// DEBUGGING COLOR CODING
|
||||
/*
|
||||
|
||||
memcpy(_varray[_index[0]].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double)); // blue if updated
|
||||
memcpy(_varray[_index[1]].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double));
|
||||
|
||||
memcpy(_varray[_index[2]].velocity, glm::value_ptr(glm::vec4(1, 0, 0, 1)), 4 * sizeof(double)); // red
|
||||
memcpy(_varray[_index[3]].velocity, glm::value_ptr(glm::vec4(1, 0, 0, 1)), 4 * sizeof(double));
|
||||
*/
|
||||
|
||||
_updated[_index[2]] = false;
|
||||
_updated[_index[3]] = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#include <openspace/rendering/renderabletrail.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <iomanip>
|
||||
#include <utility> // std::move
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableTrail";
|
||||
}
|
||||
|
||||
namespace openspace{
|
||||
RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _vaoID(0)
|
||||
, _vBufferID(0)
|
||||
, _iBufferID(0)
|
||||
, _mode(GL_LINE_STRIP){
|
||||
|
||||
|
||||
double lightTime = 0.0;
|
||||
double planetYear = 31536000;
|
||||
_time = SM.convertStringToTdbSeconds("2005 nov 01 00:00:00");
|
||||
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
|
||||
|
||||
double et = _time - planetYear;
|
||||
|
||||
int segments = 40; // note to self: code not look nice. cleanup for clarity later.
|
||||
psc pscpos, pscvel;
|
||||
|
||||
_isize = (segments+2);
|
||||
_vsize = (segments+2);
|
||||
//_varray = new float[_vsize];
|
||||
_iarray = new int[_isize];
|
||||
|
||||
_updated = new bool[_vsize];
|
||||
std::fill(_updated, _updated + _vsize, false);
|
||||
|
||||
//static_assert(sizeof(Vertex) == 64, "The size of the Vertex needs to be 64 for performance");
|
||||
|
||||
_increment = planetYear / segments;
|
||||
for (int i = 0; i < segments+1; i++){
|
||||
|
||||
SM.getTargetPscState("EARTH", et, "GALACTIC", "LT+S", "SUN", pscpos, pscvel, lightTime);
|
||||
|
||||
psc tmppos = glm::vec4(i, i, i, 7);
|
||||
_varray.push_back(tmppos[0]);
|
||||
_varray.push_back(tmppos[1]);
|
||||
_varray.push_back(tmppos[2]);
|
||||
_varray.push_back(tmppos[3]);
|
||||
|
||||
//memcpy(_varray[i].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
|
||||
glm::vec4 color = glm::vec4(1, (i % 2 == 0), 1, 1);
|
||||
|
||||
_varray.push_back(color[0]);
|
||||
_varray.push_back(color[1]);
|
||||
_varray.push_back(color[2]);
|
||||
_varray.push_back(color[3]);
|
||||
|
||||
_intervals.push_back(std::pair<int, double>(i, et));
|
||||
|
||||
_iarray[i] = i; // remove indx in this class at some point!
|
||||
et += _increment;
|
||||
}
|
||||
_stride = 8;
|
||||
_vsize = _varray.size();
|
||||
_vtotal = static_cast<int>(_vsize / _stride);
|
||||
/*
|
||||
std::cout << "before : " << std::endl;
|
||||
for (int i = 0; i < _vsize-1; i++){
|
||||
std::cout << _varray[i] << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/// how to std::move()
|
||||
int m = 8;
|
||||
for (int i = _vsize-1; i+1-m != 0; i--){
|
||||
|
||||
std:: cout << i << " " << i-m << std::endl;
|
||||
_varray[i] = std::move(_varray[i - m]);
|
||||
}
|
||||
/*
|
||||
std::cout << "after : " << std::endl;
|
||||
for (int i = 0; i < _vsize - 1; i++){
|
||||
std::cout << _varray[i] << std::endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
RenderableTrail::~RenderableTrail(){
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool RenderableTrail::initialize(){
|
||||
bool completeSuccess = true;
|
||||
if (_programObject == nullptr)
|
||||
completeSuccess
|
||||
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
|
||||
|
||||
loadTexture();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
|
||||
// Initialize and upload to graphics card
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vBufferID);
|
||||
glGenBuffers(1, &_iBufferID);
|
||||
|
||||
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]);
|
||||
|
||||
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, GL_STATIC_DRAW);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableTrail::deinitialize(){
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableTrail::render(const RenderData& data){
|
||||
assert(_programObject);
|
||||
_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("campos", campos.vec4());
|
||||
_programObject->setUniform("objpos", currentPosition.vec4());
|
||||
_programObject->setUniform("camrot", camrot);
|
||||
_programObject->setUniform("scaling", scaling.vec2());
|
||||
|
||||
if (_oldTime != _time){
|
||||
int m = 8;
|
||||
for (int i = _vsize - 1; i + 1 - m != 0; i--){
|
||||
_varray[i] = std::move(_varray[i - m]);
|
||||
}
|
||||
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
|
||||
_varray[4] = 1;
|
||||
_varray[5] = 1;
|
||||
_varray[6] = 1;
|
||||
_varray[7] = 1;
|
||||
}_oldTime = _time;
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
|
||||
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(_mode, 0, _vtotal);
|
||||
glBindVertexArray(0);
|
||||
|
||||
glPointSize(2.f);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_POINTS, 0, _vtotal);
|
||||
glBindVertexArray(0);
|
||||
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderableTrail::update(const UpdateData& data){
|
||||
double lightTime;
|
||||
_time = data.time;
|
||||
|
||||
SM.getTargetPscState("EARTH", data.time, "GALACTIC", "LT+S", "SUN", _pscpos, _pscvel, lightTime);
|
||||
}
|
||||
|
||||
void RenderableTrail::loadTexture()
|
||||
{
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
// renderables
|
||||
#include <openspace/rendering/stars/renderablestars.h>
|
||||
#include <openspace/rendering/renderableephemeris.h>
|
||||
#include <openspace/rendering/renderabletrail.h>
|
||||
#include <openspace/rendering/renderablesphericalgrid.h>
|
||||
#include <openspace/rendering/renderablefieldlines.h>
|
||||
#include <openspace/rendering/planets/renderableplanet.h>
|
||||
@@ -63,6 +64,9 @@ void FactoryManager::initialize()
|
||||
"RenderableStars");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableEphemeris>(
|
||||
"RenderableEphemeris");
|
||||
//will replace ephemeris class soon...
|
||||
_manager->factory<Renderable>()->registerClass<RenderableTrail>(
|
||||
"RenderableTrail");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(
|
||||
"RenderableSphericalGrid");
|
||||
//_manager->factory<Renderable>()->registerClass<RenderableVolumeCL>(
|
||||
|
||||
Reference in New Issue
Block a user