mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:17:40 +02:00
remove all contact info before removing objects
This commit is contained in:
parent
618712538a
commit
532f0683e8
2 changed files with 29 additions and 20 deletions
|
@ -136,23 +136,19 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) {
|
||||||
motionState->clearIncomingDirtyFlags();
|
motionState->clearIncomingDirtyFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
|
||||||
void PhysicsEngine::removeObjectFromDynamicsWorld(ObjectMotionState* object) {
|
|
||||||
// wake up anything touching this object
|
|
||||||
bump(object);
|
|
||||||
removeContacts(object);
|
|
||||||
|
|
||||||
btRigidBody* body = object->getRigidBody();
|
|
||||||
assert(body);
|
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
||||||
|
// first bump and prune contacts for all objects in the list
|
||||||
for (auto object : objects) {
|
for (auto object : objects) {
|
||||||
removeObjectFromDynamicsWorld(object);
|
bumpAndPruneContacts(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
// then remove them
|
||||||
|
for (auto object : objects) {
|
||||||
|
btRigidBody* body = object->getRigidBody();
|
||||||
|
assert(body);
|
||||||
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
btRigidBody* body = object->getRigidBody();
|
|
||||||
object->setRigidBody(nullptr);
|
object->setRigidBody(nullptr);
|
||||||
body->setMotionState(nullptr);
|
body->setMotionState(nullptr);
|
||||||
delete body;
|
delete body;
|
||||||
|
@ -163,7 +159,8 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
||||||
void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
||||||
for (auto object : objects) {
|
for (auto object : objects) {
|
||||||
btRigidBody* body = object->getRigidBody();
|
btRigidBody* body = object->getRigidBody();
|
||||||
removeObjectFromDynamicsWorld(object);
|
assert(body);
|
||||||
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
object->setRigidBody(nullptr);
|
object->setRigidBody(nullptr);
|
||||||
|
@ -200,7 +197,13 @@ VectorOfMotionStates PhysicsEngine::changeObjects(const VectorOfMotionStates& ob
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::reinsertObject(ObjectMotionState* object) {
|
void PhysicsEngine::reinsertObject(ObjectMotionState* object) {
|
||||||
removeObjectFromDynamicsWorld(object);
|
// remove object from DynamicsWorld
|
||||||
|
bumpAndPruneContacts(object);
|
||||||
|
btRigidBody* body = object->getRigidBody();
|
||||||
|
assert(body);
|
||||||
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
|
// add it back
|
||||||
addObjectToDynamicsWorld(object);
|
addObjectToDynamicsWorld(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,13 +405,14 @@ void PhysicsEngine::dumpStatsIfNecessary() {
|
||||||
// CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
|
// CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
|
||||||
// CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
|
// CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
|
||||||
|
|
||||||
void PhysicsEngine::bump(ObjectMotionState* motionState) {
|
void PhysicsEngine::bumpAndPruneContacts(ObjectMotionState* motionState) {
|
||||||
// Find all objects that touch the object corresponding to motionState and flag the other objects
|
// Find all objects that touch the object corresponding to motionState and flag the other objects
|
||||||
// for simulation ownership by the local simulation.
|
// for simulation ownership by the local simulation.
|
||||||
|
|
||||||
assert(motionState);
|
assert(motionState);
|
||||||
btCollisionObject* object = motionState->getRigidBody();
|
btCollisionObject* object = motionState->getRigidBody();
|
||||||
|
|
||||||
|
std::vector<btPersistentManifold*> staleManifolds;
|
||||||
int numManifolds = _collisionDispatcher->getNumManifolds();
|
int numManifolds = _collisionDispatcher->getNumManifolds();
|
||||||
for (int i = 0; i < numManifolds; ++i) {
|
for (int i = 0; i < numManifolds; ++i) {
|
||||||
btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i);
|
btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i);
|
||||||
|
@ -423,6 +427,7 @@ void PhysicsEngine::bump(ObjectMotionState* motionState) {
|
||||||
objectA->setActivationState(ACTIVE_TAG);
|
objectA->setActivationState(ACTIVE_TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
staleManifolds.push_back(contactManifold);
|
||||||
} else if (objectA == object) {
|
} else if (objectA == object) {
|
||||||
if (!objectB->isStaticOrKinematicObject()) {
|
if (!objectB->isStaticOrKinematicObject()) {
|
||||||
ObjectMotionState* motionStateB = static_cast<ObjectMotionState*>(objectB->getUserPointer());
|
ObjectMotionState* motionStateB = static_cast<ObjectMotionState*>(objectB->getUserPointer());
|
||||||
|
@ -431,9 +436,14 @@ void PhysicsEngine::bump(ObjectMotionState* motionState) {
|
||||||
objectB->setActivationState(ACTIVE_TAG);
|
objectB->setActivationState(ACTIVE_TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
staleManifolds.push_back(contactManifold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto manifold : staleManifolds) {
|
||||||
|
_collisionDispatcher->releaseManifold(manifold);
|
||||||
|
}
|
||||||
|
removeContacts(motionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::setCharacterController(CharacterController* character) {
|
void PhysicsEngine::setCharacterController(CharacterController* character) {
|
||||||
|
|
|
@ -78,9 +78,6 @@ public:
|
||||||
/// \return position of simulation origin in domain-frame
|
/// \return position of simulation origin in domain-frame
|
||||||
const glm::vec3& getOriginOffset() const { return _originOffset; }
|
const glm::vec3& getOriginOffset() const { return _originOffset; }
|
||||||
|
|
||||||
/// \brief call bump on any objects that touch the object corresponding to motionState
|
|
||||||
void bump(ObjectMotionState* motionState);
|
|
||||||
|
|
||||||
void setCharacterController(CharacterController* character);
|
void setCharacterController(CharacterController* character);
|
||||||
|
|
||||||
void dumpNextStats() { _dumpNextStats = true; }
|
void dumpNextStats() { _dumpNextStats = true; }
|
||||||
|
@ -94,7 +91,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addObjectToDynamicsWorld(ObjectMotionState* motionState);
|
void addObjectToDynamicsWorld(ObjectMotionState* motionState);
|
||||||
void removeObjectFromDynamicsWorld(ObjectMotionState* motionState);
|
|
||||||
|
/// \brief bump any objects that touch this one, then remove contact info
|
||||||
|
void bumpAndPruneContacts(ObjectMotionState* motionState);
|
||||||
|
|
||||||
void removeContacts(ObjectMotionState* motionState);
|
void removeContacts(ObjectMotionState* motionState);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue