content/hifi-content/howard/scripts/dev-welcome.js
2022-02-13 23:27:08 +01:00

64 lines
2.3 KiB
JavaScript

var typeBlacklist = ["Zone"]; /* for now, disallow all zone entities */
var center = {x: 0, y: 0, z: 0}; /* also nothing can move within 5 meters of 0,0,0 */
var radius = 5;
var epsilon = 0.01;
var aBitMore = 5 * (1 + epsilon);
var staticBounceSpeed = 0.5; /* If edit within radius that has no velocity. */
var Vec3 = {
distance: function distance(a, b) {
var x = a.x - b.x,
y = a.y - b.y,
z = a.z - b.z;
return Math.sqrt((x * x) + (y * y) + (z * z));
},
ZERO: {x: 0, y: 0, z: 0},
length: function length(v) {
return Vec3.distance(Vec3.ZERO, v);
},
multiply: function multiply(s, v) {
return {x: s * v.x, y: s * v.y, z: s * v.z};
},
normalize: function normalize(v) {
var length = Vec3.length(v);
return Vec3.multiply(1/length, v);
}
};
function filter(p, filterType) {
if (p.type && (typeBlacklist.indexOf(p.type) != -1)) {
print("filtering out " + p.type + " entity!");
return false
}
if (p.position) {
var distance = Vec3.distance(center, p.position);
var reject = distance <= radius;
var normal;
if (reject) {
print('rejecting type', filterType, 'packet near origin');
if (filterType === Entities.ADD_FILTER_TYPE) {
return false;
} else { /* Others are Entities.EDIT_FILTER_TYPE and Entities.PHYSICS_FILTER_TYPE. */
normal = Vec3.normalize(p.position);
p.position = Vec3.multiply(aBitMore, normal);
p.velocity = (p.velocity && Vec3.length(p.velocity) > epsilon) ?
Vec3.multiply(-1, p.velocity) : Vec3.multiply(staticBounceSpeed, normal);
p.acceleration = Vec3.ZERO;
}
}
}
if (p.dimensions && (filterType !== Entities.ADD_FILTER_TYPE)) {
if (p.dimensions.x > 11) {
p.dimensions.x = 11;
print('capping x dimension');
}
if (p.dimensions.y > 11) {
p.dimensions.y = 11;
print('capping y dimension');
}
if (p.dimensions.z > 11) {
p.dimensions.z = 11;
print('capping z dimension');
}
}
return p;
}