Merge branch 'master' into 20639

This commit is contained in:
David Rowe 2015-08-12 16:34:53 -07:00
commit c0439f123b
6 changed files with 86 additions and 105 deletions

View file

@ -161,16 +161,6 @@ QByteArray AvatarData::toByteArray() {
// Body scale // Body scale
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale); destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale);
// Head rotation
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalPitch());
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw());
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll());
// Body lean
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist);
// Lookat Position // Lookat Position
memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition));
destinationBuffer += sizeof(_headData->_lookAtPosition); destinationBuffer += sizeof(_headData->_lookAtPosition);
@ -283,25 +273,20 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
// The absolute minimum size of the update data is as follows: // The absolute minimum size of the update data is as follows:
// 50 bytes of "plain old data" { // 36 bytes of "plain old data" {
// position = 12 bytes // position = 12 bytes
// bodyYaw = 2 (compressed float) // bodyYaw = 2 (compressed float)
// bodyPitch = 2 (compressed float) // bodyPitch = 2 (compressed float)
// bodyRoll = 2 (compressed float) // bodyRoll = 2 (compressed float)
// targetScale = 2 (compressed float) // targetScale = 2 (compressed float)
// headPitch = 2 (compressed float)
// headYaw = 2 (compressed float)
// headRoll = 2 (compressed float)
// leanForward = 2 (compressed float)
// leanSideways = 2 (compressed float)
// torsoTwist = 2 (compressed float)
// lookAt = 12 // lookAt = 12
// audioLoudness = 4 // audioLoudness = 4
// } // }
// + 1 byte for varying data
// + 1 byte for pupilSize // + 1 byte for pupilSize
// + 1 byte for numJoints (0) // + 1 byte for numJoints (0)
// = 51 bytes // = 39 bytes
int minPossibleSize = 51; int minPossibleSize = 39;
int maxAvailableSize = buffer.size(); int maxAvailableSize = buffer.size();
if (minPossibleSize > maxAvailableSize) { if (minPossibleSize > maxAvailableSize) {
@ -359,39 +344,6 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
_targetScale = scale; _targetScale = scale;
} // 20 bytes } // 20 bytes
{ // Head rotation
//(NOTE: This needs to become a quaternion to save two bytes)
float headYaw, headPitch, headRoll;
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)) {
qCDebug(avatars) << "Discard nan AvatarData::headYaw,headPitch,headRoll; displayName = '" << _displayName << "'";
}
return maxAvailableSize;
}
_headData->setBasePitch(headPitch);
_headData->setBaseYaw(headYaw);
_headData->setBaseRoll(headRoll);
} // 6 bytes
{ // Head lean (relative to pelvis)
float leanForward, leanSideways, torsoTwist;
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanForward);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanSideways);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &torsoTwist);
if (glm::isnan(leanForward) || glm::isnan(leanSideways)) {
if (shouldLogError(now)) {
qCDebug(avatars) << "Discard nan AvatarData::leanForward,leanSideways,torsoTwise; displayName = '" << _displayName << "'";
}
return maxAvailableSize;
}
_headData->_leanForward = leanForward;
_headData->_leanSideways = leanSideways;
_headData->_torsoTwist = torsoTwist;
} // 6 bytes
{ // Lookat Position { // Lookat Position
glm::vec3 lookAt; glm::vec3 lookAt;
memcpy(&lookAt, sourceBuffer, sizeof(lookAt)); memcpy(&lookAt, sourceBuffer, sizeof(lookAt));

View file

@ -1185,74 +1185,84 @@ void EntityItem::setDimensions(const glm::vec3& value) {
return; return;
} }
_transform.setScale(value); _transform.setScale(value);
requiresRecalcBoxes();
} }
/// The maximum bounding cube for the entity, independent of it's rotation. /// The maximum bounding cube for the entity, independent of it's rotation.
/// This accounts for the registration point (upon which rotation occurs around). /// This accounts for the registration point (upon which rotation occurs around).
/// ///
AACube EntityItem::getMaximumAACube() const { const AACube& EntityItem::getMaximumAACube() const {
// * we know that the position is the center of rotation if (_recalcMaxAACube) {
glm::vec3 centerOfRotation = getPosition(); // also where _registration point is // * we know that the position is the center of rotation
glm::vec3 centerOfRotation = getPosition(); // also where _registration point is
// * we know that the registration point is the center of rotation // * we know that the registration point is the center of rotation
// * we can calculate the length of the furthest extent from the registration point // * we can calculate the length of the furthest extent from the registration point
// as the dimensions * max (registrationPoint, (1.0,1.0,1.0) - registrationPoint) // as the dimensions * max (registrationPoint, (1.0,1.0,1.0) - registrationPoint)
glm::vec3 registrationPoint = (getDimensions() * getRegistrationPoint()); glm::vec3 registrationPoint = (getDimensions() * getRegistrationPoint());
glm::vec3 registrationRemainder = (getDimensions() * (glm::vec3(1.0f, 1.0f, 1.0f) - getRegistrationPoint())); glm::vec3 registrationRemainder = (getDimensions() * (glm::vec3(1.0f, 1.0f, 1.0f) - getRegistrationPoint()));
glm::vec3 furthestExtentFromRegistration = glm::max(registrationPoint, registrationRemainder); glm::vec3 furthestExtentFromRegistration = glm::max(registrationPoint, registrationRemainder);
// * we know that if you rotate in any direction you would create a sphere // * we know that if you rotate in any direction you would create a sphere
// that has a radius of the length of furthest extent from registration point // that has a radius of the length of furthest extent from registration point
float radius = glm::length(furthestExtentFromRegistration); float radius = glm::length(furthestExtentFromRegistration);
// * we know that the minimum bounding cube of this maximum possible sphere is // * we know that the minimum bounding cube of this maximum possible sphere is
// (center - radius) to (center + radius) // (center - radius) to (center + radius)
glm::vec3 minimumCorner = centerOfRotation - glm::vec3(radius, radius, radius); glm::vec3 minimumCorner = centerOfRotation - glm::vec3(radius, radius, radius);
AACube boundingCube(minimumCorner, radius * 2.0f); _maxAACube = AACube(minimumCorner, radius * 2.0f);
return boundingCube; _recalcMaxAACube = false;
}
return _maxAACube;
} }
/// The minimum bounding cube for the entity accounting for it's rotation. /// The minimum bounding cube for the entity accounting for it's rotation.
/// This accounts for the registration point (upon which rotation occurs around). /// This accounts for the registration point (upon which rotation occurs around).
/// ///
AACube EntityItem::getMinimumAACube() const { const AACube& EntityItem::getMinimumAACube() const {
// _position represents the position of the registration point. if (_recalcMinAACube) {
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; // _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * getRegistrationPoint()); glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * getRegistrationPoint());
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder; glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity }; Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation()); Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
// shift the extents to be relative to the position/registration point // shift the extents to be relative to the position/registration point
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition()); rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
// the cube that best encompasses extents is... // the cube that best encompasses extents is...
AABox box(rotatedExtentsRelativeToRegistrationPoint); AABox box(rotatedExtentsRelativeToRegistrationPoint);
glm::vec3 centerOfBox = box.calcCenter(); glm::vec3 centerOfBox = box.calcCenter();
float longestSide = box.getLargestDimension(); float longestSide = box.getLargestDimension();
float halfLongestSide = longestSide / 2.0f; float halfLongestSide = longestSide / 2.0f;
glm::vec3 cornerOfCube = centerOfBox - glm::vec3(halfLongestSide, halfLongestSide, halfLongestSide); glm::vec3 cornerOfCube = centerOfBox - glm::vec3(halfLongestSide, halfLongestSide, halfLongestSide);
_minAACube = AACube(cornerOfCube, longestSide);
// old implementation... not correct!!! _recalcMinAACube = false;
return AACube(cornerOfCube, longestSide); }
return _minAACube;
} }
AABox EntityItem::getAABox() const { const AABox& EntityItem::getAABox() const {
// _position represents the position of the registration point. if (_recalcAABox) {
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; // _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * _registrationPoint); glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * _registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder; glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity }; Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation()); Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
// shift the extents to be relative to the position/registration point // shift the extents to be relative to the position/registration point
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition()); rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
return AABox(rotatedExtentsRelativeToRegistrationPoint); _cachedAABox = AABox(rotatedExtentsRelativeToRegistrationPoint);
_recalcAABox = false;
}
return _cachedAABox;
} }
// NOTE: This should only be used in cases of old bitstreams which only contain radius data // NOTE: This should only be used in cases of old bitstreams which only contain radius data

View file

@ -214,14 +214,16 @@ public:
void setTranformToCenter(const Transform& transform); void setTranformToCenter(const Transform& transform);
inline const Transform& getTransform() const { return _transform; } inline const Transform& getTransform() const { return _transform; }
inline void setTransform(const Transform& transform) { _transform = transform; } inline void setTransform(const Transform& transform) { _transform = transform; requiresRecalcBoxes(); }
/// Position in meters (0.0 - TREE_SCALE) /// Position in meters (0.0 - TREE_SCALE)
inline const glm::vec3& getPosition() const { return _transform.getTranslation(); } inline const glm::vec3& getPosition() const { return _transform.getTranslation(); }
inline void setPosition(const glm::vec3& value) { _transform.setTranslation(value); } inline void setPosition(const glm::vec3& value) { _transform.setTranslation(value); requiresRecalcBoxes(); }
inline const glm::quat& getRotation() const { return _transform.getRotation(); } inline const glm::quat& getRotation() const { return _transform.getRotation(); }
inline void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); } inline void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); requiresRecalcBoxes(); }
inline void requiresRecalcBoxes() { _recalcAABox = true; _recalcMinAACube = true; _recalcMaxAACube = true; }
// Hyperlink related getters and setters // Hyperlink related getters and setters
QString getHref() const { return _href; } QString getHref() const { return _href; }
@ -286,9 +288,9 @@ public:
quint64 getExpiry() const; quint64 getExpiry() const;
// position, size, and bounds related helpers // position, size, and bounds related helpers
AACube getMaximumAACube() const; const AACube& getMaximumAACube() const;
AACube getMinimumAACube() const; const AACube& getMinimumAACube() const;
AABox getAABox() const; /// axis aligned bounding box in world-frame (meters) const AABox& getAABox() const; /// axis aligned bounding box in world-frame (meters)
const QString& getScript() const { return _script; } const QString& getScript() const { return _script; }
void setScript(const QString& value) { _script = value; } void setScript(const QString& value) { _script = value; }
@ -303,7 +305,7 @@ public:
/// registration point as ratio of entity /// registration point as ratio of entity
void setRegistrationPoint(const glm::vec3& value) void setRegistrationPoint(const glm::vec3& value)
{ _registrationPoint = glm::clamp(value, 0.0f, 1.0f); } { _registrationPoint = glm::clamp(value, 0.0f, 1.0f); requiresRecalcBoxes(); }
const glm::vec3& getAngularVelocity() const { return _angularVelocity; } const glm::vec3& getAngularVelocity() const { return _angularVelocity; }
void setAngularVelocity(const glm::vec3& value) { _angularVelocity = value; } void setAngularVelocity(const glm::vec3& value) { _angularVelocity = value; }
@ -434,6 +436,13 @@ protected:
quint64 _changedOnServer; quint64 _changedOnServer;
Transform _transform; Transform _transform;
mutable AABox _cachedAABox;
mutable AACube _maxAACube;
mutable AACube _minAACube;
mutable bool _recalcAABox = true;
mutable bool _recalcMinAACube = true;
mutable bool _recalcMaxAACube = true;
float _glowLevel; float _glowLevel;
float _localRenderAlpha; float _localRenderAlpha;
float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3 float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3

View file

@ -65,7 +65,14 @@ ViveControllerManager::ViveControllerManager() :
bool ViveControllerManager::isSupported() const { bool ViveControllerManager::isSupported() const {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return vr::VR_IsHmdPresent(); bool success = vr::VR_IsHmdPresent();
if (success) {
vr::HmdError eError = vr::HmdError_None;
auto hmd = vr::VR_Init(&eError);
success = (hmd != nullptr);
vr::VR_Shutdown();
}
return success;
#else #else
return false; return false;
#endif #endif

View file

@ -68,6 +68,8 @@ PacketVersion versionForPacketType(PacketType::Value packetType) {
case EntityEdit: case EntityEdit:
case EntityData: case EntityData:
return VERSION_ENTITIES_POLYLINE; return VERSION_ENTITIES_POLYLINE;
case AvatarData:
return VERSION_AVATAR_NO_LEAN;
default: default:
return 11; return 11;
} }

View file

@ -142,5 +142,6 @@ const PacketVersion VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE
const PacketVersion VERSION_ENTITIES_NEW_PROTOCOL_LAYER = 35; const PacketVersion VERSION_ENTITIES_NEW_PROTOCOL_LAYER = 35;
const PacketVersion VERSION_POLYVOX_TEXTURES = 36; const PacketVersion VERSION_POLYVOX_TEXTURES = 36;
const PacketVersion VERSION_ENTITIES_POLYLINE = 37; const PacketVersion VERSION_ENTITIES_POLYLINE = 37;
const PacketVersion VERSION_AVATAR_NO_LEAN = 38;
#endif // hifi_PacketHeaders_h #endif // hifi_PacketHeaders_h