From 9a4161519d2c2625231aaca568abee54c5a4456c Mon Sep 17 00:00:00 2001 From: turanszkij Date: Tue, 8 Sep 2015 23:28:19 +0200 Subject: [PATCH] updated lua bindings --- WickedEngine/Matrix_BindLua.cpp | 57 +++++++++++++++++++++++++++++++ WickedEngine/Matrix_BindLua.h | 2 ++ WickedEngine/wiLoader_BindLua.cpp | 2 ++ 3 files changed, 61 insertions(+) diff --git a/WickedEngine/Matrix_BindLua.cpp b/WickedEngine/Matrix_BindLua.cpp index c64f025987..43a4904a07 100644 --- a/WickedEngine/Matrix_BindLua.cpp +++ b/WickedEngine/Matrix_BindLua.cpp @@ -15,6 +15,9 @@ Luna::FunctionType Matrix_BindLua::methods[] = { lunamethod(Matrix_BindLua, RotationZ), lunamethod(Matrix_BindLua, RotationQuaternion), lunamethod(Matrix_BindLua, Scale), + lunamethod(Matrix_BindLua, LookTo), + lunamethod(Matrix_BindLua, LookAt), + lunamethod(Matrix_BindLua, Add), lunamethod(Matrix_BindLua, Multiply), lunamethod(Matrix_BindLua, Transpose), @@ -180,6 +183,60 @@ int Matrix_BindLua::Scale(lua_State* L) return 1; } +int Matrix_BindLua::LookTo(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* pos = Luna::lightcheck(L, 1); + Vector_BindLua* dir = Luna::lightcheck(L, 2); + if (pos != nullptr && dir != nullptr) + { + XMVECTOR Up; + if (argc > 3) + { + Vector_BindLua* up = Luna::lightcheck(L, 3); + Up = up->vector; + } + else + Up = XMVectorSet(0, 1, 0, 0); + Luna::push(L, new Matrix_BindLua(XMMatrixLookToLH(pos->vector, dir->vector, Up))); + } + else + wiLua::SError(L, "LookTo(Vector eye, Vector direction, opt Vector up) argument is not a Vector!"); + } + else + wiLua::SError(L, "LookTo(Vector eye, Vector direction, opt Vector up) not enough arguments!"); + return 1; +} + +int Matrix_BindLua::LookAt(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* pos = Luna::lightcheck(L, 1); + Vector_BindLua* dir = Luna::lightcheck(L, 2); + if (dir != nullptr) + { + XMVECTOR Up; + if (argc > 3) + { + Vector_BindLua* up = Luna::lightcheck(L, 3); + Up = up->vector; + } + else + Up = XMVectorSet(0, 1, 0, 0); + Luna::push(L, new Matrix_BindLua(XMMatrixLookAtLH(pos->vector, dir->vector, Up))); + } + else + wiLua::SError(L, "LookAt(Vector eye, Vector focusPos, opt Vector up) argument is not a Vector!"); + } + else + wiLua::SError(L, "LookAt(Vector eye, Vector focusPos, opt Vector up) not enough arguments!"); + return 1; +} + int Matrix_BindLua::Multiply(lua_State* L) { int argc = wiLua::SGetArgCount(L); diff --git a/WickedEngine/Matrix_BindLua.h b/WickedEngine/Matrix_BindLua.h index e1e119179b..807f67c431 100644 --- a/WickedEngine/Matrix_BindLua.h +++ b/WickedEngine/Matrix_BindLua.h @@ -25,6 +25,8 @@ class Matrix_BindLua int RotationZ(lua_State* L); int RotationQuaternion(lua_State* L); int Scale(lua_State* L); + int LookTo(lua_State* L); + int LookAt(lua_State* L); int Multiply(lua_State* L); int Add(lua_State* L); diff --git a/WickedEngine/wiLoader_BindLua.cpp b/WickedEngine/wiLoader_BindLua.cpp index 6a85d330b4..e24271bc47 100644 --- a/WickedEngine/wiLoader_BindLua.cpp +++ b/WickedEngine/wiLoader_BindLua.cpp @@ -789,6 +789,8 @@ void Armature_BindLua::Bind() const char Ray_BindLua::className[] = "Ray"; Luna::FunctionType Ray_BindLua::methods[] = { + lunamethod(Ray_BindLua, GetOrigin), + lunamethod(Ray_BindLua, GetDirection), { NULL, NULL } }; Luna::PropertyType Ray_BindLua::properties[] = {