diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-02-05 11:39:53 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-02-08 17:52:13 +0300 |
commit | dd65a44c9a192d62f7661090682ee0dc99fb0491 (patch) | |
tree | 38a4a150113aca9c09de3851052597ee0f8bdfb9 /source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | |
parent | 51b645a655eb41c5b73d8487ee7df9ba99fc692b (diff) |
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
Diffstat (limited to 'source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp')
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index bcdc6f471ec..c43a3f782a7 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -2261,6 +2261,7 @@ void CcdPhysicsEnvironment::CallbackTriggers() int numManifolds = dispatcher->getNumManifolds(); for (int i=0;i<numManifolds;i++) { + bool colliding_ctrl0 = true; btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i); int numContacts = manifold->getNumContacts(); if (!numContacts) continue; @@ -2289,12 +2290,27 @@ void CcdPhysicsEnvironment::CallbackTriggers() if (iter == m_triggerControllers.end()) { iter = m_triggerControllers.find(ctrl1); + colliding_ctrl0 = false; } if (iter != m_triggerControllers.end()) { + static PHY_CollData coll_data; + const btManifoldPoint &cp = manifold->getContactPoint(0); + + /* Make sure that "point1" is always on the object we report on, and + * "point2" on the other object. Also ensure the normal is oriented + * correctly. */ + btVector3 point1 = colliding_ctrl0 ? cp.m_positionWorldOnA : cp.m_positionWorldOnB; + btVector3 point2 = colliding_ctrl0 ? cp.m_positionWorldOnB : cp.m_positionWorldOnA; + btVector3 normal = colliding_ctrl0 ? -cp.m_normalWorldOnB : cp.m_normalWorldOnB; + + coll_data.m_point1 = MT_Vector3(point1.m_floats); + coll_data.m_point2 = MT_Vector3(point2.m_floats); + coll_data.m_normal = MT_Vector3(normal.m_floats); + m_triggerCallbacks[PHY_OBJECT_RESPONSE](m_triggerCallbacksUserPtrs[PHY_OBJECT_RESPONSE], - ctrl0,ctrl1,0); + ctrl0, ctrl1, &coll_data); } // Bullet does not refresh the manifold contact point for object without contact response // may need to remove this when a newer Bullet version is integrated |