Updated Oculus pickray

This commit is contained in:
Atlante45 2014-12-03 17:05:42 -08:00
parent bd39688c62
commit 8d814ab07b

View file

@ -161,23 +161,21 @@ void ApplicationOverlay::displayOverlayTexture() {
} }
void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direction) const { void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direction) const {
MyAvatar* myAvatar = Application::getInstance()->getAvatar(); static const float MOUSE_PITCH_RANGE = 1.0f * PI;
static const float MOUSE_YAW_RANGE = 0.5f * TWO_PI;
//invert y direction const MyAvatar* myAvatar = Application::getInstance()->getAvatar();
y = 1.0 - y; const GLCanvas* glWidget = Application::getInstance()->getGLWidget();
const int widgetWidth = glWidget->width();
//Get position on hemisphere UI const int widgetHeight = glWidget->height();
x = sin((x - 0.5f) * _textureFov);
y = sin((y - 0.5f) * _textureFov); const float pitch = -(y / widgetHeight - 0.5f) * MOUSE_PITCH_RANGE;
const float yaw = -(x / widgetWidth - 0.5f) * MOUSE_YAW_RANGE;
float dist = sqrt(x * x + y * y); const glm::quat orientation(glm::vec3(pitch, yaw, 0.0f));
float z = -sqrt(1.0f - dist * dist); const glm::vec3 localDirection = orientation * IDENTITY_FRONT;
glm::vec3 relativePosition = myAvatar->getDefaultEyePosition() +
glm::normalize(myAvatar->getOrientation() * glm::vec3(x, y, z));
//Rotate the UI pick ray by the avatar orientation //Rotate the UI pick ray by the avatar orientation
direction = glm::normalize(relativePosition - Application::getInstance()->getCamera()->getPosition()); direction = myAvatar->getOrientation() * localDirection;
} }
// Calculates the click location on the screen by taking into account any // Calculates the click location on the screen by taking into account any