diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index d8fcc47b60..2ad2cf5c7d 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -390,6 +390,11 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() const { */ } +// virtual +void EntityMotionState::bump() { + setShouldClaimSimulationOwnership(true); +} + void EntityMotionState::resetMeasuredBodyAcceleration() { _lastMeasureStep = ObjectMotionState::getWorldSimulationStep(); _lastVelocity = bulletToGLM(_body->getLinearVelocity()); diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index e00969e007..43e1f64c82 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -67,6 +67,8 @@ public: virtual const glm::vec3& getObjectAngularVelocity() const { return _entity->getAngularVelocity(); } virtual const glm::vec3& getObjectGravity() const { return _entity->getGravity(); } + virtual void bump(); + EntityItem* getEntity() const { return _entity; } void resetMeasuredBodyAcceleration(); diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index 253ce57847..e885d46046 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -114,6 +114,8 @@ public: virtual const glm::vec3& getObjectAngularVelocity() const = 0; virtual const glm::vec3& getObjectGravity() const = 0; + virtual void bump() = 0; + friend class PhysicsEngine; protected: diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 1029dc064f..01f3b41604 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -381,86 +381,35 @@ void PhysicsEngine::dumpStatsIfNecessary() { // CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing // CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing -void PhysicsEngine::bump(ObjectMotionState* object) { - assert(object); - /* TODO: Andrew to implement this - // If this node is doing something like deleting an entity, scan for contacts involving the - // entity. For each found, flag the other entity involved as being simulated by this node. - int numManifolds = _collisionDispatcher->getNumManifolds(); - for (int i = 0; i < numManifolds; ++i) { - btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i); - if (contactManifold->getNumContacts() > 0) { - const btCollisionObject* objectA = static_cast(contactManifold->getBody0()); - const btCollisionObject* objectB = static_cast(contactManifold->getBody1()); - if (objectA && objectB) { - void* a = objectA->getUserPointer(); - void* b = objectB->getUserPointer(); - if (a && b) { - EntityMotionState* entityMotionStateA = static_cast(a); - EntityMotionState* entityMotionStateB = static_cast(b); - EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : nullptr; - EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : nullptr; - if (entityA && entityB) { - if (entityA == bumpEntity) { - entityMotionStateB->setShouldClaimSimulationOwnership(true); - if (!objectB->isActive()) { - objectB->setActivationState(ACTIVE_TAG); - } - } - if (entityB == bumpEntity) { - entityMotionStateA->setShouldClaimSimulationOwnership(true); - if (!objectA->isActive()) { - objectA->setActivationState(ACTIVE_TAG); - } - } - } - } - } - } - } - */ -} +void PhysicsEngine::bump(ObjectMotionState* motionState) { + // Find all objects that touch the object corresponding to motionState and flag the other objects + // for simulation ownership by the local simulation. + + assert(motionState); + btCollisionObject* object = motionState->getRigidBody(); -/* -// TODO: convert bump() to take an ObjectMotionState. -// Expose SimulationID to ObjectMotionState -void PhysicsEngine::bump(EntityItem* bumpEntity) { - // If this node is doing something like deleting an entity, scan for contacts involving the - // entity. For each found, flag the other entity involved as being simulated by this node. int numManifolds = _collisionDispatcher->getNumManifolds(); for (int i = 0; i < numManifolds; ++i) { btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i); if (contactManifold->getNumContacts() > 0) { const btCollisionObject* objectA = static_cast(contactManifold->getBody0()); const btCollisionObject* objectB = static_cast(contactManifold->getBody1()); - if (objectA && objectB) { - void* a = objectA->getUserPointer(); - void* b = objectB->getUserPointer(); - if (a && b) { - EntityMotionState* entityMotionStateA = static_cast(a); - EntityMotionState* entityMotionStateB = static_cast(b); - EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : nullptr; - EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : nullptr; - if (entityA && entityB) { - if (entityA == bumpEntity) { - entityMotionStateB->setShouldClaimSimulationOwnership(true); - if (!objectB->isActive()) { - objectB->setActivationState(ACTIVE_TAG); - } - } - if (entityB == bumpEntity) { - entityMotionStateA->setShouldClaimSimulationOwnership(true); - if (!objectA->isActive()) { - objectA->setActivationState(ACTIVE_TAG); - } - } - } + if (objectB == object) { + ObjectMotionState* motionStateA = static_cast(objectA->getUserPointer()); + if (motionStateA) { + motionStateA->bump(); + objectA->setActivationState(ACTIVE_TAG); + } + } else if (objectA == object) { + ObjectMotionState* motionStateB = static_cast(objectB->getUserPointer()); + if (motionStateB) { + motionStateB->bump(); + objectB->setActivationState(ACTIVE_TAG); } } } } } -*/ void PhysicsEngine::setCharacterController(DynamicCharacterController* character) { if (_characterController != character) {