From 1cc438440445274fada0645c996fe23c6b81e4c2 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 7 Apr 2015 17:13:30 +0200 Subject: [PATCH] Add new frame of reference for cursor --- interface/src/ui/ApplicationOverlay.cpp | 21 +++++++++++++++++++++ interface/src/ui/ApplicationOverlay.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 7fc3ba170d..e11b46ad95 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -1125,6 +1126,26 @@ void ApplicationOverlay::TexturedHemisphere::render() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } +glm::vec2 ApplicationOverlay::directionToSpherical(glm::vec3 direction) const { + glm::vec2 result; + // Compute yaw + glm::vec3 normalProjection = glm::normalize(glm::vec3(direction.x, 0.0f, direction.z)); + result.x = glm::acos(glm::dot(IDENTITY_FRONT, normalProjection)); + if (glm::dot(IDENTITY_RIGHT, normalProjection) > 0.0f) { + result.x = -glm::abs(result.x); + } else { + result.x = glm::abs(result.x); + } + // Compute pitch + result.y = angleBetween(IDENTITY_UP, direction) - PI_OVER_TWO; + + return result; +} + +glm::vec3 ApplicationOverlay::sphericalToDirection(glm::vec2 sphericalPos) const { + glm::quat rotation(glm::vec3(sphericalPos.y, sphericalPos.x, 0.0f)); + return rotation * IDENTITY_FRONT; +} glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const { QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 58b79adcda..cc424d0c8f 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -45,11 +45,14 @@ public: // Converter from one frame of reference to another. // Frame of reference: + // Direction: Ray that represents the spherical values // Screen: Position on the screen (x,y) // Spherical: Pitch and yaw that gives the position on the sphere we project on (yaw,pitch) // Overlay: Position on the overlay (x,y) // (x,y) in Overlay are similar than (x,y) in Screen except they can be outside of the bound of te screen. // This allows for picking outside of the screen projection in 3D. + glm::vec2 directionToSpherical(glm::vec3 direction) const; + glm::vec3 sphericalToDirection(glm::vec2 sphericalPos) const; glm::vec2 screenToSpherical(glm::vec2 screenPos) const; glm::vec2 sphericalToScreen(glm::vec2 sphericalPos) const; glm::vec2 sphericalToOverlay(glm::vec2 sphericalPos) const;