From dd65a44c9a192d62f7661090682ee0dc99fb0491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Feb 2015 09:39:53 +0100 Subject: 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 --- source/gameengine/Ketsji/KX_TouchEventManager.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_TouchEventManager.h') diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.h b/source/gameengine/Ketsji/KX_TouchEventManager.h index bd4903c1545..d9c6fdad307 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.h +++ b/source/gameengine/Ketsji/KX_TouchEventManager.h @@ -45,7 +45,29 @@ class PHY_IPhysicsEnvironment; class KX_TouchEventManager : public SCA_EventManager { - typedef std::pair NewCollision; + /** + * Contains two colliding objects and the first contact point. + */ + class NewCollision { + public: + PHY_IPhysicsController *first; + PHY_IPhysicsController *second; + PHY_CollData *colldata; + + /** + * Creates a copy of the given PHY_CollData; freeing that copy should be done by the owner of + * the NewCollision object. + * + * This allows us to efficiently store NewCollision objects in a std::set without creating more + * copies of colldata, as the NewCollision copy constructor reuses the pointer and doesn't clone + * it again. */ + NewCollision(PHY_IPhysicsController *first, + PHY_IPhysicsController *second, + const PHY_CollData *colldata); + NewCollision(const NewCollision &to_copy); + bool operator<(const NewCollision &other) const; + }; + PHY_IPhysicsEnvironment* m_physEnv; std::set m_newCollisions; -- cgit v1.2.3