From 30b32f27f82eb508d61b8054ff5c0dd1b490e889 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 6 Apr 2016 11:46:02 -0700 Subject: [PATCH] rotateable lid --- .../DomainContent/Home/musicBox/lid.js | 74 +++---------------- .../DomainContent/Home/musicBox/wrapper.js | 21 +----- 2 files changed, 13 insertions(+), 82 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/musicBox/lid.js b/unpublishedScripts/DomainContent/Home/musicBox/lid.js index 0ae822e940..10ef595b10 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/lid.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/lid.js @@ -46,20 +46,7 @@ startNearTrigger: function() { this.getParts(); }, - getGrabConstraints: function() { - var defaultConstraints = { - positionLocked: false, - rotationLocked: false, - positionMod: false, - rotationMod: { - pitch: false, - yaw: false, - roll: false - } - } - var constraints = getEntityCustomData(GRAB_CONSTRAINTS_USER_DATA_KEY, this.grabbedEntity, defaultConstraints); - return constraints; - }, + getHandPosition: function() { if (this.hand === 'left') { return MyAvatar.getLeftPalmPosition(); @@ -71,66 +58,24 @@ }, continueNearTrigger: function(myID, paramsArray) { paramsArray.forEach(function(param, index) { - print('PARAM::' + param) if (index === 0) { _this.hand = param; } }); - print('HAND:: ' + _this.hand); - - var constraints = this.getGrabConstraints(); - var handPosition = this.getHandPosition(); - - - var modTypes = []; - if (constraints.rotationMod !== false) { - if (constraints.rotationMod.pitch !== false) { - modTypes.push('pitch') - } - if (constraints.rotationMod.yaw !== false) { - modTypes.push('yaw') - } - if (constraints.rotationMod.roll !== false) { - modTypes.push('roll') - } - } - - - - // var properties = Entities.getEntityProperties(this.entityID); - - // var constraints = this.getGrabConstraints(); - // if (constraints.rotationMod !== false) { - // //implement the rotation modifier - // var grabbedProps = Entities.getEntityProperties(this.grabbedEntity); - - var handPosition = this.getHandPosition(); - - var modTypes = []; - - if (constraints.rotationMod.pitch !== false) { - modTypes.push('pitch') - } - if (constraints.rotationMod.yaw !== false) { - modTypes.push('yaw') - } - if (constraints.rotationMod.roll !== false) { - modTypes.push('roll') - } - // get the base position // get the hand position - // + // get the distance between + // use that value to scale the angle of the lid rotation var baseProps = Entities.getEntityProperties(_this.base); var baseBoxPosition = baseProps.position; var handPosition = _this.getHandPosition(); var lidProps = Entities.getEntityProperties(_this.entityID); - + var distaceHandToBaseBox = Vec3.distance(baseBoxPosition, handPosition); - var safeEuler = Quat.safeEulerAngles() + var safeEuler = Quat.safeEulerAngles(baseProps.rotation); var finalRotation = { x: 0, y: 0, @@ -142,7 +87,7 @@ var maxDistance = 0.4; - var finalAngle = scale(distance, 0, maxDistance, 0, 75) + var finalAngle = scaleValue(distaceHandToBaseBox, 0.1, maxDistance, 0, 75) print('FINAL ANGLE:: ' + finalAngle); @@ -153,10 +98,9 @@ finalAngle = 75; } finalRotation.z = finalAngle; + _this.handleLidActivities(finalRotation) - - }, handleLidActivities: function(finalRotation) { @@ -185,10 +129,10 @@ this.stopHat(); } - var hatHeight = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTATION, 0, 0.04); + var hatHeight = scaleValue(constraint, 0, 75, 0, 0.04); Entities.editEntity(this.entityID, { - rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) + localRotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) }) var VERTICAL_OFFSET = 0.025; diff --git a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js index a38b55a3f0..66bdcba198 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js @@ -80,26 +80,13 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { position: startPosition, parentID: baseID, registrationPoint: LID_REGISTRATION_POINT, - dynamic: false, + dynamic: true, script: LID_SCRIPT_URL, collidesWith: 'myAvatar,otherAvatar', userData: JSON.stringify({ 'hifiHomeKey': { 'reset': true }, - grabConstraintsKey: { - rotationMod: { - pitch: false, - yaw: false, - roll: { - min: 0, - max: 75, - startingAxis: 'y', - startingPoint: startPosition.y, - distanceToMax: startPosition.y + 0.35 - } - } - }, grabbableKey: { wantsTrigger: true, disableReleaseVelocity: true @@ -184,9 +171,9 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { name: 'home_music_box_base', type: 'Model', position: BASE_POSITION, - // dynamic: true, - // shapeType: 'compound', - // compoundShapeURL: 'atp:/boxHull2.obj', + dynamic: true, + shapeType: 'compound', + compoundShapeURL: 'atp:/boxHull2.obj', dimensions: { x: 0.1661, y: 0.0928,