mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
coding standard
This commit is contained in:
parent
1873558df1
commit
a12e8e34db
3 changed files with 99 additions and 96 deletions
|
@ -19,6 +19,7 @@ var SCRIPT_URL = Script.resolvePath("./entity_scripts/floatingLanternBox.js?v="
|
||||||
var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2));
|
var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2));
|
||||||
START_POSITION.y -= .6;
|
START_POSITION.y -= .6;
|
||||||
var LIFETIME = 3600;
|
var LIFETIME = 3600;
|
||||||
|
var SCALE_FACTOR = 1;
|
||||||
|
|
||||||
var lanternBox = {
|
var lanternBox = {
|
||||||
type: "Model",
|
type: "Model",
|
||||||
|
@ -31,9 +32,9 @@ var lanternBox = {
|
||||||
position: START_POSITION,
|
position: START_POSITION,
|
||||||
lifetime: LIFETIME,
|
lifetime: LIFETIME,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: 0.8696,
|
x: 0.8696 * SCALE_FACTOR,
|
||||||
y: 0.58531,
|
y: 0.58531 * SCALE_FACTOR,
|
||||||
z: 0.9264
|
z: 0.9264 * SCALE_FACTOR
|
||||||
},
|
},
|
||||||
owningAvatarID: MyAvatar.sessionUUID
|
owningAvatarID: MyAvatar.sessionUUID
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,93 +14,93 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var _this;
|
var _this;
|
||||||
|
|
||||||
var SLOW_SPIN_THRESHOLD = 0.1;
|
var SLOW_SPIN_THRESHOLD = 0.1;
|
||||||
var ROTATION_COMPLETE_THRESHOLD = 0.01;
|
var ROTATION_COMPLETE_THRESHOLD = 0.01;
|
||||||
var ROTATION_SPEED = 0.2;
|
var ROTATION_SPEED = 0.2;
|
||||||
var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0};
|
var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0};
|
||||||
|
|
||||||
|
|
||||||
floatingLantern = function() {
|
floatingLantern = function() {
|
||||||
_this = this;
|
_this = this;
|
||||||
this.updateConnected = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
floatingLantern.prototype = {
|
|
||||||
|
|
||||||
preload: function(entityID) {
|
|
||||||
this.entityID = entityID;
|
|
||||||
},
|
|
||||||
|
|
||||||
unload: function(entityID) {
|
|
||||||
this.disconnectUpdate();
|
|
||||||
},
|
|
||||||
|
|
||||||
startNearGrab: function() {
|
|
||||||
this.disconnectUpdate();
|
|
||||||
},
|
|
||||||
|
|
||||||
startDistantGrab: function() {
|
|
||||||
this.disconnectUpdate();
|
|
||||||
},
|
|
||||||
|
|
||||||
releaseGrab: function() {
|
|
||||||
Entities.editEntity(this.entityID, {
|
|
||||||
gravity: {
|
|
||||||
x: 0,
|
|
||||||
y: 0.5,
|
|
||||||
z: 0
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
update: function(dt) {
|
|
||||||
var lanternProps = Entities.getEntityProperties(_this.entityID);
|
|
||||||
|
|
||||||
if(lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) {
|
|
||||||
|
|
||||||
var spinningSlowly = (
|
|
||||||
Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD &&
|
|
||||||
Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD &&
|
|
||||||
Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD
|
|
||||||
);
|
|
||||||
|
|
||||||
var rotationComplete = (
|
|
||||||
Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD &&
|
|
||||||
Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD &&
|
|
||||||
Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD
|
|
||||||
);
|
|
||||||
|
|
||||||
if(spinningSlowly && !rotationComplete) {
|
|
||||||
var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt);
|
|
||||||
|
|
||||||
Entities.editEntity(_this.entityID, {
|
|
||||||
rotation: newRotation,
|
|
||||||
angularVelocity: {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
connectUpdate: function() {
|
|
||||||
if(!this.updateConnected) {
|
|
||||||
this.updateConnected = true;
|
|
||||||
Script.update.connect(this.update);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
disconnectUpdate: function() {
|
|
||||||
if(this.updateConnected) {
|
|
||||||
this.updateConnected = false;
|
this.updateConnected = false;
|
||||||
Script.update.disconnect(this.update);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return new floatingLantern();
|
floatingLantern.prototype = {
|
||||||
|
|
||||||
|
preload: function(entityID) {
|
||||||
|
this.entityID = entityID;
|
||||||
|
},
|
||||||
|
|
||||||
|
unload: function(entityID) {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
startNearGrab: function() {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
startDistantGrab: function() {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
releaseGrab: function() {
|
||||||
|
Entities.editEntity(this.entityID, {
|
||||||
|
gravity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0.5,
|
||||||
|
z: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function(dt) {
|
||||||
|
var lanternProps = Entities.getEntityProperties(_this.entityID);
|
||||||
|
|
||||||
|
if (lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) {
|
||||||
|
|
||||||
|
var spinningSlowly = (
|
||||||
|
Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD
|
||||||
|
);
|
||||||
|
|
||||||
|
var rotationComplete = (
|
||||||
|
Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD
|
||||||
|
);
|
||||||
|
|
||||||
|
if (spinningSlowly && !rotationComplete) {
|
||||||
|
var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt);
|
||||||
|
|
||||||
|
Entities.editEntity(_this.entityID, {
|
||||||
|
rotation: newRotation,
|
||||||
|
angularVelocity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
connectUpdate: function() {
|
||||||
|
if (!this.updateConnected) {
|
||||||
|
this.updateConnected = true;
|
||||||
|
Script.update.connect(this.update);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
disconnectUpdate: function() {
|
||||||
|
if (this.updateConnected) {
|
||||||
|
this.updateConnected = false;
|
||||||
|
Script.update.disconnect(this.update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new floatingLantern();
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
var LIFETIME = 120;
|
var LIFETIME = 120;
|
||||||
var RESPAWN_INTERVAL = 1000;
|
var RESPAWN_INTERVAL = 1000;
|
||||||
var MAX_LANTERNS = 4;
|
var MAX_LANTERNS = 4;
|
||||||
|
var SCALE_FACTOR = 1;
|
||||||
|
|
||||||
var LANTERN = {
|
var LANTERN = {
|
||||||
type: "Model",
|
type: "Model",
|
||||||
|
@ -29,9 +30,9 @@
|
||||||
modelURL: LANTERN_MODEL_URL,
|
modelURL: LANTERN_MODEL_URL,
|
||||||
script: LANTERN_SCRIPT_URL,
|
script: LANTERN_SCRIPT_URL,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: 0.2049,
|
x: 0.2049 * SCALE_FACTOR,
|
||||||
y: 0.4,
|
y: 0.4 * SCALE_FACTOR,
|
||||||
z: 0.2049
|
z: 0.2049 * SCALE_FACTOR
|
||||||
},
|
},
|
||||||
gravity: {
|
gravity: {
|
||||||
x: 0,
|
x: 0,
|
||||||
|
@ -57,14 +58,15 @@
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
var props = Entities.getEntityProperties(this.entityID);
|
var props = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
if(props.owningAvatarID === MyAvatar.sessionUUID){
|
if (props.owningAvatarID === MyAvatar.sessionUUID) {
|
||||||
this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL);
|
this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function(entityID) {
|
unload: function(entityID) {
|
||||||
if(this.respawnTimer)
|
if (this.respawnTimer) {
|
||||||
Script.clearInterval(this.respawnTimer);
|
Script.clearInterval(this.respawnTimer);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spawnAllLanterns: function() {
|
spawnAllLanterns: function() {
|
||||||
|
@ -72,14 +74,14 @@
|
||||||
var lanternCount = 0;
|
var lanternCount = 0;
|
||||||
var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75);
|
var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75);
|
||||||
|
|
||||||
for(var i = 0; i < nearbyEntities.length; i++) {
|
for (var i = 0; i < nearbyEntities.length; i++) {
|
||||||
var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name;
|
var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name;
|
||||||
if(name === "Floating Lantern") {
|
if (name === "Floating Lantern") {
|
||||||
lanternCount++;
|
lanternCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(lanternCount++ < MAX_LANTERNS) {
|
while (lanternCount++ < MAX_LANTERNS) {
|
||||||
this.spawnLantern();
|
this.spawnLantern();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue