From f53455ee5563a9d001805660daf30fa8c6ad96c0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Nov 2014 11:40:47 -0800 Subject: [PATCH] use a ray from the near clip for action ray --- examples/lobby.js | 4 +++- interface/src/Application.cpp | 4 ++-- interface/src/Camera.h | 2 -- interface/src/scripting/JoystickScriptingInterface.cpp | 3 ++- libraries/octree/src/ViewFrustum.cpp | 7 +++++++ libraries/octree/src/ViewFrustum.h | 3 +++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/lobby.js b/examples/lobby.js index 474ee515e3..7aa2039683 100644 --- a/examples/lobby.js +++ b/examples/lobby.js @@ -81,7 +81,8 @@ function drawLobby() { size: RETICLE_SPHERE_SIZE, color: { red: 0, green: 255, blue: 0 }, alpha: 1.0, - solid: true + solid: true, + ignoreRayIntersection: true }); // add an attachment on this avatar so other people see them in the lobby @@ -128,6 +129,7 @@ function cleanupLobby() { function actionStartEvent(event) { if (panelWall) { + // we've got an action event and our panel wall is up // check if we hit a panel and if we should jump there var result = Overlays.findRayIntersection(event.actionRay); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2438db18f8..1209774806 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1117,7 +1117,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (!event->isAutoRepeat()) { // this starts an HFActionEvent HFActionEvent startActionEvent(HFActionEvent::startType(), - Application::getInstance()->getCamera()->getPickRay()); + _viewFrustum.computePickRay(0.5f, 0.5f)); sendEvent(this, &startActionEvent); } @@ -1208,7 +1208,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { case Qt::Key_Space: { if (!event->isAutoRepeat()) { // this ends the HFActionEvent - HFActionEvent endActionEvent(HFActionEvent::endType(), Application::getInstance()->getCamera()->getPickRay()); + HFActionEvent endActionEvent(HFActionEvent::endType(), _viewFrustum.computePickRay(0.5f, 0.5f)); sendEvent(this, &endActionEvent); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index e1f14a0a77..bc7a3c5687 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -56,8 +56,6 @@ public: void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; } void setScale(const float s) { _scale = s; } - PickRay getPickRay() const { return PickRay(getPosition(), getRotation() * IDENTITY_FRONT); } - glm::vec3 getPosition() const { return _position + _hmdPosition; } glm::quat getRotation() const { return _rotation * _hmdRotation; } const glm::vec3& getHmdPosition() const { return _hmdPosition; } diff --git a/interface/src/scripting/JoystickScriptingInterface.cpp b/interface/src/scripting/JoystickScriptingInterface.cpp index 7fc4e48843..68affeda5b 100644 --- a/interface/src/scripting/JoystickScriptingInterface.cpp +++ b/interface/src/scripting/JoystickScriptingInterface.cpp @@ -129,7 +129,8 @@ void JoystickScriptingInterface::update() { : HFActionEvent::endType(); // global action events fire in the center of the screen - HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->getPickRay()); + HFActionEvent actionEvent(actionType, + Application::getInstance()->getViewFrustum()->computePickRay(0.5f, 0.5f)); qApp->sendEvent(qApp, &actionEvent); } diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index c1348e28c7..0549c60134 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -583,6 +583,13 @@ bool ViewFrustum::isVerySimilar(const ViewFrustum& compareTo, bool debug) const return result; } +PickRay ViewFrustum::computePickRay(float x, float y) { + glm::vec3 pickRayOrigin; + glm::vec3 pickRayDirection; + computePickRay(x, y, pickRayOrigin, pickRayDirection); + return PickRay(pickRayOrigin, pickRayDirection); +} + void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const { origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft); direction = glm::normalize(origin - (_position + _orientation * _eyeOffsetPosition)); diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index f1894c7cab..1fd306617b 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -17,6 +17,8 @@ #include #include +#include + #include "AABox.h" #include "AACube.h" #include "Plane.h" @@ -105,6 +107,7 @@ public: bool isVerySimilar(const ViewFrustum& compareTo, bool debug = false) const; bool isVerySimilar(const ViewFrustum* compareTo, bool debug = false) const { return isVerySimilar(*compareTo, debug); } + PickRay computePickRay(float x, float y); void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const; void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearValue, float& farValue,