SDK/Lua: Bind Matrix4
This commit is contained in:
parent
baf4cb0e16
commit
6885e99ee7
|
|
@ -143,6 +143,86 @@ namespace Nz
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param address Resulting IP address
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_String:
|
||||
address->BuildFromAddress(instance.CheckString(index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
*address = *static_cast<IpAddress*>(instance.CheckUserdata(index, "IpAddress"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4d* mat, TypeTag<Matrix4d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
{
|
||||
double values[16];
|
||||
for (std::size_t i = 0; i < 16; ++i)
|
||||
{
|
||||
instance.PushInteger(i + 1);
|
||||
instance.GetTable();
|
||||
|
||||
values[i] = instance.CheckNumber(-1);
|
||||
instance.Pop();
|
||||
}
|
||||
|
||||
mat->Set(values);
|
||||
return 1;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "Matrix4"))
|
||||
mat->Set(*static_cast<Matrix4d*>(instance.ToUserdata(index)));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4f* mat, TypeTag<Matrix4f>)
|
||||
{
|
||||
Matrix4d matDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &matDouble, TypeTag<Matrix4d>());
|
||||
|
||||
mat->Set(matDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
|
|
@ -165,6 +245,53 @@ namespace Nz
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
quat->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
|
||||
else
|
||||
quat->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
|
||||
{
|
||||
Quaterniond quatDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
|
||||
|
||||
quat->Set(quatDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
|
|
@ -222,76 +349,6 @@ namespace Nz
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
quat->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
|
||||
else
|
||||
quat->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param quat Resulting quaternion
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
|
||||
{
|
||||
Quaterniond quatDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
|
||||
|
||||
quat->Set(quatDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param index Index type
|
||||
* \param address Resulting IP address
|
||||
*/
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_String:
|
||||
address->BuildFromAddress(instance.CheckString(index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
*address = *static_cast<IpAddress*>(instance.CheckUserdata(index, "IpAddress"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Queries arguments for Lua
|
||||
* \return 1 in case of success
|
||||
|
|
@ -473,6 +530,7 @@ namespace Nz
|
|||
*renderable = *static_cast<InstancedRenderableRef*>(instance.CheckUserdata(index, "InstancedRenderable"));
|
||||
else
|
||||
*renderable = *static_cast<InstancedRenderableRef*>(instance.CheckUserdata(index, "Model"));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -619,6 +677,48 @@ namespace Nz
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param val Resulting IP address
|
||||
*/
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag<IpAddress>)
|
||||
{
|
||||
instance.PushInstance<IpAddress>("IpAddress", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param val Resulting rectangle
|
||||
*/
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4d&& val, TypeTag<Matrix4d>)
|
||||
{
|
||||
instance.PushInstance<Matrix4d>("Matrix4", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param val Resulting rectangle
|
||||
*/
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4f&& val, TypeTag<Matrix4f>)
|
||||
{
|
||||
instance.PushInstance<Matrix4d>("Matrix4", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
|
|
@ -647,20 +747,6 @@ namespace Nz
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
*
|
||||
* \param instance Lua instance to interact with
|
||||
* \param val Resulting IP address
|
||||
*/
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag<IpAddress>)
|
||||
{
|
||||
instance.PushInstance<IpAddress>("IpAddress", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replies by value for Lua
|
||||
* \return 1 in case of success
|
||||
|
|
@ -669,7 +755,7 @@ namespace Nz
|
|||
* \param val Resulting rectangle
|
||||
*/
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectf>)
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectd>)
|
||||
{
|
||||
instance.PushInstance<Rectd>("Rect", val);
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace Ndk
|
|||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||
Nz::LuaClass<Nz::Matrix4d> matrix4dClass;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||
Nz::LuaClass<Nz::Rectd> rectClass;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Ndk
|
|||
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
matrix4dClass("Matrix4"),
|
||||
quaternionClass("Quaternion"),
|
||||
rectClass("Rect"),
|
||||
vector2dClass("Vector2"),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue