From 387e7b74a96c39f8b6e8ea6f78fa5369824a8691 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 16:58:39 -0700 Subject: [PATCH] Return wand to its original position if it hasnt moved for 5 seconds, better particles, wand scaled to human size --- examples/toys/bubblewand/bubble.js | 27 +++++---- examples/toys/bubblewand/createWand.js | 18 +++--- examples/toys/bubblewand/wand.js | 80 +++++++++++++++++++------- 3 files changed, 86 insertions(+), 39 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index 845ad58e17..231b1cc7ca 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -12,8 +12,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { - Script.include("../../utilities.js"); - Script.include("../../libraries/utils.js"); + // Script.include("../../utilities.js"); + // Script.include("../../libraries/utils.js"); + + + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -69,7 +73,7 @@ Script.update.disconnect(this.internalUpdate); var position = properties.position; _t.endOfBubble(position); - print('UNLOAD PROPS' + JSON.stringify(position)); + // print('UNLOAD PROPS' + JSON.stringify(position)); }; @@ -107,7 +111,7 @@ animationSettings: animationSettings, animationIsPlaying: true, position: position, - lifetime: 1.0, + lifetime: 0.2, dimensions: { x: 1, y: 1, @@ -115,22 +119,25 @@ }, emitVelocity: { x: 0, - y: -1, + y: 0, z: 0 }, velocitySpread: { - x: 1, - y: 0, - z: 1 + x: 0.45, + y: 0.45, + z: 0.45 }, emitAcceleration: { x: 0, - y: -1, + y: -0.1, z: 0 }, + alphaStart: 1.0, + alpha: 1, + alphaFinish: 0.0, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", color: BUBBLE_PARTICLE_COLOR, - lifespan: 1.0, + lifespan: 0.2, visible: true, locked: false }); diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 50af1b251d..24db08d2c1 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -10,30 +10,32 @@ -Script.include("../../utilities.js"); -Script.include("../../libraries/utils.js"); +// Script.include("../../utilities.js"); +// Script.include("../../libraries/utils.js"); + +Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); +Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; -var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); +var scriptURL = 'http://hifi-public.s3.amazonaws.com/scripts/bubblewand/wand.js?' + randInt(0, 10000); //for local testing //var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); //create the wand in front of the avatar -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); var wand = Entities.addEntity({ type: "Model", modelURL: wandModel, position: center, dimensions: { - x: 0.1, - y: 1, - z: 0.1 + x: 0.05, + y: 0.5, + z: 0.05 }, //must be enabled to be grabbable in the physics engine - collisionsWillMove: true, compoundShapeURL: wandCollisionShape, script: scriptURL diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index e4a9f7231f..87bdfc6648 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -16,13 +16,20 @@ function convertRange(value, r1, r2) { } (function() { - Script.include("../../utilities.js"); - Script.include("../../libraries/utils.js"); + + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); + + + // Script.include("../../utilities.js"); + // Script.include("../../libraries/utils.js"); + + var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); - var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); - //for local testing - //var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); + var bubbleScript = 'http://hifi-public.s3.amazonaws.com/scripts/toys/bubblewand/bubble.js?' + randInt(1, 10000); + + // var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); //for local testing var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -127,6 +134,9 @@ function convertRange(value, r1, r2) { // print('PRELOAD') this.entityID = entityID; this.properties = Entities.getEntityProperties(this.entityID); + BubbleWand.originalProperties = this.properties; + print('rotation???' + JSON.stringify(BubbleWand.originalProperties.rotation)); + } this.unload = function(entityID) { @@ -150,11 +160,14 @@ function convertRange(value, r1, r2) { var BubbleWand = { bubbles: [], + timeSinceMoved: 0, + resetAtTime: 5, currentBubble: null, - update: function() { - BubbleWand.internalUpdate(); + update: function(dt) { + BubbleWand.internalUpdate(dt); }, - internalUpdate: function() { + internalUpdate: function(dt) { + var _t = this; //get the current position of the wand var properties = Entities.getEntityProperties(wandEntity.entityID); @@ -162,9 +175,16 @@ function convertRange(value, r1, r2) { //if the wand is in the gust detector, activate mouth mode and change the overlay color var hitTargetWithWand = findSphereSphereHit(wandPosition, HAND_SIZE / 2, getGustDetectorPosition(), TARGET_SIZE / 2) - var velocity = Vec3.subtract(wandPosition, BubbleWand.lastPosition) + var velocity = Vec3.subtract(wandPosition, _t.lastPosition) var velocityStrength = Vec3.length(velocity) * 100; + + var upVector = Quat.getUp(properties.rotation); + var frontVector = Quat.getFront(properties.rotation); + var upOffset = Vec3.multiply(upVector, 0.2); + var wandTipPosition = Vec3.sum(wandPosition, upOffset); + _t.wandTipPosition = wandTipPosition; + var mouthMode; if (hitTargetWithWand) { @@ -172,8 +192,18 @@ function convertRange(value, r1, r2) { } else { mouthMode = false; } + //print('velocityStrength'+velocityStrength) - + //we want to reset the object to its original position if its been a while since it has moved + if (velocityStrength === 0) { + _t.timeSinceMoved = _t.timeSinceMoved + dt; + if (_t.timeSinceMoved > _t.resetAtTime) { + _t.timeSinceMoved = 0; + _t.returnToOriginalLocation(); + } + } else { + _t.timeSinceMoved = 0; + } //debug overlays for mouth mode if (overlays) { @@ -225,7 +255,7 @@ function convertRange(value, r1, r2) { //add some variation in bubble sizes var bubbleSize = randInt(1, 5); - bubbleSize = bubbleSize / 10; + bubbleSize = bubbleSize / 50; //release the bubble if its dimensions are bigger than the bubble size if (dimensions.x > bubbleSize) { @@ -249,14 +279,14 @@ function convertRange(value, r1, r2) { return } else { if (mouthMode) { - dimensions.x += 0.015 * convertedVolume; - dimensions.y += 0.015 * convertedVolume; - dimensions.z += 0.015 * convertedVolume; + dimensions.x += 0.005 * convertedVolume; + dimensions.y += 0.005 * convertedVolume; + dimensions.z += 0.005 * convertedVolume; } else { - dimensions.x += 0.015 * velocityStrength; - dimensions.y += 0.015 * velocityStrength; - dimensions.z += 0.015 * velocityStrength; + dimensions.x += 0.005 * velocityStrength; + dimensions.y += 0.005 * velocityStrength; + dimensions.z += 0.005 * velocityStrength; } } @@ -298,10 +328,7 @@ function convertRange(value, r1, r2) { var wandPosition = properties.position; var upVector = Quat.getUp(properties.rotation); var frontVector = Quat.getFront(properties.rotation); - var upOffset = Vec3.multiply(upVector, 0.4); - // var forwardOffset = Vec3.multiply(frontVector, 0.1); - // var offsetVector = Vec3.sum(upOffset, forwardOffset); - // var wandTipPosition = Vec3.sum(wandPosition, offsetVector); + var upOffset = Vec3.multiply(upVector, 0.2); var wandTipPosition = Vec3.sum(wandPosition, upOffset); _t.wandTipPosition = wandTipPosition; @@ -329,8 +356,19 @@ function convertRange(value, r1, r2) { //add this bubble to an array of bubbles so we can keep track of them _t.bubbles.push(_t.currentBubble) + }, + returnToOriginalLocation: function() { + var _t = this; + Script.update.disconnect(BubbleWand.update) + _t.currentBubble = null; + Entities.deleteEntity(_t.currentBubble); + Entities.editEntity(wandEntity.entityID, _t.originalProperties) + _t.spawnBubble(); + Script.update.connect(BubbleWand.update); + }, init: function() { + var _t = this; this.spawnBubble(); Script.update.connect(BubbleWand.update);