diff --git a/examples/baseball/createBatButton.js b/examples/baseball/createBatButton.js index 75f3dee26e..bbd2bea9f2 100644 --- a/examples/baseball/createBatButton.js +++ b/examples/baseball/createBatButton.js @@ -51,10 +51,9 @@ var batUserData = { grabbableKey: { spatialKey: { - relativePosition: { x: 0.9, y: 0, z: 0 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45), - perHandRelativePosition: { x: 0.0, y: -0.05, z: -0.04 }, - perHandRelativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0) + leftRelativePosition: { x: 0.9, y: 0.05, z: -0.05 }, + rightRelativePosition: { x: 0.9, y: 0.05, z: 0.05 }, + relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45) } } } diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 272c2903af..828bbd9bbf 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -200,6 +200,33 @@ function entityIsGrabbedByOther(entityID) { return false; } +function getSpatialOffsetPosition(hand, spatialKey) { + if (hand !== RIGHT_HAND && spatialKey.leftRelativePosition) { + return spatialKey.leftRelativePosition; + } + if (hand === RIGHT_HAND && spatialKey.rightRelativePosition) { + return spatialKey.rightRelativePosition; + } + if (spatialKey.relativePosition) { + return spatialKey.relativePosition; + } + + return Vec3.ZERO; +} + +function getSpatialOffsetRotation(hand, spatialKey) { + if (hand !== RIGHT_HAND && spatialKey.leftRelativeRotation) { + return spatialKey.leftRelativeRotation; + } + if (hand === RIGHT_HAND && spatialKey.rightRelativeRotation) { + return spatialKey.rightRelativeRotation; + } + if (spatialKey.relativeRotation) { + return spatialKey.relativeRotation; + } + + return Quat.IDENTITY; +} function MyController(hand) { this.hand = hand; @@ -223,20 +250,11 @@ function MyController(hand) { this.triggerValue = 0; // rolling average of trigger value this.rawTriggerValue = 0; this.rawBumperValue = 0; - + this.overlayLine = null; - - this.offsetPosition = { - x: 0.0, - y: 0.0, - z: 0.0 - }; - this.offsetRotation = { - x: 0.0, - y: 0.0, - z: 0.0, - w: 1.0 - }; + + this.offsetPosition = Vec3.ZERO; + this.offsetRotation = Quat.IDENTITY; var _this = this; @@ -815,12 +833,8 @@ function MyController(hand) { if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) { // if an object is "equipped" and has a spatialKey, use it. - if (grabbableData.spatialKey.relativePosition) { - this.offsetPosition = grabbableData.spatialKey.relativePosition; - } - if (grabbableData.spatialKey.relativeRotation) { - this.offsetRotation = grabbableData.spatialKey.relativeRotation; - } + this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); + this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); } else { var objectRotation = grabbedProperties.rotation; this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); @@ -946,23 +960,8 @@ function MyController(hand) { var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); // use a spring to pull the object to where it will be when equipped - var relativeRotation = { - x: 0.0, - y: 0.0, - z: 0.0, - w: 1.0 - }; - var relativePosition = { - x: 0.0, - y: 0.0, - z: 0.0 - }; - if (grabbableData.spatialKey.relativePosition) { - relativePosition = grabbableData.spatialKey.relativePosition; - } - if (grabbableData.spatialKey.relativeRotation) { - relativeRotation = grabbableData.spatialKey.relativeRotation; - } + var relativeRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); + var relativePosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); var handRotation = this.getHandRotation(); var handPosition = this.getHandPosition(); var targetRotation = Quat.multiply(handRotation, relativeRotation); diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 14e3ed86ec..90199fb70f 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -67,12 +67,17 @@ } var BOW_SPATIAL_KEY = { - relativePosition: { - x: 0, + leftRelativePosition: { + x: 0.05, y: 0.06, - z: 0.11 + z: -0.05 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90) + rightRelativePosition: { + x: -0.05, + y: 0.06, + z: -0.05 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90) } diff --git a/examples/toybox/bow/createBow.js b/examples/toybox/bow/createBow.js index 880b0920e8..9a9ed98c20 100644 --- a/examples/toybox/bow/createBow.js +++ b/examples/toybox/bow/createBow.js @@ -48,12 +48,17 @@ var bow = Entities.addEntity({ grabbableKey: { invertSolidWhileHeld: true, spatialKey: { - relativePosition: { - x: 0, + leftRelativePosition: { + x: 0.05, y: 0.06, - z: 0.11 + z: -0.05 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90) + rightRelativePosition: { + x: -0.05, + y: 0.06, + z: -0.05 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90) } } }) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index afa404717c..e0ea226a53 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -33,64 +33,45 @@ AvatarActionHold::~AvatarActionHold() { } std::shared_ptr AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position) { - std::shared_ptr holdingAvatar = nullptr; + auto avatarManager = DependencyManager::get(); + auto holdingAvatar = std::static_pointer_cast(avatarManager->getAvatarBySessionID(_holderID)); + + if (!holdingAvatar) { + return holdingAvatar; + } withTryReadLock([&]{ - QSharedPointer avatarManager = DependencyManager::get(); - AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID); - holdingAvatar = std::static_pointer_cast(holdingAvatarData); - - if (holdingAvatar) { - bool isRightHand = (_hand == "right"); - glm::vec3 palmPosition { Vectors::ZERO }; - glm::quat palmRotation { Quaternions::IDENTITY }; - - - static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y); - if (_ignoreIK && holdingAvatar->isMyAvatar()) { - // We cannot ignore other avatars IK and this is not the point of this option - // This is meant to make the grabbing behavior more reactive. - if (isRightHand) { - palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition(); - palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation(); - } else { - palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition(); - palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation(); - palmRotation *= yFlip; // Match right hand frame of reference - } - } else { - if (isRightHand) { - palmPosition = holdingAvatar->getRightPalmPosition(); - palmRotation = holdingAvatar->getRightPalmRotation(); - } else { - palmPosition = holdingAvatar->getLeftPalmPosition(); - palmRotation = holdingAvatar->getLeftPalmRotation(); - palmRotation *= yFlip; // Match right hand frame of reference - } - } - - rotation = palmRotation * _relativeRotation; - position = palmPosition + rotation * _relativePosition; + bool isRightHand = (_hand == "right"); + glm::vec3 palmPosition { Vectors::ZERO }; + glm::quat palmRotation { Quaternions::IDENTITY }; + if (_ignoreIK && holdingAvatar->isMyAvatar()) { + // We cannot ignore other avatars IK and this is not the point of this option + // This is meant to make the grabbing behavior more reactive. if (isRightHand) { - rotation *= _perHandRelativeRotation; - position += rotation * _perHandRelativePosition; + palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition(); + palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation(); } else { - auto mirroredRotation = _perHandRelativeRotation; - auto mirroredPosition = _perHandRelativePosition; - - // Mirror along z axis - auto eulerAngles = safeEulerAngles(mirroredRotation); - eulerAngles.x *= -1; - eulerAngles.y *= -1; - mirroredRotation = glm::quat(eulerAngles); - - mirroredPosition.z *= -1; - - rotation *= mirroredRotation; - position += rotation * mirroredPosition; + palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition(); + palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation(); + } + } else { + if (isRightHand) { + palmPosition = holdingAvatar->getRightPalmPosition(); + palmRotation = holdingAvatar->getRightPalmRotation(); + } else { + palmPosition = holdingAvatar->getLeftPalmPosition(); + palmRotation = holdingAvatar->getLeftPalmRotation(); } } + + if (!isRightHand) { + static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y); + palmRotation *= yFlip; // Match right hand frame of reference + } + + rotation = palmRotation * _relativeRotation; + position = palmPosition + rotation * _relativePosition; }); return holdingAvatar; @@ -196,8 +177,6 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) { bool AvatarActionHold::updateArguments(QVariantMap arguments) { glm::vec3 relativePosition; glm::quat relativeRotation; - glm::vec3 perHandRelativePosition; - glm::quat perHandRelativeRotation; float timeScale; QString hand; QUuid holderID; @@ -213,26 +192,12 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) { if (!ok) { relativePosition = _relativePosition; } - + ok = true; relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false); if (!ok) { relativeRotation = _relativeRotation; } - - ok = true; - perHandRelativePosition = EntityActionInterface::extractVec3Argument("hold", arguments, - "perHandRelativePosition", ok, false); - if (!ok) { - perHandRelativePosition = _perHandRelativePosition; - } - - ok = true; - perHandRelativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, - "perHandRelativeRotation", ok, false); - if (!ok) { - perHandRelativeRotation = _perHandRelativeRotation; - } ok = true; timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false); @@ -255,25 +220,17 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) { if (!ok) { _kinematic = false; } - + ok = true; kinematicSetVelocity = EntityActionInterface::extractBooleanArgument("hold", arguments, "kinematicSetVelocity", ok, false); if (!ok) { _kinematicSetVelocity = false; } - - ok = true; - ignoreIK = EntityActionInterface::extractBooleanArgument("hold", arguments, "ignoreIK", ok, false); - if (!ok) { - _ignoreIK = true; - } if (somethingChanged || relativePosition != _relativePosition || relativeRotation != _relativeRotation || - perHandRelativePosition != _perHandRelativePosition || - perHandRelativeRotation != _perHandRelativeRotation || timeScale != _linearTimeScale || hand != _hand || holderID != _holderID || @@ -288,8 +245,6 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) { withWriteLock([&] { _relativePosition = relativePosition; _relativeRotation = relativeRotation; - _perHandRelativePosition = perHandRelativePosition; - _perHandRelativeRotation = perHandRelativeRotation; const float MIN_TIMESCALE = 0.1f; _linearTimeScale = glm::max(MIN_TIMESCALE, timeScale); _angularTimeScale = _linearTimeScale; @@ -318,8 +273,6 @@ QVariantMap AvatarActionHold::getArguments() { arguments["holderID"] = _holderID; arguments["relativePosition"] = glmToQMap(_relativePosition); arguments["relativeRotation"] = glmToQMap(_relativeRotation); - arguments["perHandRelativePosition"] = glmToQMap(_perHandRelativePosition); - arguments["perHandRelativeRotation"] = glmToQMap(_perHandRelativeRotation); arguments["timeScale"] = _linearTimeScale; arguments["hand"] = _hand; arguments["kinematic"] = _kinematic; @@ -341,8 +294,6 @@ QByteArray AvatarActionHold::serialize() const { dataStream << _holderID; dataStream << _relativePosition; dataStream << _relativeRotation; - dataStream << _perHandRelativePosition; - dataStream << _perHandRelativeRotation; dataStream << _linearTimeScale; dataStream << _hand; @@ -376,8 +327,6 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) { dataStream >> _holderID; dataStream >> _relativePosition; dataStream >> _relativeRotation; - dataStream >> _perHandRelativePosition; - dataStream >> _perHandRelativeRotation; dataStream >> _linearTimeScale; _angularTimeScale = _linearTimeScale; dataStream >> _hand; diff --git a/interface/src/avatar/AvatarActionHold.h b/interface/src/avatar/AvatarActionHold.h index c9563e5e88..8a6948dde2 100644 --- a/interface/src/avatar/AvatarActionHold.h +++ b/interface/src/avatar/AvatarActionHold.h @@ -38,15 +38,12 @@ public: std::shared_ptr getTarget(glm::quat& rotation, glm::vec3& position); private: + void doKinematicUpdate(float deltaTimeStep); + static const uint16_t holdVersion; - void doKinematicUpdate(float deltaTimeStep); - - glm::vec3 _relativePosition { 0.0f }; - glm::quat _relativeRotation; - glm::vec3 _perHandRelativePosition { 0.0f }; - glm::quat _perHandRelativeRotation; - + glm::vec3 _relativePosition { Vectors::ZERO }; + glm::quat _relativeRotation { Quaternions::IDENTITY }; QString _hand { "right" }; QUuid _holderID; diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 9df597109c..9fc6855d3b 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -402,7 +402,7 @@ void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) { AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) { if (sessionID == _myAvatar->getSessionUUID()) { - return std::static_pointer_cast(_myAvatar); + return _myAvatar; } return findAvatar(sessionID); diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 7bb3a1e46f..2f685b7e08 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET; + return VERSION_ENTITIES_POLYLINE_TEXTURE; case PacketType::AvatarData: case PacketType::BulkAvatarData: default: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 5610d31661..23df89b3d7 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -160,6 +160,5 @@ const PacketVersion VERSION_ENTITIES_KEYLIGHT_PROPERTIES_GROUP = 47; const PacketVersion VERSION_ENTITIES_KEYLIGHT_PROPERTIES_GROUP_BIS = 48; const PacketVersion VERSION_ENTITIES_PARTICLES_ADDITIVE_BLENDING = 49; const PacketVersion VERSION_ENTITIES_POLYLINE_TEXTURE = 50; -const PacketVersion VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET = 51; #endif // hifi_PacketHeaders_h