From ef0a157111c628ddc9321e23b31d1001404599ee Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 16 Jul 2015 16:00:39 -0700 Subject: [PATCH 1/2] Fixes for oculus rift support * should work in standing and 'seated' mode * OculusBaseDisplayPlugin getModelView now only applies eye offset to match behavior from the OpenVRPlugin --- interface/src/avatar/MyAvatar.cpp | 18 ++++++++++++++---- interface/src/avatar/MyAvatar.h | 2 +- .../oculus/OculusBaseDisplayPlugin.cpp | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f420e63594..27ef887158 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -250,6 +250,14 @@ void MyAvatar::simulate(float deltaTime) { maybeUpdateBillboard(); } +glm::mat4 MyAvatar::getSensorToWorldMatrix() const { + if (getStandingHMDSensorMode()) { + return _sensorToWorldMatrix; + } else { + return createMatFromQuatAndPos(getWorldAlignedOrientation(), getDefaultEyePosition()); + } +} + // best called at end of main loop, just before rendering. // update sensor to world matrix from current body position and hmd sensor. // This is so the correct camera can be used for rendering. @@ -261,10 +269,12 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) { _hmdSensorOrientation = glm::quat_cast(hmdSensorMatrix); _bodySensorMatrix = deriveBodyFromHMDSensor(); - // set the body position/orientation to reflect motion due to the head. - auto worldMat = _sensorToWorldMatrix * _bodySensorMatrix; - setPosition(extractTranslation(worldMat)); - setOrientation(glm::quat_cast(worldMat)); + if (getStandingHMDSensorMode()) { + // set the body position/orientation to reflect motion due to the head. + auto worldMat = _sensorToWorldMatrix * _bodySensorMatrix; + setPosition(extractTranslation(worldMat)); + setOrientation(glm::quat_cast(worldMat)); + } } // best called at end of main loop, just before rendering. diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 99fee87036..c322205158 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -48,7 +48,7 @@ public: const glm::mat4& getHMDSensorMatrix() const { return _hmdSensorMatrix; } const glm::vec3& getHMDSensorPosition() const { return _hmdSensorPosition; } const glm::quat& getHMDSensorOrientation() const { return _hmdSensorOrientation; } - glm::mat4 getSensorToWorldMatrix() const { return _sensorToWorldMatrix; } + glm::mat4 getSensorToWorldMatrix() const; // best called at start of main loop just after we have a fresh hmd pose. // update internal body position from new hmd pose. diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp index 24697de89f..61feb00cd0 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp @@ -54,7 +54,9 @@ glm::mat4 OculusBaseDisplayPlugin::getProjection(Eye eye, const glm::mat4& baseP } glm::mat4 OculusBaseDisplayPlugin::getModelview(Eye eye, const glm::mat4& baseModelview) const { - return baseModelview * toGlm(_eyePoses[eye]); + auto eyeOffsetMat = glm::mat4(); + setTranslation(eyeOffsetMat, toGlm(_eyeOffsets[eye])); + return baseModelview * eyeOffsetMat; } void OculusBaseDisplayPlugin::resetSensors() { From 157c20e57b9c7f4e7b631e380ab5b9f74dc734dc Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 15 Jul 2015 19:13:47 -0700 Subject: [PATCH 2/2] goToLocation should work properly in standing HMD mode --- interface/src/avatar/MyAvatar.cpp | 50 +++++++++++++++---------------- interface/src/avatar/MyAvatar.h | 4 +++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 27ef887158..e39b75a9ce 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -108,7 +108,10 @@ MyAvatar::MyAvatar() : _hmdSensorPosition(), _bodySensorMatrix(), _sensorToWorldMatrix(), - _standingHMDSensorMode(false) + _standingHMDSensorMode(false), + _goToPending(false), + _goToPosition(), + _goToOrientation() { _firstPersonSkeletonModel.setIsFirstPerson(true); @@ -159,6 +162,12 @@ void MyAvatar::reset() { void MyAvatar::update(float deltaTime) { + if (_goToPending) { + setPosition(_goToPosition); + setOrientation(_goToOrientation); + _goToPending = false; + } + if (_referential) { _referential->update(); } @@ -262,7 +271,6 @@ glm::mat4 MyAvatar::getSensorToWorldMatrix() const { // update sensor to world matrix from current body position and hmd sensor. // This is so the correct camera can be used for rendering. void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) { - // update the sensorMatrices based on the new hmd pose _hmdSensorMatrix = hmdSensorMatrix; _hmdSensorPosition = extractTranslation(hmdSensorMatrix); @@ -1635,35 +1643,27 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition, qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", " << newPosition.y << ", " << newPosition.z; - if (qApp->isHMDMode() && getStandingHMDSensorMode()) { - // AJT: FIXME, does not work with orientation. - // AJT: FIXME, does not work with shouldFaceLocation flag. - // Set the orientation of the sensor room, not the avatar itself. - glm::mat4 m; - m[3] = glm::vec4(newPosition, 1); - _sensorToWorldMatrix = m; - } else { - glm::vec3 shiftedPosition = newPosition; - if (hasOrientation) { - qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is " - << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; + _goToPending = true; + _goToPosition = newPosition; + _goToOrientation = getOrientation(); + if (hasOrientation) { + qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is " + << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; - // orient the user to face the target - glm::quat quatOrientation = newOrientation; + // orient the user to face the target + glm::quat quatOrientation = newOrientation; - if (shouldFaceLocation) { - quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); + if (shouldFaceLocation) { + quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); - // move the user a couple units away - const float DISTANCE_TO_USER = 2.0f; - shiftedPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER; - } - - setOrientation(quatOrientation); + // move the user a couple units away + const float DISTANCE_TO_USER = 2.0f; + _goToPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER; } - slamPosition(shiftedPosition); + _goToOrientation = quatOrientation; } + emit transformChanged(); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c322205158..92170a1ddb 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -331,6 +331,10 @@ private: glm::mat4 _sensorToWorldMatrix; bool _standingHMDSensorMode; + + bool _goToPending; + glm::vec3 _goToPosition; + glm::quat _goToOrientation; }; #endif // hifi_MyAvatar_h