made randomly chosen sound persistent between sessions by storing sound index in user data. Now using previous rotation and position to compute offset position

This commit is contained in:
Eric Levin 2015-04-08 09:20:29 -07:00
parent a16f6c2ce4
commit 6de4cec836

View file

@ -3,18 +3,22 @@
var soundURLs = ["https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_1.wav",
"https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav",
"https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_3.wav"];
var soundURL = soundURLs[Math.floor(Math.random() * soundURLs.length)];
this.sound = SoundCache.getSound(soundURL);
this.sound = ;
this.entityId = entityId;
this.properties = Entities.getEntityProperties(this.entityId);
this.previousPosition = this.properties.position;
this.previousRotation = this.properties.rotation;
this.getUserData()
if (!this.userData) {
this.userData = {};
this.userData.lightOn = false;
this.userData.soundIndex = Math.floor(Math.random() * soundURLs.length);
this.updateUserData();
}
this.sound = SoundCache.getSound(soundURLs[this.userData.soundIndex]);
}
this.getUserData = function() {
if (this.properties.userData) {
this.userData = JSON.parse(this.properties.userData);
@ -64,11 +68,13 @@
this.tryMoveLight = function() {
if (this.light) {
//compute offset position
var offsetPosition = Quat.multiply(Quat.inverse(this.properties.rotation), Vec3.subtract(this.lightProperties.position, this.properties.position));
var offsetPosition = Quat.multiply(Quat.inverse(this.previousRotation), Vec3.subtract(this.lightProperties.position, this.previousPosition));
var newPosition = Vec3.sum(this.properties.position, Vec3.multiplyQbyV(this.properties.rotation, offsetPosition));
if (!Vec3.equal(newPosition, this.lightProperties.position)) {
Entities.editEntity(this.light, {position: newPosition});
}
this.previousPosition = this.properties.position;
this.previousRotation = this.properties.rotation;
}
}