Browse Source

Fix bug in ConstrainMouse2D.

aster 11 years ago
parent
commit
19b008d44b

+ 14 - 3
Source/Engine/Urho2D/ConstraintMouse2D.cpp

@@ -58,6 +58,14 @@ void ConstraintMouse2D::SetTarget(const Vector2& target)
         return;
         return;
 
 
     target_ = target;
     target_ = target;
+    if (joint_)
+    {
+        b2MouseJoint* mouseJoint = (b2MouseJoint*)joint_;
+        mouseJoint->SetTarget(ToB2Vec2(target_));
+
+        MarkNetworkUpdate();
+        return;
+    }
 
 
     RecreateJoint();
     RecreateJoint();
     MarkNetworkUpdate();
     MarkNetworkUpdate();
@@ -101,12 +109,15 @@ b2JointDef* ConstraintMouse2D::GetJointDef()
     if (!ownerBody_ || !otherBody_)
     if (!ownerBody_ || !otherBody_)
         return 0;
         return 0;
 
 
-    b2Body* bodyA = ownerBody_->GetBody();
-    b2Body* bodyB = otherBody_->GetBody();
+    b2Body* bodyA = otherBody_->GetBody();
+    b2Body* bodyB = ownerBody_->GetBody();
     if (!bodyA || !bodyB)
     if (!bodyA || !bodyB)
         return 0;
         return 0;
 
 
-    InitializeJointDef(&jointDef_);
+    jointDef_.bodyA = bodyA;
+    jointDef_.bodyB = bodyB;
+    jointDef_.collideConnected = collideConnected_;
+
     jointDef_.target = ToB2Vec2(target_);
     jointDef_.target = ToB2Vec2(target_);
 
 
     return &jointDef_;
     return &jointDef_;

+ 1 - 1
Source/Engine/Urho2D/ConstraintMouse2D.h

@@ -40,7 +40,7 @@ public:
     /// Register object factory.
     /// Register object factory.
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
-    /// Set target
+    /// Set target.
     void SetTarget(const Vector2& target);
     void SetTarget(const Vector2& target);
     /// Set max force.
     /// Set max force.
     void SetMaxForce(float maxForce);
     void SetMaxForce(float maxForce);