From bfad3ee02a0a8ebca3519e223f7e1deaed8e79a2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jul 2015 14:07:32 -0700 Subject: [PATCH] Fix eye directions so that they're correct when avatar leans backwards --- interface/src/avatar/FaceModel.cpp | 12 ++---- libraries/avatars/src/AvatarData.cpp | 45 ++++++++++++++-------- libraries/networking/src/PacketHeaders.cpp | 2 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 1501c52de5..170965bb4d 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -56,18 +56,14 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX glm::translate(state.getDefaultTranslationInConstrainedFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation))); glm::vec3 pitchYawRoll = safeEulerAngles(_owningHead->getFinalOrientationInLocalFrame()); - if (owningAvatar->isMyAvatar()) { - glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(), - _owningHead->getTorsoTwist(), - _owningHead->getFinalLeanSideways())); - pitchYawRoll -= lean; - } - + glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(), + _owningHead->getTorsoTwist(), + _owningHead->getFinalLeanSideways())); + pitchYawRoll -= lean; state.setRotationInConstrainedFrame(glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2])) * glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1])) * glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0])) * joint.rotation, DEFAULT_PRIORITY); - } void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentState, const FBXJoint& joint, JointState& state) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 9a6400ae16..a7fdcdeafd 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -161,19 +161,15 @@ QByteArray AvatarData::toByteArray() { // Body scale destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale); - // Head rotation (NOTE: This needs to become a quaternion to save two bytes) - glm::vec3 pitchYawRoll = glm::vec3(_headData->getFinalPitch(), - _headData->getFinalYaw(), - _headData->getFinalRoll()); - if (this->isMyAvatar()) { - glm::vec3 lean = glm::vec3(_headData->getFinalLeanForward(), - _headData->getTorsoTwist(), - _headData->getFinalLeanSideways()); - pitchYawRoll -= lean; - } - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.x); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.y); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.z); + // Head rotation + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalPitch()); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw()); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll()); + + // Body lean + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); // Lookat Position memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); @@ -291,13 +287,16 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { // headPitch = 2 (compressed float) // headYaw = 2 (compressed float) // headRoll = 2 (compressed float) + // leanForward = 2 (compressed float) + // leanSideways = 2 (compressed float) + // torsoTwist = 2 (compressed float) // lookAt = 12 // audioLoudness = 4 // } // + 1 byte for pupilSize // + 1 byte for numJoints (0) - // = 45 bytes - int minPossibleSize = 45; + // = 51 bytes + int minPossibleSize = 51; int maxAvailableSize = packet.size() - offset; if (minPossibleSize > maxAvailableSize) { @@ -371,6 +370,22 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { _headData->setBaseYaw(headYaw); _headData->setBaseRoll(headRoll); } // 6 bytes + + { // Head lean (relative to pelvis) + float leanForward, leanSideways, torsoTwist; + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanForward); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanSideways); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &torsoTwist); + if (glm::isnan(leanForward) || glm::isnan(leanSideways)) { + if (shouldLogError(now)) { + qCDebug(avatars) << "Discard nan AvatarData::leanForward,leanSideways,torsoTwise; displayName = '" << _displayName << "'"; + } + return maxAvailableSize; + } + _headData->_leanForward = leanForward; + _headData->_leanSideways = leanSideways; + _headData->_torsoTwist = torsoTwist; + } // 6 bytes { // Lookat Position glm::vec3 lookAt; diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 42ee9f3025..74b6aa55f1 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -55,7 +55,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketTypeInjectAudio: return 1; case PacketTypeAvatarData: - return 6; + return 7; case PacketTypeAvatarIdentity: return 1; case PacketTypeEnvironmentData: