mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 05:42:08 +02:00
CR style feedback
This commit is contained in:
parent
3936dda099
commit
8aa0525f45
2 changed files with 36 additions and 16 deletions
|
@ -1,8 +1,21 @@
|
|||
//
|
||||
// keep-in-zone-example.js
|
||||
//
|
||||
//
|
||||
// Created by Brad Hefta-Gaub to use Entities on Dec. 15, 2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// This sample entity edit filter script will keep any entity inside the bounding box of the zone this filter is applied to.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
function filter(properties, type, originalProperties, zoneProperties) {
|
||||
|
||||
var nearZero = 0.0001 * Math.random() + 0.001;
|
||||
|
||||
/* Clamp position changes to bounding box of zone.*/
|
||||
/* Clamp position changes to bounding box of zone.*/
|
||||
function clamp(val, min, max) {
|
||||
/* Random near-zero value used as "zero" to prevent two sequential updates from being
|
||||
exactly the same (which would cause them to be ignored) */
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
//
|
||||
// position-example.js
|
||||
//
|
||||
//
|
||||
// Created by Brad Hefta-Gaub to use Entities on Dec. 15, 2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// This sample entity edit filter script will only allow position to be changed by no more than 5 meters on any axis.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
function filter(properties, type, originalProperties) {
|
||||
|
||||
/* Clamp position changes.*/
|
||||
var maxChange = 5;
|
||||
function sign(val) {
|
||||
if (val > 0) {
|
||||
return 1;
|
||||
} else if (val < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clamp position changes.*/
|
||||
var maxChange = 5;
|
||||
|
||||
function clamp(val, min, max) {
|
||||
if (val > max) {
|
||||
|
@ -27,9 +31,12 @@ function filter(properties, type, originalProperties) {
|
|||
exactly the same (which would cause them to be ignored) */
|
||||
var nearZero = 0.0001 * Math.random() + 0.001;
|
||||
var maxFudgeChange = (maxChange + nearZero);
|
||||
properties.position.x = clamp(properties.position.x, originalProperties.position.x - maxFudgeChange, originalProperties.position.x + maxFudgeChange);
|
||||
properties.position.y = clamp(properties.position.y, originalProperties.position.y - maxFudgeChange, originalProperties.position.y + maxFudgeChange);
|
||||
properties.position.z = clamp(properties.position.z, originalProperties.position.z - maxFudgeChange, originalProperties.position.z + maxFudgeChange);
|
||||
properties.position.x = clamp(properties.position.x, originalProperties.position.x
|
||||
- maxFudgeChange, originalProperties.position.x + maxFudgeChange);
|
||||
properties.position.y = clamp(properties.position.y, originalProperties.position.y
|
||||
- maxFudgeChange, originalProperties.position.y + maxFudgeChange);
|
||||
properties.position.z = clamp(properties.position.z, originalProperties.position.z
|
||||
- maxFudgeChange, originalProperties.position.z + maxFudgeChange);
|
||||
}
|
||||
|
||||
return properties;
|
||||
|
|
Loading…
Reference in a new issue