From 99065f10fa8eb9ce9987902fc8fcfccb2be023ce Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 1 Dec 2015 12:27:09 -0800 Subject: [PATCH 1/2] Avatar Warning fixes on linux --- interface/src/Application.cpp | 1 - interface/src/avatar/MyAvatar.cpp | 5 ++++- interface/src/avatar/SkeletonModel.cpp | 6 ------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5ac14ac0ec..f18c6c87ca 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2577,7 +2577,6 @@ void Application::setAvatarUpdateThreading(bool isThreaded) { return; } - auto myAvatar = getMyAvatar(); if (_avatarUpdate) { _avatarUpdate->terminate(); // Must be before we shutdown anim graph. } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 39b09fb9de..029aefcac4 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1808,7 +1808,10 @@ glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const { int neckIndex = _rig->indexOfJoint("Neck"); int hipsIndex = _rig->indexOfJoint("Hips"); - glm::vec3 rigMiddleEyePos = leftEyeIndex != -1 ? _rig->getAbsoluteDefaultPose(leftEyeIndex).trans : DEFAULT_RIG_MIDDLE_EYE_POS; + glm::vec3 rigMiddleEyePos = DEFAULT_RIG_MIDDLE_EYE_POS; + if (leftEyeIndex >= 0 && rightEyeIndex >= 0) { + rigMiddleEyePos = (_rig->getAbsoluteDefaultPose(leftEyeIndex).trans + _rig->getAbsoluteDefaultPose(rightEyeIndex).trans) / 2.0f; + } glm::vec3 rigNeckPos = neckIndex != -1 ? _rig->getAbsoluteDefaultPose(neckIndex).trans : DEFAULT_RIG_NECK_POS; glm::vec3 rigHipsPos = hipsIndex != -1 ? _rig->getAbsoluteDefaultPose(hipsIndex).trans : DEFAULT_RIG_HIPS_POS; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index d438e6f528..342f8315e1 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -42,7 +42,6 @@ SkeletonModel::~SkeletonModel() { void SkeletonModel::initJointStates() { const FBXGeometry& geometry = _geometry->getFBXGeometry(); - glm::mat4 geometryOffset = geometry.offset; glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset); _rig->initJointStates(geometry, modelOffset); @@ -237,11 +236,6 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) { if (parentJointIndex == -1) { return; } - - // the palm's position must be transformed into the model-frame - glm::quat inverseRotation = glm::inverse(_rotation); - glm::vec3 palmPosition = inverseRotation * (palm.getPosition() - _translation); - glm::quat palmRotation = inverseRotation * palm.getRotation(); } bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const { From 0b05a341a842c89b3bef25ebb6034e08859850f0 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 2 Dec 2015 10:18:02 -0800 Subject: [PATCH 2/2] MyAvatar::reset() improvements Body should not orient under the HMD body without changing the HMD view point. It's more predictable and less likely to make you sick. It also should reset the height of the character to cancel out squatting, if the HMD position is low. --- interface/src/avatar/MyAvatar.cpp | 33 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 029aefcac4..eca39a0a44 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -232,30 +232,27 @@ void MyAvatar::reset(bool andReload) { setThrust(glm::vec3(0.0f)); if (andReload) { - // Get fresh data, in case we're really slow and out of wack. - _hmdSensorMatrix = qApp->getHMDSensorPose(); - _hmdSensorPosition = extractTranslation(_hmdSensorMatrix); - _hmdSensorOrientation = glm::quat_cast(_hmdSensorMatrix); - - // Reset body position/orientation under the head. + // derive the desired body orientation from the *old* hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation.. + + // transform this body into world space auto worldBodyMatrix = _sensorToWorldMatrix * newBodySensorMatrix; - glm::vec3 worldBodyPos = extractTranslation(worldBodyMatrix); - glm::quat worldBodyRot = glm::normalize(glm::quat_cast(worldBodyMatrix)); - - // FIXME: Hack to retain the previous behavior wrt height. - // I'd like to make the body match head height, but that will have to wait for separate PR. - worldBodyPos.y = getPosition().y; + auto worldBodyPos = extractTranslation(worldBodyMatrix); + auto worldBodyRot = glm::normalize(glm::quat_cast(worldBodyMatrix)); + // this will become our new position. setPosition(worldBodyPos); setOrientation(worldBodyRot); - // If there is any discrepency between positioning and the head (as there is in initial deriveBodyFromHMDSensor), - // we can make that right by setting _bodySensorMatrix = newBodySensorMatrix. - // However, doing so will make the head want to point to the previous body orientation, as cached above. - //_bodySensorMatrix = newBodySensorMatrix; - //updateSensorToWorldMatrix(); // Uses updated position/orientation and _bodySensorMatrix changes - qApp->setRawAvatarUpdateThreading(); + // now sample the new hmd orientation AFTER sensor reset. + updateFromHMDSensorMatrix(qApp->getHMDSensorPose()); + + // update the body in sensor space using the new hmd sensor sample + _bodySensorMatrix = deriveBodyFromHMDSensor(); + + // rebuild the sensor to world matrix such that, the HMD will point in the desired orientation. + // i.e. the along avatar's current position and orientation. + updateSensorToWorldMatrix(); } }