From a11bf7f15ba2f7810f3837713a3fc9dba4c7b4db Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 19 Sep 2014 14:26:44 -0700 Subject: [PATCH] Decouple Rift head tracking from avatar's head position This makes the Rift's view reflect the user's physical movements exactly while the avatar follows the movements as best it can. --- interface/src/Application.cpp | 2 +- interface/src/avatar/Avatar.cpp | 4 ---- interface/src/avatar/Avatar.h | 1 - interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/avatar/SkeletonModel.cpp | 7 +++++++ interface/src/avatar/SkeletonModel.h | 6 ++++++ 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a20a6553d4..00cf3b9d01 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -682,7 +682,7 @@ void Application::paintGL() { if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { OculusManager::display(whichCamera.getRotation(), whichCamera.getPosition(), whichCamera); } else { - OculusManager::display(_myAvatar->getWorldAlignedOrientation(), whichCamera.getPosition(), whichCamera); + OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getUprightHeadPosition(), whichCamera); } } else if (TV3DManager::isConnected()) { diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 6f421965db..22e7697b40 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -1028,10 +1028,6 @@ float Avatar::getPelvisFloatingHeight() const { return -_skeletonModel.getBindExtents().minimum.y; } -float Avatar::getPelvisToHeadLength() const { - return glm::distance(_position, getHead()->getPosition()); -} - void Avatar::setShowDisplayName(bool showDisplayName) { if (!Menu::getInstance()->isOptionChecked(MenuOption::NamesAboveHeads)) { _displayNameAlpha = 0.0f; diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index c449a0d1b9..58add5aecd 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -223,7 +223,6 @@ protected: float getSkeletonHeight() const; float getHeadHeight() const; float getPelvisFloatingHeight() const; - float getPelvisToHeadLength() const; glm::vec3 getDisplayNamePosition(); void renderDisplayName(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 27f74f185d..e59de3628a 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -977,7 +977,7 @@ void MyAvatar::clearLookAtTargetAvatar() { } glm::vec3 MyAvatar::getUprightHeadPosition() const { - return _position + getWorldAlignedOrientation() * glm::vec3(0.0f, getPelvisToHeadLength(), 0.0f); + return _position + getWorldAlignedOrientation() * _skeletonModel.getDefaultHeadModelPosition(); } const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 86ca42b15e..2e53412be4 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -656,6 +656,13 @@ void SkeletonModel::buildShapes() { // This method moves the shapes to their default positions in Model frame. computeBoundingShape(geometry); + int headJointIndex = _geometry->getFBXGeometry().headJointIndex; + if (0 <= headJointIndex && headJointIndex < _jointStates.size()) { + getJointPosition(headJointIndex, _defaultHeadModelPosition); + } else { + _defaultHeadModelPosition = glm::vec3(0.f, 0.f, 0.f); + } + // While the shapes are in their default position we disable collisions between // joints that are currently colliding. disableCurrentSelfCollisions(); diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index ca0007ddb4..036811a926 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -97,6 +97,10 @@ public: /// \return whether or not both eye meshes were found bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; + /// Gets the default position of the head in model frame coordinates. + /// \return whether or not the head was found. + glm::vec3 getDefaultHeadModelPosition() const { return _defaultHeadModelPosition; } + virtual void updateVisibleJointStates(); SkeletonRagdoll* buildRagdoll(); @@ -146,6 +150,8 @@ private: CapsuleShape _boundingShape; glm::vec3 _boundingShapeLocalOffset; SkeletonRagdoll* _ragdoll; + + glm::vec3 _defaultHeadModelPosition; }; #endif // hifi_SkeletonModel_h