From e9461f812d77111cc70f065e14d83111d24eb777 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 22 Apr 2017 17:09:26 -0700 Subject: [PATCH] don't run motor for other's hinge --- .../physics/src/ObjectConstraintHinge.cpp | 19 +++++++++++++------ .../system/libraries/entitySelectionTool.js | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libraries/physics/src/ObjectConstraintHinge.cpp b/libraries/physics/src/ObjectConstraintHinge.cpp index c3044c5431..036adbc915 100644 --- a/libraries/physics/src/ObjectConstraintHinge.cpp +++ b/libraries/physics/src/ObjectConstraintHinge.cpp @@ -52,6 +52,13 @@ void ObjectConstraintHinge::prepareForPhysicsSimulation() { // setting the motor velocity doesn't appear to work for anyone. constantly adjusting the // target angle seems to work. // https://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=7020 + + if (!isMine()) { + // XXX + // don't activate motor for someone else's action? + // maybe don't if this interface isn't the sim owner? + return; + } uint64_t now = usecTimestampNow(); withWriteLock([&]{ btHingeConstraint* constraint = static_cast(_constraint); @@ -69,12 +76,12 @@ void ObjectConstraintHinge::prepareForPhysicsSimulation() { float dt = (float)(now - _previousMotorTime) / (float)USECS_PER_SECOND; float t = (float)(now - _startMotorTime) / (float)USECS_PER_SECOND; float motorTarget = _motorVelocity * t; - while (motorTarget > PI) { - motorTarget -= PI; - } - while (motorTarget < PI) { - motorTarget += PI; - } + + // brige motorTarget into the range of [-PI, PI] + motorTarget += PI; + motorTarget = fmodf(motorTarget, 2.0f * PI); + motorTarget -= PI; + if (!_motorEnabled) { constraint->enableMotor(true); _motorEnabled = true; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 79d45d5cd2..bb3d3a57c1 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -2490,6 +2490,7 @@ SelectionDisplay = (function() { y: 0, z: vector.z }); + print("translateXZTool " + JSON.stringify(newPosition)); Entities.editEntity(SelectionManager.selections[i], { position: newPosition, });