Browse Source

Adding AngelScript bindings for Matrix2

TheComet 10 years ago
parent
commit
a42299202c
1 changed files with 44 additions and 0 deletions
  1. 44 0
      Source/Urho3D/AngelScript/MathAPI.cpp

+ 44 - 0
Source/Urho3D/AngelScript/MathAPI.cpp

@@ -26,6 +26,7 @@
 #include "../Math/Frustum.h"
 #include "../Math/Frustum.h"
 #include "../Math/Polyhedron.h"
 #include "../Math/Polyhedron.h"
 #include "../Math/Ray.h"
 #include "../Math/Ray.h"
+#include "../Math/Matrix2.h"
 
 
 namespace Urho3D
 namespace Urho3D
 {
 {
@@ -535,6 +536,48 @@ static void RegisterMatrix3(asIScriptEngine* engine)
     engine->RegisterObjectProperty("Matrix3", "float m22", offsetof(Matrix3, m22_));
     engine->RegisterObjectProperty("Matrix3", "float m22", offsetof(Matrix3, m22_));
 }
 }
 
 
+static void ConstructMatrix2(Matrix2* ptr)
+{
+    new(ptr) Matrix2();
+}
+
+static void ConstructMatrix2Copy(const Matrix2& mat, Matrix2* ptr)
+{
+    new(ptr) Matrix2(mat);
+}
+
+static void ConstructMatrix2Init(float v00, float v01, float v10, float v11, Matrix2* ptr)
+{
+    new(ptr) Matrix2(v00, v01, v10, v11);
+}
+
+static void RegisterMatrix2(asIScriptEngine* engine)
+{
+    engine->RegisterObjectType("Matrix2", sizeof(Matrix2), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
+    engine->RegisterObjectBehaviour("Matrix2", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructMatrix2), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("Matrix2", asBEHAVE_CONSTRUCT, "void f(const Matrix2&in)", asFUNCTION(ConstructMatrix2Copy), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("Matrix2", asBEHAVE_CONSTRUCT, "void f(float, float, float, float)", asFUNCTION(ConstructMatrix2Init), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 opMul(const Matrix2&in) const", asMETHODPR(Matrix2, operator *, (const Matrix2&) const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 opMul(float) const", asMETHODPR(Matrix2, operator *, (float) const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Vector2 opMul(const Vector2&in) const", asMETHODPR(Matrix2, operator *, (const Vector2&) const, Vector2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 opAdd(const Matrix2&in) const", asMETHODPR(Matrix2, operator +, (const Matrix2 &) const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 opSub(const Matrix2&in) const", asMETHODPR(Matrix2, operator -, (const Matrix2 &) const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2& opAssign(const Matrix2&in)", asMETHODPR(Matrix2, operator =, (const Matrix2 &), Matrix2&), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "bool opEquals(const Matrix2&in) const", asMETHOD(Matrix2, operator ==), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Vector2 Scale() const", asMETHODPR(Matrix2, Scale, () const, Vector2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 Scaled(const Vector2&in) const", asMETHODPR(Matrix2, Scaled, (const Vector2 &) const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "void SetScale(const Vector2&in)", asMETHODPR(Matrix2,SetScale, (const Vector2 &), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "void SetScale(float)", asMETHODPR(Matrix2,SetScale, (float), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 Transpose() const", asMETHODPR(Matrix2, Transpose, () const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "Matrix2 Inverse() const", asMETHODPR(Matrix2, Inverse, () const, Matrix2), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "bool Equals(const Matrix2&in) const", asMETHOD(Matrix2, Equals), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Matrix2", "String ToString() const", asMETHOD(Matrix2, ToString), asCALL_THISCALL);
+    engine->RegisterObjectProperty("Matrix2", "float m00", offsetof(Matrix2, m00_));
+    engine->RegisterObjectProperty("Matrix2", "float m01", offsetof(Matrix2, m01_));
+    engine->RegisterObjectProperty("Matrix2", "float m10", offsetof(Matrix2, m10_));
+    engine->RegisterObjectProperty("Matrix2", "float m11", offsetof(Matrix2, m11_));
+}
+
 static void ConstructMatrix4(Matrix4* ptr)
 static void ConstructMatrix4(Matrix4* ptr)
 {
 {
     new(ptr) Matrix4();
     new(ptr) Matrix4();
@@ -1207,6 +1250,7 @@ void RegisterMathAPI(asIScriptEngine* engine)
     RegisterVector3(engine);
     RegisterVector3(engine);
     RegisterVector4(engine);
     RegisterVector4(engine);
     RegisterQuaternion(engine);
     RegisterQuaternion(engine);
+    RegisterMatrix2(engine);
     RegisterMatrix3(engine);
     RegisterMatrix3(engine);
     RegisterMatrix4(engine);
     RegisterMatrix4(engine);
     RegisterMatrix3x4(engine);
     RegisterMatrix3x4(engine);