From 2667f827cf8788ea832c17d921af792675b7cc34 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 6 Apr 2016 14:03:51 -0700 Subject: [PATCH] working opening lid for music box --- .../DomainContent/Home/musicBox/baseBox.js | 34 ++++++++++++++++++ .../DomainContent/Home/musicBox/lid.js | 36 +++++++++++++++++++ .../DomainContent/Home/musicBox/wrapper.js | 5 +-- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 unpublishedScripts/DomainContent/Home/musicBox/baseBox.js diff --git a/unpublishedScripts/DomainContent/Home/musicBox/baseBox.js b/unpublishedScripts/DomainContent/Home/musicBox/baseBox.js new file mode 100644 index 0000000000..6635f06087 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/musicBox/baseBox.js @@ -0,0 +1,34 @@ +(function() { + + var _this; + + function BaseBox() { + _this = this; + return this; + } + + BaseBox.prototype = { + preload: function(entityID) { + this.entityID = entityID; + }, + continueNearGrab: function() { + var myProps = Entities.getEntityProperties(_this.entityID) + var results = Entities.findEntities(myProps.position, 2); + var lid = null; + results.forEach(function(result) { + var resultProps = Entities.getEntityProperties(result); + if (resultProps.name.indexOf('music_box_lid') > -1) { + lid = result; + } + }); + if (lid === null) { + return; + } else { + Entities.callEntityMethod(lid, 'updateHatRotation'); + Entities.callEntityMethod(lid, 'updateKeyRotation'); + } + } + } + + return new BaseBox +}) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/musicBox/lid.js b/unpublishedScripts/DomainContent/Home/musicBox/lid.js index 10ef595b10..be7b1bb9d4 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/lid.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/lid.js @@ -131,6 +131,8 @@ var hatHeight = scaleValue(constraint, 0, 75, 0, 0.04); + this.updateHatRotation(); + this.updateKeyRotation(); Entities.editEntity(this.entityID, { localRotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) }) @@ -152,6 +154,40 @@ }, + updateHatRotation: function() { + var baseProps = Entities.getEntityProperties(_this.base); + var localAngularVelocity = { + x: 0, + y: 0.785398, + z: 0, + }; + + var worldAngularVelocity = Vec3.multiplyQbyV(baseProps.rotation, localAngularVelocity); + Entities.editEntity(_this.hat, { + angularVelocity: worldAngularVelocity + }) + + print('UPDATE HAT ANGULAR VELOCITY!' + JSON.stringify(worldAngularVelocity)); + + }, + + updateKeyRotation: function() { + var baseProps = Entities.getEntityProperties(_this.base); + var localAngularVelocity = { + x: 0, + y: 0, + z: 0.785398, + }; + + var worldAngularVelocity = Vec3.multiplyQbyV(baseProps.rotation, localAngularVelocity); + Entities.editEntity(this.key, { + angularVelocity: worldAngularVelocity + }) + + print('UPDATE KEY ANGULAR VELOCITY!' + JSON.stringify(worldAngularVelocity)); + + }, + playMusic: function() { if (this.musicIsPlaying !== true) { var properties = Entities.getEntityProperties(this.entityID); diff --git a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js index 66bdcba198..176b0632f1 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js @@ -60,7 +60,7 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { var LID_SCRIPT_URL = Script.resolvePath('lid.js?' + Math.random()); - + var BASE_SCRIPT_URL = Script.resolvePath('baseBox.js?' + Math.random()); var base, lid, hat, key; function createLid(baseID) { @@ -173,12 +173,13 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { position: BASE_POSITION, dynamic: true, shapeType: 'compound', - compoundShapeURL: 'atp:/boxHull2.obj', + compoundShapeURL: 'atp:/boxHull3.obj', dimensions: { x: 0.1661, y: 0.0928, z: 0.2022 }, + script: BASE_SCRIPT_URL, userData: JSON.stringify({ 'hifiHomeKey': { 'reset': true