add ObjectMotionType::bump(), use in PhysicsEngine

This commit is contained in:
Andrew Meadows 2015-05-01 14:39:33 -07:00
parent 3c9474b736
commit 42ec39c578
4 changed files with 26 additions and 68 deletions

View file

@ -390,6 +390,11 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() const {
*/ */
} }
// virtual
void EntityMotionState::bump() {
setShouldClaimSimulationOwnership(true);
}
void EntityMotionState::resetMeasuredBodyAcceleration() { void EntityMotionState::resetMeasuredBodyAcceleration() {
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep(); _lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
_lastVelocity = bulletToGLM(_body->getLinearVelocity()); _lastVelocity = bulletToGLM(_body->getLinearVelocity());

View file

@ -67,6 +67,8 @@ public:
virtual const glm::vec3& getObjectAngularVelocity() const { return _entity->getAngularVelocity(); } virtual const glm::vec3& getObjectAngularVelocity() const { return _entity->getAngularVelocity(); }
virtual const glm::vec3& getObjectGravity() const { return _entity->getGravity(); } virtual const glm::vec3& getObjectGravity() const { return _entity->getGravity(); }
virtual void bump();
EntityItem* getEntity() const { return _entity; } EntityItem* getEntity() const { return _entity; }
void resetMeasuredBodyAcceleration(); void resetMeasuredBodyAcceleration();

View file

@ -114,6 +114,8 @@ public:
virtual const glm::vec3& getObjectAngularVelocity() const = 0; virtual const glm::vec3& getObjectAngularVelocity() const = 0;
virtual const glm::vec3& getObjectGravity() const = 0; virtual const glm::vec3& getObjectGravity() const = 0;
virtual void bump() = 0;
friend class PhysicsEngine; friend class PhysicsEngine;
protected: protected:

View file

@ -381,86 +381,35 @@ 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* object) { void PhysicsEngine::bump(ObjectMotionState* motionState) {
assert(object); // Find all objects that touch the object corresponding to motionState and flag the other objects
/* TODO: Andrew to implement this // for simulation ownership by the local simulation.
// 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. assert(motionState);
int numManifolds = _collisionDispatcher->getNumManifolds(); btCollisionObject* object = motionState->getRigidBody();
for (int i = 0; i < numManifolds; ++i) {
btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i);
if (contactManifold->getNumContacts() > 0) {
const btCollisionObject* objectA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
const btCollisionObject* objectB = static_cast<const btCollisionObject*>(contactManifold->getBody1());
if (objectA && objectB) {
void* a = objectA->getUserPointer();
void* b = objectB->getUserPointer();
if (a && b) {
EntityMotionState* entityMotionStateA = static_cast<EntityMotionState*>(a);
EntityMotionState* entityMotionStateB = static_cast<EntityMotionState*>(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);
}
}
}
}
}
}
}
*/
}
/*
// 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(); 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);
if (contactManifold->getNumContacts() > 0) { if (contactManifold->getNumContacts() > 0) {
const btCollisionObject* objectA = static_cast<const btCollisionObject*>(contactManifold->getBody0()); const btCollisionObject* objectA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
const btCollisionObject* objectB = static_cast<const btCollisionObject*>(contactManifold->getBody1()); const btCollisionObject* objectB = static_cast<const btCollisionObject*>(contactManifold->getBody1());
if (objectA && objectB) { if (objectB == object) {
void* a = objectA->getUserPointer(); ObjectMotionState* motionStateA = static_cast<ObjectMotionState*>(objectA->getUserPointer());
void* b = objectB->getUserPointer(); if (motionStateA) {
if (a && b) { motionStateA->bump();
EntityMotionState* entityMotionStateA = static_cast<EntityMotionState*>(a); objectA->setActivationState(ACTIVE_TAG);
EntityMotionState* entityMotionStateB = static_cast<EntityMotionState*>(b); }
EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : nullptr; } else if (objectA == object) {
EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : nullptr; ObjectMotionState* motionStateB = static_cast<ObjectMotionState*>(objectB->getUserPointer());
if (entityA && entityB) { if (motionStateB) {
if (entityA == bumpEntity) { motionStateB->bump();
entityMotionStateB->setShouldClaimSimulationOwnership(true); objectB->setActivationState(ACTIVE_TAG);
if (!objectB->isActive()) {
objectB->setActivationState(ACTIVE_TAG);
}
}
if (entityB == bumpEntity) {
entityMotionStateA->setShouldClaimSimulationOwnership(true);
if (!objectA->isActive()) {
objectA->setActivationState(ACTIVE_TAG);
}
}
}
} }
} }
} }
} }
} }
*/
void PhysicsEngine::setCharacterController(DynamicCharacterController* character) { void PhysicsEngine::setCharacterController(DynamicCharacterController* character) {
if (_characterController != character) { if (_characterController != character) {