mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:24:36 +02:00
Simple raypicking for scripts with oculus rift.
This commit is contained in:
parent
5ed1dfc4b0
commit
936f04cece
3 changed files with 28 additions and 4 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "devices/OculusManager.h"
|
||||||
|
|
||||||
const float CAMERA_FIRST_PERSON_MODE_UP_SHIFT = 0.0f;
|
const float CAMERA_FIRST_PERSON_MODE_UP_SHIFT = 0.0f;
|
||||||
const float CAMERA_FIRST_PERSON_MODE_DISTANCE = 0.0f;
|
const float CAMERA_FIRST_PERSON_MODE_DISTANCE = 0.0f;
|
||||||
|
@ -264,7 +265,12 @@ PickRay CameraScriptableObject::computePickRay(float x, float y) {
|
||||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||||
PickRay result;
|
PickRay result;
|
||||||
_viewFrustum->computePickRay(x / screenWidth, y / screenHeight, result.origin, result.direction);
|
if (OculusManager::isConnected()) {
|
||||||
|
result.origin = _camera->getPosition();
|
||||||
|
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||||
|
} else {
|
||||||
|
_viewFrustum->computePickRay(x / screenWidth, y / screenHeight, result.origin, result.direction);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,6 +297,25 @@ void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) {
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float textureFov = PI / 2.5f;
|
||||||
|
|
||||||
|
void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direction) const {
|
||||||
|
glm::quat rot = Application::getInstance()->getAvatar()->getOrientation();
|
||||||
|
|
||||||
|
//invert y direction
|
||||||
|
y = 1.0 - y;
|
||||||
|
|
||||||
|
//Get position on hemisphere UI
|
||||||
|
x = sin((x - 0.5f) * textureFov);
|
||||||
|
y = sin((y - 0.5f) * textureFov);
|
||||||
|
|
||||||
|
float dist = sqrt(x * x + y * y);
|
||||||
|
float z = -sqrt(1.0f - dist * dist);
|
||||||
|
|
||||||
|
//Rotate the UI pick ray by the avatar orientation
|
||||||
|
direction = glm::normalize(rot * glm::vec3(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
// Fast helper functions
|
// Fast helper functions
|
||||||
inline float max(float a, float b) {
|
inline float max(float a, float b) {
|
||||||
return (a > b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
|
@ -306,8 +325,6 @@ inline float min(float a, float b) {
|
||||||
return (a < b) ? a : b;
|
return (a < b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float textureFov = PI / 2.5f;
|
|
||||||
|
|
||||||
// Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane.
|
// Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane.
|
||||||
void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
|
void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
class Overlays;
|
class Overlays;
|
||||||
class QOpenGLFramebufferObject;
|
class QOpenGLFramebufferObject;
|
||||||
|
|
||||||
// Handles the drawing of the overlays to the scree
|
// Handles the drawing of the overlays to the screen
|
||||||
class ApplicationOverlay {
|
class ApplicationOverlay {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ public:
|
||||||
void renderOverlay(bool renderToTexture = false);
|
void renderOverlay(bool renderToTexture = false);
|
||||||
void displayOverlayTexture(Camera& whichCamera);
|
void displayOverlayTexture(Camera& whichCamera);
|
||||||
void displayOverlayTextureOculus(Camera& whichCamera);
|
void displayOverlayTextureOculus(Camera& whichCamera);
|
||||||
|
void computeOculusPickRay(float x, float y, glm::vec3& direction) const;
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
QOpenGLFramebufferObject* getFramebufferObject();
|
QOpenGLFramebufferObject* getFramebufferObject();
|
||||||
|
|
Loading…
Reference in a new issue