Răsfoiți Sursa

Add Lua and AngelScript binding.

aster2013 11 ani în urmă
părinte
comite
90f87a2a2c

+ 1 - 1
Source/Engine/LuaScript/CMakeLists.txt

@@ -63,7 +63,7 @@ install (FILES ${H_FILES} DESTINATION ${DEST_INCLUDE_DIR})
 set (LIBS ../../ThirdParty/Lua${JIT}/src)
 set (LIBS ../../ThirdParty/Lua${JIT}/src)
 set (LINK_LIBS_ONLY toluapp)
 set (LINK_LIBS_ONLY toluapp)
 set (INCLUDE_DIRS_ONLY . .. ../Audio ../Container ../Core ../Engine ../Graphics ../Input ../IO ../Math ../Navigation ../Network ../Physics ../Resource ../Scene ../UI  ../Urho2D
 set (INCLUDE_DIRS_ONLY . .. ../Audio ../Container ../Core ../Engine ../Graphics ../Input ../IO ../Math ../Navigation ../Network ../Physics ../Resource ../Scene ../UI  ../Urho2D
-    ../../ThirdParty/Bullet/src ../../ThirdParty/kNet/include ../../ThirdParty/SDL/include ../../ThirdParty/toluapp/include ${CMAKE_BINARY_DIR}/Engine)
+    ../../ThirdParty/Box2D ../../ThirdParty/Bullet/src ../../ThirdParty/kNet/include ../../ThirdParty/SDL/include ../../ThirdParty/toluapp/include ${CMAKE_BINARY_DIR}/Engine)
 
 
 # Setup target
 # Setup target
 setup_library ()
 setup_library ()

+ 30 - 1
Source/Engine/LuaScript/ToluaUtils.cpp

@@ -169,7 +169,7 @@ template<> void* ToluaToPODVector<unsigned>(lua_State* L, int narg, void* def)
     if (!lua_istable(L, narg))
     if (!lua_istable(L, narg))
         return 0;
         return 0;
 
 
-    static Vector<unsigned> result;
+    static PODVector<unsigned> result;
     result.Clear();
     result.Clear();
 
 
     int length = lua_objlen(L, narg);
     int length = lua_objlen(L, narg);
@@ -193,6 +193,35 @@ template<> void* ToluaToPODVector<unsigned>(lua_State* L, int narg, void* def)
     return &result;
     return &result;
 }
 }
 
 
+template<> void* ToluaToPODVector<Vector2>(lua_State* L, int narg, void* def)
+{
+    if (!lua_istable(L, narg))
+        return 0;
+
+    static PODVector<Vector2> result;
+    result.Clear();
+
+    int length = lua_objlen(L, narg);
+    for (int i = 1; i <= length; ++i)
+    {
+        lua_pushinteger(L, i);
+        lua_gettable(L, narg);
+
+        if (!lua_isnumber(L, -1))
+        {
+            lua_pop(L, 1);
+            return 0;
+        }
+
+        Vector2* value = (Vector2*)tolua_touserdata(L, -1, 0);
+        result.Push(*value);
+
+        lua_pop(L, 1);
+    }
+
+    return &result;
+}
+
 template<> int ToluaPushPODVector<int>(lua_State* L, void* data, const char*)
 template<> int ToluaPushPODVector<int>(lua_State* L, void* data, const char*)
 {
 {
     const PODVector<int>& vector = *((const PODVector<int>*)data);
     const PODVector<int>& vector = *((const PODVector<int>*)data);

+ 2 - 0
Source/Engine/LuaScript/ToluaUtils.h

@@ -101,6 +101,8 @@ template<> int ToluaIsPODVector<unsigned>(lua_State* L, int lo, const char* type
 template<typename T> void* ToluaToPODVector(lua_State* L, int narg, void* def);
 template<typename T> void* ToluaToPODVector(lua_State* L, int narg, void* def);
 /// Convert PODVector<unsigned>.
 /// Convert PODVector<unsigned>.
 template<> void* ToluaToPODVector<unsigned>(lua_State* L, int narg, void* def);
 template<> void* ToluaToPODVector<unsigned>(lua_State* L, int narg, void* def);
+/// Convert PODVector<Vector2>.
+template<> void* ToluaToPODVector<Vector2>(lua_State* L, int narg, void* def);
 
 
 /// Push PODVector<T> to Lua as a table.
 /// Push PODVector<T> to Lua as a table.
 template<typename T> int ToluaPushPODVector(lua_State* L, void* data, const char* type);
 template<typename T> int ToluaPushPODVector(lua_State* L, void* data, const char* type);

+ 41 - 0
Source/Engine/LuaScript/pkgs/Urho2D/CollisionShape2D.pkg

@@ -0,0 +1,41 @@
+$#include "CollisionShape2D.h"
+
+class CollisionShape2D : Component
+{
+    void SetSensor(bool sensor);
+    void SetCategoryBits(unsigned short categoryBits);
+    void SetMaskBits(unsigned short maskBits);
+    void SetGroupIndex(short groupIndex);
+    void SetDensity(float density);
+    void SetFriction(float friction);
+    void SetRestitution(float restitution);
+
+    void SetCircle(float radius, const Vector2& center = Vector2::ZERO);
+    void SetBox(const Vector2& halfSize, const Vector2& center = Vector2::ZERO);
+    void SetBox(float halfWidth, float halfHeight, const Vector2& center = Vector2::ZERO);
+    void SetChain(const PODVector<Vector2>& vertices);
+    void SetPolygon(const PODVector<Vector2>& vertices);
+    void SetEdge(const Vector2& vertex1, const Vector2& vertex2);
+
+    bool IsSensor() const;
+    unsigned short GetCategoryBits() const;
+    unsigned short GetMaskBits() const;
+    short GetGroupIndex() const;
+    float GetDensity() const;
+    float GetFriction() const;
+    float GetRestitution() const;
+    float GetMass() const;
+    float GetInertia() const;
+    Vector2 GetMassCenter() const;
+
+    tolua_property__is_set bool sensor;
+    tolua_property__get_set unsigned short categoryBits;
+    tolua_property__get_set unsigned short maskBits;
+    tolua_property__get_set short groupIndex;
+    tolua_property__get_set float density;
+    tolua_property__get_set float friction;
+    tolua_property__get_set float restitution;
+    tolua_readonly tolua_property__get_set float mass;
+    tolua_readonly tolua_property__get_set float inertia;
+    tolua_readonly tolua_property__get_set Vector2 massCenter;
+};

+ 48 - 0
Source/Engine/LuaScript/pkgs/Urho2D/PhysicsWorld2D.pkg

@@ -0,0 +1,48 @@
+$#include "PhysicsWorld2D.h"
+
+class PhysicsWorld2D : public Component
+{
+    void SetDrawShape(bool drawShape);
+    void SetDrawJoint(bool drawJoint);
+    void SetDrawAabb(bool drawAabb);
+    void SetDrawPair(bool drawPair);
+    void SetDrawCenterOfMass(bool drawCenterOfMass);
+    void SetAllowSleeping(bool enable);
+    void SetWarmStarting(bool enable);
+    void SetContinuousPhysics(bool enable);
+    void SetSubStepping(bool enable);
+    void SetGravity(const Vector2& gravity);
+    void SetAutoClearForces(bool enable);
+    void SetVelocityIterations(unsigned velocityIterations);
+    void SetPositionIterations(unsigned positionIterations);
+
+    void DrawDebugGeometry();
+
+    bool GetDrawShape() const;
+    bool GetDrawJoint() const;
+    bool GetDrawAabb() const;
+    bool GetDrawPair() const;
+    bool GetDrawCenterOfMass() const;
+    bool GetAllowSleeping() const;
+    bool GetWarmStarting() const;
+    bool GetContinuousPhysics() const;
+    bool GetSubStepping() const;
+    bool GetAutoClearForces() const;
+    const Vector2& GetGravity() const;
+    unsigned GetVelocityIterations() const;
+    unsigned GetPositionIterations() const;
+
+    tolua_property__get_set bool drawShape;
+    tolua_property__get_set bool drawJoint;
+    tolua_property__get_set bool drawAabb;
+    tolua_property__get_set bool drawPair;
+    tolua_property__get_set bool drawCenterOfMass;
+    tolua_property__get_set bool allowSleeping;
+    tolua_property__get_set bool warmStarting;
+    tolua_property__get_set bool continuousPhysics;
+    tolua_property__get_set bool subStepping;
+    tolua_property__get_set bool autoClearForces;
+    tolua_property__get_set Vector2& gravity;
+    tolua_property__get_set unsigned velocityIterations;
+    tolua_property__get_set unsigned positionIterations;
+};

+ 59 - 0
Source/Engine/LuaScript/pkgs/Urho2D/RigidBody2D.pkg

@@ -0,0 +1,59 @@
+$#include "RigidBody2D.h"
+
+enum BodyType2D
+{
+    BT_STATIC = b2_staticBody,
+    BT_DYNAMIC = b2_dynamicBody,
+    BT_KINEMATIC = b2_kinematicBody,
+};
+
+class RigidBody2D : Component
+{
+    void SetBodyType(BodyType2D bodyType);
+    void SetMass(float mass);
+    void SetInertia(float inertia);
+    void SetMassCenter(const Vector2& center);
+    void SetUseFixtureMass(bool useFixtureMass);
+    void SetLinearDamping(float linearDamping);
+    void SetAngularDamping(float angularDamping);
+    void SetAllowSleep(bool allowSleep);
+    void SetFixedRotation(bool fixedRotation);
+    void SetBullet(bool bullet);
+    void SetGravityScale(float gravityScale);
+    void SetAwake(bool awake);
+    void SetLinearVelocity(const Vector2& linearVelocity);
+    void SetAngularVelocity(float angularVelocity);
+    void ApplyForce(const Vector2& force, const Vector2& point,  bool wake);
+    void ApplyForceToCenter(const Vector2& force, bool wake);
+    void ApplyTorque(float torque, bool wake);
+    void ApplyLinearImpulse(const Vector2& impulse, const Vector2& point, bool wake);
+    void ApplyAngularImpulse(float impulse, bool wake);
+
+    BodyType2D GetBodyType() const;
+    float GetMass() const;
+    float GetInertia() const;
+    Vector2 GetMassCenter() const;
+    bool GetUseFixtureMass() const;
+    float GetLinearDamping() const;
+    float GetAngularDamping() const;
+    bool IsAllowSleep() const;
+    bool IsFixedRotation() const;
+    bool IsBullet() const;
+    float GetGravityScale() const;
+    bool IsAwake() const;
+    Vector2 GetLinearVelocity() const;
+
+    tolua_property__get_set BodyType2D bodyType;
+    tolua_property__get_set float mass;
+    tolua_property__get_set float inertia;
+    tolua_property__get_set Vector2 massCenter;
+    tolua_property__get_set bool useFixtureMass;
+    tolua_property__get_set float linearDamping;
+    tolua_property__get_set float angularDamping;
+    tolua_property__is_set bool allowSleep;
+    tolua_property__is_set bool fixedRotation;
+    tolua_property__is_set bool bullet;
+    tolua_property__get_set float gravityScale;
+    tolua_property__is_set bool awake;
+    tolua_property__get_set Vector2 linearVelocity;
+};

+ 4 - 0
Source/Engine/LuaScript/pkgs/Urho2DLuaAPI.pkg

@@ -7,5 +7,9 @@ $pfile "Urho2D/AnimatedSprite2D.pkg"
 $pfile "Urho2D/ParticleModel2D.pkg"
 $pfile "Urho2D/ParticleModel2D.pkg"
 $pfile "Urho2D/ParticleEmitter2D.pkg"
 $pfile "Urho2D/ParticleEmitter2D.pkg"
 
 
+$pfile "Urho2D/PhysicsWorld2D.pkg"
+$pfile "Urho2D/RigidBody2D.pkg"
+$pfile "Urho2D/CollisionShape2D.pkg"
+
 $using namespace Urho3D;
 $using namespace Urho3D;
 $#pragma warning(disable:4800)
 $#pragma warning(disable:4800)

+ 118 - 12
Source/Engine/Script/Urho2DAPI.cpp

@@ -24,9 +24,12 @@
 #include "AnimatedSprite2D.h"
 #include "AnimatedSprite2D.h"
 #include "Animation2D.h"
 #include "Animation2D.h"
 #include "APITemplates.h"
 #include "APITemplates.h"
+#include "CollisionShape2D.h"
 #include "Drawable2D.h"
 #include "Drawable2D.h"
 #include "ParticleEmitter2D.h"
 #include "ParticleEmitter2D.h"
 #include "ParticleModel2D.h"
 #include "ParticleModel2D.h"
+#include "PhysicsWorld2D.h"
+#include "RigidBody2D.h"
 #include "Sprite2D.h"
 #include "Sprite2D.h"
 #include "SpriteSheet2D.h"
 #include "SpriteSheet2D.h"
 #include "StaticSprite2D.h"
 #include "StaticSprite2D.h"
@@ -41,11 +44,11 @@ namespace Urho3D
 static void RegisterSprite2D(asIScriptEngine* engine)
 static void RegisterSprite2D(asIScriptEngine* engine)
 {
 {
     RegisterResource<Sprite2D>(engine, "Sprite2D");
     RegisterResource<Sprite2D>(engine, "Sprite2D");
-    engine->RegisterObjectMethod("Sprite2D", "void set_texture(Texture2D@+)", asMETHODPR(Sprite2D, SetTexture, (Texture2D*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Sprite2D", "void set_texture(Texture2D@+)", asMETHOD(Sprite2D, SetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "Texture2D@+ get_texture() const", asMETHOD(Sprite2D, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "Texture2D@+ get_texture() const", asMETHOD(Sprite2D, GetTexture), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Sprite2D", "void set_rectangle(const IntRect&in)", asMETHODPR(Sprite2D, SetRectangle, (const IntRect&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Sprite2D", "void set_rectangle(const IntRect&in)", asMETHOD(Sprite2D, SetRectangle), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "const IntRect& get_rectangle() const", asMETHOD(Sprite2D, GetRectangle), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "const IntRect& get_rectangle() const", asMETHOD(Sprite2D, GetRectangle), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Sprite2D", "void set_hotSpot(const Vector2&in)", asMETHODPR(Sprite2D, SetHotSpot, (const Vector2&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Sprite2D", "void set_hotSpot(const Vector2&in)", asMETHOD(Sprite2D, SetHotSpot), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "const Vector2& get_hotSpot() const", asMETHOD(Sprite2D, GetHotSpot), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sprite2D", "const Vector2& get_hotSpot() const", asMETHOD(Sprite2D, GetHotSpot), asCALL_THISCALL);
 }
 }
 
 
@@ -53,9 +56,9 @@ static void RegisterSpriteSheet2D(asIScriptEngine* engine)
 {
 {
     RegisterResource<SpriteSheet2D>(engine, "SpriteSheet2D");
     RegisterResource<SpriteSheet2D>(engine, "SpriteSheet2D");
     engine->RegisterObjectMethod("SpriteSheet2D", "Texture2D@+ get_texture() const", asMETHOD(SpriteSheet2D, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("SpriteSheet2D", "Texture2D@+ get_texture() const", asMETHOD(SpriteSheet2D, GetTexture), asCALL_THISCALL);
-    engine->RegisterObjectMethod("SpriteSheet2D", "Sprite2D@+ GetSprite(const String&)", asMETHODPR(SpriteSheet2D, GetSprite, (const String&) const, Sprite2D*), asCALL_THISCALL);
-    engine->RegisterObjectMethod("SpriteSheet2D", "void DefineSprite(const String&, const IntRect&, const Vector2&)", asMETHODPR(SpriteSheet2D, DefineSprite, (const String&, const IntRect&, const Vector2&), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod("SpriteSheet2D", "void UpdateSprite(const String&, const IntRect&, const Vector2&)", asMETHODPR(SpriteSheet2D, UpdateSprite, (const String&, const IntRect&, const Vector2&), void), asCALL_THISCALL);    
+    engine->RegisterObjectMethod("SpriteSheet2D", "Sprite2D@+ GetSprite(const String&)", asMETHOD(SpriteSheet2D, GetSprite), asCALL_THISCALL);
+    engine->RegisterObjectMethod("SpriteSheet2D", "void DefineSprite(const String&, const IntRect&, const Vector2&)", asMETHOD(SpriteSheet2D, DefineSprite), asCALL_THISCALL);
+    engine->RegisterObjectMethod("SpriteSheet2D", "void UpdateSprite(const String&, const IntRect&, const Vector2&)", asMETHOD(SpriteSheet2D, UpdateSprite), asCALL_THISCALL);
 }
 }
 
 
 /// Template function for registering a class derived from Drawable2D.
 /// Template function for registering a class derived from Drawable2D.
@@ -63,9 +66,9 @@ template <class T> void RegisterDrawable2D(asIScriptEngine* engine, const char*
 {
 {
     RegisterDrawable<T>(engine, className);
     RegisterDrawable<T>(engine, className);
     RegisterSubclass<Drawable2D, T>(engine, "Drawable2D", className);
     RegisterSubclass<Drawable2D, T>(engine, "Drawable2D", className);
-    engine->RegisterObjectMethod(className, "void set_sprite(Sprite2D@+)", asMETHODPR(T, SetSprite, (Sprite2D*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_sprite(Sprite2D@+)", asMETHOD(T, SetSprite), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Sprite2D@+ get_sprite() const", asMETHOD(T, GetSprite), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Sprite2D@+ get_sprite() const", asMETHOD(T, GetSprite), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_material(Material@+)", asMETHODPR(T, SetMaterial, (Material*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_material(Material@+)", asMETHOD(T, SetMaterial), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Material@+ get_material() const", asMETHOD(T, GetMaterial), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Material@+ get_material() const", asMETHOD(T, GetMaterial), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_blendMode(BlendMode)", asMETHOD(T, SetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_blendMode(BlendMode)", asMETHOD(T, SetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "BlendMode get_blendMode() const", asMETHOD(T, GetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "BlendMode get_blendMode() const", asMETHOD(T, GetBlendMode), asCALL_THISCALL);
@@ -76,7 +79,7 @@ template <class T> void RegisterDrawable2D(asIScriptEngine* engine, const char*
 static void RegisterDrawable2D(asIScriptEngine* engine)
 static void RegisterDrawable2D(asIScriptEngine* engine)
 {
 {
     engine->RegisterGlobalProperty("const float PIXEL_SIZE", (void*)&PIXEL_SIZE);
     engine->RegisterGlobalProperty("const float PIXEL_SIZE", (void*)&PIXEL_SIZE);
-    
+
     RegisterDrawable2D<Drawable2D>(engine, "Drawable2D");
     RegisterDrawable2D<Drawable2D>(engine, "Drawable2D");
 }
 }
 
 
@@ -85,10 +88,10 @@ template <class T> void RegisterStaticSprite2D(asIScriptEngine* engine, const ch
 {
 {
     RegisterDrawable2D<T>(engine, className);
     RegisterDrawable2D<T>(engine, className);
     RegisterSubclass<StaticSprite2D, T>(engine, "StaticSprite2D", className);
     RegisterSubclass<StaticSprite2D, T>(engine, "StaticSprite2D", className);
-    engine->RegisterObjectMethod(className, "void SetFlip(bool, bool)", asMETHODPR(T, SetFlip, (bool, bool), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void SetFlip(bool, bool)", asMETHOD(T, SetFlip), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_flipX(bool)", asMETHOD(T, SetFlipX), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_flipX(bool)", asMETHOD(T, SetFlipX), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_flipX() const", asMETHOD(T, GetFlipX), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_flipX() const", asMETHOD(T, GetFlipX), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_flipY(bool)", asMETHOD(T, SetFlipY), asCALL_THISCALL);    
+    engine->RegisterObjectMethod(className, "void set_flipY(bool)", asMETHOD(T, SetFlipY), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_flipY() const", asMETHOD(T, GetFlipY), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_flipY() const", asMETHOD(T, GetFlipY), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_color(const Color&in)", asMETHOD(T, SetColor), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_color(const Color&in)", asMETHOD(T, SetColor), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "const Color& get_color() const", asMETHOD(T, GetColor), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "const Color& get_color() const", asMETHOD(T, GetColor), asCALL_THISCALL);
@@ -136,10 +139,110 @@ static void RegisterParticleModel2D(asIScriptEngine* engine)
 static void RegisterParticleEmitter2D(asIScriptEngine* engine)
 static void RegisterParticleEmitter2D(asIScriptEngine* engine)
 {
 {
     RegisterDrawable2D<ParticleEmitter2D>(engine, "ParticleEmitter2D");
     RegisterDrawable2D<ParticleEmitter2D>(engine, "ParticleEmitter2D");
-    engine->RegisterObjectMethod("ParticleEmitter2D", "void set_model(ParticleModel2D@+)", asMETHODPR(ParticleEmitter2D, SetModel, (ParticleModel2D*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ParticleEmitter2D", "void set_model(ParticleModel2D@+)", asMETHOD(ParticleEmitter2D, SetModel), asCALL_THISCALL);
     engine->RegisterObjectMethod("ParticleEmitter2D", "ParticleModel2D@+ get_model() const", asMETHOD(ParticleEmitter2D, GetModel), asCALL_THISCALL);
     engine->RegisterObjectMethod("ParticleEmitter2D", "ParticleModel2D@+ get_model() const", asMETHOD(ParticleEmitter2D, GetModel), asCALL_THISCALL);
 }
 }
 
 
+
+static void RegisterPhysicsWorld2D(asIScriptEngine* engine)
+{
+    RegisterComponent<PhysicsWorld2D>(engine, "PhysicsWorld2D");
+
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_drawShape(bool)", asMETHOD(PhysicsWorld2D, SetDrawShape), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_drawShape() const", asMETHOD(PhysicsWorld2D, GetDrawShape), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_drawJoint(bool)", asMETHOD(PhysicsWorld2D, SetDrawJoint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_drawJoint() const", asMETHOD(PhysicsWorld2D, GetDrawJoint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_drawAabb(bool)", asMETHOD(PhysicsWorld2D, SetDrawAabb), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_drawAabb() const", asMETHOD(PhysicsWorld2D, GetDrawAabb), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_drawPair(bool)", asMETHOD(PhysicsWorld2D, SetDrawPair), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_drawPair() const", asMETHOD(PhysicsWorld2D, GetDrawPair), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_drawCenterOfMass(bool)", asMETHOD(PhysicsWorld2D, SetDrawCenterOfMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_drawCenterOfMass() const", asMETHOD(PhysicsWorld2D, GetDrawCenterOfMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_allowSleeping(bool)", asMETHOD(PhysicsWorld2D, SetAllowSleeping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_allowSleeping() const", asMETHOD(PhysicsWorld2D, GetAllowSleeping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_warmStarting(bool)", asMETHOD(PhysicsWorld2D, SetWarmStarting), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_warmStarting() const", asMETHOD(PhysicsWorld2D, GetWarmStarting), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_continuousPhysics(bool)", asMETHOD(PhysicsWorld2D, SetContinuousPhysics), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_continuousPhysics() const", asMETHOD(PhysicsWorld2D, GetContinuousPhysics), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_subStepping(bool)", asMETHOD(PhysicsWorld2D, SetSubStepping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_subStepping() const", asMETHOD(PhysicsWorld2D, GetSubStepping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_gravity(const Vector2&in)", asMETHOD(PhysicsWorld2D, SetGravity), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "const Vector2& get_gravity() const", asMETHOD(PhysicsWorld2D, GetGravity), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_autoClearForces(bool)", asMETHOD(PhysicsWorld2D, SetAutoClearForces), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "bool get_autoClearForces() const", asMETHOD(PhysicsWorld2D, GetAutoClearForces), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_velocityIterations(uint)", asMETHOD(PhysicsWorld2D, SetVelocityIterations), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "uint get_velocityIterations() const", asMETHOD(PhysicsWorld2D, GetVelocityIterations), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "void set_positionIterations(uint)", asMETHOD(PhysicsWorld2D, SetPositionIterations), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PhysicsWorld2D", "uint get_positionIterations() const", asMETHOD(PhysicsWorld2D, GetPositionIterations), asCALL_THISCALL);
+}
+
+static void RegisterRigidBody2D(asIScriptEngine* engine)
+{
+    engine->RegisterEnum("BodyType2D");
+    engine->RegisterEnumValue("BodyType2D", "BT_STATIC", BT_STATIC);
+    engine->RegisterEnumValue("BodyType2D", "BT_DYNAMIC", BT_DYNAMIC);
+    engine->RegisterEnumValue("BodyType2D", "BT_KINEMATIC", BT_KINEMATIC);
+
+    RegisterComponent<RigidBody2D>(engine, "RigidBody2D");
+
+    engine->RegisterObjectMethod("RigidBody2D", "void set_bodyType(BodyType2D)", asMETHOD(RigidBody2D, SetBodyType), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "BodyType2D get_bodyType() const", asMETHOD(RigidBody2D, GetBodyType), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_mass(float)", asMETHOD(RigidBody2D, SetMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "float get_mass() const", asMETHOD(RigidBody2D, GetMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_inertia(float)", asMETHOD(RigidBody2D, SetInertia), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "float get_inertia() const", asMETHOD(RigidBody2D, GetInertia), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_massCenter(Vector2)", asMETHOD(RigidBody2D, SetMassCenter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "Vector2 get_massCenter() const", asMETHOD(RigidBody2D, GetMassCenter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_useFixtureMass(bool)", asMETHOD(RigidBody2D, SetUseFixtureMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "bool get_useFixtureMass() const", asMETHOD(RigidBody2D, GetUseFixtureMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_linearDamping(float)", asMETHOD(RigidBody2D, SetLinearDamping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "float get_linearDamping() const", asMETHOD(RigidBody2D, GetLinearDamping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_angularDamping(float)", asMETHOD(RigidBody2D, SetAngularDamping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "float get_angularDamping() const", asMETHOD(RigidBody2D, GetAngularDamping), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_allowSleep(bool)", asMETHOD(RigidBody2D, SetAllowSleep), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "bool get_allowSleep() const", asMETHOD(RigidBody2D, IsAllowSleep), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_fixedRotation(bool)", asMETHOD(RigidBody2D, SetFixedRotation), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "bool get_fixedRotation() const", asMETHOD(RigidBody2D, IsFixedRotation), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_bullet(bool)", asMETHOD(RigidBody2D, SetBullet), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "bool get_bullet() const", asMETHOD(RigidBody2D, IsBullet), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_gravityScale(float)", asMETHOD(RigidBody2D, SetGravityScale), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "float get_gravityScale() const", asMETHOD(RigidBody2D, GetGravityScale), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_awake(bool)", asMETHOD(RigidBody2D, SetAwake), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "bool get_awake() const", asMETHOD(RigidBody2D, IsAwake), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void set_linearVelocity(Vector2)", asMETHOD(RigidBody2D, SetLinearVelocity), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "Vector2 get_linearVelocity() const", asMETHOD(RigidBody2D, GetLinearVelocity), asCALL_THISCALL);
+
+    engine->RegisterObjectMethod("RigidBody2D", "void ApplyForce(const Vector2&in, const Vector2&in, bool)", asMETHOD(RigidBody2D, ApplyForce), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void ApplyForceToCenter(const Vector2&in, bool)", asMETHOD(RigidBody2D, ApplyForceToCenter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void ApplyTorque(float torque, bool)", asMETHOD(RigidBody2D, ApplyTorque), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void ApplyLinearImpulse(const Vector2&in, const Vector2&in, bool)", asMETHOD(RigidBody2D, ApplyLinearImpulse), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody2D", "void ApplyAngularImpulse(float, bool)", asMETHOD(RigidBody2D, ApplyAngularImpulse), asCALL_THISCALL);
+}
+
+static void RegisterCollisionShape2D(asIScriptEngine* engine)
+{
+    RegisterComponent<CollisionShape2D>(engine, "CollisionShape2D");
+
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_sensor(bool)", asMETHOD(CollisionShape2D, SetSensor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "bool get_sensor() const", asMETHOD(CollisionShape2D, IsSensor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_categoryBits(uint16)", asMETHOD(CollisionShape2D, SetCategoryBits), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "uint16 get_categoryBits() const", asMETHOD(CollisionShape2D, GetCategoryBits), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_maskBits(uint16)", asMETHOD(CollisionShape2D, SetMaskBits), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "uint16 get_maskBits() const", asMETHOD(CollisionShape2D, GetMaskBits), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_groupIndex(int16)", asMETHOD(CollisionShape2D, SetGroupIndex), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "int16 get_groupIndex() const", asMETHOD(CollisionShape2D, GetGroupIndex), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_density(float)", asMETHOD(CollisionShape2D, SetDensity), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "float get_density() const", asMETHOD(CollisionShape2D, GetDensity), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_friction(float)", asMETHOD(CollisionShape2D, SetFriction), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "float get_friction() const", asMETHOD(CollisionShape2D, GetFriction), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "void set_restitution(float)", asMETHOD(CollisionShape2D, SetRestitution), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "float get_restitution() const", asMETHOD(CollisionShape2D, GetRestitution), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "float get_mass() const", asMETHOD(CollisionShape2D, GetMass), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "float get_inertia() const", asMETHOD(CollisionShape2D, GetInertia), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CollisionShape2D", "Vector2 get_massCenter() const", asMETHOD(CollisionShape2D, GetMassCenter), asCALL_THISCALL);
+
+}
+
 void RegisterUrho2DAPI(asIScriptEngine* engine)
 void RegisterUrho2DAPI(asIScriptEngine* engine)
 {
 {
     RegisterSprite2D(engine);
     RegisterSprite2D(engine);
@@ -150,6 +253,9 @@ void RegisterUrho2DAPI(asIScriptEngine* engine)
     RegisterAnimatedSprite2D(engine);
     RegisterAnimatedSprite2D(engine);
     RegisterParticleModel2D(engine);
     RegisterParticleModel2D(engine);
     RegisterParticleEmitter2D(engine);
     RegisterParticleEmitter2D(engine);
+    RegisterPhysicsWorld2D(engine);
+    RegisterRigidBody2D(engine);
+    RegisterCollisionShape2D(engine);
 }
 }
 
 
 }
 }