From 630f1ce9d9ce55a7e983e14e1c43fd9c65bbef14 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 6 May 2015 16:13:07 -0700 Subject: [PATCH] isMovingVsServer function --- libraries/physics/src/EntityMotionState.cpp | 19 +++++++++++-------- libraries/physics/src/EntityMotionState.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 1f4b45318f..f9d054379a 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -93,6 +93,15 @@ bool EntityMotionState::isMoving() const { return _entity && _entity->isMoving(); } +bool EntityMotionState::isMovingVsServer() const { + auto alignmentDot = glm::abs(glm::dot(_sentRotation, _entity->getRotation())); + if (glm::distance(_sentPosition, _entity->getPosition()) > IGNORE_POSITION_DELTA || + alignmentDot < IGNORE_ALIGNMENT_DOT) { + return true; + } + return false; +} + // This callback is invoked by the physics simulation in two cases: // (1) when the RigidBody is first added to the world // (irregardless of MotionType: STATIC, DYNAMIC, or KINEMATIC) @@ -133,15 +142,9 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { _entity->setLastSimulated(usecTimestampNow()); // if (_entity->getSimulatorID().isNull() && isMoving()) { - if (_entity->getSimulatorID().isNull()) { + if (_entity->getSimulatorID().isNull() && isMovingVsServer()) { // if object is moving and has no owner, attempt to claim simulation ownership. - auto alignmentDot = glm::abs(glm::dot(_sentRotation, _entity->getRotation())); - if (glm::distance(_sentPosition, _entity->getPosition()) > IGNORE_POSITION_DELTA || - alignmentDot < IGNORE_ALIGNMENT_DOT) { - _movingStepsWithoutSimulationOwner++; - } else { - _movingStepsWithoutSimulationOwner = 0; - } + _movingStepsWithoutSimulationOwner++; } else { _movingStepsWithoutSimulationOwner = 0; } diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 39f6bc0814..71b1962368 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -36,6 +36,7 @@ public: virtual MotionType computeObjectMotionType() const; virtual bool isMoving() const; + virtual bool isMovingVsServer() const; // this relays incoming position/rotation to the RigidBody virtual void getWorldTransform(btTransform& worldTrans) const;