From 182edf0e9ae11add375821fc7c7aa314e58da0b0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 10 Jan 2017 09:41:11 -0800 Subject: [PATCH] change avatarOrientation to use SixByteQuat packing --- libraries/avatars/src/AvatarData.cpp | 17 +++++++++++++---- libraries/avatars/src/AvatarData.h | 8 ++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index be21abcfd5..e70e73f8b5 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -313,13 +313,16 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent } if (hasAvatarOrientation) { - auto data = reinterpret_cast(destinationBuffer); auto localOrientation = getLocalOrientation(); + /* + auto data = reinterpret_cast(destinationBuffer); glm::vec3 bodyEulerAngles = glm::degrees(safeEulerAngles(localOrientation)); packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 0), bodyEulerAngles.y); packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 1), bodyEulerAngles.x); packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 2), bodyEulerAngles.z); destinationBuffer += sizeof(AvatarDataPacket::AvatarOrientation); + */ + destinationBuffer += packOrientationQuatToSixBytes(destinationBuffer, localOrientation); } if (hasAvatarScale) { @@ -704,6 +707,8 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { auto startSection = sourceBuffer; PACKET_READ_CHECK(AvatarOrientation, sizeof(AvatarDataPacket::AvatarOrientation)); + + /* auto data = reinterpret_cast(sourceBuffer); float pitch, yaw, roll; unpackFloatAngleFromTwoByte(data->localOrientation + 0, &yaw); @@ -715,15 +720,19 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { } return buffer.size(); } - - glm::quat currentOrientation = getLocalOrientation(); glm::vec3 newEulerAngles(pitch, yaw, roll); glm::quat newOrientation = glm::quat(glm::radians(newEulerAngles)); + sourceBuffer += sizeof(AvatarDataPacket::AvatarOrientation); + */ + + glm::quat newOrientation; + sourceBuffer += unpackOrientationQuatFromSixBytes(sourceBuffer, newOrientation); + + glm::quat currentOrientation = getLocalOrientation(); if (currentOrientation != newOrientation) { _hasNewJointRotations = true; setLocalOrientation(newOrientation); } - sourceBuffer += sizeof(AvatarDataPacket::AvatarOrientation); int numBytesRead = sourceBuffer - startSection; _avatarOrientationRate.increment(numBytesRead); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index bb6135dc7e..a31166920a 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -177,9 +177,13 @@ namespace AvatarDataPacket { const size_t AVATAR_DIMENSIONS_SIZE = 12; + using SixByteQuat = uint8_t[6]; PACKED_BEGIN struct AvatarOrientation { - smallFloat localOrientation[3]; // avatar's local euler angles (degrees, compressed) relative to the - // thing it's attached to, or world relative if not attached + //smallFloat localOrientation[3]; // avatar's local euler angles (degrees, compressed) relative to the + // thing it's attached to, or world relative if not attached + + SixByteQuat avatarOrientation; // encodeded and compressed by packOrientationQuatToSixBytes() + } PACKED_END; const size_t AVATAR_ORIENTATION_SIZE = 6;