added renderablepath and made changes to renderabletrail

This commit is contained in:
michal
2014-10-08 16:15:37 -04:00
parent 36925cbde7
commit 1ed4b74d3e
10 changed files with 266 additions and 227 deletions

View File

@@ -22,8 +22,8 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RENDERABLETPATH_H__
#define __RENDERABLETPATH_H__
#ifndef __RenderablePath_H__
#define __RenderablePath_H__
// open space includes
#include <openspace/rendering/renderable.h>
@@ -36,56 +36,58 @@
//#include <openspace/util/runtimedata.h>
namespace openspace {
class RenderablePath : public Renderable{
public:
RenderablePath(const ghoul::Dictionary& dictionary);
~RenderablePath();
class RenderablePath : public Renderable{
public:
RenderablePath(const ghoul::Dictionary& dictionary);
~RenderablePath();
bool initialize() override;
bool deinitialize() override;
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.
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
void fullYearSweep();
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
// modfile reads
// spice
std::string _target;
std::string _observer;
std::string _frame;
// color
glm::vec3 _c;
double _r, _g, _b;
/* 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;
// 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;
void nextIndex();
void nextIndex();
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
unsigned int _vtotal;
unsigned int _stride;
//Vertex* _varray;
std::vector<float> _varray;
int* _iarray;
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
unsigned int _vtotal;
unsigned int _stride;
bool* _updated;
//Vertex* _varray;
std::vector<float> _varray;
int* _iarray;
psc _pscpos, _pscvel;
//used for update of trail
psc _pscpos, _pscvel;
double _increment;
double _time = 0;
double _oldTime = 0;
std::vector<std::pair<int, double>> _intervals;
double _increment;
// etc...
double _time = 0;
double _oldTime = 0;
};
int _delta = 0;
int _dtprogress = 0;
};
}
#endif

View File

@@ -37,6 +37,7 @@ namespace configurationmanager {
const std::string keyStartupScript = "StartupScripts";
const std::string keySpiceTimeKernel = "SpiceKernel.Time";
const std::string keySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
const std::string keySpiceNewHorizons = "SpiceKernel.NewHorizons";
} // namespace configurationmanager
namespace scenegraph {

View File

@@ -12,7 +12,8 @@ return {
},
SpiceKernel = {
Time = "${OPENSPACE_DATA}/spice/naif0010.tls",
LeapSecond = "${OPENSPACE_DATA}/spice/pck00010.tpc"
LeapSecond = "${OPENSPACE_DATA}/spice/pck00010.tpc",
NewHorizons = "${OPENSPACE_DATA}/spice/nhmeta.tm"
},
SGCTConfig = "${SGCT}/single.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",

View File

@@ -1,5 +1,6 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.time.setTime("2005-11-01T00:00:00")
--openspace.time.setTime("2006-06-04T22:00:00")
openspace.time.setDeltaTime(200000.0)
--openspace.time.setDeltaTime(30000.0)
print(openspace.time.currentTimeUTC())

View File

@@ -237,7 +237,7 @@ bool OpenSpaceEngine::initialize()
// initialize OpenSpace helpers
SpiceManager::initialize();
Time::initialize();
using constants::configurationmanager::keySpiceTimeKernel;
std::string timeKernel;
bool success = OsEng.configurationManager().getValue(keySpiceTimeKernel, timeKernel);
@@ -259,6 +259,45 @@ bool OpenSpaceEngine::initialize()
}
SpiceManager::ref().loadKernel(std::move(leapSecondKernel));
//New Horizons - I need this working. It sort of does but clashes with the rest
/*
using constants::configurationmanager::keySpiceNewHorizons;
std::string newHorizonsKernel;
success = OsEng.configurationManager().getValue(keySpiceNewHorizons, newHorizonsKernel);
if (!success) {
LERROR("Configuration file does not contain a '" << keySpiceNewHorizons << "'");
return false;
}
SpiceManager::ref().loadKernel(std::move(newHorizonsKernel));
*/
// ^ whats missing!? set in constants, set in cfg file... wtf...doing it manually...
//#define NEWHORIZONS
#ifdef NEWHORIZONS
// metakernel loading doesnt seem to work... it should. to tired to even
// CK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/ck/merged_nhpc_2006_v011.bc");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/ck/merged_nhpc_2007_v006.bc");
// FK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/fk/nh_v200.tf");
// IK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/ik/nh_lorri_v100.ti");
// LSK already loaded
//PCK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/pck/pck00008.tpc");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/pck/new_horizons_413.tsc");
//SLCK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/sclk/new_horizons_413.tsc");
//SPK
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/de413.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/jup260.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/nh_nep_ura_000.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/nh_plu017.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/nh_recon_e2j_v1.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/nh_recon_j2sep07_prelimv1.bsp");
SpiceManager::ref().loadKernel("C:/Users/michal/Documents/openspace3/openspace-data/spice/spk/sb_2002jf56_2.bsp");
#endif
FactoryManager::initialize();
scriptEngine().initialize();

View File

@@ -31,211 +31,201 @@
#include <openspace/util/spicemanager.h>
#include <iomanip>
#include <utility> // std::move
#include <utility>
namespace {
const std::string _loggerCat = "RenderablePath";
}
//constants
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";
}
#define DEBUG
namespace openspace{
RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINE_STRIP){
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINE_STRIP){
assert(dictionary.getValue(keyBody, _target));
assert(dictionary.getValue(keyObserver, _observer));
assert(dictionary.getValue(keyFrame, _frame));
/*assert(dictionary.getValue(keyTropicalOrbitPeriod, _tropic));
assert(dictionary.getValue(keyEarthOrbitRatio, _ratio));
assert(dictionary.getValue(keyDayLength, _day));//not used now, will be though.
// values in modfiles set from here*/
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html
double lightTime = 0.0;
double planetYear = 31536000;
SpiceManager::ref().getETfromDate("2005 jan 09 00:00:00", _time);
// -------------------------------------- ^ 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++){
SpiceManager::ref().getTargetState("EARTH", "SUN", "GALACTIC", "LT+S", et, 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;
}
*/
//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];
}
}
void RenderablePath::fullYearSweep(){
double lightTime = 0.0;
SpiceManager::ref().getETfromDate("2006 jul 04 22:00:00", _time);
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
double et2 = 0;
//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);
RenderablePath::~RenderablePath(){
deinitialize();
}
double et = _time;
int segments = 20000;
_increment = 6*3600;
_isize = (segments + 2);
_vsize = (segments + 2);
_iarray = new int[_isize];
int indx = 0;
for (int i = 0; i < segments + 1; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime);
if (_pscpos[0] != 0 && _pscpos[1] != 0 && _pscpos[2] != 0 && _pscpos[3] != 1){
/*std::cout << _target << " " << _observer << " " << _frame <<
_pscpos[0] << " " << _pscpos[1] << " " << _pscpos[2] << " " << _pscpos[3] << std::endl;
*/
_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(1.f);
#endif
indx++;
_iarray[indx] = indx;
}
et += _increment;
}
_stride = 8;
_vsize = _varray.size();
_vtotal = static_cast<int>(_vsize / _stride);
}
RenderablePath::~RenderablePath(){
deinitialize();
}
bool RenderablePath::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
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);
//TEXTURES DISABLED FOR NOW
//loadTexture();
completeSuccess &= (_texture != nullptr);
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;
fullYearSweep();
// Initialize and upload to graphics card
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenBuffers(1, &_iBufferID);
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)));
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;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
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)));
glBindVertexArray(0);
return completeSuccess;
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
bool RenderablePath::deinitialize(){
delete _texture;
_texture = nullptr;
return true;
}
glBindVertexArray(0);
void RenderablePath::render(const RenderData& data){
assert(_programObject);
_programObject->activate();
return completeSuccess;
}
// 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);
bool RenderablePath::deinitialize(){
delete _texture;
_texture = nullptr;
return true;
}
glm::mat4 transform = glm::mat4(1);
void RenderablePath::render(const RenderData& data){
assert(_programObject);
_programObject->activate();
// setup the data to the shader
//_programObject->setUniform("objectVelocity", pscvel.vec4());
// 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);
_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;
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());
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(_mode, 0, _vtotal);
glBindVertexArray(0);
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, _vtotal);
glBindVertexArray(0);
_programObject->deactivate();
}
glPointSize(2.f);
void RenderablePath::update(const UpdateData& data){
double lightTime;
_time = data.time;
_delta = data.delta;
int newhorizons = 0;
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, _vtotal);
glBindVertexArray(0);
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", data.time, _pscpos, _pscvel, lightTime);
}
_programObject->deactivate();
}
void RenderablePath::update(const UpdateData& data){
double lightTime;
_time = data.time;
SpiceManager::ref().getTargetState("EARTH", "SUN", "GALACTIC", "LT+S", data.time, _pscpos, _pscvel, lightTime);
}
void RenderablePath::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
void RenderablePath::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
}
}
}
}
}

View File

@@ -77,9 +77,9 @@ namespace openspace{
}
void RenderableTrail::fullYearSweep(){
double lightTime = 0.0;
SpiceManager::ref().getETfromDate("2005 nov 01 00:00:00", _time);
SpiceManager::ref().getETfromDate("2005 nov 01 22:00:00", _time);
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
double et = _time;
double planetYear = 31540000 * _ratio;
int segments = _tropic;
@@ -93,8 +93,6 @@ void RenderableTrail::fullYearSweep(){
for (int i = 0; i < segments + 1; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime);
//std::cout << planetYear << " " << segments << " " << _increment << std::endl;
//psc tmppos = glm::vec4(i, i, i, 7);
_varray.push_back(_pscpos[0]);
_varray.push_back(_pscpos[1]);
@@ -191,7 +189,7 @@ void RenderableTrail::render(const RenderData& data){
if (_oldTime != _time){ // only update when time actually progresses
_dtprogress += _delta*sgct::Engine::instance()->getDt(); // compute how far time has progressed
if (_dtprogress > 86400){
if (_dtprogress > _increment){
//reset progress counter
_dtprogress = 0;
@@ -232,6 +230,8 @@ void RenderableTrail::update(const UpdateData& data){
double lightTime;
_time = data.time;
_delta = data.delta;
int newhorizons =0;
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", data.time, _pscpos, _pscvel, lightTime);
}

View File

@@ -31,6 +31,9 @@
#include <openspace/rendering/stars/renderablestars.h>
#include <openspace/rendering/renderableephemeris.h>
#include <openspace/rendering/renderabletrail.h>
#include <openspace/rendering/renderablepath.h>
#include <openspace/rendering/renderablesphericalgrid.h>
#include <openspace/rendering/renderablefieldlines.h>
#include <openspace/rendering/planets/renderableplanet.h>
@@ -66,6 +69,8 @@ void FactoryManager::initialize()
_manager->factory<Renderable>()->registerClass<RenderableEphemeris>(
"RenderableEphemeris");
//will replace ephemeris class soon...
_manager->factory<Renderable>()->registerClass<RenderablePath>(
"RenderablePath");
_manager->factory<Renderable>()->registerClass<RenderableTrail>(
"RenderableTrail");
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(

View File

@@ -71,7 +71,7 @@ PowerScaledCoordinate::PowerScaledCoordinate(const PowerScaledCoordinate& rhs) {
PowerScaledCoordinate
PowerScaledCoordinate::CreatePowerScaledCoordinate(double d1, double d2, double d3)
{
char buff[60];
char buff[600];
// find the number with maximum number of digits
double ad1 = abs(d1);

View File

@@ -89,7 +89,7 @@ int SpiceManager::loadKernel(std::string filePath) {
furnsh_c(filePath.c_str());
FileSys.setCurrentDirectory(currentDirectory);
std::cout << filePath.c_str() << std::endl;
int failed = failed_c();
if (failed) {
char msg[1024];