Browse Source

Add more Constraint2D. [ci skip]

aster2013 11 years ago
parent
commit
d96310f82e

+ 7 - 1
Source/Engine/LuaScript/pkgs/Urho2DLuaAPI.pkg

@@ -6,15 +6,21 @@ $pfile "Urho2D/Animation2D.pkg"
 $pfile "Urho2D/AnimatedSprite2D.pkg"
 $pfile "Urho2D/AnimatedSprite2D.pkg"
 $pfile "Urho2D/ParticleModel2D.pkg"
 $pfile "Urho2D/ParticleModel2D.pkg"
 $pfile "Urho2D/ParticleEmitter2D.pkg"
 $pfile "Urho2D/ParticleEmitter2D.pkg"
+
 $pfile "Urho2D/RigidBody2D.pkg"
 $pfile "Urho2D/RigidBody2D.pkg"
 $pfile "Urho2D/PhysicsWorld2D.pkg"
 $pfile "Urho2D/PhysicsWorld2D.pkg"
+
 $pfile "Urho2D/CollisionShape2D.pkg"
 $pfile "Urho2D/CollisionShape2D.pkg"
 $pfile "Urho2D/CollisionBox2D.pkg"
 $pfile "Urho2D/CollisionBox2D.pkg"
-$pfile "Urho2D/CollisionCircle2D.pkg"
 $pfile "Urho2D/CollisionChain2D.pkg"
 $pfile "Urho2D/CollisionChain2D.pkg"
+$pfile "Urho2D/CollisionCircle2D.pkg"
 $pfile "Urho2D/CollisionEdge2D.pkg"
 $pfile "Urho2D/CollisionEdge2D.pkg"
 $pfile "Urho2D/CollisionPolygon2D.pkg"
 $pfile "Urho2D/CollisionPolygon2D.pkg"
+
 $pfile "Urho2D/Constraint2D.pkg"
 $pfile "Urho2D/Constraint2D.pkg"
+$pfile "Urho2D/ConstraintDistance2D.pkg"
+$pfile "Urho2D/ConstraintFriction2D.pkg"
+$pfile "Urho2D/ConstraintPulley2D.pkg"
 $pfile "Urho2D/ConstraintRevolute2D.pkg"
 $pfile "Urho2D/ConstraintRevolute2D.pkg"
 $pfile "Urho2D/ConstraintRope2D.pkg"
 $pfile "Urho2D/ConstraintRope2D.pkg"
 
 

+ 48 - 0
Source/Engine/Script/Urho2DAPI.cpp

@@ -31,6 +31,9 @@
 #include "CollisionPolygon2D.h"
 #include "CollisionPolygon2D.h"
 #include "CollisionShape2D.h"
 #include "CollisionShape2D.h"
 #include "Constraint2D.h"
 #include "Constraint2D.h"
+#include "ConstraintDistance2D.h"
+#include "ConstraintFriction2D.h"
+#include "ConstraintPulley2D.h"
 #include "ConstraintRevolute2D.h"
 #include "ConstraintRevolute2D.h"
 #include "ConstraintRope2D.h"
 #include "ConstraintRope2D.h"
 #include "Drawable2D.h"
 #include "Drawable2D.h"
@@ -415,6 +418,46 @@ static void RegisterConstraint2D(asIScriptEngine* engine)
     RegisterConstraint2D<Constraint2D>(engine, "Constraint2D");
     RegisterConstraint2D<Constraint2D>(engine, "Constraint2D");
 }
 }
 
 
+static void RegisterConstraintDistance2D(asIScriptEngine* engine)
+{
+    RegisterConstraint2D<ConstraintDistance2D>(engine, "ConstraintDistance2D");
+    engine->RegisterObjectMethod("ConstraintDistance2D", "void set_ownerBodyAnchor(const Vector2&)", asMETHOD(ConstraintDistance2D, SetOwnerBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "const Vector2& get_ownerBodyAnchor() const", asMETHOD(ConstraintDistance2D, GetOwnerBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "void set_otherBodyAnchor(const Vector2&)", asMETHOD(ConstraintDistance2D, SetOtherBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "const Vector2& get_otherBodyAnchor() const", asMETHOD(ConstraintDistance2D, GetOtherBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "void set_frequencyHz(float)", asMETHOD(ConstraintDistance2D, SetFrequencyHz), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "float get_frequencyHz() const", asMETHOD(ConstraintDistance2D, GetFrequencyHz), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "void set_dampingRatio(float)", asMETHOD(ConstraintDistance2D, SetDampingRatio), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintDistance2D", "float get_dampingRatio() const", asMETHOD(ConstraintDistance2D, GetDampingRatio), asCALL_THISCALL);
+}
+
+static void RegisterConstraintFriction2D(asIScriptEngine* engine)
+{
+    RegisterConstraint2D<ConstraintFriction2D>(engine, "ConstraintFriction2D");
+    engine->RegisterObjectMethod("ConstraintFriction2D", "void set_anchorPoint(const Vector2&)", asMETHOD(ConstraintFriction2D, SetAnchorPoint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintFriction2D", "const Vector2& get_anchorPoint() const", asMETHOD(ConstraintFriction2D, GetAnchorPoint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintFriction2D", "void set_maxForce(float)", asMETHOD(ConstraintFriction2D, SetMaxForce), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintFriction2D", "float get_maxForce() const", asMETHOD(ConstraintFriction2D, GetMaxForce), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintFriction2D", "void set_maxTorque(float)", asMETHOD(ConstraintFriction2D, SetMaxTorque), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintFriction2D", "float get_maxTorque() const", asMETHOD(ConstraintFriction2D, GetMaxTorque), asCALL_THISCALL);
+}
+
+static void RegisterConstraintPulley2D(asIScriptEngine* engine)
+{
+    RegisterConstraint2D<ConstraintPulley2D>(engine, "ConstraintPulley2D");
+    engine->RegisterObjectMethod("ConstraintPulley2D", "void set_ownerBodyGroundAnchor(const Vector2&)", asMETHOD(ConstraintPulley2D, SetOwnerBodyGroundAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "const Vector2& get_ownerBodyGroundAnchor() const", asMETHOD(ConstraintPulley2D, GetOwnerBodyGroundAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "void set_otherBodyGroundAnchor(const Vector2&)", asMETHOD(ConstraintPulley2D, SetOtherBodyGroundAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "const Vector2& get_otherBodyGroundAnchor() const", asMETHOD(ConstraintPulley2D, GetOtherBodyGroundAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "void set_ownerBodyAnchor(const Vector2&)", asMETHOD(ConstraintPulley2D, SetOwnerBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "const Vector2& get_ownerBodyAnchor() const", asMETHOD(ConstraintPulley2D, GetOwnerBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "void set_otherBodyAnchor(const Vector2&)", asMETHOD(ConstraintPulley2D, SetOtherBodyAnchor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "const Vector2& get_otherBodyAnchor() const", asMETHOD(ConstraintPulley2D, GetOtherBodyAnchor), asCALL_THISCALL);
+
+    engine->RegisterObjectMethod("ConstraintPulley2D", "void set_ratio(float)", asMETHOD(ConstraintPulley2D, SetRatio), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ConstraintPulley2D", "float get_ratio() const", asMETHOD(ConstraintPulley2D, GetRatio), asCALL_THISCALL);
+}
+
 static void RegisterConstraintRevolute2D(asIScriptEngine* engine)
 static void RegisterConstraintRevolute2D(asIScriptEngine* engine)
 {
 {
     RegisterConstraint2D<ConstraintRevolute2D>(engine, "ConstraintRevolute2D");
     RegisterConstraint2D<ConstraintRevolute2D>(engine, "ConstraintRevolute2D");
@@ -458,13 +501,18 @@ void RegisterUrho2DAPI(asIScriptEngine* engine)
 
 
     RegisterRigidBody2D(engine);
     RegisterRigidBody2D(engine);
     RegisterPhysicsWorld2D(engine);
     RegisterPhysicsWorld2D(engine);
+
     RegisterCollisionShape2D(engine);
     RegisterCollisionShape2D(engine);
     RegisterCollisionBox2D(engine);
     RegisterCollisionBox2D(engine);
     RegisterCollisionCircle2D(engine);
     RegisterCollisionCircle2D(engine);
     RegisterCollisionChain2D(engine);
     RegisterCollisionChain2D(engine);
     RegisterCollisionEdge2D(engine);
     RegisterCollisionEdge2D(engine);
     RegisterCollisionPolygon2D(engine);
     RegisterCollisionPolygon2D(engine);
+    
     RegisterConstraint2D(engine);
     RegisterConstraint2D(engine);
+    RegisterConstraintDistance2D(engine);
+    RegisterConstraintFriction2D(engine);
+    RegisterConstraintPulley2D(engine);
     RegisterConstraintRevolute2D(engine);
     RegisterConstraintRevolute2D(engine);
     RegisterConstraintRope2D(engine);
     RegisterConstraintRope2D(engine);
 }
 }

+ 123 - 0
Source/Engine/Urho2D/ConstraintDistance2D.cpp

@@ -0,0 +1,123 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "Precompiled.h"
+#include "ConstraintDistance2D.h"
+#include "Context.h"
+#include "PhysicsUtils2D.h"
+#include "RigidBody2D.h"
+
+#include "DebugNew.h"
+
+namespace Urho3D
+{
+
+extern const char* URHO2D_CATEGORY;
+
+ConstraintDistance2D::ConstraintDistance2D(Context* context) : 
+    Constraint2D(context),
+    ownerBodyAnchor_(Vector2::ZERO),
+    otherBodyAnchor_(Vector2::ZERO),
+    frequencyHz_(0.0f),
+    dampingRatio_(0.0f)
+{
+
+}
+
+ConstraintDistance2D::~ConstraintDistance2D()
+{
+}
+
+void ConstraintDistance2D::RegisterObject(Context* context)
+{
+    context->RegisterFactory<ConstraintDistance2D>(URHO2D_CATEGORY);
+    
+    REF_ACCESSOR_ATTRIBUTE(ConstraintDistance2D, VAR_VECTOR2, "Owner Body Anchor", GetOwnerBodyAnchor, SetOwnerBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(ConstraintDistance2D, VAR_VECTOR2, "Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE(ConstraintDistance2D, VAR_FLOAT, "Frequency Hz", GetFrequencyHz, SetFrequencyHz, float, 0.0f, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE(ConstraintDistance2D, VAR_FLOAT, "Damping Ratio", GetDampingRatio, SetDampingRatio, float, 0.0f, AM_DEFAULT);
+    COPY_BASE_ATTRIBUTES(ConstraintDistance2D, Constraint2D);
+}
+
+void ConstraintDistance2D::SetOwnerBodyAnchor(const Vector2& anchor)
+{
+    if (anchor == ownerBodyAnchor_)
+        return;
+
+    ownerBodyAnchor_ = anchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintDistance2D::SetOtherBodyAnchor(const Vector2& anchor)
+{
+    if (anchor == otherBodyAnchor_)
+        return;
+
+    otherBodyAnchor_ = anchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintDistance2D::SetFrequencyHz(float frequencyHz)
+{
+    if (frequencyHz == frequencyHz_)
+        return;
+
+    frequencyHz_ = frequencyHz;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintDistance2D::SetDampingRatio(float dampingRatio)
+{
+    if (dampingRatio == dampingRatio_)
+        return;
+
+    dampingRatio_ = dampingRatio;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+b2JointDef* ConstraintDistance2D::CreateJointDef()
+{
+    if (!ownerBody_ || !otherBody_)
+        return 0;
+
+    b2Body* bodyA = ownerBody_->GetBody();
+    b2Body* bodyB = otherBody_->GetBody();
+    if (!bodyA || !bodyB)
+        return 0;
+
+    b2DistanceJointDef* jointDef = new b2DistanceJointDef;
+    jointDef->Initialize(bodyA, bodyB, ToB2Vec2(ownerBodyAnchor_), ToB2Vec2(otherBodyAnchor_));
+    jointDef->frequencyHz = frequencyHz_;
+    jointDef->dampingRatio = dampingRatio_;
+
+    return jointDef;
+}
+
+}

+ 75 - 0
Source/Engine/Urho2D/ConstraintDistance2D.h

@@ -0,0 +1,75 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "Constraint2D.h"
+
+namespace Urho3D
+{
+
+/// 2D distance constraint component.
+class URHO3D_API ConstraintDistance2D : public Constraint2D
+{
+    OBJECT(ConstraintDistance2D);
+
+public:
+    /// Construct.
+    ConstraintDistance2D(Context* scontext);
+    /// Destruct.
+    virtual ~ConstraintDistance2D();
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+
+    /// Set owner body anchor point.
+    void SetOwnerBodyAnchor(const Vector2& anchor);
+    /// Set other body anchor point.
+    void SetOtherBodyAnchor(const Vector2& anchor);
+    /// Set frequency Hz.
+    void SetFrequencyHz(float frequencyHz);
+    /// Set damping ratio.
+    void SetDampingRatio(float dampingRatio);
+
+    /// Return owner body anchor point.
+    const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
+    /// Return other body anchor point.
+    const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
+    /// Return frequency Hz.
+    float GetFrequencyHz() const { return frequencyHz_; }
+    /// Return damping ratio.
+    float GetDampingRatio() const { return dampingRatio_; }
+
+private:
+    /// Create Joint def.
+    virtual b2JointDef* CreateJointDef();
+
+    /// Owner body anchor.
+    Vector2 ownerBodyAnchor_;
+    /// Other body anchor.
+    Vector2 otherBodyAnchor_;
+    /// Frequency Hz.
+    float frequencyHz_;
+    /// Damping ratio.
+    float dampingRatio_;
+};
+
+}

+ 111 - 0
Source/Engine/Urho2D/ConstraintFriction2D.cpp

@@ -0,0 +1,111 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "Precompiled.h"
+#include "ConstraintFriction2D.h"
+#include "Context.h"
+#include "PhysicsUtils2D.h"
+#include "RigidBody2D.h"
+
+#include "DebugNew.h"
+
+namespace Urho3D
+{
+
+extern const char* URHO2D_CATEGORY;
+
+ConstraintFriction2D::ConstraintFriction2D(Context* context) : 
+    Constraint2D(context),
+    anchorPoint_(Vector2::ZERO),
+    maxForce_(0.0f),
+    maxTorque_(0.0f)
+{
+
+}
+
+ConstraintFriction2D::~ConstraintFriction2D()
+{
+}
+
+void ConstraintFriction2D::RegisterObject(Context* context)
+{
+    context->RegisterFactory<ConstraintFriction2D>(URHO2D_CATEGORY);
+    
+    REF_ACCESSOR_ATTRIBUTE(ConstraintFriction2D, VAR_VECTOR2, "Anchor Point", GetAnchorPoint, SetAnchorPoint, Vector2, Vector2::ZERO, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE(ConstraintFriction2D, VAR_FLOAT, "Max Force", GetMaxForce, SetMaxForce, float, 0.0f, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE(ConstraintFriction2D, VAR_FLOAT, "Max Torque", GetMaxTorque, SetMaxTorque, float, 0.0f, AM_DEFAULT);
+    COPY_BASE_ATTRIBUTES(ConstraintFriction2D, Constraint2D);
+}
+
+void ConstraintFriction2D::SetAnchorPoint(const Vector2& anchorPoint)
+{
+    if (anchorPoint == anchorPoint_)
+        return;
+
+    anchorPoint_ = anchorPoint;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintFriction2D::SetMaxForce(float maxForce)
+{
+    if (maxForce == maxForce_)
+        return;
+
+    maxForce_ = maxForce;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+
+void ConstraintFriction2D::SetMaxTorque(float maxTorque)
+{
+    if (maxTorque == maxTorque_)
+        return;
+
+    maxTorque_ = maxTorque;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+b2JointDef* ConstraintFriction2D::CreateJointDef()
+{
+    if (!ownerBody_ || !otherBody_)
+        return 0;
+
+    b2Body* bodyA = ownerBody_->GetBody();
+    b2Body* bodyB = otherBody_->GetBody();
+    if (!bodyA || !bodyB)
+        return 0;
+
+    b2FrictionJointDef* jointDef = new b2FrictionJointDef;
+    jointDef->Initialize(bodyA, bodyB, ToB2Vec2(anchorPoint_));
+    jointDef->maxForce = maxForce_;
+    jointDef->maxTorque = maxTorque_;
+
+    return jointDef;
+}
+
+}

+ 69 - 0
Source/Engine/Urho2D/ConstraintFriction2D.h

@@ -0,0 +1,69 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "Constraint2D.h"
+
+namespace Urho3D
+{
+
+/// 2D friction constraint component.
+class URHO3D_API ConstraintFriction2D : public Constraint2D
+{
+    OBJECT(ConstraintFriction2D);
+
+public:
+    /// Construct.
+    ConstraintFriction2D(Context* scontext);
+    /// Destruct.
+    virtual ~ConstraintFriction2D();
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+
+    /// Set anchor point.
+    void SetAnchorPoint(const Vector2& anchor);
+    /// Set max force.
+    void SetMaxForce(float maxForce);
+    /// Set max torque.
+    void SetMaxTorque(float maxTorque);
+
+    /// Return anchor point.
+    const Vector2& GetAnchorPoint() const { return anchorPoint_; }
+    /// Set max force.
+    float GetMaxForce() const { return maxForce_; }
+    /// Set max torque.
+    float GetMaxTorque() const { return maxTorque_; }
+
+private:
+    /// Create Joint def.
+    virtual b2JointDef* CreateJointDef();
+
+    /// Anchor point.
+    Vector2 anchorPoint_;
+    /// Max force.
+    float maxForce_;
+    /// Max torque.
+    float maxTorque_;
+};
+
+}

+ 134 - 0
Source/Engine/Urho2D/ConstraintPulley2D.cpp

@@ -0,0 +1,134 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "Precompiled.h"
+#include "ConstraintPulley2D.h"
+#include "Context.h"
+#include "PhysicsUtils2D.h"
+#include "RigidBody2D.h"
+
+#include "DebugNew.h"
+
+namespace Urho3D
+{
+
+extern const char* URHO2D_CATEGORY;
+
+ConstraintPulley2D::ConstraintPulley2D(Context* context) : 
+    Constraint2D(context),
+    ownerBodyGroundAnchor_(-1.0f, 1.0f),
+    otherBodyGroundAnchor_(1.0f, 1.0f),
+    ownerBodyAnchor_(-1.0f, 0.0f),
+    otherBodyAnchor_(1.0f, 0.0f),
+    ratio_(1.0f)
+{
+
+}
+
+ConstraintPulley2D::~ConstraintPulley2D()
+{
+}
+
+void ConstraintPulley2D::RegisterObject(Context* context)
+{
+    context->RegisterFactory<ConstraintPulley2D>(URHO2D_CATEGORY);
+    
+    REF_ACCESSOR_ATTRIBUTE(ConstraintPulley2D, VAR_VECTOR2, "Owner Body Ground Anchor", GetOwnerBodyGroundAnchor, SetOwnerBodyGroundAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(ConstraintPulley2D, VAR_VECTOR2, "Other Body Ground Anchor", GetOtherBodyGroundAnchor, SetOtherBodyGroundAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(ConstraintPulley2D, VAR_VECTOR2, "Owner Body Anchor", GetOwnerBodyAnchor, SetOwnerBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(ConstraintPulley2D, VAR_VECTOR2, "Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);    
+    ACCESSOR_ATTRIBUTE(ConstraintPulley2D, VAR_FLOAT, "Ratio", GetRatio, SetRatio, float, 0.0f, AM_DEFAULT);
+    COPY_BASE_ATTRIBUTES(ConstraintPulley2D, Constraint2D);
+}
+
+void ConstraintPulley2D::SetOwnerBodyGroundAnchor(const Vector2& groundAnchor)
+{
+    if (groundAnchor == ownerBodyGroundAnchor_)
+        return;
+
+    ownerBodyGroundAnchor_ = groundAnchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintPulley2D::SetOtherBodyGroundAnchor(const Vector2& groundAnchor)
+{
+    if (groundAnchor == otherBodyGroundAnchor_)
+        return;
+
+    otherBodyGroundAnchor_ = groundAnchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintPulley2D::SetOwnerBodyAnchor(const Vector2& anchor)
+{
+    if (anchor == ownerBodyAnchor_)
+        return;
+
+    ownerBodyAnchor_ = anchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintPulley2D::SetOtherBodyAnchor(const Vector2& anchor)
+{
+    if (anchor == otherBodyAnchor_)
+        return;
+
+    otherBodyAnchor_ = anchor;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+void ConstraintPulley2D::SetRatio(float ratio)
+{
+    if (ratio == ratio)
+        return;
+
+    ratio_ = ratio;
+
+    RecreateJoint();
+    MarkNetworkUpdate();
+}
+
+b2JointDef* ConstraintPulley2D::CreateJointDef()
+{
+    if (!ownerBody_ || !otherBody_)
+        return 0;
+
+    b2Body* bodyA = ownerBody_->GetBody();
+    b2Body* bodyB = otherBody_->GetBody();
+    if (!bodyA || !bodyB)
+        return 0;
+
+    b2PulleyJointDef* jointDef = new b2PulleyJointDef;
+    jointDef->Initialize(bodyA, bodyB, ToB2Vec2(ownerBodyGroundAnchor_), ToB2Vec2(otherBodyGroundAnchor_), ToB2Vec2(ownerBodyAnchor_), ToB2Vec2(otherBodyAnchor_), ratio_);
+
+    return jointDef;
+}
+
+}

+ 82 - 0
Source/Engine/Urho2D/ConstraintPulley2D.h

@@ -0,0 +1,82 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "Constraint2D.h"
+
+namespace Urho3D
+{
+
+/// 2D pulley constraint component.
+class URHO3D_API ConstraintPulley2D : public Constraint2D
+{
+    OBJECT(ConstraintPulley2D);
+
+public:
+    /// Construct.
+    ConstraintPulley2D(Context* scontext);
+    /// Destruct.
+    virtual ~ConstraintPulley2D();
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+
+    /// Set other body ground anchor point.
+    void SetOwnerBodyGroundAnchor(const Vector2& groundAnchor);
+    /// Set other body ground anchor point.
+    void SetOtherBodyGroundAnchor(const Vector2& groundAnchor);
+    /// Set owner body anchor point.
+    void SetOwnerBodyAnchor(const Vector2& anchor);
+    /// Set other body anchor point.
+    void SetOtherBodyAnchor(const Vector2& anchor);
+    /// Set ratio.
+    void SetRatio(float ratio);
+
+    /// Return owner body ground anchor point.
+    const Vector2& GetOwnerBodyGroundAnchor() const { return ownerBodyGroundAnchor_; }
+    /// return other body ground anchor point.
+    const Vector2& GetOtherBodyGroundAnchor() const { return otherBodyGroundAnchor_; }
+    /// Return owner body anchor point.
+    const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
+    /// Return other body anchor point.
+    const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
+    /// Return ratio.
+    float GetRatio() const { return ratio_; }
+
+
+private:
+    /// Create Joint def.
+    virtual b2JointDef* CreateJointDef();
+
+    /// Owner body ground anchor.
+    Vector2 ownerBodyGroundAnchor_;
+    /// Other body ground anchor.
+    Vector2 otherBodyGroundAnchor_;
+    /// Owner body anchor.
+    Vector2 ownerBodyAnchor_;
+    /// Other body anchor.
+    Vector2 otherBodyAnchor_;
+    /// Ratio.
+    float ratio_;
+};
+
+}

+ 9 - 2
Source/Engine/Urho2D/Urho2D.cpp

@@ -1,4 +1,4 @@
-//
+
 // Copyright (c) 2008-2014 the Urho3D project.
 // Copyright (c) 2008-2014 the Urho3D project.
 //
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -30,6 +30,9 @@
 #include "CollisionPolygon2D.h"
 #include "CollisionPolygon2D.h"
 #include "CollisionShape2D.h"
 #include "CollisionShape2D.h"
 #include "Constraint2D.h"
 #include "Constraint2D.h"
+#include "ConstraintDistance2D.h"
+#include "ConstraintFriction2D.h"
+#include "ConstraintPulley2D.h"
 #include "ConstraintRevolute2D.h"
 #include "ConstraintRevolute2D.h"
 #include "ConstraintRope2D.h"
 #include "ConstraintRope2D.h"
 #include "Context.h"
 #include "Context.h"
@@ -63,16 +66,20 @@ void RegisterUrho2DLibrary(Context* context)
 
 
     PhysicsWorld2D::RegisterObject(context);
     PhysicsWorld2D::RegisterObject(context);
     RigidBody2D::RegisterObject(context);
     RigidBody2D::RegisterObject(context);
+    
     CollisionShape2D::RegisterObject(context);
     CollisionShape2D::RegisterObject(context);
     CollisionBox2D::RegisterObject(context);
     CollisionBox2D::RegisterObject(context);
     CollisionChain2D::RegisterObject(context);
     CollisionChain2D::RegisterObject(context);
     CollisionCircle2D::RegisterObject(context);
     CollisionCircle2D::RegisterObject(context);
     CollisionEdge2D::RegisterObject(context);
     CollisionEdge2D::RegisterObject(context);
     CollisionPolygon2D::RegisterObject(context);
     CollisionPolygon2D::RegisterObject(context);
+
     Constraint2D::RegisterObject(context);
     Constraint2D::RegisterObject(context);
+    ConstraintDistance2D::RegisterObject(context);
+    ConstraintFriction2D::RegisterObject(context);
+    ConstraintPulley2D::RegisterObject(context);
     ConstraintRevolute2D::RegisterObject(context);
     ConstraintRevolute2D::RegisterObject(context);
     ConstraintRope2D::RegisterObject(context);
     ConstraintRope2D::RegisterObject(context);
-
 }
 }
 
 
 }
 }