SDK/Lua: Bind Matrix4

This commit is contained in:
Lynix
2016-10-20 17:24:22 +02:00
parent baf4cb0e16
commit 6885e99ee7
5 changed files with 290 additions and 85 deletions

View File

@@ -23,6 +23,7 @@ namespace Ndk
// Math
eulerAnglesClass("EulerAngles"),
matrix4dClass("Matrix4"),
quaternionClass("Quaternion"),
rectClass("Rect"),
vector2dClass("Vector2"),

View File

@@ -154,6 +154,64 @@ namespace Ndk
return false;
});
/*********************************** Nz::Matrix4 **********************************/
matrix4dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
switch (argCount)
{
case 0:
Nz::PlacementNew(matrix, Nz::Matrix4d::Zero());
return true;
case 1:
if (lua.IsOfType(1, "Matrix4"))
Nz::PlacementNew(matrix, *static_cast<Nz::Matrix4d*>(lua.ToUserdata(1)));
break;
case 16:
{
double values[16];
for (std::size_t i = 0; i < 16; ++i)
values[i] = lua.CheckNumber(i);
Nz::PlacementNew(matrix, values);
return true;
}
}
lua.Error("No matching overload for constructor");
return false;
});
matrix4dClass.BindMethod("__tostring", &Nz::Matrix4d::ToString);
matrix4dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
{
int argIndex = 1;
std::size_t index = lua.Check<std::size_t>(&argIndex);
if (index < 1 || index > 16)
return false;
lua.Push(instance[index - 1]);
return true;
});
matrix4dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
{
int argIndex = 1;
std::size_t index = lua.Check<std::size_t>(&argIndex);
if (index < 1 || index > 16)
return false;
instance[index - 1] = lua.CheckNumber(argIndex);
return true;
});
/*********************************** Nz::Rect **********************************/
rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount)
{
@@ -694,6 +752,7 @@ namespace Ndk
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
{
eulerAnglesClass.Register(instance);
matrix4dClass.Register(instance);
quaternionClass.Register(instance);
rectClass.Register(instance);
vector2dClass.Register(instance);

View File

@@ -139,6 +139,64 @@ namespace Ndk
#ifndef NDK_SERVER
/*********************************** Ndk::GraphicsComponent **********************************/
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent) -> int
{
/*
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
*/
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
switch (argCount)
{
case 1:
{
int argIndex = 1;
gfxComponent->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
return 0;
}
case 2:
{
int index = 1;
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&index);
if (lua.IsOfType(index, Nz::LuaType_Number))
{
int renderOrder = lua.Check<int>(&index);
gfxComponent->Attach(renderable, renderOrder);
}
else if (lua.IsOfType(index, "Matrix4"))
{
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&index);
int renderOrder = lua.Check<int>(&index);
gfxComponent->Attach(renderable, localMatrix, renderOrder);
}
else
break;
return 0;
}
case 3:
{
int index = 1;
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&index);
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&index);
int renderOrder = lua.Check<int>(&index);
gfxComponent->Attach(renderable, localMatrix, renderOrder);
return 0;
}
}
lua.Error("No matching overload for method GetMemoryUsage");
return 0;
});
graphicsComponent.BindMethod("Attach", (void(Ndk::GraphicsComponent::*)(Nz::InstancedRenderableRef, int)) &GraphicsComponent::Attach, 0);
#endif