Add new frame of reference for cursor

This commit is contained in:
Atlante45 2015-04-07 17:13:30 +02:00
parent ae6ee54569
commit 1cc4384404
2 changed files with 24 additions and 0 deletions

View file

@ -14,6 +14,7 @@
#include <QOpenGLFramebufferObject>
#include <avatar/AvatarManager.h>
#include <GLMHelpers.h>
#include <PathUtils.h>
#include <PerfStat.h>
@ -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();

View file

@ -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;