From 1164a1b3bf43cba1549cc8303edf5fdf8d74d6ec Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 12 Feb 2017 08:27:39 -0800 Subject: [PATCH] some fixes for when an avatar is a child of something else --- assignment-client/src/avatars/AvatarMixer.cpp | 4 +-- interface/src/avatar/Avatar.cpp | 4 +++ libraries/avatars/src/AvatarData.cpp | 35 +++++++++---------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 61164ee8d7..bf85918145 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -405,7 +405,7 @@ void AvatarMixer::broadcastAvatarData() { otherNodeData->getLastReceivedSequenceNumber()); // determine if avatar is in view, to determine how much data to include... - glm::vec3 otherNodeBoxScale = (otherNodeData->getPosition() - otherNodeData->getGlobalBoundingBoxCorner()) * 2.0f; + glm::vec3 otherNodeBoxScale = (otherPosition - otherNodeData->getGlobalBoundingBoxCorner()) * 2.0f; AABox otherNodeBox(otherNodeData->getGlobalBoundingBoxCorner(), otherNodeBoxScale); bool isInView = nodeData->otherAvatarInView(otherNodeBox); @@ -431,7 +431,7 @@ void AvatarMixer::broadcastAvatarData() { auto lastEncodeForOther = nodeData->getLastOtherAvatarEncodeTime(otherNode->getUUID()); QVector& lastSentJointsForOther = nodeData->getLastOtherAvatarSentJoints(otherNode->getUUID()); bool distanceAdjust = true; - glm::vec3 viewerPosition = nodeData->getPosition(); + glm::vec3 viewerPosition = myPosition; auto bytes = otherAvatar.toByteArray(detail, lastEncodeForOther, lastSentJointsForOther, distanceAdjust, viewerPosition, &lastSentJointsForOther); numAvatarDataBytes += avatarPacketList->write(bytes); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index ab97f563f6..ec82ac9ff8 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -1324,6 +1324,7 @@ void Avatar::setParentID(const QUuid& parentID) { if (!isMyAvatar()) { return; } + QUuid initialParentID = getParentID(); bool success; Transform beforeChangeTransform = getTransform(success); SpatiallyNestable::setParentID(parentID); @@ -1332,6 +1333,9 @@ void Avatar::setParentID(const QUuid& parentID) { if (!success) { qCDebug(interfaceapp) << "Avatar::setParentID failed to reset avatar's location."; } + if (initialParentID != parentID) { + _parentChanged = usecTimestampNow(); + } } } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index af060429af..89cabbce3e 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -405,6 +405,18 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent _additionalFlagsRateOutbound.increment(numBytes); } + if (hasParentInfo) { + auto startSection = destinationBuffer; + auto parentInfo = reinterpret_cast(destinationBuffer); + QByteArray referentialAsBytes = parentID.toRfc4122(); + memcpy(parentInfo->parentUUID, referentialAsBytes.data(), referentialAsBytes.size()); + parentInfo->parentJointIndex = _parentJointIndex; + destinationBuffer += sizeof(AvatarDataPacket::ParentInfo); + + int numBytes = destinationBuffer - startSection; + _parentInfoRateOutbound.increment(numBytes); + } + if (hasAvatarLocalPosition) { auto startSection = destinationBuffer; auto data = reinterpret_cast(destinationBuffer); @@ -418,18 +430,6 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent _localPositionRateOutbound.increment(numBytes); } - if (hasParentInfo) { - auto startSection = destinationBuffer; - auto parentInfo = reinterpret_cast(destinationBuffer); - QByteArray referentialAsBytes = parentID.toRfc4122(); - memcpy(parentInfo->parentUUID, referentialAsBytes.data(), referentialAsBytes.size()); - parentInfo->parentJointIndex = _parentJointIndex; - destinationBuffer += sizeof(AvatarDataPacket::ParentInfo); - - int numBytes = destinationBuffer - startSection; - _parentInfoRateOutbound.increment(numBytes); - } - // If it is connected, pack up the data if (hasFaceTrackerInfo) { auto startSection = destinationBuffer; @@ -904,19 +904,18 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { auto newParentID = QUuid::fromRfc4122(byteArray); - if ((_parentID != newParentID) || (_parentJointIndex = parentInfo->parentJointIndex)) { - _parentID = newParentID; - _parentJointIndex = parentInfo->parentJointIndex; + if ((_parentID != newParentID) || (_parentJointIndex != parentInfo->parentJointIndex)) { + setParentID(newParentID); + setParentJointIndex(parentInfo->parentJointIndex); _parentChanged = usecTimestampNow(); } int numBytesRead = sourceBuffer - startSection; _parentInfoRate.increment(numBytesRead); _parentInfoUpdateRate.increment(); - } - else { + } else { // FIXME - this aint totally right, for switching to parent/no-parent - _parentID = QUuid(); + setParentID(QUuid()); } if (hasAvatarLocalPosition) {