diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 5f77d1e782..478603dedf 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -38,10 +38,10 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI //// XXX - auto nodeList = DependencyManager::get(); - QUuid myNodeID = nodeList->getSessionUUID(); - QString x = properties.getSimulatorID() == myNodeID ? "me" : properties.getSimulatorID().toString(); - qDebug() << "sending update:" << properties.simulatorIDChanged() << x; + // auto nodeList = DependencyManager::get(); + // QUuid myNodeID = nodeList->getSessionUUID(); + // QString x = properties.getSimulatorID() == myNodeID ? "me" : properties.getSimulatorID().toString(); + // qDebug() << "sending update:" << properties.simulatorIDChanged() << x; //// XXX diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 3f342c4d86..b771279efa 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -699,6 +699,7 @@ void EntityItem::simulate(const quint64& now) { qCDebug(entities) << " MOVING...="; qCDebug(entities) << " hasVelocity=" << hasVelocity(); qCDebug(entities) << " hasGravity=" << hasGravity(); + qCDebug(entities) << " hasAcceleration=" << hasAcceleration(); qCDebug(entities) << " hasAngularVelocity=" << hasAngularVelocity(); qCDebug(entities) << " getAngularVelocity=" << getAngularVelocity(); } @@ -788,13 +789,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) { position = newPosition; - // apply gravity - if (hasGravity()) { - // handle resting on surface case, this is definitely a bit of a hack, and it only works on the - // "ground" plane of the domain, but for now it's what we've got - velocity += getGravity() * timeElapsed; - } - + // apply effective acceleration, which will be the same as gravity if the Entity isn't at rest. if (hasAcceleration()) { velocity += getAcceleration() * timeElapsed; } @@ -1151,14 +1146,8 @@ void EntityItem::updateGravity(const glm::vec3& value) { } void EntityItem::updateAcceleration(const glm::vec3& value) { - if (glm::distance(_acceleration, value) > MIN_ACCELERATION_DELTA) { - if (glm::length(value) < MIN_ACCELERATION_DELTA) { - _acceleration = ENTITY_ITEM_ZERO_VEC3; - } else { - _acceleration = value; - } - _dirtyFlags |= EntityItem::DIRTY_VELOCITY; - } + _acceleration = value; + _dirtyFlags |= EntityItem::DIRTY_VELOCITY; } void EntityItem::updateAngularVelocity(const glm::vec3& value) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index b9def4f1db..96186b4c91 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -195,8 +195,8 @@ public: void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in meters bool hasGravity() const { return _gravity != ENTITY_ITEM_ZERO_VEC3; } - const glm::vec3 getAcceleration() const { return _acceleration; } /// get acceleration in meters/second - void setAcceleration(const glm::vec3& value) { _acceleration = value; } /// acceleration in meters/second + const glm::vec3 getAcceleration() const { return _acceleration; } /// get acceleration in meters/second/second + void setAcceleration(const glm::vec3& value) { _acceleration = value; } /// acceleration in meters/second/second bool hasAcceleration() const { return _acceleration != ENTITY_ITEM_ZERO_VEC3; } float getDamping() const { return _damping; } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f5468a0978..95a3dff6af 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -18,6 +18,7 @@ #include "PhysicsHelpers.h" #include "PhysicsLogging.h" +static const float MEASURED_ACCELERATION_CLOSE_TO_ZERO = 0.05; QSet* _outgoingEntityList; @@ -166,8 +167,8 @@ void EntityMotionState::updateObjectVelocities() { _sentAngularVelocity = _entity->getAngularVelocity(); setAngularVelocity(_sentAngularVelocity); - _sentAcceleration = _entity->getGravity(); - setGravity(_sentAcceleration); + _sentGravity = _entity->getGravity(); + setGravity(_sentGravity); _body->setActivationState(ACTIVE_TAG); } @@ -191,8 +192,8 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) { } auto nodeList = DependencyManager::get(); - QUuid myNodeID = nodeList->getSessionUUID(); - QUuid simulatorID = _entity->getSimulatorID(); + const QUuid& myNodeID = nodeList->getSessionUUID(); + const QUuid& simulatorID = _entity->getSimulatorID(); if (!simulatorID.isNull() && simulatorID != myNodeID) { // some other Node owns the simulating of this, so don't broadcast the results of local simulation. @@ -203,13 +204,18 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) { } void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) { - if (!_entity->isKnownID()) { return; // never update entities that are unknown } if (_outgoingPacketFlags) { EntityItemProperties properties = _entity->getProperties(); + if (glm::length(_measuredAcceleration) < MEASURED_ACCELERATION_CLOSE_TO_ZERO) { + _entity->setAcceleration(glm::vec3(0)); + } else { + _entity->setAcceleration(_entity->getGravity()); + } + if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); @@ -245,12 +251,13 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ _sentMoving = false; } properties.setVelocity(_sentVelocity); - _sentAcceleration = bulletToGLM(_body->getGravity()); - properties.setGravity(_sentAcceleration); + _sentGravity = _entity->getGravity(); + properties.setGravity(_entity->getGravity()); + _sentAcceleration = _entity->getAcceleration(); + properties.setAcceleration(_sentAcceleration); properties.setAngularVelocity(_sentAngularVelocity); } - auto nodeList = DependencyManager::get(); QUuid myNodeID = nodeList->getSessionUUID(); QUuid simulatorID = _entity->getSimulatorID(); diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 3d790ff7d4..852f2a96bd 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -57,6 +57,7 @@ ObjectMotionState::ObjectMotionState() : _sentRotation(), _sentVelocity(0.0f), _sentAngularVelocity(0.0f), + _sentGravity(0.0f), _sentAcceleration(0.0f), _lastSimulationStep(0), _lastVelocity(0.0f), @@ -174,7 +175,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationStep) { // Else we measure the error between current and extrapolated transform (according to expected behavior // of remote EntitySimulation) and return true if the error is significant. - // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame + // NOTE: math is done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. // compute position error diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index 9b5d6e7aa6..ad9ef861b9 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -138,6 +138,7 @@ protected: glm::quat _sentRotation;; glm::vec3 _sentVelocity; glm::vec3 _sentAngularVelocity; // radians per second + glm::vec3 _sentGravity; glm::vec3 _sentAcceleration; uint32_t _lastSimulationStep;