From 47b2eb457a3fd9ce5147a927bdb544152cb5e25c Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 4 Aug 2014 22:57:24 +0200 Subject: [PATCH] Allow the user to attach user data to a ProxyShape object --- src/collision/ProxyShape.cpp | 2 +- src/collision/ProxyShape.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/collision/ProxyShape.cpp b/src/collision/ProxyShape.cpp index 299f6423..396bef0d 100644 --- a/src/collision/ProxyShape.cpp +++ b/src/collision/ProxyShape.cpp @@ -8,7 +8,7 @@ using namespace reactphysics3d; ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transform& transform, decimal mass) :mBody(body), mCollisionShape(shape), mLocalToBodyTransform(transform), mMass(mass), - mNext(NULL), mBroadPhaseID(-1), mCachedCollisionData(NULL) { + mNext(NULL), mBroadPhaseID(-1), mCachedCollisionData(NULL), mUserData(NULL) { } diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 3d989140..e4646692 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -44,6 +44,9 @@ class ProxyShape { /// Cached collision data void* mCachedCollisionData; + /// Pointer to user data + void* mUserData; + // -------------------- Methods -------------------- // /// Private copy-constructor @@ -81,6 +84,12 @@ class ProxyShape { /// Return the mass of the collision shape decimal getMass() const; + /// Return a pointer to the user data attached to this body + void* getUserData() const; + + /// Attach user data to this body + void setUserData(void* userData); + /// Return the local to parent body transform const Transform& getLocalToBodyTransform() const; @@ -121,6 +130,16 @@ inline decimal ProxyShape::getMass() const { return mMass; } +// Return a pointer to the user data attached to this body +inline void* ProxyShape::getUserData() const { + return mUserData; +} + +// Attach user data to this body +inline void ProxyShape::setUserData(void* userData) { + mUserData = userData; +} + // Return the local to parent body transform inline const Transform& ProxyShape::getLocalToBodyTransform() const { return mLocalToBodyTransform;