From b4988b0998b0f5c40962cbd5fa4817294ee13cb4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Dec 2015 15:09:10 -0800 Subject: [PATCH 1/6] Taking individual avatar hand size into consideration for grabbing objects --- examples/controllers/handControllerGrab.js | 9 ++- examples/libraries/utils.js | 27 +++++++ unpublishedScripts/hiddenEntityReset.js | 67 +-------------- unpublishedScripts/masterReset.js | 94 +++++----------------- 4 files changed, 54 insertions(+), 143 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 9e7623b483..7afb687f6d 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -226,6 +226,9 @@ function getSpatialOffsetPosition(hand, spatialKey) { position = spatialKey.relativePosition; } + // add the relative hand center offset + var handSizeRatio = calculateHandSizeRatio(); + position = Vec3.multiply(position, handSizeRatio); return position; } @@ -1159,12 +1162,14 @@ 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; - if (grabbableData.spatialKey.relativePosition) { + if (grabbableData.spatialKey.relativePosition || grabbableData.spatialKey.rightRelativePosition + || grabbableData.spatialKey.leftRelativePosition) { this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); } else { this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); } - if (grabbableData.spatialKey.relativeRotation) { + if (grabbableData.spatialKey.relativeRotation || grabbableData.spatialKey.rightRelativeRotation + || grabbableData.spatialKey.leftRelativeRotation) { this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); } else { this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index 5d14bfb7dd..37dccd5ac8 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -271,3 +271,30 @@ hexToRgb = function(hex) { } : null; } +calculateHandSizeRatio = function() { + // Get the ratio of the current avatar's hand to Owen's hand + + // var standardCenterHandPoint = 0.11288; + var standardCenterHandPoint = 0.11288; + var jointNames = MyAvatar.getJointNames(); + //get distance from handJoint up to leftHandIndex3 as a proxy for center of hand + var wristToFingertipDistance = 0;; + for (var i = 0; i < jointNames.length; i++) { + var jointName = jointNames[i]; + print(jointName) + if (jointName.indexOf("LeftHandIndex") !== -1) { + // translations are relative to parent joint, so simply add them together + // joints face down the y-axis + var translation = MyAvatar.getDefaultJointTranslation(i).y; + wristToFingertipDistance += translation; + } + } + // Right now units are in cm, so convert to meters + wristToFingertipDistance /= 100; + + var centerHandPoint = wristToFingertipDistance/2; + + // Compare against standard hand (Owen) + var handSizeRatio = centerHandPoint/standardCenterHandPoint; + return handSizeRatio; +} diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index 94d815796b..e8783bbbcb 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -169,7 +169,7 @@ } function createRaveStick(position) { - var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/rave/raveStick.fbx"; + var modelURL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/raveStick.fbx"; var stick = Entities.addEntity({ type: "Model", name: "raveStick", @@ -205,71 +205,6 @@ } }) }); - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0) - var forwardVec = Quat.getFront(Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0))); - forwardVec = Vec3.normalize(forwardVec); - var forwardQuat = orientationOf(forwardVec); - position = Vec3.sum(position, Vec3.multiply(Quat.getFront(rotation), 0.1)); - position.z += 0.1; - position.x += -0.035; - var color = { - red: 0, - green: 200, - blue: 40 - }; - var props = { - type: "ParticleEffect", - position: position, - parentID: stick, - isEmitting: true, - name: "raveBeam", - colorStart: color, - colorSpread: { - red: 200, - green: 10, - blue: 10 - }, - color: { - red: 200, - green: 200, - blue: 255 - }, - colorFinish: color, - maxParticles: 100000, - lifespan: 1, - emitRate: 1000, - emitOrientation: forwardQuat, - emitSpeed: 0.2, - speedSpread: 0.0, - polarStart: 0, - polarFinish: 0.0, - azimuthStart: 0.1, - azimuthFinish: 0.01, - emitAcceleration: { - x: 0, - y: 0, - z: 0 - }, - accelerationSpread: { - x: 0.00, - y: 0.00, - z: 0.00 - }, - radiusStart: 0.03, - radiusFinish: 0.025, - alpha: 0.7, - alphaSpread:0.1, - alphaStart: 0.5, - alphaFinish: 0.5, - textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png", - emitterShouldTrail: false, - userData: JSON.stringify({ - resetMe: { - resetMe: true - } - }) - } - var beam = Entities.addEntity(props); } diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 9afbd0a68b..f3c38b2adf 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -148,7 +148,7 @@ MasterReset = function() { } function createRaveStick(position) { - var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/rave/raveStick.fbx"; + var modelURL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/raveStick.fbx"; var stick = Entities.addEntity({ type: "Model", name: "raveStick", @@ -173,10 +173,15 @@ MasterReset = function() { }, grabbableKey: { spatialKey: { - relativePosition: { - x: 0, + rightRelativePosition: { + x: 0.02, y: 0, - z: -0.1 + z: 0 + }, + leftRelativePosition: { + x: -0.02, + y: 0, + z: 0 }, relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) }, @@ -184,72 +189,6 @@ MasterReset = function() { } }) }); - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0) - var forwardVec = Quat.getFront(Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0))); - forwardVec = Vec3.normalize(forwardVec); - var forwardQuat = orientationOf(forwardVec); - position = Vec3.sum(position, Vec3.multiply(Quat.getFront(rotation), 0.1)); - position.z += 0.1; - position.x += -0.035; - var color = { - red: 0, - green: 200, - blue: 40 - }; - var props = { - type: "ParticleEffect", - position: position, - parentID: stick, - isEmitting: true, - name: "raveBeam", - colorStart: color, - colorSpread: { - red: 200, - green: 10, - blue: 10 - }, - color: { - red: 200, - green: 200, - blue: 255 - }, - colorFinish: color, - maxParticles: 100000, - lifespan: 1, - emitRate: 1000, - emitOrientation: forwardQuat, - emitSpeed: 0.2, - speedSpread: 0.0, - polarStart: 0, - polarFinish: 0.0, - azimuthStart: 0.1, - azimuthFinish: 0.01, - emitAcceleration: { - x: 0, - y: 0, - z: 0 - }, - accelerationSpread: { - x: 0.00, - y: 0.00, - z: 0.00 - }, - radiusStart: 0.03, - radiusFinish: 0.025, - alpha: 0.7, - alphaSpread: 0.1, - alphaStart: 0.5, - alphaFinish: 0.5, - textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png", - emitterShouldTrail: false, - userData: JSON.stringify({ - resetMe: { - resetMe: true - } - }) - } - var beam = Entities.addEntity(props); - } function createGun(position) { @@ -283,10 +222,15 @@ MasterReset = function() { userData: JSON.stringify({ grabbableKey: { spatialKey: { - relativePosition: { - x: 0, + rightRelativePosition: { + x: 0.02, y: 0, - z: -0.1 + z: -0.03 + }, + leftRelativePosition: { + x: -0.02, + y: 0, + z: -0.03 }, relativeRotation: Quat.fromPitchYawRollDegrees(100, 90, 0) }, @@ -1136,9 +1080,9 @@ MasterReset = function() { grabbableKey: { spatialKey: { relativePosition: { - x: -0.05, + x: 0, y: 0, - z: 0.0 + z: .06 }, relativeRotation: Quat.fromPitchYawRollDegrees(0,-90, -90) }, From 24796c1a1eb46cce988752634bd40ba62cf28bdd Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Dec 2015 10:14:36 -0800 Subject: [PATCH 2/6] updated ravestick spawner relative position --- examples/flowArts/raveStick/raveStick.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/flowArts/raveStick/raveStick.js b/examples/flowArts/raveStick/raveStick.js index c51e8b5d89..5fb019bf97 100644 --- a/examples/flowArts/raveStick/raveStick.js +++ b/examples/flowArts/raveStick/raveStick.js @@ -40,13 +40,18 @@ RaveStick = function(spawnPosition) { userData: JSON.stringify({ grabbableKey: { spatialKey: { - relativePosition: { - x: 0, - y: 0, - z: -0.1 + rightRelativePosition: { + x: 0.02, + y: 0, + z: 0 + }, + leftRelativePosition: { + x: -0.02, + y: 0, + z: 0 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) }, - relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) - }, invertSolidWhileHeld: true } }) From c4d7b7b9bb2afc5abd5f084c45391ef51a372fca Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 10:21:23 -0800 Subject: [PATCH 3/6] Update utils.js --- examples/libraries/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index 37dccd5ac8..115c1bcb65 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -274,7 +274,6 @@ hexToRgb = function(hex) { calculateHandSizeRatio = function() { // Get the ratio of the current avatar's hand to Owen's hand - // var standardCenterHandPoint = 0.11288; var standardCenterHandPoint = 0.11288; var jointNames = MyAvatar.getJointNames(); //get distance from handJoint up to leftHandIndex3 as a proxy for center of hand From 679070ff6e1b155fcb8388aa3c446515499e4d8f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 10:22:02 -0800 Subject: [PATCH 4/6] Update hiddenEntityReset.js --- unpublishedScripts/hiddenEntityReset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index e8783bbbcb..a53d6e721f 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -169,7 +169,7 @@ } function createRaveStick(position) { - var modelURL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/raveStick.fbx"; + var modelURL = "http://hifi-content.s3.amazonaws.com/eric/models/raveStick.fbx"; var stick = Entities.addEntity({ type: "Model", name: "raveStick", From 4f80753d7b0c9ec88f49cc3ea3034d5929967e9f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 10:22:34 -0800 Subject: [PATCH 5/6] Update masterReset.js --- unpublishedScripts/masterReset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index f3c38b2adf..b82c8340e4 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -148,7 +148,7 @@ MasterReset = function() { } function createRaveStick(position) { - var modelURL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/raveStick.fbx"; + var modelURL = "http://hifi-content.s3.amazonaws.com/eric/models/raveStick.fbx"; var stick = Entities.addEntity({ type: "Model", name: "raveStick", From 4b50a030e06aeffd105abd977511e4f1932edf30 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 10:23:08 -0800 Subject: [PATCH 6/6] Update masterReset.js --- unpublishedScripts/masterReset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index b82c8340e4..2d6d9a0d01 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -1082,7 +1082,7 @@ MasterReset = function() { relativePosition: { x: 0, y: 0, - z: .06 + z: 0.06 }, relativeRotation: Quat.fromPitchYawRollDegrees(0,-90, -90) },