diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 32594a7225..296b4ab68a 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -54,7 +54,6 @@ Head::Head(Avatar* owningAvatar) : _deltaRoll(0.0f), _deltaLeanSideways(0.0f), _deltaLeanForward(0.0f), - _torsoTwist(0.0f), _isCameraMoving(false), _isLookingAtMe(false), _faceModel(this), diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index dece0a8565..255ea823e9 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -76,9 +76,6 @@ public: float getFinalLeanSideways() const { return _leanSideways + _deltaLeanSideways; } float getFinalLeanForward() const { return _leanForward + _deltaLeanForward; } - float getTorsoTwist() const { return _torsoTwist; } - void setTorsoTwist(float torsoTwist) { _torsoTwist = torsoTwist; } - glm::quat getEyeRotation(const glm::vec3& eyePosition) const; const glm::vec3& getRightEyePosition() const { return _rightEyePosition; } @@ -151,8 +148,6 @@ private: // delta lean angles for lean perturbations (driven by collisions) float _deltaLeanSideways; float _deltaLeanForward; - - float _torsoTwist; bool _isCameraMoving; bool _isLookingAtMe; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index cc45da610f..d2108c79e2 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -158,15 +158,18 @@ QByteArray AvatarData::toByteArray() { destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale); // Head rotation (NOTE: This needs to become a quaternion to save two bytes) - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw()); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalPitch()); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll()); - - // Head lean X,Z (head lateral and fwd/back motion relative to torso) - memcpy(destinationBuffer, &_headData->_leanSideways, sizeof(_headData->_leanSideways)); - destinationBuffer += sizeof(_headData->_leanSideways); - memcpy(destinationBuffer, &_headData->_leanForward, sizeof(_headData->_leanForward)); - destinationBuffer += sizeof(_headData->_leanForward); + 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); // Lookat Position memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); @@ -287,18 +290,16 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { // bodyPitch = 2 (compressed float) // bodyRoll = 2 (compressed float) // targetScale = 2 (compressed float) - // headYaw = 2 (compressed float) // headPitch = 2 (compressed float) + // headYaw = 2 (compressed float) // headRoll = 2 (compressed float) - // leanSideways = 4 - // leanForward = 4 // lookAt = 12 // audioLoudness = 4 // } // + 1 byte for pupilSize // + 1 byte for numJoints (0) - // = 53 bytes - int minPossibleSize = 52; + // = 45 bytes + int minPossibleSize = 45; int maxAvailableSize = packet.size() - offset; if (minPossibleSize > maxAvailableSize) { @@ -356,8 +357,8 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { { // Head rotation //(NOTE: This needs to become a quaternion to save two bytes) float headYaw, headPitch, headRoll; - sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headPitch); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headRoll); if (glm::isnan(headYaw) || glm::isnan(headPitch) || glm::isnan(headRoll)) { if (shouldLogError(now)) { @@ -365,27 +366,10 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { } return maxAvailableSize; } - _headData->setBaseYaw(headYaw); _headData->setBasePitch(headPitch); + _headData->setBaseYaw(headYaw); _headData->setBaseRoll(headRoll); } // 6 bytes - - // Head lean (relative to pelvis) - { - float leanSideways, leanForward; - memcpy(&leanSideways, sourceBuffer, sizeof(float)); - sourceBuffer += sizeof(float); - memcpy(&leanForward, sourceBuffer, sizeof(float)); - sourceBuffer += sizeof(float); - if (glm::isnan(leanSideways) || glm::isnan(leanForward)) { - if (shouldLogError(now)) { - qDebug() << "Discard nan AvatarData::leanSideways,leanForward; displayName = '" << _displayName << "'"; - } - return maxAvailableSize; - } - _headData->_leanSideways = leanSideways; - _headData->_leanForward = leanForward; - } // 8 bytes { // Lookat Position glm::vec3 lookAt; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 84653ef673..a429a7af93 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -152,6 +152,8 @@ class AvatarData : public QObject { public: AvatarData(); virtual ~AvatarData(); + + virtual bool isMyAvatar() { return false; } const QUuid& getSessionUUID() const { return _sessionUUID; } diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index 511ab50c11..5bf33d1153 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -24,6 +24,7 @@ HeadData::HeadData(AvatarData* owningAvatar) : _baseRoll(0.0f), _leanSideways(0.0f), _leanForward(0.0f), + _torsoTwist(0.0f), _lookAtPosition(0.0f, 0.0f, 0.0f), _audioLoudness(0.0f), _isFaceshiftConnected(false), diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index 3a4eb3c808..cef5d5fbca 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -71,11 +71,13 @@ public: float getLeanSideways() const { return _leanSideways; } float getLeanForward() const { return _leanForward; } + float getTorsoTwist() const { return _torsoTwist; } virtual float getFinalLeanSideways() const { return _leanSideways; } virtual float getFinalLeanForward() const { return _leanForward; } void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; } void setLeanForward(float leanForward) { _leanForward = leanForward; } + void setTorsoTwist(float torsoTwist) { _torsoTwist = torsoTwist; } friend class AvatarData; @@ -86,6 +88,7 @@ protected: float _baseRoll; float _leanSideways; float _leanForward; + float _torsoTwist; glm::vec3 _lookAtPosition; float _audioLoudness; diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index f2c292b528..54368b1423 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -57,7 +57,7 @@ PacketVersion versionForPacketType(PacketType type) { case PacketTypeInjectAudio: return 1; case PacketTypeAvatarData: - return 4; + return 5; case PacketTypeAvatarIdentity: return 1; case PacketTypeEnvironmentData: