From ae48d76c6007506ae6474b683289d1333f7b3f62 Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 15 Oct 2014 15:42:56 -0400 Subject: [PATCH 01/16] merged openspace-data and reset time parameters to around jupiters little red dot observation (we want to focus on that for now) --- openspace-data | 2 +- scripts/default_startup.lua | 2 +- src/rendering/renderablefov.cpp | 4 ++-- src/rendering/renderabletrail.cpp | 4 ++-- src/rendering/renderablewavefrontobject.cpp | 9 ++++++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/openspace-data b/openspace-data index 078b74de34..765e241626 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 078b74de3490cf1358b53257b0b29bb91455610b +Subproject commit 765e241626e3b67170fb08c6561f2fd1dfe97b92 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index ac91556db3..8a562f5b1c 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,5 +1,5 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') -openspace.time.setTime("2007-02-26T12:00:00") +openspace.time.setTime("2007-02-26T17:00:00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index 485bf2e8a9..eb82fc0f6f 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -174,7 +174,7 @@ bool RenderableFov::initialize(){ &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject); _startTrail; - SpiceManager::ref().getETfromDate("2007 feb 26 12:00:00", _startTrail); + SpiceManager::ref().getETfromDate("2007 feb 26 20:00:00", _startTrail); fullYearSweep(); sendToGPU(); @@ -234,7 +234,7 @@ void RenderableFov::update(const UpdateData& data){ _time = data.time; _delta = data.delta; - openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix); + //openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix); } void RenderableFov::loadTexture() diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index dfa3deb649..1ef78428ff 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -161,8 +161,8 @@ bool RenderableTrail::initialize(){ completeSuccess &= (_texture != nullptr); _startTrail; - SpiceManager::ref().getETfromDate("2007 feb 26 12:00:00", _startTrail); - //SpiceManager::ref().getETfromDate("2006 aug 22 20:00:00", _startTrail); + //SpiceManager::ref().getETfromDate("2006 jan 19 20:00:00", _startTrail); + SpiceManager::ref().getETfromDate("2007 feb 26 17:00:00", _startTrail); diff --git a/src/rendering/renderablewavefrontobject.cpp b/src/rendering/renderablewavefrontobject.cpp index 0baa8b7068..99916c204c 100644 --- a/src/rendering/renderablewavefrontobject.cpp +++ b/src/rendering/renderablewavefrontobject.cpp @@ -224,7 +224,7 @@ void RenderableWavefrontObject::loadObj(const char *filename){ vertexIndex = _iarray[m] * 3; _iarray[m] = m; - _varray[m].location[3] = 2; + _varray[m].location[3] = 7; int q = 0; while (q < 3){ _varray[m].location[q] = tempVertexArray[vertexIndex + q]; @@ -265,7 +265,7 @@ bool RenderableWavefrontObject::initialize() completeSuccess &= (_texture != nullptr); //completeSuccess &= _geometry->initialize(this); - PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1,2); + PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1,7); setBoundingSphere(ps); @@ -336,7 +336,9 @@ void RenderableWavefrontObject::render(const RenderData& data) glm::mat4 scaler = glm::scale(transform, glm::vec3(0, 0, -1)); //earth needs to be rotated for that to work. - glm::mat4 rot_x = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0)); + glm::mat4 rot_x = glm::rotate(transform, 270.f, glm::vec3(1, 0, 0)); + glm::mat4 rot_y = glm::rotate(transform, 90.f, glm::vec3(0, 1, 0)); + glm::mat4 tmp = glm::mat4(1); for (int i = 0; i < 3; i++){ @@ -346,6 +348,7 @@ void RenderableWavefrontObject::render(const RenderData& data) } transform *= tmp; transform *= rot_x; + //transform *= rot_y; glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); glm::vec4 camSpaceEye = -(modelview*currentPosition.vec4()); From 97df29706c61b6ec305f85273445c83f2c4464c3 Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 15 Oct 2014 18:42:14 -0400 Subject: [PATCH 02/16] small changes, return solarsystem to original state --- ext/ghoul | 2 +- openspace-data | 2 +- scripts/default_startup.lua | 2 +- shaders/pscstandard_fs.glsl | 4 ++-- src/scenegraph/spiceephemeris.cpp | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 1f1386215e..ba68d54517 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 1f1386215e517179f7a4e80e64693fd3ebc2b339 +Subproject commit ba68d5451755ed20baccaf82dcb886186b5a1834 diff --git a/openspace-data b/openspace-data index 765e241626..26b896ed47 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 765e241626e3b67170fb08c6561f2fd1dfe97b92 +Subproject commit 26b896ed47ced54d24245d8947b8b2f47551740a diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index e574ef21f1..cb4071ff30 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -3,6 +3,6 @@ openspace.time.setTime("2007-02-26T17:00:00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) -openspace.time.setDeltaTime(2000.0) +openspace.time.setDeltaTime(200000.0) --openspace.time.setDeltaTime(30000.0) -- print(openspace.time.currentTimeUTC()) diff --git a/shaders/pscstandard_fs.glsl b/shaders/pscstandard_fs.glsl index 3d1c243bba..ab973718df 100644 --- a/shaders/pscstandard_fs.glsl +++ b/shaders/pscstandard_fs.glsl @@ -70,8 +70,8 @@ void main() spec = specular * pow(intSpec, shine); } */ - diffuse = max(intensity * diffuse, ambient); - + //diffuse = max(intensity * diffuse, ambient); + //diffuse = vec4(1); ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth); addToBuffer(frag); diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 45aa2d18ed..4623406fc1 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -76,6 +76,7 @@ void SpiceEphemeris::update(const UpdateData& data) { glm::dvec3 position(0,0,0); double lightTime = 0.0; SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "NONE", data.time, position, lightTime); + _position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z); _position[3] += 3; } From 099bcc2c9b2afdde112008ea3dda657885784811 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 16 Oct 2014 16:13:54 -0400 Subject: [PATCH 03/16] changing renderabletrail class to work for planetocentric --- include/openspace/rendering/renderabletrail.h | 1 + openspace-data | 2 +- scripts/default_startup.lua | 2 +- src/rendering/renderabletrail.cpp | 15 +++++++++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/openspace/rendering/renderabletrail.h b/include/openspace/rendering/renderabletrail.h index 15fb191094..30376ff880 100644 --- a/include/openspace/rendering/renderabletrail.h +++ b/include/openspace/rendering/renderabletrail.h @@ -58,6 +58,7 @@ public: std::string _target; std::string _observer; std::string _frame; + std::string _orbitVariety; // color glm::vec3 _c; double _r, _g, _b; diff --git a/openspace-data b/openspace-data index 26b896ed47..588e958d81 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 26b896ed47ced54d24245d8947b8b2f47551740a +Subproject commit 588e958d81514daedb6f2fd9096832f0dc76ef69 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index cb4071ff30..11f4afa199 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -3,6 +3,6 @@ openspace.time.setTime("2007-02-26T17:00:00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) -openspace.time.setDeltaTime(200000.0) +openspace.time.setDeltaTime(20000.0) --openspace.time.setDeltaTime(30000.0) -- print(openspace.time.currentTimeUTC()) diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 1ef78428ff..76b8ef6710 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -38,6 +38,7 @@ namespace { const std::string keyBody = "Body"; const std::string keyObserver = "Observer"; const std::string keyFrame = "Frame"; + const std::string keyOrbitVariety = "OrbitVariety"; const std::string keyPathModule = "ModulePath"; const std::string keyColor = "RGB"; const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod"; @@ -65,6 +66,12 @@ namespace openspace{ 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 + + if (!dictionary.getValue(keyOrbitVariety, _orbitVariety)){ + _orbitVariety = "heliocentric"; + } + if (_target == "IO") + std::cout << _target << " has orbit variety : " << _orbitVariety << std::endl; //white is default col if (!dictionary.getValue(keyColor, _c)){ @@ -230,17 +237,17 @@ void RenderableTrail::render(const RenderData& data){ updateTrail(); - + /* glBindVertexArray(_vaoID); glDrawArrays(_mode, 0, _vtotal); glBindVertexArray(0); - /* + */ glPointSize(2.f); glBindVertexArray(_vaoID); glDrawArrays(GL_POINTS, 0, _vtotal); glBindVertexArray(0); - */ + _programObject->deactivate(); } @@ -249,7 +256,7 @@ void RenderableTrail::update(const UpdateData& data){ _time = data.time; _delta = data.delta; - SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time+_increment, _pscpos, _pscvel, lightTime); + SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time + _increment, _pscpos, _pscvel, lightTime); } void RenderableTrail::loadTexture() From 50b4c1ec366a09c15ffcfbad602453a68ff8c69f Mon Sep 17 00:00:00 2001 From: michal Date: Mon, 20 Oct 2014 16:00:38 -0400 Subject: [PATCH 04/16] fixed renderabletrail class to suit for all different delta times, tropical orbits etc etc. lot of stuff to do with precision and set time intervals (pain in the ass). works clockwork. changes to modules etc. will do more fixes soon. Incoming. --- include/openspace/rendering/renderabletrail.h | 18 +-- scripts/default_startup.lua | 4 +- shaders/pscstandard_fs.glsl | 2 +- src/rendering/renderabletrail.cpp | 153 ++++++++++-------- src/rendering/renderablewavefrontobject.cpp | 24 +-- 5 files changed, 115 insertions(+), 86 deletions(-) diff --git a/include/openspace/rendering/renderabletrail.h b/include/openspace/rendering/renderabletrail.h index 30376ff880..8748f92b99 100644 --- a/include/openspace/rendering/renderabletrail.h +++ b/include/openspace/rendering/renderabletrail.h @@ -61,14 +61,13 @@ public: std::string _orbitVariety; // color glm::vec3 _c; - double _r, _g, _b; + float _r, _g, _b; // orbit relational data - double _tropic; - double _ratio; - double _day; + float _tropic; + float _ratio; + float _day; // 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; @@ -89,12 +88,13 @@ public: int* _iarray; bool _once = false; - + double lightTime; //used for update of trail psc _pscpos, _pscvel; - double _increment; - double _time = 0; - double _oldTime = 0; + float _increment; + float _time = 0; + float _oldTime = 0; + float _dtEt; int _delta = 0; int _dtprogress = 0; diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index 11f4afa199..99a37cac97 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -3,6 +3,8 @@ openspace.time.setTime("2007-02-26T17:00:00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) -openspace.time.setDeltaTime(20000.0) +--openspace.time.setDeltaTime(5000.00) +openspace.time.setDeltaTime(1000) --openspace.time.setDeltaTime(30000.0) -- print(openspace.time.currentTimeUTC()) + diff --git a/shaders/pscstandard_fs.glsl b/shaders/pscstandard_fs.glsl index ab973718df..a0dc64aa16 100644 --- a/shaders/pscstandard_fs.glsl +++ b/shaders/pscstandard_fs.glsl @@ -70,7 +70,7 @@ void main() spec = specular * pow(intSpec, shine); } */ - //diffuse = max(intensity * diffuse, ambient); + diffuse = max(intensity * diffuse, ambient); //diffuse = vec4(1); ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth); diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 76b8ef6710..2238e4e920 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -31,14 +31,19 @@ #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 = "RenderableTrail"; //constants const std::string keyBody = "Body"; const std::string keyObserver = "Observer"; const std::string keyFrame = "Frame"; - const std::string keyOrbitVariety = "OrbitVariety"; const std::string keyPathModule = "ModulePath"; const std::string keyColor = "RGB"; const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod"; @@ -66,61 +71,59 @@ namespace openspace{ 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 - - if (!dictionary.getValue(keyOrbitVariety, _orbitVariety)){ - _orbitVariety = "heliocentric"; - } - if (_target == "IO") - std::cout << _target << " has orbit variety : " << _orbitVariety << std::endl; - //white is default col + + //white is default col if (!dictionary.getValue(keyColor, _c)){ _c = glm::vec3(0.0); - }else{ + }else{ //to understand, ref to line 115. _r = 1 / _c[0]; _g = 1 / _c[1]; _b = 1 / _c[2]; } } + +/* This algorithm estimates and precomputes the number of segments required for +* any planetary object in space, given a tropical orbit period and earth-to-planet +* orbit ratio. In doing so, it finds the exact increment of time corresponding +* to a planetary year. +* Therefore all planets need said constants, for other objects we need a different, +* and most likely heuristic measure to easily estimate a nodal time-increment. +* Trivial, yet - a TODO. +*/ void RenderableTrail::fullYearSweep(){ double lightTime = 0.0; - // -------------------------------------- ^ this has to be simulation start-time, not passed in here though -- - - if (_target == "JUPITER BARYCENTER"){ - _tropic *= 20; - } - double et = _startTrail; double planetYear = 31540000 * _ratio; int segments = _tropic; - _increment = planetYear / _tropic; + _increment = planetYear / _tropic; _isize = (segments + 2); _vsize = (segments + 2); _iarray = new int[_isize]; - double p = 1.0 / _tropic; - for (int i = 0; i < segments + 1; i++){ + for (int i = 0; i < segments+2; i++){ SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime); _pscpos[3] += 3; - _varray.push_back(_pscpos[0]); - _varray.push_back(_pscpos[1]); - _varray.push_back(_pscpos[2]); - _varray.push_back(_pscpos[3]); + + for (int k = 0; k < 4; k++) + _varray.push_back(_pscpos[k]); #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)); + float p = (float)i / _tropic; + _varray.push_back(1.f - p * _r); + _varray.push_back(1.f - p * _g); + _varray.push_back(1.f - p * _b); + _varray.push_back(1.f - p); #else _varray.push_back(1.f ); _varray.push_back(1.f ); _varray.push_back(1.f ); _varray.push_back(1.f ); #endif - _iarray[i] = i; // remove indx in this class at some point! + _iarray[i] = i; + if (i != 0) //very first point needs to be alllocated twice. et -= _increment; } _stride = 8; @@ -170,12 +173,10 @@ bool RenderableTrail::initialize(){ _startTrail; //SpiceManager::ref().getETfromDate("2006 jan 19 20:00:00", _startTrail); SpiceManager::ref().getETfromDate("2007 feb 26 17:00:00", _startTrail); + _dtEt = _startTrail; - - - fullYearSweep(); - sendToGPU(); - + fullYearSweep(); + sendToGPU(); return completeSuccess; } @@ -186,32 +187,60 @@ bool RenderableTrail::deinitialize(){ return true; } +// Tried interpolation but then realised this still gives straight lines (latenight thing). +// Not allowed Splines so therefore - query spice for each point (bah...) +// From psc paper: +/* +psc pscInterpolate(psc p0, psc p1, float t){ + assert(t >= 0 && t <= 1); + + float s = (1.f - t)*p0[3] + t*p1[3]; + + float x = ((1.f - t)*p0[0] + t*p1[0]); + float y = ((1.f - t)*p0[1] + t*p1[1]); + float z = ((1.f - t)*p0[2] + t*p1[2]); + + return PowerScaledCoordinate::PowerScaledCoordinate(x,y,z,s); +} +*/ + void RenderableTrail::updateTrail(){ - if (_oldTime != _time){ // only update when time actually progresses - _dtprogress += _delta*sgct::Engine::instance()->getDt(); // compute how far time has progressed - if (_dtprogress > _increment){ - //reset progress counter - _dtprogress = 0; + int m = _stride; + float *begin = &_varray[0]; + float *end = &_varray[_vsize - 1] + 1; - int m = 8; - for (int i = _vsize - 1; i + 1 - m != 0; i--){ - _varray[i] = std::move(_varray[i - m]); - } - int n = 4; - while (n < _vsize - 8){ - for (int i = 0; i < 4; i++){ - _varray[n + i] = _varray[n + 8 + i]; - } - n += 8; - } - //add last pt - _pscpos[3] += 3; - memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double)); + // update only when time progresses + if (_oldTime != _time){ + // if time progressed more than N _increments + while (_dtEt < _time){ + // get intermediary points + psc dtPoint; + SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", _dtEt, dtPoint, _pscvel, lightTime); + dtPoint[3] += 3; + + // overwrite the old position + memcpy(begin, glm::value_ptr(dtPoint.vec4()), 4 * sizeof(float)); + // shift array + for (int k = _vsize-m; k > 0; k -= m){ + memcpy(&_varray[k], &_varray[k - m], 4 * sizeof(float)); + } + // keep track of progression + _dtEt += _increment; } + //add earths current position + memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(float)); + _varray[4] = 1.f; + _varray[5] = 1.f; + _varray[6] = 1.f; + _varray[7] = 1.f; }_oldTime = _time; + // update GPU + // NOTE: vbo interleaved, makes possible color update more efficient - tightly packed. + // if NO color update : would be more efficient to have these as separate + // => N/2 updates per drawcall. glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]); } @@ -222,10 +251,8 @@ void RenderableTrail::render(const RenderData& data){ // 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); + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); glm::mat4 transform = glm::mat4(1); @@ -235,15 +262,14 @@ void RenderableTrail::render(const RenderData& data){ _programObject->setUniform("ModelTransform", transform); setPscUniforms(_programObject, &data.camera, data.position); - updateTrail(); - /* + glBindVertexArray(_vaoID); glDrawArrays(_mode, 0, _vtotal); glBindVertexArray(0); - */ + glPointSize(2.f); - + // nodes of equal time glBindVertexArray(_vaoID); glDrawArrays(GL_POINTS, 0, _vtotal); glBindVertexArray(0); @@ -252,11 +278,12 @@ void RenderableTrail::render(const RenderData& data){ } void RenderableTrail::update(const UpdateData& data){ - double lightTime; _time = data.time; _delta = data.delta; - - SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time + _increment, _pscpos, _pscvel, lightTime); + + SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time, _pscpos, _pscvel, lightTime); + _pscpos[3] += 3; // KM to M + } void RenderableTrail::loadTexture() diff --git a/src/rendering/renderablewavefrontobject.cpp b/src/rendering/renderablewavefrontobject.cpp index 99916c204c..a5bda0e212 100644 --- a/src/rendering/renderablewavefrontobject.cpp +++ b/src/rendering/renderablewavefrontobject.cpp @@ -137,15 +137,15 @@ void RenderableWavefrontObject::loadObj(const char *filename){ _vsize = indicesSize; // float arrays - float *tempVertexArray = (float*)malloc(vertexSize*sizeof(float)); - float *tempVertexNormalArray = (float*)malloc(vertexNormalSize*sizeof(float)); - float *tempVertexTextureArray = (float*)malloc(vertexTextureSize*sizeof(float)); - _varray = (Vertex*)malloc(_vsize*sizeof(Vertex)); + float *tempVertexArray = new float[vertexSize];// vertexSize*sizeof(float)); + float *tempVertexNormalArray = new float[vertexNormalSize]; + float *tempVertexTextureArray = new float[vertexTextureSize]; + _varray = new Vertex[_vsize]; // int arrays - _iarray = (int*)malloc(_isize*sizeof(int)); - int *tempNormalIndicesArray = (int*)malloc(_isize*sizeof(int)); - int *tempTextureIndicesArray = (int*)malloc(_isize*sizeof(int)); + _iarray = new int[_isize]; + int *tempNormalIndicesArray = new int[_isize]; + int *tempTextureIndicesArray = new int[_isize]; // keeping track of the array indexes unsigned int i = 0; @@ -243,11 +243,11 @@ void RenderableWavefrontObject::loadObj(const char *filename){ m++; } // free up memory - free(tempVertexArray); - free(tempVertexNormalArray); - free(tempNormalIndicesArray); - free(tempVertexTextureArray); - free(tempTextureIndicesArray); + delete [] tempVertexArray; + delete [] tempVertexNormalArray; + delete [] tempNormalIndicesArray; + delete [] tempVertexTextureArray; + delete [] tempTextureIndicesArray; } RenderableWavefrontObject::~RenderableWavefrontObject(){ From 4a6e9dd67190cef5a2c0acddbc16abc3b3acdda6 Mon Sep 17 00:00:00 2001 From: michal Date: Mon, 20 Oct 2014 16:01:04 -0400 Subject: [PATCH 05/16] forgot to add openspace-data. fix. --- openspace-data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openspace-data b/openspace-data index 588e958d81..a31e5da7f3 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 588e958d81514daedb6f2fd9096832f0dc76ef69 +Subproject commit a31e5da7f3c15c8a644268047440035b3d0af962 From 54809c6376ee21a8d1955207b1cbc126351fa53d Mon Sep 17 00:00:00 2001 From: michal Date: Mon, 20 Oct 2014 18:29:55 -0400 Subject: [PATCH 06/16] Pluto geometry artefacts commit. --- .../rendering/renderablewavefrontobject.h | 15 ++------ include/openspace/util/constants.h | 1 - scripts/default_startup.lua | 6 ++-- src/rendering/renderablepath.cpp | 1 + src/rendering/renderabletrail.cpp | 4 +-- src/rendering/renderablewavefrontobject.cpp | 35 ++++++++----------- src/util/powerscaledsphere.cpp | 2 +- 7 files changed, 23 insertions(+), 41 deletions(-) diff --git a/include/openspace/rendering/renderablewavefrontobject.h b/include/openspace/rendering/renderablewavefrontobject.h index c0370d1a25..755b5958b9 100644 --- a/include/openspace/rendering/renderablewavefrontobject.h +++ b/include/openspace/rendering/renderablewavefrontobject.h @@ -83,19 +83,8 @@ private: glm::dmat3 _stateMatrix; // might need this - std::string _target; - - ///NH FOV - - GLuint _vaoFOV = 10; - GLuint _vboFOV = 11; - GLuint _iboFOV = 12; - - unsigned int _isizeFOV; - unsigned int _vsizeFOV; - std::vector _varrayFOV; - int *_iarrayFOV; - + std::string _source; + std::string _destination; }; diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 49e8787045..9c8b0ce40d 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -37,7 +37,6 @@ 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 { diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index 99a37cac97..fa714ec348 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,10 +1,10 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') -openspace.time.setTime("2007-02-26T17:00:00") ---openspace.time.setTime("2006-08-22T20:00:00") +--openspace.time.setTime("2006-02-26T17:00:00") +openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) --openspace.time.setDeltaTime(5000.00) -openspace.time.setDeltaTime(1000) +openspace.time.setDeltaTime(10) --openspace.time.setDeltaTime(30000.0) -- print(openspace.time.currentTimeUTC()) diff --git a/src/rendering/renderablepath.cpp b/src/rendering/renderablepath.cpp index c61fbea9f7..25b4963f07 100644 --- a/src/rendering/renderablepath.cpp +++ b/src/rendering/renderablepath.cpp @@ -77,6 +77,7 @@ namespace openspace{ void RenderablePath::fullYearSweep(){ double lightTime = 0.0; SpiceManager::ref().getETfromDate("2006 jan 20 19: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); diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 2238e4e920..a4127d4e60 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -171,8 +171,8 @@ bool RenderableTrail::initialize(){ completeSuccess &= (_texture != nullptr); _startTrail; - //SpiceManager::ref().getETfromDate("2006 jan 19 20:00:00", _startTrail); - SpiceManager::ref().getETfromDate("2007 feb 26 17:00:00", _startTrail); + SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail); + //SpiceManager::ref().getETfromDate("2007 feb 26 17:00:00", _startTrail); _dtEt = _startTrail; fullYearSweep(); diff --git a/src/rendering/renderablewavefrontobject.cpp b/src/rendering/renderablewavefrontobject.cpp index a5bda0e212..d578070fb8 100644 --- a/src/rendering/renderablewavefrontobject.cpp +++ b/src/rendering/renderablewavefrontobject.cpp @@ -42,6 +42,8 @@ namespace { const std::string _loggerCat = "RenderableWavefrontObject"; + const std::string keySource = "Rotation.Source"; + const std::string keyDestination = "Rotation.Destination"; } namespace openspace { @@ -51,28 +53,25 @@ RenderableWavefrontObject::RenderableWavefrontObject(const ghoul::Dictionary& di , _programObject(nullptr) , _fovProgram(nullptr) , _texture(nullptr) + , _mode(GL_TRIANGLES) { std::string name; - bool success = dictionary.getValue(constants::scenegraphnode::keyName, name); - assert(success); + assert(dictionary.getValue(constants::scenegraphnode::keyName, name)); std::string path; - dictionary.getValue(constants::scenegraph::keyPathModule, path); + assert(dictionary.getValue(constants::scenegraph::keyPathModule, path)); std::string texturePath = ""; if (dictionary.hasKey("Textures.Color")) { - dictionary.getValue("Textures.Color", texturePath); + assert(dictionary.getValue("Textures.Color", texturePath)); _colorTexturePath = path + "/" + texturePath; } addProperty(_colorTexturePath); _colorTexturePath.onChange(std::bind(&RenderableWavefrontObject::loadTexture, this)); - _mode = GL_TRIANGLES; - std::string file; - dictionary.getValue(constants::renderablewavefrontobject::keyObjFile, file); - + assert(dictionary.getValue(constants::renderablewavefrontobject::keyObjFile, file)); const std::string filename = FileSys.absolutePath(file); std::cout << "OBJECT LOADER FILENAME : " << filename << std::endl; @@ -86,11 +85,10 @@ RenderableWavefrontObject::RenderableWavefrontObject(const ghoul::Dictionary& di }else { LERROR("Did not find file..\n"); } - + assert(dictionary.getValue(keySource , _source)); + assert(dictionary.getValue(keyDestination , _destination)); } - - void RenderableWavefrontObject::loadObj(const char *filename){ // temporary int vertexSize = 0; @@ -137,7 +135,7 @@ void RenderableWavefrontObject::loadObj(const char *filename){ _vsize = indicesSize; // float arrays - float *tempVertexArray = new float[vertexSize];// vertexSize*sizeof(float)); + float *tempVertexArray = new float[vertexSize]; float *tempVertexNormalArray = new float[vertexNormalSize]; float *tempVertexTextureArray = new float[vertexTextureSize]; _varray = new Vertex[_vsize]; @@ -224,7 +222,7 @@ void RenderableWavefrontObject::loadObj(const char *filename){ vertexIndex = _iarray[m] * 3; _iarray[m] = m; - _varray[m].location[3] = 7; + _varray[m].location[3] = 7; // I need to set this proper at some point. int q = 0; while (q < 3){ _varray[m].location[q] = tempVertexArray[vertexIndex + q]; @@ -346,8 +344,8 @@ void RenderableWavefrontObject::render(const RenderData& data) tmp[i][j] = _stateMatrix[i][j]; } } - transform *= tmp; - transform *= rot_x; + //transform *= tmp; + //transform *= rot_x; //transform *= rot_y; glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); @@ -378,18 +376,13 @@ void RenderableWavefrontObject::render(const RenderData& data) name.resize(32); std::vector bounds; glm::dvec3 boresight; - - bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds); - glm::vec4 a(boresight, 1); - a = transform*a; - //std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl; } void RenderableWavefrontObject::update(const UpdateData& data) { glm::dvec3 position(0, 0, 0); // set spice-orientation in accordance to timestamp - openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix); + openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, data.time, _stateMatrix); } diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index 27c274c7cc..8990fbede4 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -40,7 +40,7 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen : _vaoID(0) , _vBufferID(0) , _iBufferID(0) - , _mode(GL_TRIANGLES) + , _mode(GL_LINES) , _isize(6 * segments * segments) , _vsize((segments + 1) * (segments + 1)) , _varray(new Vertex[_vsize]) From d098a37ea7633341d503513fdffaf386b2bd1e35 Mon Sep 17 00:00:00 2001 From: michal Date: Mon, 20 Oct 2014 18:30:21 -0400 Subject: [PATCH 07/16] openspace-data for pluto artefact commit --- openspace-data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openspace-data b/openspace-data index a31e5da7f3..8607807557 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit a31e5da7f3c15c8a644268047440035b3d0af962 +Subproject commit 8607807557c508d64a9d38bafa6f3cf771618490 From 64ee84ede1048d4307ca79822dc19673977a8c2b Mon Sep 17 00:00:00 2001 From: michal Date: Tue, 21 Oct 2014 12:49:39 -0400 Subject: [PATCH 08/16] Fixed model oriantation After 32 maya exports and about 600 different attempts of different rotations / scalings along each axis I realised that the model is in fact correctly aligned and that what we are seing are precisional errors with the stupid boresight-polygon-baton. Nevertheless, out of all of those Im keeping some of the more cruicial test-objects (8 to be precise) for future reference, these can be deleted at some point, I just really want to keep them for now, comfort blanket. --- openspace-data | 2 +- scripts/default_startup.lua | 6 +++--- shaders/grid_fs.glsl | 8 +++---- src/rendering/renderabletrail.cpp | 4 ++-- src/rendering/renderablewavefrontobject.cpp | 24 +++++++++++++++------ src/scenegraph/spiceephemeris.cpp | 2 +- src/util/powerscaledsphere.cpp | 2 +- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/openspace-data b/openspace-data index 8607807557..918a182699 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 8607807557c508d64a9d38bafa6f3cf771618490 +Subproject commit 918a18269909336ef8f1a1ba9f2ee70d2c6042cb diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index fa714ec348..c382648263 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,10 +1,10 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') ---openspace.time.setTime("2006-02-26T17:00:00") -openspace.time.setTime("2006-08-22T20:00:00") +openspace.time.setTime("2007-02-26T17:41:00") +--openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) --openspace.time.setDeltaTime(5000.00) -openspace.time.setDeltaTime(10) +openspace.time.setDeltaTime(1000) --openspace.time.setDeltaTime(30000.0) -- print(openspace.time.currentTimeUTC()) diff --git a/shaders/grid_fs.glsl b/shaders/grid_fs.glsl index b4281b0ae8..c18d0281db 100644 --- a/shaders/grid_fs.glsl +++ b/shaders/grid_fs.glsl @@ -40,13 +40,13 @@ void main() //diffuse = vec4(depth*5,0.0, 0.0, 1.0); //diffuse = vec4(vs_position.w,0.0, 0.0, 1.0); - vec4 diffuse = vec4(1,0,0,1); - if( floor(vs_st[0]) == -2){ + vec4 diffuse = vec4(0.4,0.4,0.4,1); + /*if( floor(vs_st[0]) == -2){ diffuse = gridColor*2.f; }else{ diffuse = gridColor; - } - diffuse = gridColor; + }*/ + diffuse = gridColor; vec4 position = vs_position; diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index a4127d4e60..89118e64f2 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -171,8 +171,8 @@ bool RenderableTrail::initialize(){ completeSuccess &= (_texture != nullptr); _startTrail; - SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail); - //SpiceManager::ref().getETfromDate("2007 feb 26 17:00:00", _startTrail); + // SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail); + SpiceManager::ref().getETfromDate("2007 feb 26 17:41:00", _startTrail); _dtEt = _startTrail; fullYearSweep(); diff --git a/src/rendering/renderablewavefrontobject.cpp b/src/rendering/renderablewavefrontobject.cpp index d578070fb8..14ef82ff87 100644 --- a/src/rendering/renderablewavefrontobject.cpp +++ b/src/rendering/renderablewavefrontobject.cpp @@ -331,11 +331,13 @@ void RenderableWavefrontObject::render(const RenderData& data) // scale the planet to appropriate size since the planet is a unit sphere glm::mat4 transform = glm::mat4(1); - glm::mat4 scaler = glm::scale(transform, glm::vec3(0, 0, -1)); + glm::mat4 scale_n_z = glm::scale(transform, glm::vec3(1, 1, -1)); //earth needs to be rotated for that to work. - glm::mat4 rot_x = glm::rotate(transform, 270.f, glm::vec3(1, 0, 0)); - glm::mat4 rot_y = glm::rotate(transform, 90.f, glm::vec3(0, 1, 0)); + glm::mat4 rot_x = glm::rotate(transform, 180.f, glm::vec3(1, 0, 0)); + glm::mat4 rot_n_x = glm::rotate(transform, 90.f, glm::vec3(-1, 0, 0)); + + glm::mat4 rot_y = glm::rotate(transform, 90.f, glm::vec3(0, -1, 0)); glm::mat4 tmp = glm::mat4(1); @@ -344,17 +346,27 @@ void RenderableWavefrontObject::render(const RenderData& data) tmp[i][j] = _stateMatrix[i][j]; } } - //transform *= tmp; + + transform *= tmp; + //transform *= scale_n_z; + //transform *= rot_x; + //transform *= scale_n_z; + + + //transform *= rot_x; - //transform *= rot_y; glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); glm::vec4 camSpaceEye = -(modelview*currentPosition.vec4()); // setup the data to the shader // _programObject->setUniform("camdir", camSpaceEye); + + psc tmpPos = data.position; + //tmpPos[1] += 0.01;// move slightly to in x + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _programObject->setUniform("ModelTransform", transform); - setPscUniforms(_programObject, &data.camera, data.position); + setPscUniforms(_programObject, &data.camera, tmpPos); // Bind texture ghoul::opengl::TextureUnit unit; diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 4623406fc1..3f7a71e28f 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -75,7 +75,7 @@ void SpiceEphemeris::update(const UpdateData& data) { glm::dvec3 position(0,0,0); double lightTime = 0.0; - SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "NONE", data.time, position, lightTime); + SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "CN+S", data.time, position, lightTime); _position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z); _position[3] += 3; diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index 8990fbede4..27c274c7cc 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -40,7 +40,7 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen : _vaoID(0) , _vBufferID(0) , _iBufferID(0) - , _mode(GL_LINES) + , _mode(GL_TRIANGLES) , _isize(6 * segments * segments) , _vsize((segments + 1) * (segments + 1)) , _varray(new Vertex[_vsize]) From bd802c261f74a840b9ff31864f0ec615a11bf273 Mon Sep 17 00:00:00 2001 From: michal Date: Tue, 21 Oct 2014 13:44:44 -0400 Subject: [PATCH 09/16] ghoul submodule stuff --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index ba68d54517..999399a275 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit ba68d5451755ed20baccaf82dcb886186b5a1834 +Subproject commit 999399a27548c4adf5267d1569af4edb5f794658 From 3a8b2ac4a216b06ce6e0a0c05a02272926598582 Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 22 Oct 2014 15:19:15 -0400 Subject: [PATCH 10/16] smallchanges --- ext/ghoul | 2 +- openspace-data | 2 +- src/rendering/renderablefov.cpp | 17 +++-------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 999399a275..68c53264aa 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 999399a27548c4adf5267d1569af4edb5f794658 +Subproject commit 68c53264aaf05e1fc9526a857ac38db2d620557e diff --git a/openspace-data b/openspace-data index 918a182699..48d8d0c0c4 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 918a18269909336ef8f1a1ba9f2ee70d2c6042cb +Subproject commit 48d8d0c0c415012a9cb1969a2336d4d536c1391f diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index eb82fc0f6f..74b48023bc 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -105,7 +105,7 @@ void RenderableFov::fullYearSweep(){ } } tmat *= tmp; - tmat *= rot_x; + //tmat *= rot_x; std::string shape, name; shape.resize(32); @@ -116,8 +116,8 @@ void RenderableFov::fullYearSweep(){ bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds); glm::vec4 bsight_t(boresight[0], boresight[1], boresight[2], 1); - //psc bor = PowerScaledCoordinate::CreatePowerScaledCoordinate(boresight[0], boresight[1], boresight[2]); - bsight_t = tmat*bsight_t; + psc bor = PowerScaledCoordinate::CreatePowerScaledCoordinate(boresight[0], boresight[1], boresight[2]); + bsight_t = tmat*bor.vec4(); _varray.push_back(bsight_t[0]); _varray.push_back(bsight_t[1]); @@ -132,7 +132,6 @@ void RenderableFov::fullYearSweep(){ _iarray[1] = 1; - _stride = 8; _vsize = _varray.size(); _vtotal = static_cast(_vsize / _stride); @@ -203,16 +202,6 @@ void RenderableFov::render(const RenderData& data){ glm::mat4 camrot = data.camera.viewRotationMatrix(); glm::mat4 tmat = glm::mat4(1); - glm::mat4 rot_x = glm::rotate(tmat, 90.f, glm::vec3(1, 0, 0)); - - glm::mat4 tmp = glm::mat4(1); - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - tmp[i][j] = _stateMatrix[i][j]; - } - } - tmat *= tmp; - tmat *= rot_x; glm::mat4 transform(1); // setup the data to the shader From 5ece54cdc08ccbfd58aba00931b6a2fd827eedb9 Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 22 Oct 2014 16:09:05 -0400 Subject: [PATCH 11/16] openspace-data issue in sourcetree, pushing --- openspace-data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openspace-data b/openspace-data index 8607807557..48d8d0c0c4 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 8607807557c508d64a9d38bafa6f3cf771618490 +Subproject commit 48d8d0c0c415012a9cb1969a2336d4d536c1391f From 2dab6e41d5f07f1796c5870d3c210009f8afefc2 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 23 Oct 2014 11:37:22 -0400 Subject: [PATCH 12/16] begin merge with develop --- openspace-data | 2 +- shaders/generated/ABufferHeaders.hglsl | 2 ++ shaders/generated/ABufferSamplerCalls.hglsl | 0 shaders/generated/ABufferSamplers.hglsl | 0 shaders/generated/ABufferTransferFunctionVisualizer.hglsl | 3 +++ shaders/generated/constants.hglsl | 7 +++++++ 6 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 shaders/generated/ABufferHeaders.hglsl create mode 100644 shaders/generated/ABufferSamplerCalls.hglsl create mode 100644 shaders/generated/ABufferSamplers.hglsl create mode 100644 shaders/generated/ABufferTransferFunctionVisualizer.hglsl create mode 100644 shaders/generated/constants.hglsl diff --git a/openspace-data b/openspace-data index 48d8d0c0c4..fda98355cc 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 48d8d0c0c415012a9cb1969a2336d4d536c1391f +Subproject commit fda98355cc85718d1ed9a476a4c7289914e6c871 diff --git a/shaders/generated/ABufferHeaders.hglsl b/shaders/generated/ABufferHeaders.hglsl new file mode 100644 index 0000000000..9237cae1cf --- /dev/null +++ b/shaders/generated/ABufferHeaders.hglsl @@ -0,0 +1,2 @@ +#define MAX_VOLUMES 0 +#define MAX_TF 0 diff --git a/shaders/generated/ABufferSamplerCalls.hglsl b/shaders/generated/ABufferSamplerCalls.hglsl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shaders/generated/ABufferSamplers.hglsl b/shaders/generated/ABufferSamplers.hglsl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shaders/generated/ABufferTransferFunctionVisualizer.hglsl b/shaders/generated/ABufferTransferFunctionVisualizer.hglsl new file mode 100644 index 0000000000..6ae2cdcef8 --- /dev/null +++ b/shaders/generated/ABufferTransferFunctionVisualizer.hglsl @@ -0,0 +1,3 @@ +float showfunc_size = 20.0; +float SCREEN_HEIGHTf = float(SCREEN_HEIGHT); +float SCREEN_WIDTHf = float(SCREEN_WIDTH); diff --git a/shaders/generated/constants.hglsl b/shaders/generated/constants.hglsl new file mode 100644 index 0000000000..0daeff1d1d --- /dev/null +++ b/shaders/generated/constants.hglsl @@ -0,0 +1,7 @@ +#define SCREEN_WIDTH 1280 +#define SCREEN_HEIGHT 720 +#define MAX_LAYERS 32 +#define ABUFFER_SINGLE_LINKED 1 +#define ABUFFER_FIXED 2 +#define ABUFFER_DYNAMIC 3 +#define ABUFFER_IMPLEMENTATION ABUFFER_SINGLE_LINKED From ecfc4ad79a1b491666e6985f6c7962591f14e72d Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 23 Oct 2014 18:49:15 -0400 Subject: [PATCH 13/16] reshaping the modelloader class to suit the overall design of openspace --- .../openspace/rendering/model/modelgeometry.h | 53 ++++ .../rendering/model/renderablemodel.h | 75 +++++ .../rendering/model/wavefrontgeometry.h | 74 +++++ .../rendering/planets/renderableplanet.h | 1 - ...blewavefrontobject.h => renderablemodel.h} | 22 +- include/openspace/util/constants.h | 11 +- include/openspace/util/time.h | 12 + src/engine/openspaceengine.cpp | 2 +- src/interaction/interactionhandler.cpp | 7 +- src/rendering/model/modelgeometry.cpp | 79 ++++++ src/rendering/model/renderablemodel.cpp | 177 ++++++++++++ .../wavefrontgeometry.cpp} | 261 ++++++------------ src/rendering/planets/renderableplanet.cpp | 17 +- src/util/factorymanager.cpp | 20 +- src/util/time.cpp | 4 + 15 files changed, 601 insertions(+), 214 deletions(-) create mode 100644 include/openspace/rendering/model/modelgeometry.h create mode 100644 include/openspace/rendering/model/renderablemodel.h create mode 100644 include/openspace/rendering/model/wavefrontgeometry.h rename include/openspace/rendering/{renderablewavefrontobject.h => renderablemodel.h} (91%) create mode 100644 src/rendering/model/modelgeometry.cpp create mode 100644 src/rendering/model/renderablemodel.cpp rename src/rendering/{renderablewavefrontobject.cpp => model/wavefrontgeometry.cpp} (56%) diff --git a/include/openspace/rendering/model/modelgeometry.h b/include/openspace/rendering/model/modelgeometry.h new file mode 100644 index 0000000000..34c52afe0d --- /dev/null +++ b/include/openspace/rendering/model/modelgeometry.h @@ -0,0 +1,53 @@ +/***************************************************************************************** + * * + * 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 __MODELGEOMETRY_H__ +#define __MODELGEOMETRY_H__ + +#include +#include +#include + +namespace openspace { + +namespace modelgeometry { + +class ModelGeometry : public properties::PropertyOwner { +public: + static ModelGeometry* createFromDictionary(const ghoul::Dictionary& dictionary); + + ModelGeometry(); + virtual ~ModelGeometry(); + virtual bool initialize(RenderableModel* parent); + virtual void deinitialize(); + virtual void render() = 0; + +protected: + RenderableModel* _parent; +}; + +} // namespace modelgeometry +} // namespace openspace + +#endif // __MODELGEOMETRY_H__ diff --git a/include/openspace/rendering/model/renderablemodel.h b/include/openspace/rendering/model/renderablemodel.h new file mode 100644 index 0000000000..1a3fc0615c --- /dev/null +++ b/include/openspace/rendering/model/renderablemodel.h @@ -0,0 +1,75 @@ +/***************************************************************************************** +* * +* 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 __RENDERABLEMODEL_H__ +#define __RENDERABLEMODEL_H__ + +// open space includes +#include + +#include +#include + +// ghoul includes +#include +#include + +namespace openspace { + +namespace modelgeometry { +class ModelGeometry; +} + +class RenderableModel : public Renderable { +public: + RenderableModel(const ghoul::Dictionary& dictionary); + ~RenderableModel(); + + bool initialize() override; + bool deinitialize() override; + + void render(const RenderData& data) override; + void update(const UpdateData& data) override; + + +protected: + void loadTexture(); + +private: + properties::StringProperty _colorTexturePath; + ghoul::opengl::ProgramObject* _programObject; + ghoul::opengl::Texture* _texture; + + modelgeometry::ModelGeometry* _geometry; + + glm::dmat3 _stateMatrix; + + std::string _source; + std::string _destination; + +}; + +} // namespace openspace + +#endif // __RENDERABLEMODEL_H__ \ No newline at end of file diff --git a/include/openspace/rendering/model/wavefrontgeometry.h b/include/openspace/rendering/model/wavefrontgeometry.h new file mode 100644 index 0000000000..f0b4e43b4a --- /dev/null +++ b/include/openspace/rendering/model/wavefrontgeometry.h @@ -0,0 +1,74 @@ +/***************************************************************************************** +* * +* 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 __WAVEFRONTOBJECT_H__ +#define __WAVEFRONTOBJECT_H__ + +#include + +namespace openspace { + +class RenderableModel; + +namespace modelgeometry { + +class WavefrontGeometry : public ModelGeometry { +public: + WavefrontGeometry(const ghoul::Dictionary& dictionary); + ~WavefrontGeometry(); + + bool initialize(RenderableModel* parent) override; + void deinitialize() override; + void render() override; + /* + typedef struct + { + GLfloat location[4]; + GLfloat tex[2]; + GLfloat normal[3]; + //GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase + } Vertex; + */ + +protected: + //void loadObj(const char *filename); +private: + void createSphere(); + /* + GLuint _vaoID = 6; + GLuint _vBufferID = 7; + GLuint _iBufferID = 8; + + GLenum _mode; + unsigned int _isize; + unsigned int _vsize; + Vertex* _varray; + int* _iarray; + */ +}; + +} // namespace modelgeometry +} // namespace openspace + +#endif // __WAVEFRONTOBJECT_H__ diff --git a/include/openspace/rendering/planets/renderableplanet.h b/include/openspace/rendering/planets/renderableplanet.h index 668f16e10f..1ccae2a8c2 100644 --- a/include/openspace/rendering/planets/renderableplanet.h +++ b/include/openspace/rendering/planets/renderableplanet.h @@ -57,7 +57,6 @@ protected: private: properties::StringProperty _colorTexturePath; - ghoul::opengl::ProgramObject* _programObject; ghoul::opengl::Texture* _texture; planetgeometry::PlanetGeometry* _geometry; diff --git a/include/openspace/rendering/renderablewavefrontobject.h b/include/openspace/rendering/renderablemodel.h similarity index 91% rename from include/openspace/rendering/renderablewavefrontobject.h rename to include/openspace/rendering/renderablemodel.h index a82c7a66ae..ba23205fd9 100644 --- a/include/openspace/rendering/renderablewavefrontobject.h +++ b/include/openspace/rendering/renderablemodel.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __RENDERABLEWAVEFRONTOBJECT_H__ -#define __RENDERABLEWAVEFRONTOBJECT_H__ +#ifndef __RENDERABLEMODEL_H__ +#define __RENDERABLEMODEL_H__ // open space includes #include @@ -37,10 +37,14 @@ namespace openspace { -class RenderableWavefrontObject : public Renderable { +namespace modelgeometry { +class ModelGeometry; +} + +class RenderableModel : public Renderable { public: - RenderableWavefrontObject(const ghoul::Dictionary& dictionary); - ~RenderableWavefrontObject(); + RenderableModel(const ghoul::Dictionary& dictionary); + ~RenderableModel(); bool initialize() override; bool deinitialize() override; @@ -59,6 +63,8 @@ public: //GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase } Vertex; + + protected: void loadTexture(); void loadObj(const char *filename); @@ -67,9 +73,9 @@ private: properties::StringProperty _colorTexturePath; ghoul::opengl::ProgramObject* _programObject; ghoul::opengl::Texture* _texture; + modelgeometry::ModelGeometry* _geometry; - ghoul::opengl::ProgramObject* _fovProgram; - + float abc; GLuint _vaoID = 6; GLuint _vBufferID = 7; @@ -90,4 +96,4 @@ private: } // namespace openspace -#endif // __RENDERABLEWAVEFRONTOBJECT_H__ \ No newline at end of file +#endif // __RENDERABLEMODEL_H__ \ No newline at end of file diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 88d13a46b6..dc3b5fbbb7 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -67,17 +67,22 @@ namespace renderable { } // namespace renderable namespace renderableplanet { - const std::string keyGeometry = "Geometry"; const std::string keyFrame = "Frame"; + const std::string keyGeometry = "Geometry"; } // namespace renderableplanet namespace planetgeometry { const std::string keyType = "Type"; } // namespace planetgeometry -namespace renderablewavefrontobject { +namespace renderablemodel { + const std::string keyGeometry = "Geometry"; +} // namespace renderablemodel + +namespace modelgeometry { + const std::string keyType = "Type"; const std::string keyObjFile = "ObjFile"; -} // namespace renderableplanet +} // namespace modelgeometry namespace renderablestars { const std::string keySpeckFile = "SpeckFile"; diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 1735fa260e..910cffa8c7 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -134,6 +134,18 @@ public: */ double advanceTime(double tickTime); + /** + * Retreats the simulation time using the deltaTime() and the tickTime. + * The deltaTime() is the number of simulation seconds that pass for each real-time + * second. tickTime is the number of real-time seconds that passed since + * the last call to this method. If this method is called in the render loop, the + * tickTime should be equivalent to the frame time. + * \param tickTime The number of real-time seconds that passed since the last call + * to this method + * \return The new time value after retreating the time + */ + double retreatTime(double tickTime); + /** * Returns the Lua library that contains all Lua functions available to change the * current time, retrieve the current time etc. The functions contained are diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index c80e0dae14..dbdfe454de 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -409,7 +409,7 @@ void OpenSpaceEngine::preSynchronization() { _interactionHandler.update(dt); _interactionHandler.lockControls(); - Time::ref().advanceTime(dt); + //Time::ref().advanceTime(dt); } } diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 6d08d3762b..6562b19fb1 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -406,8 +406,11 @@ void InteractionHandler::keyboardCallback(int key, int action) { glm::quat rot = glm::quat(euler); orbit(rot); } - if (key == SGCT_KEY_Q) { - Time::ref().advanceTime(dt); + if (key == SGCT_KEY_Z) { + Time::ref().advanceTime(sgct::Engine::instance()->getDt()); + } + if (key == SGCT_KEY_X) { + Time::ref().retreatTime(sgct::Engine::instance()->getDt()); } if (key == 262) { glm::vec3 euler(0.0, speed * dt, 0.0); diff --git a/src/rendering/model/modelgeometry.cpp b/src/rendering/model/modelgeometry.cpp new file mode 100644 index 0000000000..c94bc31695 --- /dev/null +++ b/src/rendering/model/modelgeometry.cpp @@ -0,0 +1,79 @@ +/***************************************************************************************** + * * + * 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 +#include +#include +#include + +namespace { +const std::string _loggerCat = "ModelGeometry"; +} + +namespace openspace { +namespace modelgeometry { + +ModelGeometry* ModelGeometry::createFromDictionary(const ghoul::Dictionary& dictionary) +{ + std::string geometryType; + const bool success = dictionary.getValue( + constants::modelgeometry::keyType, geometryType); + if (!success) { + LERROR("ModelGeometry did not contain a correct value of the key '" + << constants::modelgeometry::keyType << "'"); + return nullptr; + } + ghoul::TemplateFactory* factory + = FactoryManager::ref().factory(); + + ModelGeometry* result = factory->create(geometryType, dictionary); + if (result == nullptr) { + LERROR("Failed to create a ModelGeometry object of type '" << geometryType + << "'"); + return nullptr; + } + return result; +} + +ModelGeometry::ModelGeometry() + : _parent(nullptr) +{ + setName("ModelGeometry"); +} + +ModelGeometry::~ModelGeometry() +{ +} + +bool ModelGeometry::initialize(RenderableModel* parent){ + _parent = parent; + return true; +} + + void ModelGeometry::deinitialize() +{ +} + +} // namespace planetgeometry +} // namespace openspace diff --git a/src/rendering/model/renderablemodel.cpp b/src/rendering/model/renderablemodel.cpp new file mode 100644 index 0000000000..d19cce054b --- /dev/null +++ b/src/rendering/model/renderablemodel.cpp @@ -0,0 +1,177 @@ +/***************************************************************************************** +* * +* 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. * +****************************************************************************************/ + +// temporary includes (will fix as soon as I figure out how class hierarchy should work, +// ie after I see model on screen) + +// open space includes +#include +#include +#include + + +#include +#include +#include + +#include +#include + +#include +#include + +namespace { +const std::string _loggerCat = "RenderableModel"; + const std::string keySource = "Rotation.Source"; + const std::string keyDestination = "Rotation.Destination"; +} + +namespace openspace { + +RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _colorTexturePath("colorTexture", "Color Texture") + , _programObject(nullptr) + , _texture(nullptr) + , _geometry(nullptr) +{ + std::string name; + bool success = dictionary.getValue(constants::scenegraphnode::keyName, name); + assert(success); + + std::string path; + success = dictionary.getValue(constants::scenegraph::keyPathModule, path); + assert(success); + + ghoul::Dictionary geometryDictionary; + success = dictionary.getValue( + constants::renderablemodel::keyGeometry, geometryDictionary); + if (success) { + geometryDictionary.setValue(constants::scenegraphnode::keyName, name); + geometryDictionary.setValue(constants::scenegraph::keyPathModule, path); + _geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary); + } + + std::string texturePath = ""; + success = dictionary.getValue("Textures.Color", texturePath); + if (success) + _colorTexturePath = path + "/" + texturePath; + + addPropertySubOwner(_geometry); + + addProperty(_colorTexturePath); + _colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this)); + + assert(dictionary.getValue(keySource, _source)); + assert(dictionary.getValue(keyDestination, _destination)); +} + + +RenderableModel::~RenderableModel(){ + deinitialize(); +} + +bool RenderableModel::initialize(){ + bool completeSuccess = true; + if (_programObject == nullptr) + completeSuccess + &= OsEng.ref().configurationManager().getValue("pscShader", _programObject); + + loadTexture(); + completeSuccess &= (_texture != nullptr); + completeSuccess &= _geometry->initialize(this); + + return completeSuccess; +} + +bool RenderableModel::deinitialize(){ + _geometry->deinitialize(); + delete _geometry; + _geometry = nullptr; + delete _texture; + _texture = nullptr; + return true; +} + +void RenderableModel::render(const RenderData& data) +{ + if (!_programObject) return; + if (!_texture) return; + + // activate shader + _programObject->activate(); + + + // scale the planet to appropriate size since the planet is a unit sphere + glm::mat4 transform = glm::mat4(1); + + glm::mat4 tmp = glm::mat4(1); + for (int i = 0; i < 3; i++){ + for (int j = 0; j < 3; j++){ + tmp[i][j] = _stateMatrix[i][j]; + } + } + + transform *= tmp; + + glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); + glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz; + // setup the data to the shader +// _programObject->setUniform("camdir", camSpaceEye); + + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); + _programObject->setUniform("ModelTransform", transform); + setPscUniforms(_programObject, &data.camera, data.position); + + // Bind texture + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _programObject->setUniform("texture1", unit); + + _geometry->render(); + + // disable shader + _programObject->deactivate(); +} + +void RenderableModel::update(const UpdateData& data){ + // set spice-orientation in accordance to timestamp + openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, data.time, _stateMatrix); + +} + +void RenderableModel::loadTexture() +{ + delete _texture; + _texture = nullptr; + if (_colorTexturePath.value() != "") { + _texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath)); + if (_texture) { + LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'"); + _texture->uploadTexture(); + } + } +} +} // namespace openspace diff --git a/src/rendering/renderablewavefrontobject.cpp b/src/rendering/model/wavefrontgeometry.cpp similarity index 56% rename from src/rendering/renderablewavefrontobject.cpp rename to src/rendering/model/wavefrontgeometry.cpp index 0436ffd000..fb99bea6b1 100644 --- a/src/rendering/renderablewavefrontobject.cpp +++ b/src/rendering/model/wavefrontgeometry.cpp @@ -21,79 +21,57 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - -// temporary includes (will fix as soon as I figure out how class hierarchy should work, -// ie after I see model on screen) #include -// open space includes -#include +#include #include - -#include -#include #include -#include -#include - -#include -#include namespace { -const std::string _loggerCat = "RenderableWavefrontObject"; - const std::string keySource = "Rotation.Source"; - const std::string keyDestination = "Rotation.Destination"; + const std::string _loggerCat = "WavefrontGeometry"; } namespace openspace { -RenderableWavefrontObject::RenderableWavefrontObject(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) - , _colorTexturePath("colorTexture", "Color Texture") - , _programObject(nullptr) - , _fovProgram(nullptr) - , _texture(nullptr) - , _mode(GL_TRIANGLES) - , _isize(0) - , _vsize(0) - , _varray(nullptr) - , _iarray(nullptr) +namespace modelgeometry { + +WavefrontGeometry::WavefrontGeometry(const ghoul::Dictionary& dictionary) + : ModelGeometry() + /*, _mode(GL_TRIANGLES) + , _isize(0) + , _vsize(0) + , _varray(nullptr) + , _iarray(nullptr)*/ { - std::string name; - assert(dictionary.getValue(constants::scenegraphnode::keyName, name)); - - std::string path; - assert(dictionary.getValue(constants::scenegraph::keyPathModule, path)); - - std::string texturePath = ""; - if (dictionary.hasKey("Textures.Color")) { - assert(dictionary.getValue("Textures.Color", texturePath)); - _colorTexturePath = path + "/" + texturePath; - } - - addProperty(_colorTexturePath); - _colorTexturePath.onChange(std::bind(&RenderableWavefrontObject::loadTexture, this)); + using constants::scenegraphnode::keyName; + // The name is passed down from the SceneGraphNode + std::string name; + bool success = dictionary.getValue(keyName, name); + assert(success); + /* std::string file; - assert(dictionary.getValue(constants::renderablewavefrontobject::keyObjFile, file)); + success = dictionary.getValue(constants::modelgeometry::keyObjFile, file); + if (!success) { + LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '" + << constants::modelgeometry::keyObjFile << "'"); + } const std::string filename = FileSys.absolutePath(file); - std::cout << "OBJECT LOADER FILENAME : " << filename << std::endl; - std::ifstream ifile(filename.c_str()); - if (ifile){ LDEBUG("Found file..\n"); ifile.close(); loadObj(filename.c_str()); - }else { + } + else { LERROR("Did not find file..\n"); } - assert(dictionary.getValue(keySource , _source)); - assert(dictionary.getValue(keyDestination , _destination)); -} -void RenderableWavefrontObject::loadObj(const char *filename){ + */ +} +/* +void WavefrontGeometry::loadObj(const char *filename){ // temporary int vertexSize = 0; int vertexNormalSize = 0; @@ -134,7 +112,6 @@ void RenderableWavefrontObject::loadObj(const char *filename){ } } } - /* END LINE COUNT */ // allocate memory for all arrays _isize = indicesSize; _vsize = indicesSize; @@ -246,39 +223,45 @@ void RenderableWavefrontObject::loadObj(const char *filename){ m++; } // free up memory - delete [] tempVertexArray; - delete [] tempVertexNormalArray; - delete [] tempNormalIndicesArray; - delete [] tempVertexTextureArray; - delete [] tempTextureIndicesArray; + delete[] tempVertexArray; + delete[] tempVertexNormalArray; + delete[] tempNormalIndicesArray; + delete[] tempVertexTextureArray; + delete[] tempTextureIndicesArray; +} +*/ + +WavefrontGeometry::~WavefrontGeometry(){ } -RenderableWavefrontObject::~RenderableWavefrontObject(){ - deinitialize(); -} - -bool RenderableWavefrontObject::initialize() -{ - if(_isize == 0) - return false; - - bool completeSuccess = true; - if (_programObject == nullptr) - completeSuccess - &= OsEng.ref().configurationManager().getValue("pscShader", _programObject); - - loadTexture(); - completeSuccess &= (_texture != nullptr); - //completeSuccess &= _geometry->initialize(this); - - PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1,7); - setBoundingSphere(ps); - +bool WavefrontGeometry::initialize(RenderableModel* parent){ + bool success = WavefrontGeometry::initialize(parent); + createSphere(); + /* + if (_isize == 0) return false; GLuint errorID; - glGenVertexArrays(1, &_vaoID); - glGenBuffers(1, &_vBufferID); - glGenBuffers(1, &_iBufferID); + if (_vaoID == 0) + glGenVertexArrays(1, &_vaoID); + + if (_vBufferID == 0) { + glGenBuffers(1, &_vBufferID); + + if (_vBufferID == 0) { + LERROR("Could not create vertex buffer"); + return false; + } + } + + if (_iBufferID == 0) { + glGenBuffers(1, &_iBufferID); + + if (_iBufferID == 0) { + LERROR("Could not create index buffer"); + return false; + } + } + glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); @@ -288,11 +271,11 @@ bool RenderableWavefrontObject::initialize() glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, location))); + reinterpret_cast(offsetof(Vertex, location))); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, tex))); + reinterpret_cast(offsetof(Vertex, tex))); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, normal))); + reinterpret_cast(offsetof(Vertex, normal))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW); @@ -303,120 +286,36 @@ bool RenderableWavefrontObject::initialize() LERROR("OpenGL error: " << glewGetErrorString(errorID)); return false; } - return completeSuccess; + */ + return success; } -bool RenderableWavefrontObject::deinitialize() -{ +void WavefrontGeometry::deinitialize(){ + /* delete[] _varray; delete[] _iarray; glDeleteBuffers(1, &_vBufferID); glDeleteBuffers(1, &_iBufferID); glDeleteVertexArrays(1, &_vaoID); - - delete _texture; - _texture = nullptr; - return true; + */ } -void RenderableWavefrontObject::render(const RenderData& data) -{ - if (!_programObject) - return; - if (!_texture) - return; - - // activate shader - _programObject->activate(); - - // fetch data - psc currentPosition = data.position; - psc campos = data.camera.position(); - glm::mat4 camrot = data.camera.viewRotationMatrix(); - // PowerScaledScalar scaling = camera->scaling(); - - - // scale the planet to appropriate size since the planet is a unit sphere - glm::mat4 transform = glm::mat4(1); - glm::mat4 scale_n_z = glm::scale(transform, glm::vec3(1, 1, -1)); - - //earth needs to be rotated for that to work. - glm::mat4 rot_x = glm::rotate(transform, 180.f, glm::vec3(1, 0, 0)); - glm::mat4 rot_n_x = glm::rotate(transform, 90.f, glm::vec3(-1, 0, 0)); - - glm::mat4 rot_y = glm::rotate(transform, 90.f, glm::vec3(0, -1, 0)); - - - glm::mat4 tmp = glm::mat4(1); - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - tmp[i][j] = _stateMatrix[i][j]; - } - } - - transform *= tmp; - //transform *= scale_n_z; - //transform *= rot_x; - //transform *= scale_n_z; - - - - //transform *= rot_x; - - glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); - glm::vec4 camSpaceEye = -(modelview*currentPosition.vec4()); - // setup the data to the shader -// _programObject->setUniform("camdir", camSpaceEye); - - psc tmpPos = data.position; - //tmpPos[1] += 0.01;// move slightly to in x - - _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); - _programObject->setUniform("ModelTransform", transform); - setPscUniforms(_programObject, &data.camera, tmpPos); - - // Bind texture - ghoul::opengl::TextureUnit unit; - unit.activate(); - _texture->bind(); - _programObject->setUniform("texture1", unit); - - // render +void WavefrontGeometry::render(){ + // render + /* glBindVertexArray(_vaoID); // select first VAO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); glDrawElements(_mode, _isize, GL_UNSIGNED_INT, 0); glBindVertexArray(0); - - // disable shader - _programObject->deactivate(); - - std::string shape, name; - shape.resize(32); - name.resize(32); - std::vector bounds; - glm::dvec3 boresight; + */ } -void RenderableWavefrontObject::update(const UpdateData& data) -{ - glm::dvec3 position(0, 0, 0); - // set spice-orientation in accordance to timestamp - openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, data.time, _stateMatrix); - -} - -void RenderableWavefrontObject::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 WavefrontGeometry::createSphere(){ + // create the power scaled scalar + PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1, 7); // will set proper bounding soon. + _parent->setBoundingSphere(ps); } +} // namespace modelgeometry } // namespace openspace diff --git a/src/rendering/planets/renderableplanet.cpp b/src/rendering/planets/renderableplanet.cpp index 4fe762c4ba..363bd4d0b5 100644 --- a/src/rendering/planets/renderableplanet.cpp +++ b/src/rendering/planets/renderableplanet.cpp @@ -82,13 +82,11 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) _colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this)); } -RenderablePlanet::~RenderablePlanet() -{ +RenderablePlanet::~RenderablePlanet(){ deinitialize(); } -bool RenderablePlanet::initialize() -{ +bool RenderablePlanet::initialize(){ bool completeSuccess = true; if (_programObject == nullptr) completeSuccess @@ -96,14 +94,12 @@ bool RenderablePlanet::initialize() loadTexture(); completeSuccess &= (_texture != nullptr); - completeSuccess &= _geometry->initialize(this); return completeSuccess; } -bool RenderablePlanet::deinitialize() -{ +bool RenderablePlanet::deinitialize(){ _geometry->deinitialize(); delete _geometry; _geometry = nullptr; @@ -114,10 +110,8 @@ bool RenderablePlanet::deinitialize() void RenderablePlanet::render(const RenderData& data) { - if (!_programObject) - return; - if (!_texture) - return; + if (!_programObject) return; + if (!_texture) return; // activate shader _programObject->activate(); @@ -155,7 +149,6 @@ void RenderablePlanet::render(const RenderData& data) // disable shader _programObject->deactivate(); - } void RenderablePlanet::update(const UpdateData& data){ diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index eb6769f644..650f11c357 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -27,7 +27,7 @@ #include // renderables -#include +#include #include #include #include @@ -47,6 +47,8 @@ #include #include +#include +#include namespace openspace { @@ -77,15 +79,16 @@ void FactoryManager::initialize() "RenderableFov"); _manager->factory()->registerClass( "RenderableSphericalGrid"); - _manager->factory()->registerClass( - "RenderableWavefrontObject"); + _manager->factory()->registerClass( + "RenderableModel"); //_manager->factory()->registerClass( // "RenderableVolumeCL"); _manager->factory()->registerClass( - "RenderablePlane"); + "RenderablePlane"); _manager->factory()->registerClass( - "RenderableVolumeGL"); - _manager->factory()->registerClass("RenderableFieldlines"); + "RenderableVolumeGL"); + _manager->factory()->registerClass( + "RenderableFieldlines"); // Add Ephimerides _manager->addFactory(new ghoul::TemplateFactory); @@ -96,6 +99,11 @@ void FactoryManager::initialize() _manager->addFactory(new ghoul::TemplateFactory); _manager->factory() ->registerClass("SimpleSphere"); + + // Add ModelGeometry + _manager->addFactory(new ghoul::TemplateFactory); + _manager->factory() + ->registerClass("WavefrontGeometry"); } void FactoryManager::deinitialize() diff --git a/src/util/time.cpp b/src/util/time.cpp index 38443ac42a..6e7f919dba 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -184,6 +184,10 @@ double Time::advanceTime(double tickTime) { return _time += _deltaTimePerSecond * tickTime; } +double Time::retreatTime(double tickTime) { + return _time -= _deltaTimePerSecond * tickTime; +} + void Time::setDeltaTime(double deltaT) { _deltaTimePerSecond = std::move(deltaT); } From 1e3a7a72f1958efceb69e63e8e9f3a3deee2212e Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 23 Oct 2014 18:49:54 -0400 Subject: [PATCH 14/16] openspace-data --- openspace-data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openspace-data b/openspace-data index fda98355cc..b561756350 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit fda98355cc85718d1ed9a476a4c7289914e6c871 +Subproject commit b561756350d903196265676df07f194b21461da4 From d3ea503454a38b88b3d2e44185e5d86ff29d3aab Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 23 Oct 2014 20:11:49 -0400 Subject: [PATCH 15/16] Fixes to the modelloader class --- .../rendering/model/wavefrontgeometry.h | 9 ++-- src/rendering/model/modelgeometry.cpp | 3 +- src/rendering/model/wavefrontgeometry.cpp | 52 +++++-------------- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/include/openspace/rendering/model/wavefrontgeometry.h b/include/openspace/rendering/model/wavefrontgeometry.h index f0b4e43b4a..1a13d8030c 100644 --- a/include/openspace/rendering/model/wavefrontgeometry.h +++ b/include/openspace/rendering/model/wavefrontgeometry.h @@ -41,7 +41,7 @@ public: bool initialize(RenderableModel* parent) override; void deinitialize() override; void render() override; - /* + typedef struct { GLfloat location[4]; @@ -49,13 +49,13 @@ public: GLfloat normal[3]; //GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase } Vertex; - */ + protected: - //void loadObj(const char *filename); + void loadObj(const char *filename); private: void createSphere(); - /* + GLuint _vaoID = 6; GLuint _vBufferID = 7; GLuint _iBufferID = 8; @@ -65,7 +65,6 @@ private: unsigned int _vsize; Vertex* _varray; int* _iarray; - */ }; } // namespace modelgeometry diff --git a/src/rendering/model/modelgeometry.cpp b/src/rendering/model/modelgeometry.cpp index c94bc31695..d942c3cfe5 100644 --- a/src/rendering/model/modelgeometry.cpp +++ b/src/rendering/model/modelgeometry.cpp @@ -70,10 +70,9 @@ bool ModelGeometry::initialize(RenderableModel* parent){ _parent = parent; return true; } - void ModelGeometry::deinitialize() { } -} // namespace planetgeometry +} // namespace modelgeometry } // namespace openspace diff --git a/src/rendering/model/wavefrontgeometry.cpp b/src/rendering/model/wavefrontgeometry.cpp index fb99bea6b1..aaf18196cf 100644 --- a/src/rendering/model/wavefrontgeometry.cpp +++ b/src/rendering/model/wavefrontgeometry.cpp @@ -37,11 +37,11 @@ namespace modelgeometry { WavefrontGeometry::WavefrontGeometry(const ghoul::Dictionary& dictionary) : ModelGeometry() - /*, _mode(GL_TRIANGLES) + , _mode(GL_TRIANGLES) , _isize(0) , _vsize(0) , _varray(nullptr) - , _iarray(nullptr)*/ + , _iarray(nullptr) { using constants::scenegraphnode::keyName; @@ -49,7 +49,7 @@ WavefrontGeometry::WavefrontGeometry(const ghoul::Dictionary& dictionary) std::string name; bool success = dictionary.getValue(keyName, name); assert(success); - /* + std::string file; success = dictionary.getValue(constants::modelgeometry::keyObjFile, file); if (!success) { @@ -67,10 +67,8 @@ WavefrontGeometry::WavefrontGeometry(const ghoul::Dictionary& dictionary) else { LERROR("Did not find file..\n"); } - - */ } -/* + void WavefrontGeometry::loadObj(const char *filename){ // temporary int vertexSize = 0; @@ -229,39 +227,19 @@ void WavefrontGeometry::loadObj(const char *filename){ delete[] tempVertexTextureArray; delete[] tempTextureIndicesArray; } -*/ + WavefrontGeometry::~WavefrontGeometry(){ } bool WavefrontGeometry::initialize(RenderableModel* parent){ - bool success = WavefrontGeometry::initialize(parent); + bool success = ModelGeometry::initialize(parent); createSphere(); - /* + if (_isize == 0) return false; - - GLuint errorID; - if (_vaoID == 0) - glGenVertexArrays(1, &_vaoID); - - if (_vBufferID == 0) { - glGenBuffers(1, &_vBufferID); - - if (_vBufferID == 0) { - LERROR("Could not create vertex buffer"); - return false; - } - } - - if (_iBufferID == 0) { - glGenBuffers(1, &_iBufferID); - - if (_iBufferID == 0) { - LERROR("Could not create index buffer"); - return false; - } - } - + glGenVertexArrays(1, &_vaoID); + glGenBuffers(1, &_vBufferID); + glGenBuffers(1, &_iBufferID); glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); @@ -281,39 +259,35 @@ bool WavefrontGeometry::initialize(RenderableModel* parent){ glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW); glBindVertexArray(0); - errorID = glGetError(); + GLint errorID = glGetError(); if (errorID != GL_NO_ERROR) { LERROR("OpenGL error: " << glewGetErrorString(errorID)); return false; } - */ return success; } void WavefrontGeometry::deinitialize(){ - /* delete[] _varray; delete[] _iarray; glDeleteBuffers(1, &_vBufferID); glDeleteBuffers(1, &_iBufferID); glDeleteVertexArrays(1, &_vaoID); - */ + } void WavefrontGeometry::render(){ // render - /* glBindVertexArray(_vaoID); // select first VAO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); glDrawElements(_mode, _isize, GL_UNSIGNED_INT, 0); glBindVertexArray(0); - */ } void WavefrontGeometry::createSphere(){ // create the power scaled scalar - PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1, 7); // will set proper bounding soon. + PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1, 0); // will set proper bounding soon. _parent->setBoundingSphere(ps); } From 51c8034fe9550760a2283b765a8e3c8ef92cfc48 Mon Sep 17 00:00:00 2001 From: michal Date: Fri, 24 Oct 2014 21:45:49 -0400 Subject: [PATCH 16/16] boresight works. --- openspace-data | 2 +- scripts/default_startup.lua | 6 +- src/rendering/model/wavefrontgeometry.cpp | 8 +- src/rendering/renderablefov.cpp | 134 +++++++++++----------- src/rendering/renderabletrail.cpp | 2 +- 5 files changed, 76 insertions(+), 76 deletions(-) diff --git a/openspace-data b/openspace-data index b561756350..b8179a6d15 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit b561756350d903196265676df07f194b21461da4 +Subproject commit b8179a6d15943315cc7f21dd4daca90e31e40d8c diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index c382648263..b55e7f337e 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,10 +1,10 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') -openspace.time.setTime("2007-02-26T17:41:00") +openspace.time.setTime("2007-02-26T17:30:00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) --openspace.time.setDeltaTime(5000.00) -openspace.time.setDeltaTime(1000) ---openspace.time.setDeltaTime(30000.0) +--openspace.time.setDeltaTime(864000) +openspace.time.setDeltaTime(100.0) -- print(openspace.time.currentTimeUTC()) diff --git a/src/rendering/model/wavefrontgeometry.cpp b/src/rendering/model/wavefrontgeometry.cpp index aaf18196cf..bc38ebb47e 100644 --- a/src/rendering/model/wavefrontgeometry.cpp +++ b/src/rendering/model/wavefrontgeometry.cpp @@ -162,15 +162,15 @@ void WavefrontGeometry::loadObj(const char *filename){ if (sscanf(line, "f %i/%i/%i %i/%i/%i %i/%i/%i", &i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9)){ (_iarray)[m] = i1 - 1; (tempTextureIndicesArray)[m] = i2 - 1; - (tempNormalIndicesArray)[m] = i3 - 1; + (tempNormalIndicesArray)[m] = i3 - 1; m++; (_iarray)[m] = i4 - 1; (tempTextureIndicesArray)[m] = i5 - 1; - (tempNormalIndicesArray)[m] = i6 - 1; + (tempNormalIndicesArray)[m] = i6 - 1; m++; (_iarray)[m] = i7 - 1; (tempTextureIndicesArray)[m] = i8 - 1; - (tempNormalIndicesArray)[m] = i9 - 1; + (tempNormalIndicesArray)[m] = i9 - 1; m++; } } @@ -206,7 +206,7 @@ void WavefrontGeometry::loadObj(const char *filename){ int q = 0; while (q < 3){ _varray[m].location[q] = tempVertexArray[vertexIndex + q]; - _varray[m].normal[q] = tempVertexNormalArray[normalIndex + q]; + _varray[m].normal[q] = tempVertexNormalArray[normalIndex + q]; q++; } diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index 74b48023bc..bb59e2a9c7 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -67,70 +67,21 @@ namespace openspace{ } } void RenderableFov::fullYearSweep(){ - double lightTime = 0.0; - - double et = _startTrail; - double planetYear = 31540000; - int segments = 2; - - _increment = planetYear / 4; - _isize = (segments); - _vsize = (segments); + int points = 8; + _stride = 8; + _isize = points; _iarray = new int[_isize]; - - SpiceManager::ref().getTargetState("NEW HORIZONS", "SUN", "GALACTIC", "LT+S", et, _pscpos, _pscvel, lightTime); - _pscpos[3] += 3; - _varray.push_back(_pscpos[0]); - _varray.push_back(_pscpos[1]); - _varray.push_back(_pscpos[2]); - _varray.push_back(_pscpos[3]); - - _varray.push_back(1.f ); - _varray.push_back(0.f ); - _varray.push_back(0.f ); - _varray.push_back(1.f ); - - _iarray[0] = 0; - - glm::mat4 tmat = glm::mat4(1); - glm::mat4 rot_x = glm::rotate(tmat, 90.f, glm::vec3(1, 0, 0)); - openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", et, _stateMatrix); - - glm::mat4 tmp = glm::mat4(1); - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - tmp[i][j] = _stateMatrix[i][j]; + for (int i = 0; i < points; i++){ + for (int j = 0; j < 4; j++){ + _varray.push_back(0); // pos } + for (int j = 0; j < 4; j++){ + _varray.push_back(0); // col + } + _iarray[i] = i; } - tmat *= tmp; - //tmat *= rot_x; - - std::string shape, name; - shape.resize(32); - name.resize(32); - std::vector bounds; - glm::dvec3 boresight; - - bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds); - glm::vec4 bsight_t(boresight[0], boresight[1], boresight[2], 1); - - psc bor = PowerScaledCoordinate::CreatePowerScaledCoordinate(boresight[0], boresight[1], boresight[2]); - bsight_t = tmat*bor.vec4(); - - _varray.push_back(bsight_t[0]); - _varray.push_back(bsight_t[1]); - _varray.push_back(bsight_t[2]); - _varray.push_back(2); - - _varray.push_back(1.f); - _varray.push_back(0.f); - _varray.push_back(0.f); - _varray.push_back(1.f); - - _iarray[1] = 1; - _stride = 8; _vsize = _varray.size(); @@ -169,8 +120,7 @@ void RenderableFov::sendToGPU(){ bool RenderableFov::initialize(){ bool completeSuccess = true; if (_programObject == nullptr) - completeSuccess - &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject); + completeSuccess &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject); _startTrail; SpiceManager::ref().getETfromDate("2007 feb 26 20:00:00", _startTrail); @@ -197,19 +147,69 @@ void RenderableFov::render(const RenderData& data){ _programObject->activate(); // fetch data - psc currentPosition = data.position; - psc campos = data.camera.position(); - glm::mat4 camrot = data.camera.viewRotationMatrix(); - glm::mat4 tmat = glm::mat4(1); glm::mat4 transform(1); + + glm::mat4 tmp = glm::mat4(1); + glm::mat4 rot = glm::rotate(transform, 90.f, glm::vec3(0, 1, 0)); + + for (int i = 0; i < 3; i++){ + for (int j = 0; j < 3; j++){ + tmp[i][j] = _stateMatrix[i][j]; + } + } + transform = tmp*rot; + // setup the data to the shader _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _programObject->setUniform("ModelTransform", transform); setPscUniforms(_programObject, &data.camera, data.position); - //updateData(); + + //boresight vector + std::string shape, name; + shape.resize(32); + name.resize(32); + std::vector bounds; + glm::dvec3 boresight; + + bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds); + + float size = 4 * sizeof(float); + float *begin = &_varray[0]; + + glm::vec4 origin(0); + glm::vec4 col_start(1.00, 0.89, 0.00, 1); + glm::vec4 col_end(1.00, 0.29, 0.00, 1); + glm::vec4 bsight_t(boresight[0], boresight[1], boresight[2], data.position[3]-3); + + float sc = 2.2; + glm::vec4 corner1(bounds[0][0], bounds[0][1], bounds[0][2], data.position[3]-sc); + memcpy(begin, glm::value_ptr(origin), size); + memcpy(begin + 4, glm::value_ptr(col_start), size); + memcpy(begin + 8, glm::value_ptr(corner1), size); + memcpy(begin + 12, glm::value_ptr(col_end), size); + + glm::vec4 corner2(bounds[1][0], bounds[1][1], bounds[1][2], data.position[3]-sc); + memcpy(begin + 16, glm::value_ptr(origin), size); + memcpy(begin + 20, glm::value_ptr(col_start), size); + memcpy(begin + 24, glm::value_ptr(corner2), size); + memcpy(begin + 28, glm::value_ptr(col_end), size); + + glm::vec4 corner3(bounds[2][0], bounds[2][1], bounds[2][2], data.position[3]-sc); + memcpy(begin + 32, glm::value_ptr(origin), size); + memcpy(begin + 36, glm::value_ptr(col_start), size); + memcpy(begin + 40, glm::value_ptr(corner3), size); + memcpy(begin + 44, glm::value_ptr(col_end), size); + + glm::vec4 corner4(bounds[3][0], bounds[3][1], bounds[3][2], data.position[3]-sc); + memcpy(begin + 48, glm::value_ptr(origin), size); + memcpy(begin + 52, glm::value_ptr(col_start), size); + memcpy(begin + 56, glm::value_ptr(corner4), size); + memcpy(begin + 60, glm::value_ptr(col_end), size); + + updateData(); glBindVertexArray(_vaoID); glDrawArrays(_mode, 0, _vtotal); @@ -223,7 +223,7 @@ void RenderableFov::update(const UpdateData& data){ _time = data.time; _delta = data.delta; - //openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix); + openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix); } void RenderableFov::loadTexture() diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 89118e64f2..9637a86ef9 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -172,7 +172,7 @@ bool RenderableTrail::initialize(){ _startTrail; // SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail); - SpiceManager::ref().getETfromDate("2007 feb 26 17:41:00", _startTrail); + SpiceManager::ref().getETfromDate("2007 feb 26 17:30:00", _startTrail); _dtEt = _startTrail; fullYearSweep();