diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index a68a09cf7d..99d827aa06 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -52,16 +52,7 @@ this.createLights(); } - // flip model to give illusion of light switch being flicked - var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; - var axis = {x: 0, y: 1, z: 0}; - var dQ = Quat.angleAxis(180, axis); - rotation = Quat.multiply(rotation, dQ); - - - Entities.editEntity(this.entityID, { - rotation: rotation - }); + this.flipLights(); Audio.playSound(this.switchSound, { volume: 0.5, @@ -86,7 +77,7 @@ }, createLights: function() { - + var sconceLight3 = Entities.addEntity({ type: "Light", @@ -176,6 +167,25 @@ }, + flipLights: function() { + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + + }, + + // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { @@ -191,6 +201,7 @@ //If light is off, then we create two new lights- at the position of the sconces if (lightState.on === false) { this.createLights(); + this.flipLights(); } //If lights are on, do nothing! }, diff --git a/examples/toys/lightSwitchHall.js b/examples/toys/lightSwitchHall.js index 6bc1eeab83..49ccc51b79 100644 --- a/examples/toys/lightSwitchHall.js +++ b/examples/toys/lightSwitchHall.js @@ -53,19 +53,7 @@ } // flip model to give illusion of light switch being flicked - var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; - var axis = { - x: 0, - y: 1, - z: 0 - }; - var dQ = Quat.angleAxis(180, axis); - rotation = Quat.multiply(rotation, dQ); - - - Entities.editEntity(this.entityID, { - rotation: rotation - }); + this.flipLights(); Audio.playSound(this.switchSound, { volume: 0.5, @@ -148,9 +136,27 @@ }, + flipLights: function() { + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + + }, + // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: - preload: function(entityID) { + preload: function(entityID) { this.entityID = entityID; //The light switch is static, so just cache its position once @@ -163,6 +169,8 @@ //If light is off, then we create two new lights- at the position of the sconces if (lightState.on === false) { this.createLights(); + this.flipLights(); + } //If lights are on, do nothing! },