diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index bfed81a944..e028ee89ea 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -299,9 +299,10 @@ void RenderableModelEntityItem::render(RenderArgs* args) { bool movingOrAnimating = isMoving() || isAnimatingSomething(); if ((movingOrAnimating || - _needsInitialSimulation || - _model->getTranslation() != getPosition() || - _model->getRotation() != getRotation()) + _needsInitialSimulation // || + // _model->getTranslation() != getPosition() || + // _model->getRotation() != getRotation() + ) && _model->isActive() && _dimensionsInitialized) { _model->setScaleToFit(true, getDimensions()); _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index c458c2e1f8..b6487103d1 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include #include @@ -30,6 +32,11 @@ static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4; const uint32_t LOOPS_FOR_SIMULATION_ORPHAN = 50; const quint64 USECS_BETWEEN_OWNERSHIP_BIDS = USECS_PER_SECOND / 5; +// NOTE: the threshold to use here relates to the linear displacement threshold (dX) for sending updates +// to objects that are tracked server-side (e.g. entities which use dX = 2mm). Hence an object moving +// just under this velocity threshold would trigger an update about V/dX times per second. +const float MIN_LINEAR_SPEED_SQUARED = 0.0036f; // 6 mm/sec + #ifdef WANT_DEBUG_ENTITY_TREE_LOCKS bool EntityMotionState::entityTreeIsLocked() const { EntityTreeElementPointer element = _entity ? _entity->getElement() : nullptr; @@ -548,6 +555,10 @@ void EntityMotionState::resetMeasuredBodyAcceleration() { _lastMeasureStep = ObjectMotionState::getWorldSimulationStep(); if (_body) { _lastVelocity = getBodyLinearVelocity(); + // if _lastVelocity is too slow, set it to zero + if (glm::length2(_lastVelocity) < MIN_LINEAR_SPEED_SQUARED) { + _lastVelocity *= 0.0f; + } } else { _lastVelocity = glm::vec3(0.0f); } @@ -567,6 +578,10 @@ void EntityMotionState::measureBodyAcceleration() { // Note: the integration equation for velocity uses damping: v1 = (v0 + a * dt) * (1 - D)^dt // hence the equation for acceleration is: a = (v1 / (1 - D)^dt - v0) / dt glm::vec3 velocity = getBodyLinearVelocity(); + if (glm::length2(velocity) < MIN_LINEAR_SPEED_SQUARED) { + velocity *= 0.0f; + } + _measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt; _lastVelocity = velocity; if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) { diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index d2c152d876..8bd6c3c983 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -80,16 +80,8 @@ void ObjectMotionState::setBodyGravity(const glm::vec3& gravity) const { } glm::vec3 ObjectMotionState::getBodyLinearVelocity() const { - // returns the body's velocity unless it is moving too slow in which case returns zero + // returns the body's velocity btVector3 velocity = _body->getLinearVelocity(); - - // NOTE: the threshold to use here relates to the linear displacement threshold (dX) for sending updates - // to objects that are tracked server-side (e.g. entities which use dX = 2mm). Hence an object moving - // just under this velocity threshold would trigger an update about V/dX times per second. - const float MIN_LINEAR_SPEED_SQUARED = 0.0036f; // 6 mm/sec - if (velocity.length2() < MIN_LINEAR_SPEED_SQUARED) { - velocity *= 0.0f; - } return bulletToGLM(velocity); }