From 65f53a491f9a95d4e6cb7fe69648a6a759550a5c Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 14 Jul 2016 16:39:29 +0200 Subject: [PATCH] Make MouseJoint:getBodies() return only one body (fixes #1179) Override Joint's Body getters in MouseJoint, to make the second (user-supplied) body the first body returned, and return nil for the second (internal) body --- changes.txt | 1 + src/modules/physics/box2d/Joint.h | 4 ++-- src/modules/physics/box2d/MouseJoint.cpp | 10 ++++++++++ src/modules/physics/box2d/MouseJoint.h | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/changes.txt b/changes.txt index 9f7684f8d..4f248a132 100644 --- a/changes.txt +++ b/changes.txt @@ -21,6 +21,7 @@ Released: N/A * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES. * Fixed text coloring breaking because of an empty string. * Fixed large burst of particles when dramatically increasing the emission rate of a ParticleSystem. + * Fixed MouseJoint:getBodies unconditionally erroring. * Improved performance of Channel methods by roughly 2x in many cases. diff --git a/src/modules/physics/box2d/Joint.h b/src/modules/physics/box2d/Joint.h index dd6be8e1c..258234985 100644 --- a/src/modules/physics/box2d/Joint.h +++ b/src/modules/physics/box2d/Joint.h @@ -84,8 +84,8 @@ public: **/ Type getType() const; - Body *getBodyA() const; - Body *getBodyB() const; + virtual Body *getBodyA() const; + virtual Body *getBodyB() const; /** * Gets the anchor positions of the Joint in world diff --git a/src/modules/physics/box2d/MouseJoint.cpp b/src/modules/physics/box2d/MouseJoint.cpp index b037a9c79..08e41d35e 100644 --- a/src/modules/physics/box2d/MouseJoint.cpp +++ b/src/modules/physics/box2d/MouseJoint.cpp @@ -91,6 +91,16 @@ float MouseJoint::getDampingRatio() const return joint->GetDampingRatio(); } +Body *MouseJoint::getBodyA() const +{ + return Joint::getBodyB(); +} + +Body *MouseJoint::getBodyB() const +{ + return nullptr; +} + } // box2d } // physics } // love diff --git a/src/modules/physics/box2d/MouseJoint.h b/src/modules/physics/box2d/MouseJoint.h index 803bf4b94..bf365e8d2 100644 --- a/src/modules/physics/box2d/MouseJoint.h +++ b/src/modules/physics/box2d/MouseJoint.h @@ -95,6 +95,9 @@ public: **/ float getDampingRatio() const; + virtual Body *getBodyA() const; + virtual Body *getBodyB() const; + private: // The Box2D MouseJoint object. b2MouseJoint *joint;