From 595c628c39ed3ea3f254357b42148ebe6677031c Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 11 Nov 2015 17:32:03 -0800 Subject: [PATCH] it works! --- examples/controllers/handControllerGrab.js | 4 +-- examples/toybox/bow/arrow.js | 7 ++-- examples/toybox/bow/bow.js | 42 +++++++++++----------- examples/toybox/bow/createArrow.js | 2 +- examples/toybox/bow/createBowAndArrow.js | 4 +-- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index e06cdd51c5..e0af8c2bd8 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -758,7 +758,7 @@ function MyController(hand) { if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { // if less than a 5 seconds left, refresh the actions ttl - var success = Entities.updateAction(this.grabbedEntity, this.actionID, { + Entities.updateAction(this.grabbedEntity, this.actionID, { hand: this.hand === RIGHT_HAND ? "right" : "left", timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, @@ -767,8 +767,6 @@ function MyController(hand) { kinematic: NEAR_GRABBING_KINEMATIC, kinematicSetVelocity: true }); - - print('Action update success:::'+success); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); } }; diff --git a/examples/toybox/bow/arrow.js b/examples/toybox/bow/arrow.js index a7c9d9b3f3..101271760a 100644 --- a/examples/toybox/bow/arrow.js +++ b/examples/toybox/bow/arrow.js @@ -108,15 +108,12 @@ var actionID = this.getActionID(); print('actionID' + actionID) - Entities.deleteAction(this.entityID, actionID); + var success = Entities.deleteAction(this.entityID, actionID); + print('ACTION DELETE SUCCESS:::'+success) }, tellBowArrowIsNotched: function(bowID) { this.disableGrab(); - setEntityCustomData('releaseGrabKey', this.entityID, { - shouldRelease: true, - didRelease: false - }); setEntityCustomData('grabbableKey', this.entityID, { grabbable: false, diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 2f1248dcb3..31f385e095 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -106,6 +106,7 @@ preload: function(entityID) { this.entityID = entityID; + this.bowID = entityID; }, setLeftHand: function() { @@ -440,40 +441,36 @@ updateArrowPositionInNotch: function() { //move it backwards - var handToNotch = Vec3.subtract(this.stringData.handPosition, this.notchDetectorPosition); + + + var handToNotch = Vec3.subtract(this.notchDetectorPosition,this.stringData.handPosition); + print('h2n:::'+JSON.stringify(handToNotch)) var pullBackDistance = Vec3.length(handToNotch); if (pullBackDistance >= 0.6) { pullBackDistance = 0.6; } - var pullBackOffset = Vec3.multiply(handToNotch, pullBackDistance); + var pullBackOffset = Vec3.multiply(handToNotch, -pullBackDistance); var arrowPosition = Vec3.sum(this.notchDetectorPosition, pullBackOffset); - var pushForwardOffset = Vec3.multiply(handToNotch, ARROW_OFFSET); + var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET); var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset); - var arrowRotation = this.orientationOf(handToNotch); - // print('ARROW ROTATION:: ' + JSON.stringify(arrowRotation)); + + + var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch); + + print('ARROW ROTATION:: ' + JSON.stringify(arrowRotation)); Entities.editEntity(this.arrow, { - position: this.notchDetectorPosition, - rotation: arrowRotation, - velocity: { - x: 0, - y: 0, - z: 0 - }, - angularVelocity: { - x: 0, - y: 0, - z: 0 - } + position: finalArrowPosition, + rotation: arrowRotation }) - var currentRotation = Entities.getEntityProperties(this.arrow, "rotation").rotation - // print('ACTUAL ARROW ROTATION::' +JSON.stringify(currentRotation)); + var currentRotation = Entities.getEntityProperties(this.arrow, "rotation").rotation + // print('ACTUAL ARROW ROTATION::' +JSON.stringify(currentRotation)); - print('DIFFERENCE::: ' + (1 - Quat.dot(arrowRotation, currentRotation))); + // print('DIFFERENCE::: ' + (1 - Quat.dot(arrowRotation, currentRotation))); // if (this.arrowIsBurning === true) { // Entities.editEntity(this.fire, { // position: arrowTipPosition @@ -541,7 +538,7 @@ var detectorProperties = { name: 'Hifi-NotchDetector', type: 'Box', - visible: false, + visible: true, collisionsWillMove: false, ignoreForCollisions: true, dimensions: NOTCH_DETECTOR_DIMENSIONS, @@ -574,7 +571,8 @@ this.notchDetectorPosition = detectorPosition; Entities.editEntity(this.notchDetector, { - position: this.notchDetectorPosition + position: this.notchDetectorPosition, + rotation:this.bowProperties.rotation }); }, diff --git a/examples/toybox/bow/createArrow.js b/examples/toybox/bow/createArrow.js index fd0bd7ae53..0af73b2e0f 100644 --- a/examples/toybox/bow/createArrow.js +++ b/examples/toybox/bow/createArrow.js @@ -12,7 +12,7 @@ var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx"; var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj"; -var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js'); +var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js?123'); var ARROW_DIMENSIONS = { x: 0.02, diff --git a/examples/toybox/bow/createBowAndArrow.js b/examples/toybox/bow/createBowAndArrow.js index a731891e6c..b24f0e8d32 100644 --- a/examples/toybox/bow/createBowAndArrow.js +++ b/examples/toybox/bow/createBowAndArrow.js @@ -1,2 +1,2 @@ - Script.include("createBow.js"); - Script.include("createArrow.js"); + Script.include("createBow.js?123"); + Script.include("createArrow.js?123");