BGE physics: When colliding, report first contact point to Python

This patch adds two parameters to the functions in the
collisionCallbacks list. The callback function should thus be like
this:

```
def on_colliding(other, point, normal):
    print("Colliding with %s at %s with normal %s" % (other, point, normal))

game_ob.collisionCallbacks.append(on_colliding)
```

The `point` parameter will contain the collision point in world
coordinates on the current object, and the `normal` contains the
surface normal at the collision point.

The callback functions are checked for the number of arguments
`co_argcount`. The new `point` and `normal` arguments are only passed
when `co_argcount > 1` or when `co_argcount` cannot be determined.

Reviewers: brita_, campbellbarton

Subscribers: sergey, sybren, agoose77

Projects: #game_physics

Differential Revision: https://developer.blender.org/D926
This commit is contained in:
2015-02-05 09:39:53 +01:00
parent 51b645a655
commit dd65a44c9a
6 changed files with 143 additions and 12 deletions

View File

@@ -60,7 +60,7 @@ bool KX_TouchEventManager::NewHandleCollision(void* object1, void* object2, cons
PHY_IPhysicsController* obj1 = static_cast<PHY_IPhysicsController*>(object1);
PHY_IPhysicsController* obj2 = static_cast<PHY_IPhysicsController*>(object2);
m_newCollisions.insert(std::pair<PHY_IPhysicsController*, PHY_IPhysicsController*>(obj1, obj2));
m_newCollisions.insert(NewCollision(obj1, obj2, coll_data));
return false;
}
@@ -209,9 +209,11 @@ void KX_TouchEventManager::NextFrame()
}
}
// Run python callbacks
kxObj1->RunCollisionCallbacks(kxObj2);
kxObj2->RunCollisionCallbacks(kxObj1);
PHY_CollData *colldata = cit->colldata;
kxObj1->RunCollisionCallbacks(kxObj2, colldata->m_point1, colldata->m_normal);
kxObj2->RunCollisionCallbacks(kxObj1, colldata->m_point2, -colldata->m_normal);
delete cit->colldata;
}
m_newCollisions.clear();
@@ -219,3 +221,19 @@ void KX_TouchEventManager::NextFrame()
for (it.begin();!it.end();++it)
(*it)->Activate(m_logicmgr);
}
KX_TouchEventManager::NewCollision::NewCollision(PHY_IPhysicsController *first,
PHY_IPhysicsController *second,
const PHY_CollData *colldata)
: first(first), second(second), colldata(new PHY_CollData(*colldata))
{}
KX_TouchEventManager::NewCollision::NewCollision(const NewCollision &to_copy)
: first(to_copy.first), second(to_copy.second), colldata(to_copy.colldata)
{}
bool KX_TouchEventManager::NewCollision::operator<(const NewCollision &other) const
{
return first < other.first || second < other.second || colldata < other.colldata;
}