From d368ad9054fa9c922bd2f4e8109b5320b596ae0e Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Tue, 14 Jun 2016 13:33:55 -0400 Subject: [PATCH 1/2] Correct coordinate transformation --- modules/iswa/rendering/datasphere.cpp | 5 ++++ modules/iswa/rendering/iswacygnet.cpp | 3 ++- modules/iswa/rendering/iswacygnet.h | 2 ++ src/util/transformationmanager.cpp | 35 +++------------------------ 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/modules/iswa/rendering/datasphere.cpp b/modules/iswa/rendering/datasphere.cpp index b704be05c7..8184530338 100644 --- a/modules/iswa/rendering/datasphere.cpp +++ b/modules/iswa/rendering/datasphere.cpp @@ -43,6 +43,8 @@ DataSphere::DataSphere(const ghoul::Dictionary& dictionary) _programName = "DataSphereProgram"; _vsPath = "${MODULE_ISWA}/shaders/datasphere_vs.glsl"; _fsPath = "${MODULE_ISWA}/shaders/datasphere_fs.glsl"; + + } DataSphere::~DataSphere(){} @@ -50,6 +52,9 @@ DataSphere::~DataSphere(){} bool DataSphere::initialize(){ IswaCygnet::initialize(); + //rotate 90 degrees because of the texture coordinates in PowerScaledSphere + _rotation = glm::rotate(_rotation, (float)M_PI_2, glm::vec3(1.0, 0.0, 0.0)); + if(_group){ _dataProcessor = _group->dataProcessor(); subscribeToGroup(); diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index f5c9e4e92a..a1afa13653 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -42,6 +42,7 @@ IswaCygnet::IswaCygnet(const ghoul::Dictionary& dictionary) , _shader(nullptr) , _group(nullptr) , _textureDirty(false) + , _rotation(glm::mat4(1.0f)) { std::string name; dictionary.getValue("Name", name); @@ -146,12 +147,12 @@ void IswaCygnet::render(const RenderData& data){ psc position = data.position; glm::mat4 transform = glm::mat4(1.0); - glm::mat4 rot = glm::mat4(1.0); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ transform[i][j] = static_cast(_stateMatrix[i][j]); } } + transform = transform*_rotation; position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.w); diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 6040f26f99..c123aa5c22 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -142,6 +142,7 @@ protected: std::string _fsPath; std::string _programName; + glm::mat4 _rotation; //to rotate objects with fliped texture coordniates private: bool destroyShader(); glm::dmat3 _stateMatrix; @@ -152,6 +153,7 @@ private: std::chrono::milliseconds _realTime; std::chrono::milliseconds _lastUpdateRealTime; int _minRealTimeUpdateInterval; + }; }//namespace openspace diff --git a/src/util/transformationmanager.cpp b/src/util/transformationmanager.cpp index 3b5448baf0..eee4aefb48 100644 --- a/src/util/transformationmanager.cpp +++ b/src/util/transformationmanager.cpp @@ -39,11 +39,9 @@ #else LWARNING("Kameleon module needed for transformations with dynamic frames"); #endif - _kameleonFrames = { "J2000", "GEI", "GEO", "MAG", "GSE", "GSM", "SM", "RTN", "GSEQ", //geocentric "HEE", "HAE", "HEEQ" //heliocentric }; - // _dipoleFrames = {"GSM", "MAG"}; } TransformationManager::~TransformationManager(){ @@ -68,15 +66,11 @@ _kameleon->_cxform(from.c_str(), to.c_str(), ephemerisTime, &in1, &out1); _kameleon->_cxform(from.c_str(), to.c_str(), ephemerisTime, &in2, &out2); - glm::dmat3 out = glm::dmat3( + return glm::dmat3( out0.c0 , out0.c1 , out0.c2, out1.c0 , out1.c1 , out1.c2, out2.c0 , out2.c1 , out2.c2 - ); - - // Need to rotate 90 degrees around x-axis becuase kameleon is flipped - out = glm::dmat3(glm::rotate(glm::mat4(out), (float)M_PI_2, glm::vec3(1.0f, 0.0f, 0.0f))); - return out; + );; } glm::dmat3 TransformationManager::frameTransformationMatrix(std::string from, @@ -84,32 +78,11 @@ double ephemerisTime) const { #ifdef OPENSPACE_MODULE_KAMELEON_ENABLED - auto fromit = _dipoleFrames.find(from); - auto toit = _dipoleFrames.find(to); - - // //diopole frame to J200 makes the frame rotate. - // if(fromit != _dipoleFrames.end()) from = "GSE"; - // if(toit != _dipoleFrames.end()) to = "GSE"; - - fromit = _kameleonFrames.find(from); - toit = _kameleonFrames.find(to); + auto fromit = _kameleonFrames.find(from); + auto toit = _kameleonFrames.find(to); bool fromKameleon = (fromit != _kameleonFrames.end()); bool toKameleon = (toit != _kameleonFrames.end()); - - ccmc::Position in0 = {1.f, 0.f, 0.f}; - ccmc::Position in1 = {0.f, 1.f, 0.f}; - ccmc::Position in2 = {0.f, 0.f, 1.f}; - - glm::dmat3 in( - in0.c0, in0.c1, in0.c2, - in1.c0, in1.c1, in1.c2, - in2.c0, in2.c1, in2.c2 - ); - - ccmc::Position out0; - ccmc::Position out1; - ccmc::Position out2; if(!fromKameleon && !toKameleon){ return SpiceManager::ref().frameTransformationMatrix(from, to, ephemerisTime); From 294773b2cb96d0cd0f1ad653387dd54776058cb8 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Tue, 14 Jun 2016 13:53:24 -0400 Subject: [PATCH 2/2] Updated shaders --- modules/iswa/rendering/textureplane.cpp | 4 ++-- modules/iswa/shaders/dataplane_fs.glsl | 4 ++-- .../{cygnetplane_fs.glsl => textureplane_fs.glsl} | 14 +------------- .../{cygnetplane_vs.glsl => textureplane_vs.glsl} | 0 4 files changed, 5 insertions(+), 17 deletions(-) rename modules/iswa/shaders/{cygnetplane_fs.glsl => textureplane_fs.glsl} (87%) rename modules/iswa/shaders/{cygnetplane_vs.glsl => textureplane_vs.glsl} (100%) diff --git a/modules/iswa/rendering/textureplane.cpp b/modules/iswa/rendering/textureplane.cpp index 777dac2c1a..6276fb9900 100644 --- a/modules/iswa/rendering/textureplane.cpp +++ b/modules/iswa/rendering/textureplane.cpp @@ -37,8 +37,8 @@ TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary) ,_vertexPositionBuffer(0) { _programName = "PlaneProgram"; - _vsPath = "${MODULE_ISWA}/shaders/cygnetplane_vs.glsl"; - _fsPath = "${MODULE_ISWA}/shaders/cygnetplane_fs.glsl"; + _vsPath = "${MODULE_ISWA}/shaders/textureplane_vs.glsl"; + _fsPath = "${MODULE_ISWA}/shaders/textureplane_fs.glsl"; } TexturePlane::~TexturePlane(){} diff --git a/modules/iswa/shaders/dataplane_fs.glsl b/modules/iswa/shaders/dataplane_fs.glsl index 58f45b1052..7307cf0e6e 100644 --- a/modules/iswa/shaders/dataplane_fs.glsl +++ b/modules/iswa/shaders/dataplane_fs.glsl @@ -55,7 +55,7 @@ Fragment getFragment() { if((numTransferFunctions == 1) || (numTextures > numTransferFunctions)){ for(int i=0; i(x-y)) color = transparent; diff --git a/modules/iswa/shaders/cygnetplane_fs.glsl b/modules/iswa/shaders/textureplane_fs.glsl similarity index 87% rename from modules/iswa/shaders/cygnetplane_fs.glsl rename to modules/iswa/shaders/textureplane_fs.glsl index a08658ee89..d290d159c3 100644 --- a/modules/iswa/shaders/cygnetplane_fs.glsl +++ b/modules/iswa/shaders/textureplane_fs.glsl @@ -36,19 +36,7 @@ Fragment getFragment() { vec4 position = vs_position; float depth = pscDepth(position); vec4 diffuse; - diffuse = texture(texture1, vec2(vs_st.s, 1-vs_st.t)); - - //vec4 diffuse = vec4(1,vs_st,1); - //vec4 diffuse = vec4(1,0,0,1); - // if(position.w > 9.0) { - // diffuse = vec4(1,0,0,1); - // } - - //diffuse.a = diffuse.r; - float tot = diffuse.r + diffuse.g + diffuse.b; - tot /= 3.0; - if (tot >= 0.5 || tot <= 0.05) - discard; + diffuse = texture(texture1, vs_st); diffuse.a *= transparency; diff --git a/modules/iswa/shaders/cygnetplane_vs.glsl b/modules/iswa/shaders/textureplane_vs.glsl similarity index 100% rename from modules/iswa/shaders/cygnetplane_vs.glsl rename to modules/iswa/shaders/textureplane_vs.glsl