change avatarOrientation to use SixByteQuat packing

This commit is contained in:
ZappoMan 2017-01-10 09:41:11 -08:00
parent 8bbfb51419
commit 182edf0e9a
2 changed files with 19 additions and 6 deletions

View file

@ -313,13 +313,16 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
}
if (hasAvatarOrientation) {
auto data = reinterpret_cast<AvatarDataPacket::AvatarOrientation*>(destinationBuffer);
auto localOrientation = getLocalOrientation();
/*
auto data = reinterpret_cast<AvatarDataPacket::AvatarOrientation*>(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<const AvatarDataPacket::AvatarOrientation*>(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);
}

View file

@ -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;