From 6bea32615137e84aeed7fcab58a55811df29ff72 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 16 Mar 2016 09:09:22 -0400 Subject: [PATCH] Correct euclidean to spherical conversion --- modules/base/rendering/screenspaceimage.cpp | 49 ++++++++++++++------- src/rendering/screenspacerenderable.cpp | 2 +- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/modules/base/rendering/screenspaceimage.cpp b/modules/base/rendering/screenspaceimage.cpp index e8648485e0..b9e05ba118 100644 --- a/modules/base/rendering/screenspaceimage.cpp +++ b/modules/base/rendering/screenspaceimage.cpp @@ -64,22 +64,22 @@ void ScreenSpaceImage::render(Camera* camera){ float occlusionDepth = position.z; glm::mat4 modelTransform; + position.z = _planeDepth; if(!_isFlatScreen){ occlusionDepth = position.x; - position.x = _planeDepth; - - glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), position.z, glm::vec3(0.0f, 1.0f, 0.0f)); - rotation = glm::rotate(rotation, position.y , glm::vec3(1.0f, 0.0f, 0.0f)); - glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, position.x)); + // position.x = _planeDepth; + float phi = position.y - M_PI/2.0; + glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), position.x, glm::vec3(0.0f, 1.0f, 0.0f)); + rotation = glm::rotate(rotation, phi , glm::vec3(1.0f, 0.0f, 0.0f)); + glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, _planeDepth)); modelTransform = rotation * translate; } else { - position.z = _planeDepth; modelTransform = glm::translate(glm::mat4(1.f), position); - modelTransform = glm::scale(modelTransform, glm::vec3(_scale.value()*scalingRatioY, _scale.value()*textureRatio*scalingRatioX, 1)); } + modelTransform = glm::scale(modelTransform, glm::vec3(_scale.value()*scalingRatioY, _scale.value()*textureRatio*scalingRatioX, 1)); glEnable(GL_DEPTH_TEST); _shader->activate(); @@ -131,23 +131,42 @@ void ScreenSpaceImage::update(){ _position.set(toPolar(pos)); } else { _position.set(toEuclidean(pos)); + } } } glm::vec3 ScreenSpaceImage::toEuclidean(glm::vec3 polar){ - float x = polar[0]*cos(polar[1])*sin(polar[2]); - float y = polar[0]*sin(polar[1])*sin(polar[2]); - float z = polar[0]*cos(polar[2]); + float x = polar[2]*sin(polar[0])*sin(polar[1]); + float y = polar[2]*cos(polar[1]); + float z = _planeDepth; return glm::vec3(x, y, z); } -glm::vec3 ScreenSpaceImage::toPolar(glm::vec3 euclidean){ - float r = sqrt(pow(euclidean[0], 2) + pow(euclidean[1], 2) + pow(euclidean[2], 2)); - float theta= atan2(euclidean[1],euclidean[0]); - float phi = acos(euclidean[2]/r); - return glm::vec3(r, theta, phi); +glm::vec3 ScreenSpaceImage::toPolar(glm::vec3 euclidean){ + float r = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2)); + float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0; + float phi = acos(euclidean[1]/r); + + while(phi>=M_PI){ + phi -= M_PI; + } + + if(!r){ + phi = 0; + } + + while(theta <= 0){ + theta += 2.0*M_PI; + } + + while(theta >= 2.0*M_PI) { + theta -= 2.0*M_PI; + } + + // std::cout << euclidean[2] << " " << r + return glm::vec3(theta, phi, r); } diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index e9c1544c1d..73380d48aa 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -28,7 +28,7 @@ namespace openspace { ScreenSpaceRenderable::ScreenSpaceRenderable(std::string texturePath) : _enabled("enabled", "Is Enabled", true) , _flatScreen("flatScreen", "Flat Screen", false) - , _position("position", "Position", glm::vec3(0,0,-2),glm::vec3(-2,-2, -1),glm::vec3(2, 2, 0)) + , _position("position", "Position", glm::vec3(0),glm::vec3(-4),glm::vec3(4)) , _scale("scale", "Scale" , 0.5, 0, 1) , _texturePath("texturePath", "Texture path", texturePath) , _quad(0)