diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 01047efb4a..1f4b45318f 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -47,6 +47,34 @@ EntityMotionState::~EntityMotionState() { assert(!_entity); } +void EntityMotionState::updateServerPhysicsVariables(uint32_t flags) { + if (flags & EntityItem::DIRTY_POSITION) { + _sentPosition = _entity->getPosition(); + } + if (flags & EntityItem::DIRTY_ROTATION) { + _sentRotation = _entity->getRotation(); + } + if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) { + _sentVelocity = _entity->getVelocity(); + } + if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) { + _sentAngularVelocity = _entity->getAngularVelocity(); + } +} + +// virtual +void EntityMotionState::handleEasyChanges(uint32_t flags) { + updateServerPhysicsVariables(flags); + ObjectMotionState::handleEasyChanges(flags); +} + + +// virtual +void EntityMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine) { + updateServerPhysicsVariables(flags); + ObjectMotionState::handleHardAndEasyChanges(flags, engine); +} + void EntityMotionState::clearEntity() { _entity = nullptr; } diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 49aead0050..39f6bc0814 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -28,6 +28,10 @@ public: EntityMotionState(btCollisionShape* shape, EntityItem* item); virtual ~EntityMotionState(); + void updateServerPhysicsVariables(uint32_t flags); + virtual void handleEasyChanges(uint32_t flags); + virtual void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine); + /// \return MOTION_TYPE_DYNAMIC or MOTION_TYPE_STATIC based on params set in EntityItem virtual MotionType computeObjectMotionType() const; @@ -88,6 +92,7 @@ protected: bool _sentMoving; // true if last update was moving int _numNonMovingUpdates; // RELIABLE_SEND_HACK for "not so reliable" resends of packets for non-moving objects + // TODO XXX rename _sent* to _server* uint32_t _sentStep; glm::vec3 _sentPosition; // in simulation-frame (not world-frame) glm::quat _sentRotation;; diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index 98d5b8e707..4836cf52fd 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -68,8 +68,8 @@ public: ObjectMotionState(btCollisionShape* shape); ~ObjectMotionState(); - void handleEasyChanges(uint32_t flags); - void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine); + virtual void handleEasyChanges(uint32_t flags); + virtual void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine); virtual void updateBodyMaterialProperties(); virtual void updateBodyVelocities();