working opening lid for music box

This commit is contained in:
James B. Pollack 2016-04-06 14:03:51 -07:00
parent 30b32f27f8
commit 2667f827cf
3 changed files with 73 additions and 2 deletions

View file

@ -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
})

View file

@ -131,6 +131,8 @@
var hatHeight = scaleValue(constraint, 0, 75, 0, 0.04); var hatHeight = scaleValue(constraint, 0, 75, 0, 0.04);
this.updateHatRotation();
this.updateKeyRotation();
Entities.editEntity(this.entityID, { Entities.editEntity(this.entityID, {
localRotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) 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() { playMusic: function() {
if (this.musicIsPlaying !== true) { if (this.musicIsPlaying !== true) {
var properties = Entities.getEntityProperties(this.entityID); var properties = Entities.getEntityProperties(this.entityID);

View file

@ -60,7 +60,7 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
var LID_SCRIPT_URL = Script.resolvePath('lid.js?' + Math.random()); 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; var base, lid, hat, key;
function createLid(baseID) { function createLid(baseID) {
@ -173,12 +173,13 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
position: BASE_POSITION, position: BASE_POSITION,
dynamic: true, dynamic: true,
shapeType: 'compound', shapeType: 'compound',
compoundShapeURL: 'atp:/boxHull2.obj', compoundShapeURL: 'atp:/boxHull3.obj',
dimensions: { dimensions: {
x: 0.1661, x: 0.1661,
y: 0.0928, y: 0.0928,
z: 0.2022 z: 0.2022
}, },
script: BASE_SCRIPT_URL,
userData: JSON.stringify({ userData: JSON.stringify({
'hifiHomeKey': { 'hifiHomeKey': {
'reset': true 'reset': true