mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 05:09:23 +02:00
integration of positional tracking with DK2
This commit is contained in:
parent
4ff7ff61e8
commit
75aedae300
4 changed files with 40 additions and 10 deletions
|
@ -27,8 +27,8 @@ find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${OCU
|
||||||
include(SelectLibraryConfigurations)
|
include(SelectLibraryConfigurations)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/MacOS/Debug 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/MacOS/Release 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(ApplicationServices ApplicationServices)
|
||||||
find_library(IOKit IOKit)
|
find_library(IOKit IOKit)
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
|
|
|
@ -255,6 +255,12 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
|
||||||
estimatedRotation.x *= -1.0f;
|
estimatedRotation.x *= -1.0f;
|
||||||
estimatedRotation.z *= -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 {
|
} else {
|
||||||
FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker();
|
FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker();
|
||||||
if (tracker) {
|
if (tracker) {
|
||||||
|
|
|
@ -314,7 +314,16 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glm::quat orientation;
|
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
|
//Render each eye into an fbo
|
||||||
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) {
|
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) {
|
||||||
#if defined(__APPLE__) || defined(_WIN32)
|
#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;
|
orientation.w = eyeRenderPose[eye].Orientation.w;
|
||||||
|
|
||||||
_camera->setTargetRotation(bodyOrientation * orientation);
|
_camera->setTargetRotation(bodyOrientation * orientation);
|
||||||
_camera->setTargetPosition(position);
|
_camera->setTargetPosition(position + trackerPosition);
|
||||||
|
|
||||||
_camera->update(1.0f / Application::getInstance()->getFps());
|
_camera->update(1.0f / Application::getInstance()->getFps());
|
||||||
|
|
||||||
Matrix4f proj = ovrMatrix4f_Projection(_eyeRenderDesc[eye].Fov, whichCamera.getNearClip(), whichCamera.getFarClip(), true);
|
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
|
//Tries to reconnect to the sensors
|
||||||
void OculusManager::reset() {
|
void OculusManager::reset() {
|
||||||
#ifdef HAVE_LIBOVR
|
#ifdef HAVE_LIBOVR
|
||||||
disconnect();
|
if (_isConnected) {
|
||||||
connect();
|
ovrHmd_RecenterPose(_ovrHmd);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,18 +474,18 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) {
|
||||||
#else
|
#else
|
||||||
ovrSensorState ss = ovrHmd_GetSensorState(_ovrHmd, _hmdFrameTiming.ScanoutMidpointSeconds);
|
ovrSensorState ss = ovrHmd_GetSensorState(_ovrHmd, _hmdFrameTiming.ScanoutMidpointSeconds);
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE__) || defined(_WIN32)
|
#if defined(__APPLE__) || defined(_WIN32)
|
||||||
if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) {
|
if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) {
|
||||||
#else
|
#else
|
||||||
if (ss.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) {
|
if (ss.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(_WIN32)
|
#if defined(__APPLE__) || defined(_WIN32)
|
||||||
ovrPosef pose = ts.CameraPose;
|
ovrPosef headPose = ts.HeadPose.ThePose;
|
||||||
#else
|
#else
|
||||||
ovrPosef pose = ss.Predicted.Pose;
|
ovrPosef headPose = ss.Predicted.Pose;
|
||||||
#endif
|
#endif
|
||||||
Quatf orientation = Quatf(pose.Orientation);
|
Quatf orientation = Quatf(headPose.Orientation);
|
||||||
orientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CCW, Handed_R>(&yaw, &pitch, &roll);
|
orientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CCW, Handed_R>(&yaw, &pitch, &roll);
|
||||||
} else {
|
} else {
|
||||||
yaw = 0.0f;
|
yaw = 0.0f;
|
||||||
|
@ -487,6 +498,18 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) {
|
||||||
roll = 0.0f;
|
roll = 0.0f;
|
||||||
#endif
|
#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
|
//Used to set the size of the glow framebuffers
|
||||||
QSize OculusManager::getRenderTargetSize() {
|
QSize OculusManager::getRenderTargetSize() {
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
/// param \pitch[out] pitch in radians
|
/// param \pitch[out] pitch in radians
|
||||||
/// param \roll[out] roll in radians
|
/// param \roll[out] roll in radians
|
||||||
static void getEulerAngles(float& yaw, float& pitch, float& roll);
|
static void getEulerAngles(float& yaw, float& pitch, float& roll);
|
||||||
|
static glm::vec3 getRelativePosition();
|
||||||
static QSize getRenderTargetSize();
|
static QSize getRenderTargetSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue