mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-14 00:50:04 +02:00
cleanup unused reset stuff
This commit is contained in:
parent
e1e567b1b5
commit
9aa2067e3e
1 changed files with 12 additions and 62 deletions
|
@ -20,14 +20,11 @@
|
|||
Script.include("../../libraries/utils.js");
|
||||
|
||||
var BUBBLE_MODEL = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx";
|
||||
var BUBBLE_SCRIPT = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000);
|
||||
Script.resolvePath('bubble.js?' + randInt(0, 5000));
|
||||
var BUBBLE_SCRIPT = Script.resolvePath('bubble.js?' + randInt(0, 5000));
|
||||
|
||||
var HAND_SIZE = 0.25;
|
||||
var TARGET_SIZE = 0.04;
|
||||
|
||||
|
||||
|
||||
var BUBBLE_GRAVITY = {
|
||||
x: 0,
|
||||
y: -0.1,
|
||||
|
@ -38,6 +35,7 @@
|
|||
var SHRINK_LOWER_LIMIT = 0.02;
|
||||
var SHRINK_FACTOR = 0.001;
|
||||
var VELOCITY_STRENGTH_LOWER_LIMIT = 0.01;
|
||||
var MAX_VELOCITY_STRENGTH = 10;
|
||||
var BUBBLE_DIVISOR = 50;
|
||||
var BUBBLE_LIFETIME_MIN = 3;
|
||||
var BUBBLE_LIFETIME_MAX = 8;
|
||||
|
@ -67,9 +65,7 @@
|
|||
this.preload = function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.properties = Entities.getEntityProperties(this.entityID);
|
||||
BubbleWand.originalProperties = this.properties;
|
||||
BubbleWand.init();
|
||||
print('initial position' + JSON.stringify(BubbleWand.originalProperties.position));
|
||||
}
|
||||
|
||||
this.unload = function(entityID) {
|
||||
|
@ -88,29 +84,23 @@
|
|||
var BubbleWand = {
|
||||
bubbles: [],
|
||||
timeSinceMoved: 0,
|
||||
resetAtTime: 2,
|
||||
currentBubble: null,
|
||||
atOriginalLocation: true,
|
||||
update: function(deltaTime) {
|
||||
BubbleWand.internalUpdate(deltaTime);
|
||||
},
|
||||
internalUpdate: function(deltaTime) {
|
||||
var _t = this;
|
||||
|
||||
var GRAB_USER_DATA_KEY = "grabKey";
|
||||
var defaultGrabData = {
|
||||
activated: false,
|
||||
avatarId: null
|
||||
};
|
||||
|
||||
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, wandEntity.entityID, defaultGrabData);
|
||||
if (grabData.activated && grabData.avatarId == MyAvatar.sessionUUID) {
|
||||
|
||||
// remember we're being grabbed so we can detect being released
|
||||
_t.beingGrabbed = true;
|
||||
|
||||
// print out that we're being grabbed
|
||||
// print("I'm being grabbed...");
|
||||
_t.handleGrabbedWand();
|
||||
|
||||
} else if (_t.beingGrabbed) {
|
||||
|
@ -118,7 +108,7 @@
|
|||
// if we are not being grabbed, and we previously were, then we were just released, remember that
|
||||
// and print out a message
|
||||
_t.beingGrabbed = false;
|
||||
// print("I'm was released...");
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -126,14 +116,10 @@
|
|||
handleGrabbedWand: function() {
|
||||
var _t = this;
|
||||
|
||||
// print('HANDLE GRAB 1')
|
||||
var properties = Entities.getEntityProperties(wandEntity.entityID);
|
||||
var wandPosition = properties.position;
|
||||
|
||||
var velocity = Vec3.subtract(wandPosition, _t.lastPosition)
|
||||
|
||||
// print('VELOCITY:' + JSON.stringify(velocity));
|
||||
// print('HANDLE GRAB 2')
|
||||
var velocity = Vec3.subtract(wandPosition, _t.lastPosition)
|
||||
var velocityStrength = Vec3.length(velocity) * 100;
|
||||
|
||||
var upVector = Quat.getUp(properties.rotation);
|
||||
|
@ -146,35 +132,11 @@
|
|||
velocityStrength = 0
|
||||
}
|
||||
|
||||
var isMoving;
|
||||
if (velocityStrength === 0) {
|
||||
isMoving = false;
|
||||
} else {
|
||||
isMoving = true;
|
||||
}
|
||||
// print('MOVING?' + isMoving)
|
||||
if (isMoving === true) {
|
||||
_t.timeSinceMoved = 0;
|
||||
_t.atOriginalLocation = false;
|
||||
} else {
|
||||
_t.timeSinceMoved = _t.timeSinceMoved + deltaTime;
|
||||
}
|
||||
|
||||
if (isMoving === false && _t.atOriginalLocation === false) {
|
||||
if (_t.timeSinceMoved > _t.resetAtTime) {
|
||||
_t.timeSinceMoved = 0;
|
||||
_t.returnToOriginalLocation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// default is 'wave mode', where waving the object around grows the bubbles
|
||||
|
||||
//store the last position of the wand for velocity calculations
|
||||
_t.lastPosition = wandPosition;
|
||||
|
||||
if (velocityStrength > 10) {
|
||||
velocityStrength = 10
|
||||
if (velocityStrength > MAX_VELOCITY_STRENGTH) {
|
||||
velocityStrength = MAX_VELOCITY_STRENGTH
|
||||
}
|
||||
|
||||
//actually grow the bubble
|
||||
|
@ -202,11 +164,10 @@
|
|||
return
|
||||
} else {
|
||||
|
||||
|
||||
dimensions.x += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
dimensions.y += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
dimensions.z += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
|
||||
dimensions.x += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
dimensions.y += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
dimensions.z += WAVE_MODE_GROWTH_FACTOR * velocityStrength;
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -226,9 +187,9 @@
|
|||
},
|
||||
spawnBubble: function() {
|
||||
var _t = this;
|
||||
|
||||
//create a new bubble at the tip of the wand
|
||||
//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 properties = Entities.getEntityProperties(wandEntity.entityID);
|
||||
var wandPosition = properties.position;
|
||||
var upVector = Quat.getUp(properties.rotation);
|
||||
|
@ -237,7 +198,7 @@
|
|||
var wandTipPosition = Vec3.sum(wandPosition, upOffset);
|
||||
_t.wandTipPosition = wandTipPosition;
|
||||
|
||||
//store the position of the tip on spawn for use in velocity calculations
|
||||
//store the position of the tip for use in velocity calculations
|
||||
_t.lastPosition = wandPosition;
|
||||
|
||||
//create a bubble at the wand tip
|
||||
|
@ -259,22 +220,11 @@
|
|||
//add this bubble to an array of bubbles so we can keep track of them
|
||||
_t.bubbles.push(_t.currentBubble)
|
||||
|
||||
},
|
||||
returnToOriginalLocation: function() {
|
||||
var _t = this;
|
||||
_t.atOriginalLocation = true;
|
||||
Script.update.disconnect(BubbleWand.update)
|
||||
Entities.deleteEntity(_t.currentBubble);
|
||||
Entities.editEntity(wandEntity.entityID, _t.originalProperties)
|
||||
_t.spawnBubble();
|
||||
Script.update.connect(BubbleWand.update);
|
||||
|
||||
},
|
||||
init: function() {
|
||||
var _t = this;
|
||||
this.spawnBubble();
|
||||
Script.update.connect(BubbleWand.update);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue