From 75aedae300a5e445837c0c5aec7edb618042083a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 12 Aug 2014 14:12:13 -0700 Subject: [PATCH] integration of positional tracking with DK2 --- cmake/modules/FindLibOVR.cmake | 4 +-- interface/src/avatar/MyAvatar.cpp | 6 ++++ interface/src/devices/OculusManager.cpp | 39 ++++++++++++++++++++----- interface/src/devices/OculusManager.h | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/cmake/modules/FindLibOVR.cmake b/cmake/modules/FindLibOVR.cmake index 505fd90b51..5fbe01d06b 100644 --- a/cmake/modules/FindLibOVR.cmake +++ b/cmake/modules/FindLibOVR.cmake @@ -27,8 +27,8 @@ find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${OCU include(SelectLibraryConfigurations) if (APPLE) - find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/MacOS/Debug HINTS ${OCULUS_SEARCH_DIRS}) - find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/MacOS/Release HINTS ${OCULUS_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Mac/Debug HINTS ${OCULUS_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Mac/Release HINTS ${OCULUS_SEARCH_DIRS}) find_library(ApplicationServices ApplicationServices) find_library(IOKit IOKit) elseif (UNIX) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f59064732c..08d33ff252 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -255,6 +255,12 @@ void MyAvatar::updateFromTrackers(float deltaTime) { estimatedRotation.x *= -1.0f; estimatedRotation.z *= -1.0f; + } else if (OculusManager::isConnected()) { + estimatedPosition = OculusManager::getRelativePosition(); + estimatedPosition.x *= -1.0f; + + const float OCULUS_LEAN_SCALE = 0.05f; + estimatedPosition /= OCULUS_LEAN_SCALE; } else { FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker(); if (tracker) { diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 96df5b6c7c..6ce77e3ca2 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -314,7 +314,16 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p glPushMatrix(); glm::quat orientation; - + glm::vec3 trackerPosition; + +#if defined(__APPLE__) || defined(_WIN32) + ovrTrackingState ts = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds()); + ovrVector3f ovrHeadPosition = ts.HeadPose.ThePose.Position; + + trackerPosition = glm::vec3(ovrHeadPosition.x, ovrHeadPosition.y, ovrHeadPosition.z); + trackerPosition = bodyOrientation * trackerPosition; +#endif + //Render each eye into an fbo for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) { #if defined(__APPLE__) || defined(_WIN32) @@ -330,7 +339,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p orientation.w = eyeRenderPose[eye].Orientation.w; _camera->setTargetRotation(bodyOrientation * orientation); - _camera->setTargetPosition(position); + _camera->setTargetPosition(position + trackerPosition); + _camera->update(1.0f / Application::getInstance()->getFps()); Matrix4f proj = ovrMatrix4f_Projection(_eyeRenderDesc[eye].Fov, whichCamera.getNearClip(), whichCamera.getFarClip(), true); @@ -450,8 +460,9 @@ void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { //Tries to reconnect to the sensors void OculusManager::reset() { #ifdef HAVE_LIBOVR - disconnect(); - connect(); + if (_isConnected) { + ovrHmd_RecenterPose(_ovrHmd); + } #endif } @@ -463,18 +474,18 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) { #else ovrSensorState ss = ovrHmd_GetSensorState(_ovrHmd, _hmdFrameTiming.ScanoutMidpointSeconds); #endif -#if defined(__APPLE__) || defined(_WIN32) +#if defined(__APPLE__) || defined(_WIN32) if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) { #else if (ss.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) { #endif #if defined(__APPLE__) || defined(_WIN32) - ovrPosef pose = ts.CameraPose; + ovrPosef headPose = ts.HeadPose.ThePose; #else - ovrPosef pose = ss.Predicted.Pose; + ovrPosef headPose = ss.Predicted.Pose; #endif - Quatf orientation = Quatf(pose.Orientation); + Quatf orientation = Quatf(headPose.Orientation); orientation.GetEulerAngles(&yaw, &pitch, &roll); } else { yaw = 0.0f; @@ -487,6 +498,18 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) { roll = 0.0f; #endif } + +glm::vec3 OculusManager::getRelativePosition() { +#if defined(__APPLE__) || defined(_WIN32) + ovrTrackingState trackingState = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds()); + ovrVector3f headPosition = trackingState.HeadPose.ThePose.Position; + + return glm::vec3(headPosition.x, headPosition.y, headPosition.z); +#else + // no positional tracking in Linux yet + return glm::vec3(0.0f, 0.0f, 0.0f); +#endif +} //Used to set the size of the glow framebuffers QSize OculusManager::getRenderTargetSize() { diff --git a/interface/src/devices/OculusManager.h b/interface/src/devices/OculusManager.h index 8c929bb50a..3959ea1ab7 100644 --- a/interface/src/devices/OculusManager.h +++ b/interface/src/devices/OculusManager.h @@ -40,6 +40,7 @@ public: /// param \pitch[out] pitch in radians /// param \roll[out] roll in radians static void getEulerAngles(float& yaw, float& pitch, float& roll); + static glm::vec3 getRelativePosition(); static QSize getRenderTargetSize(); private: