This commit is contained in:
James B. Pollack 2015-11-18 11:28:07 -08:00
parent 5f3e3ed9d1
commit 12e2178dd3

View file

@ -12,7 +12,7 @@
/*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
(function () { (function() {
Script.include("../../libraries/utils.js"); Script.include("../../libraries/utils.js");
@ -58,23 +58,23 @@
BubbleWand.prototype = { BubbleWand.prototype = {
timePassed: null, timePassed: null,
currentBubble: null, currentBubble: null,
preload: function (entityID) { preload: function(entityID) {
this.entityID = entityID; this.entityID = entityID;
}, },
getWandTipPosition: function (properties) { getWandTipPosition: function(properties) {
//the tip of the wand is going to be in a different place than the center, so we move in space relative to the model to find that position //the tip of the wand is going to be in a different place than the center, so we move in space relative to the model to find that position
var upVector = Quat.getUp(properties.rotation); var upVector = Quat.getUp(properties.rotation);
var upOffset = Vec3.multiply(upVector, WAND_TIP_OFFSET); var upOffset = Vec3.multiply(upVector, WAND_TIP_OFFSET);
var wandTipPosition = Vec3.sum(properties.position, upOffset); var wandTipPosition = Vec3.sum(properties.position, upOffset);
return wandTipPosition; return wandTipPosition;
}, },
addCollisionsToBubbleAfterCreation: function (bubble) { addCollisionsToBubbleAfterCreation: function(bubble) {
//if the bubble collide immediately, we get weird effects. so we add collisions after release //if the bubble collide immediately, we get weird effects. so we add collisions after release
Entities.editEntity(bubble, { Entities.editEntity(bubble, {
collisionsWillMove: true collisionsWillMove: true
}); });
}, },
randomizeBubbleGravity: function () { randomizeBubbleGravity: function() {
//change up the gravity a little bit for variation in floating effects //change up the gravity a little bit for variation in floating effects
var randomNumber = randFloat(BUBBLE_GRAVITY_MIN, BUBBLE_GRAVITY_MAX); var randomNumber = randFloat(BUBBLE_GRAVITY_MIN, BUBBLE_GRAVITY_MAX);
var gravity = { var gravity = {
@ -84,7 +84,7 @@
}; };
return gravity; return gravity;
}, },
growBubbleWithWandVelocity: function (properties, deltaTime) { growBubbleWithWandVelocity: function(properties, deltaTime) {
//get the wand and tip position for calculations //get the wand and tip position for calculations
var wandPosition = properties.position; var wandPosition = properties.position;
this.getWandTipPosition(properties); this.getWandTipPosition(properties);
@ -113,7 +113,6 @@
Entities.editEntity(this.currentBubble, { Entities.editEntity(this.currentBubble, {
velocity: velocity, velocity: velocity,
lifetime: lifetime, lifetime: lifetime,
ignoreForCollisions:false,
gravity: this.randomizeBubbleGravity() gravity: this.randomizeBubbleGravity()
}); });
@ -146,7 +145,7 @@
dimensions: dimensions dimensions: dimensions
}); });
}, },
createBubbleAtTipOfWand: function () { createBubbleAtTipOfWand: function() {
//create a new bubble at the tip of the wand //create a new bubble at the tip of the wand
var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
@ -169,18 +168,17 @@
}); });
}, },
startNearGrab: function () { startNearGrab: function() {
//create a bubble to grow at the start of the grab //create a bubble to grow at the start of the grab
if (this.currentBubble === null) { if (this.currentBubble === null) {
this.createBubbleAtTipOfWand(); this.createBubbleAtTipOfWand();
} }
}, },
continueNearGrab: function () { continueNearGrab: function() {
var deltaTime = checkInterval(); var deltaTime = checkInterval();
//only get the properties that we need //only get the properties that we need
var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
var wandTipPosition = this.getWandTipPosition(properties); var wandTipPosition = this.getWandTipPosition(properties);
//update the bubble to stay with the wand tip //update the bubble to stay with the wand tip
@ -190,7 +188,7 @@
this.growBubbleWithWandVelocity(properties, deltaTime); this.growBubbleWithWandVelocity(properties, deltaTime);
}, },
releaseGrab: function () { releaseGrab: function() {
//delete the current buble and reset state when the wand is released //delete the current buble and reset state when the wand is released
Entities.deleteEntity(this.currentBubble); Entities.deleteEntity(this.currentBubble);
this.currentBubble = null; this.currentBubble = null;