some fixes for when an avatar is a child of something else

This commit is contained in:
Seth Alves 2017-02-12 08:27:39 -08:00
parent e6142d9719
commit 1164a1b3bf
3 changed files with 23 additions and 20 deletions

View file

@ -405,7 +405,7 @@ void AvatarMixer::broadcastAvatarData() {
otherNodeData->getLastReceivedSequenceNumber()); otherNodeData->getLastReceivedSequenceNumber());
// determine if avatar is in view, to determine how much data to include... // 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); AABox otherNodeBox(otherNodeData->getGlobalBoundingBoxCorner(), otherNodeBoxScale);
bool isInView = nodeData->otherAvatarInView(otherNodeBox); bool isInView = nodeData->otherAvatarInView(otherNodeBox);
@ -431,7 +431,7 @@ void AvatarMixer::broadcastAvatarData() {
auto lastEncodeForOther = nodeData->getLastOtherAvatarEncodeTime(otherNode->getUUID()); auto lastEncodeForOther = nodeData->getLastOtherAvatarEncodeTime(otherNode->getUUID());
QVector<JointData>& lastSentJointsForOther = nodeData->getLastOtherAvatarSentJoints(otherNode->getUUID()); QVector<JointData>& lastSentJointsForOther = nodeData->getLastOtherAvatarSentJoints(otherNode->getUUID());
bool distanceAdjust = true; bool distanceAdjust = true;
glm::vec3 viewerPosition = nodeData->getPosition(); glm::vec3 viewerPosition = myPosition;
auto bytes = otherAvatar.toByteArray(detail, lastEncodeForOther, lastSentJointsForOther, distanceAdjust, viewerPosition, &lastSentJointsForOther); auto bytes = otherAvatar.toByteArray(detail, lastEncodeForOther, lastSentJointsForOther, distanceAdjust, viewerPosition, &lastSentJointsForOther);
numAvatarDataBytes += avatarPacketList->write(bytes); numAvatarDataBytes += avatarPacketList->write(bytes);

View file

@ -1324,6 +1324,7 @@ void Avatar::setParentID(const QUuid& parentID) {
if (!isMyAvatar()) { if (!isMyAvatar()) {
return; return;
} }
QUuid initialParentID = getParentID();
bool success; bool success;
Transform beforeChangeTransform = getTransform(success); Transform beforeChangeTransform = getTransform(success);
SpatiallyNestable::setParentID(parentID); SpatiallyNestable::setParentID(parentID);
@ -1332,6 +1333,9 @@ void Avatar::setParentID(const QUuid& parentID) {
if (!success) { if (!success) {
qCDebug(interfaceapp) << "Avatar::setParentID failed to reset avatar's location."; qCDebug(interfaceapp) << "Avatar::setParentID failed to reset avatar's location.";
} }
if (initialParentID != parentID) {
_parentChanged = usecTimestampNow();
}
} }
} }

View file

@ -405,6 +405,18 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
_additionalFlagsRateOutbound.increment(numBytes); _additionalFlagsRateOutbound.increment(numBytes);
} }
if (hasParentInfo) {
auto startSection = destinationBuffer;
auto parentInfo = reinterpret_cast<AvatarDataPacket::ParentInfo*>(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) { if (hasAvatarLocalPosition) {
auto startSection = destinationBuffer; auto startSection = destinationBuffer;
auto data = reinterpret_cast<AvatarDataPacket::AvatarLocalPosition*>(destinationBuffer); auto data = reinterpret_cast<AvatarDataPacket::AvatarLocalPosition*>(destinationBuffer);
@ -418,18 +430,6 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
_localPositionRateOutbound.increment(numBytes); _localPositionRateOutbound.increment(numBytes);
} }
if (hasParentInfo) {
auto startSection = destinationBuffer;
auto parentInfo = reinterpret_cast<AvatarDataPacket::ParentInfo*>(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 it is connected, pack up the data
if (hasFaceTrackerInfo) { if (hasFaceTrackerInfo) {
auto startSection = destinationBuffer; auto startSection = destinationBuffer;
@ -904,19 +904,18 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
auto newParentID = QUuid::fromRfc4122(byteArray); auto newParentID = QUuid::fromRfc4122(byteArray);
if ((_parentID != newParentID) || (_parentJointIndex = parentInfo->parentJointIndex)) { if ((_parentID != newParentID) || (_parentJointIndex != parentInfo->parentJointIndex)) {
_parentID = newParentID; setParentID(newParentID);
_parentJointIndex = parentInfo->parentJointIndex; setParentJointIndex(parentInfo->parentJointIndex);
_parentChanged = usecTimestampNow(); _parentChanged = usecTimestampNow();
} }
int numBytesRead = sourceBuffer - startSection; int numBytesRead = sourceBuffer - startSection;
_parentInfoRate.increment(numBytesRead); _parentInfoRate.increment(numBytesRead);
_parentInfoUpdateRate.increment(); _parentInfoUpdateRate.increment();
} } else {
else {
// FIXME - this aint totally right, for switching to parent/no-parent // FIXME - this aint totally right, for switching to parent/no-parent
_parentID = QUuid(); setParentID(QUuid());
} }
if (hasAvatarLocalPosition) { if (hasAvatarLocalPosition) {