From 65bc6aa37114fc3fcd9a6a9437ee3df2a702283e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 8 Dec 2015 10:48:11 -0800 Subject: [PATCH] Fix left hand grab --- examples/controllers/handControllerGrab.js | 43 ++++++++++++++++------ interface/src/avatar/AvatarActionHold.cpp | 4 +- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 138240f5d6..07894b46d1 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -202,31 +202,41 @@ function entityIsGrabbedByOther(entityID) { } function getSpatialOffsetPosition(hand, spatialKey) { + var position = Vec3.ZERO; + if (hand !== RIGHT_HAND && spatialKey.leftRelativePosition) { - return spatialKey.leftRelativePosition; + position = spatialKey.leftRelativePosition; } if (hand === RIGHT_HAND && spatialKey.rightRelativePosition) { - return spatialKey.rightRelativePosition; + position = spatialKey.rightRelativePosition; } if (spatialKey.relativePosition) { - return spatialKey.relativePosition; + position = spatialKey.relativePosition; } - return Vec3.ZERO; + return position; } +var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y); function getSpatialOffsetRotation(hand, spatialKey) { + var rotation = Quat.IDENTITY; + if (hand !== RIGHT_HAND && spatialKey.leftRelativeRotation) { - return spatialKey.leftRelativeRotation; + rotation = spatialKey.leftRelativeRotation; } if (hand === RIGHT_HAND && spatialKey.rightRelativeRotation) { - return spatialKey.rightRelativeRotation; + rotation = spatialKey.rightRelativeRotation; } if (spatialKey.relativeRotation) { - return spatialKey.relativeRotation; + rotation = spatialKey.relativeRotation; } - return Quat.IDENTITY; + // Flip left hand + if (hand !== RIGHT_HAND) { + rotation = Quat.multiply(yFlip, rotation); + } + + return rotation; } function MyController(hand) { @@ -254,6 +264,7 @@ function MyController(hand) { this.overlayLine = null; + this.ignoreIK = false; this.offsetPosition = Vec3.ZERO; this.offsetRotation = Quat.IDENTITY; @@ -853,9 +864,12 @@ function MyController(hand) { if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) { // if an object is "equipped" and has a spatialKey, use it. + this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false; this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); } else { + this.ignoreIK = false; + var objectRotation = grabbedProperties.rotation; this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); @@ -872,7 +886,8 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true + kinematicSetVelocity: true, + ignoreIK: this.ignoreIK }); if (this.actionID === NULL_ACTION_ID) { this.actionID = null; @@ -956,7 +971,8 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true + kinematicSetVelocity: true, + ignoreIK: this.ignoreIK }); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); } @@ -982,6 +998,7 @@ function MyController(hand) { // use a spring to pull the object to where it will be when equipped var relativeRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); var relativePosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); + var ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false; var handRotation = this.getHandRotation(); var handPosition = this.getHandPosition(); var targetRotation = Quat.multiply(handRotation, relativeRotation); @@ -996,7 +1013,8 @@ function MyController(hand) { linearTimeScale: EQUIP_SPRING_TIMEFRAME, targetRotation: targetRotation, angularTimeScale: EQUIP_SPRING_TIMEFRAME, - ttl: ACTION_TTL + ttl: ACTION_TTL, + ignoreIK: ignoreIK }); if (this.equipSpringID === NULL_ACTION_ID) { this.equipSpringID = null; @@ -1009,7 +1027,8 @@ function MyController(hand) { linearTimeScale: EQUIP_SPRING_TIMEFRAME, targetRotation: targetRotation, angularTimeScale: EQUIP_SPRING_TIMEFRAME, - ttl: ACTION_TTL + ttl: ACTION_TTL, + ignoreIK: ignoreIK }); } diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index fab838aa68..c2eea69a17 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -85,8 +85,8 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { QList holdActions = ownerEntity->getActionsOfType(ACTION_TYPE_HOLD); foreach (EntityActionPointer action, holdActions) { std::shared_ptr holdAction = std::static_pointer_cast(action); - glm::quat rotationForAction; - glm::vec3 positionForAction; + glm::quat rotationForAction { Quaternions::IDENTITY }; + glm::vec3 positionForAction { Vectors::ZERO }; std::shared_ptr holdingAvatar = holdAction->getTarget(rotationForAction, positionForAction); if (holdingAvatar) { holdCount ++;