mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02:00
fix JS scripts to use radians per second
in entity properties
This commit is contained in:
parent
f5352333f0
commit
5b854857c1
8 changed files with 53 additions and 21 deletions
|
@ -92,7 +92,6 @@ function checkControllerSide(whichSide) {
|
||||||
Vec3.multiply(1.0 - AVERAGE_FACTOR, averageLinearVelocity[0]));
|
Vec3.multiply(1.0 - AVERAGE_FACTOR, averageLinearVelocity[0]));
|
||||||
linearVelocity = averageLinearVelocity[0];
|
linearVelocity = averageLinearVelocity[0];
|
||||||
angularVelocity = Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getSpatialControlRawAngularVelocity(LEFT_TIP));
|
angularVelocity = Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getSpatialControlRawAngularVelocity(LEFT_TIP));
|
||||||
angularVelocity = Vec3.multiply(180.0 / Math.PI, angularVelocity);
|
|
||||||
} else {
|
} else {
|
||||||
BUTTON_FWD = RIGHT_BUTTON_FWD;
|
BUTTON_FWD = RIGHT_BUTTON_FWD;
|
||||||
BUTTON_3 = RIGHT_BUTTON_3;
|
BUTTON_3 = RIGHT_BUTTON_3;
|
||||||
|
@ -104,7 +103,6 @@ function checkControllerSide(whichSide) {
|
||||||
Vec3.multiply(1.0 - AVERAGE_FACTOR, averageLinearVelocity[1]));
|
Vec3.multiply(1.0 - AVERAGE_FACTOR, averageLinearVelocity[1]));
|
||||||
linearVelocity = averageLinearVelocity[1];
|
linearVelocity = averageLinearVelocity[1];
|
||||||
angularVelocity = Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getSpatialControlRawAngularVelocity(RIGHT_TIP));
|
angularVelocity = Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getSpatialControlRawAngularVelocity(RIGHT_TIP));
|
||||||
angularVelocity = Vec3.multiply(180.0 / Math.PI, angularVelocity);
|
|
||||||
handMessage = "RIGHT";
|
handMessage = "RIGHT";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,9 @@ function shootDice(position, velocity) {
|
||||||
position: position,
|
position: position,
|
||||||
velocity: velocity,
|
velocity: velocity,
|
||||||
rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360),
|
rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360),
|
||||||
angularVelocity: { x: Math.random() * 100, y: Math.random() * 100, z: Math.random() * 100 },
|
// NOTE: angularVelocity is in radians/sec
|
||||||
|
var maxAngularSpeed = Math.PI;
|
||||||
|
angularVelocity: { x: Math.random() * maxAngularSpeed, y: Math.random() * maxAngularSpeed, z: Math.random() * maxAngularSpeed },
|
||||||
lifetime: LIFETIME,
|
lifetime: LIFETIME,
|
||||||
gravity: { x: 0, y: GRAVITY, z: 0 },
|
gravity: { x: 0, y: GRAVITY, z: 0 },
|
||||||
shapeType: "box",
|
shapeType: "box",
|
||||||
|
|
|
@ -11,11 +11,13 @@
|
||||||
// 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
|
||||||
//
|
//
|
||||||
|
|
||||||
|
var DEGREES_TO_RADIANS = Math.PI / 180.0;
|
||||||
|
|
||||||
var lightProperties = {
|
var lightProperties = {
|
||||||
type: "Light",
|
type: "Light",
|
||||||
position: { x: 0, y: 0, z: 0 },
|
position: { x: 0, y: 0, z: 0 },
|
||||||
dimensions: { x: 1000, y: 1000, z: 1000 },
|
dimensions: { x: 1000, y: 1000, z: 1000 },
|
||||||
angularVelocity: { x: 0, y: 10, z: 0 },
|
angularVelocity: { x: 0, y: 10 * DEGREES_TO_RADIANS, z: 0 },
|
||||||
angularDamping: 0,
|
angularDamping: 0,
|
||||||
|
|
||||||
isSpotlight: true,
|
isSpotlight: true,
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
<script>
|
<script>
|
||||||
|
var PI = 3.14159265358979;
|
||||||
|
var DEGREES_TO_RADIANS = PI / 180.0;
|
||||||
|
var RADIANS_TO_DEGREES = 180.0 / PI;
|
||||||
|
|
||||||
function enableChildren(el, selector) {
|
function enableChildren(el, selector) {
|
||||||
els = el.querySelectorAll(selector);
|
els = el.querySelectorAll(selector);
|
||||||
for (var i = 0; i < els.length; i++) {
|
for (var i = 0; i < els.length; i++) {
|
||||||
|
@ -58,6 +62,22 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createEmitVec3PropertyUpdateFunctionWithMultiplier(property, elX, elY, elZ, multiplier) {
|
||||||
|
return function() {
|
||||||
|
var data = {
|
||||||
|
type: "update",
|
||||||
|
properties: {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
data.properties[property] = {
|
||||||
|
x: elX.value * multiplier,
|
||||||
|
y: elY.value * multiplier,
|
||||||
|
z: elZ.value * multiplier,
|
||||||
|
};
|
||||||
|
EventBridge.emitWebEvent(JSON.stringify(data));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function createEmitColorPropertyUpdateFunction(property, elRed, elGreen, elBlue) {
|
function createEmitColorPropertyUpdateFunction(property, elRed, elGreen, elBlue) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -227,9 +247,9 @@
|
||||||
elLinearVelocityZ.value = properties.velocity.z.toFixed(2);
|
elLinearVelocityZ.value = properties.velocity.z.toFixed(2);
|
||||||
elLinearDamping.value = properties.damping.toFixed(2);
|
elLinearDamping.value = properties.damping.toFixed(2);
|
||||||
|
|
||||||
elAngularVelocityX.value = properties.angularVelocity.x.toFixed(2);
|
elAngularVelocityX.value = (properties.angularVelocity.x * RADIANS_TO_DEGREES).toFixed(2);
|
||||||
elAngularVelocityY.value = properties.angularVelocity.y.toFixed(2);
|
elAngularVelocityY.value = (properties.angularVelocity.y * RADIANS_TO_DEGREES).toFixed(2);
|
||||||
elAngularVelocityZ.value = properties.angularVelocity.z.toFixed(2);
|
elAngularVelocityZ.value = (properties.angularVelocity.z * RADIANS_TO_DEGREES).toFixed(2);
|
||||||
elAngularDamping.value = properties.angularDamping.toFixed(2);
|
elAngularDamping.value = properties.angularDamping.toFixed(2);
|
||||||
|
|
||||||
elGravityX.value = properties.gravity.x.toFixed(2);
|
elGravityX.value = properties.gravity.x.toFixed(2);
|
||||||
|
@ -352,8 +372,8 @@
|
||||||
elLinearVelocityZ.addEventListener('change', velocityChangeFunction);
|
elLinearVelocityZ.addEventListener('change', velocityChangeFunction);
|
||||||
elLinearDamping.addEventListener('change', createEmitNumberPropertyUpdateFunction('damping'));
|
elLinearDamping.addEventListener('change', createEmitNumberPropertyUpdateFunction('damping'));
|
||||||
|
|
||||||
var angularVelocityChangeFunction = createEmitVec3PropertyUpdateFunction(
|
var angularVelocityChangeFunction = createEmitVec3PropertyUpdateFunctionWithMultiplier(
|
||||||
'angularVelocity', elAngularVelocityX, elAngularVelocityY, elAngularVelocityZ);
|
'angularVelocity', elAngularVelocityX, elAngularVelocityY, elAngularVelocityZ, DEGREES_TO_RADIANS);
|
||||||
elAngularVelocityX.addEventListener('change', angularVelocityChangeFunction);
|
elAngularVelocityX.addEventListener('change', angularVelocityChangeFunction);
|
||||||
elAngularVelocityY.addEventListener('change', angularVelocityChangeFunction);
|
elAngularVelocityY.addEventListener('change', angularVelocityChangeFunction);
|
||||||
elAngularVelocityZ.addEventListener('change', angularVelocityChangeFunction);
|
elAngularVelocityZ.addEventListener('change', angularVelocityChangeFunction);
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
// 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
|
||||||
//
|
//
|
||||||
|
|
||||||
|
var DEGREES_TO_RADIANS = Math.PI / 180.0;
|
||||||
|
var RADIANS_TO_DEGREES = 180.0 / Math.PI;
|
||||||
|
|
||||||
EntityPropertyDialogBox = (function () {
|
EntityPropertyDialogBox = (function () {
|
||||||
var that = {};
|
var that = {};
|
||||||
|
|
||||||
|
@ -146,11 +149,12 @@ EntityPropertyDialogBox = (function () {
|
||||||
index++;
|
index++;
|
||||||
array.push({ label: "Linear Damping:", value: properties.damping.toFixed(decimals) });
|
array.push({ label: "Linear Damping:", value: properties.damping.toFixed(decimals) });
|
||||||
index++;
|
index++;
|
||||||
array.push({ label: "Angular Pitch:", value: properties.angularVelocity.x.toFixed(decimals) });
|
// NOTE: angular velocity is in radians/sec but we display degrees/sec for users
|
||||||
|
array.push({ label: "Angular Pitch:", value: (properties.angularVelocity.x * RADIANS_TO_DEGREES).toFixed(decimals) });
|
||||||
index++;
|
index++;
|
||||||
array.push({ label: "Angular Yaw:", value: properties.angularVelocity.y.toFixed(decimals) });
|
array.push({ label: "Angular Yaw:", value: (properties.angularVelocity.y * RADIANS_TO_DEGREES).toFixed(decimals) });
|
||||||
index++;
|
index++;
|
||||||
array.push({ label: "Angular Roll:", value: properties.angularVelocity.z.toFixed(decimals) });
|
array.push({ label: "Angular Roll:", value: (properties.angularVelocity.z * RADIANS_TO_DEGREES).toFixed(decimals) });
|
||||||
index++;
|
index++;
|
||||||
array.push({ label: "Angular Damping:", value: properties.angularDamping.toFixed(decimals) });
|
array.push({ label: "Angular Damping:", value: properties.angularDamping.toFixed(decimals) });
|
||||||
index++;
|
index++;
|
||||||
|
@ -343,9 +347,10 @@ EntityPropertyDialogBox = (function () {
|
||||||
properties.velocity.z = array[index++].value;
|
properties.velocity.z = array[index++].value;
|
||||||
properties.damping = array[index++].value;
|
properties.damping = array[index++].value;
|
||||||
|
|
||||||
properties.angularVelocity.x = array[index++].value;
|
// NOTE: angular velocity is in radians/sec but we display degrees/sec for users
|
||||||
properties.angularVelocity.y = array[index++].value;
|
properties.angularVelocity.x = array[index++].value * DEGREES_TO_RADIANS;
|
||||||
properties.angularVelocity.z = array[index++].value;
|
properties.angularVelocity.y = array[index++].value * DEGREES_TO_RADIANS;
|
||||||
|
properties.angularVelocity.z = array[index++].value * DEGREES_TO_RADIANS;
|
||||||
properties.angularDamping = array[index++].value;
|
properties.angularDamping = array[index++].value;
|
||||||
|
|
||||||
properties.gravity.x = array[index++].value;
|
properties.gravity.x = array[index++].value;
|
||||||
|
|
|
@ -35,13 +35,15 @@ var NUM_INITIAL_PARTICLES = 200;
|
||||||
var PARTICLE_MIN_SIZE = 0.50;
|
var PARTICLE_MIN_SIZE = 0.50;
|
||||||
var PARTICLE_MAX_SIZE = 1.50;
|
var PARTICLE_MAX_SIZE = 1.50;
|
||||||
var INITIAL_VELOCITY = 5.0;
|
var INITIAL_VELOCITY = 5.0;
|
||||||
|
var DEGREES_TO_RADIANS = Math.PI / 180.0;
|
||||||
|
|
||||||
var planets = [];
|
var planets = [];
|
||||||
var particles = [];
|
var particles = [];
|
||||||
|
|
||||||
// Create planets that will extert gravity on test particles
|
// Create planets that will extert gravity on test particles
|
||||||
for (var i = 0; i < planetTypes.length; i++) {
|
for (var i = 0; i < planetTypes.length; i++) {
|
||||||
var rotationalVelocity = 10 + Math.random() * 60;
|
// NOTE: rotationalVelocity is in radians/sec
|
||||||
|
var rotationalVelocity = (10 + Math.random() * 60) * DEGREES_TO_RADIANS;
|
||||||
var position = { x: planetTypes[i].x, y: planetTypes[i].y, z: planetTypes[i].z };
|
var position = { x: planetTypes[i].x, y: planetTypes[i].y, z: planetTypes[i].z };
|
||||||
position = Vec3.multiply(MAX_RANGE / 2, position);
|
position = Vec3.multiply(MAX_RANGE / 2, position);
|
||||||
position = Vec3.sum(center, position);
|
position = Vec3.sum(center, position);
|
||||||
|
|
|
@ -20,6 +20,8 @@ var GRAVITY = -1.0;
|
||||||
var LIFETIME = 600;
|
var LIFETIME = 600;
|
||||||
var DAMPING = 0.50;
|
var DAMPING = 0.50;
|
||||||
|
|
||||||
|
var TWO_PI = 2.0 * Math.PI;
|
||||||
|
|
||||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(SCALE * 3.0, Quat.getFront(Camera.getOrientation())));
|
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(SCALE * 3.0, Quat.getFront(Camera.getOrientation())));
|
||||||
|
|
||||||
var floor = Entities.addEntity(
|
var floor = Entities.addEntity(
|
||||||
|
@ -122,7 +124,8 @@ var spinner = Entities.addEntity(
|
||||||
position: center,
|
position: center,
|
||||||
dimensions: { x: SCALE / 1.5, y: SCALE / 3.0, z: SCALE / 8.0 },
|
dimensions: { x: SCALE / 1.5, y: SCALE / 3.0, z: SCALE / 8.0 },
|
||||||
color: { red: 255, green: 0, blue: 0 },
|
color: { red: 255, green: 0, blue: 0 },
|
||||||
angularVelocity: { x: 0, y: 360, z: 0 },
|
// NOTE: angularVelocity is in radians/sec
|
||||||
|
angularVelocity: { x: 0, y: TWO_PI, z: 0 },
|
||||||
angularDamping: 0.0,
|
angularDamping: 0.0,
|
||||||
gravity: { x: 0, y: 0, z: 0 },
|
gravity: { x: 0, y: 0, z: 0 },
|
||||||
ignoreCollisions: false,
|
ignoreCollisions: false,
|
||||||
|
|
Loading…
Reference in a new issue