aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene/igeneric.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-04-10 19:55:02 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-04-10 19:55:02 -0400
commitbced528a07a2ff1591455e4c4228ec18f8e0532d (patch)
tree7686a11b6276f56eabde0bffb8716a7b1df72e29 /src/client/lua_api/scene/igeneric.cpp
parentd2b36e6c65ec8126c0ebc96adb7e011e78a5eacc (diff)
downloadbrokengine-bced528a07a2ff1591455e4c4228ec18f8e0532d.tar.gz
brokengine-bced528a07a2ff1591455e4c4228ec18f8e0532d.tar.bz2
brokengine-bced528a07a2ff1591455e4c4228ec18f8e0532d.zip
Added getpos and setpos functions for scene nodes
Diffstat (limited to 'src/client/lua_api/scene/igeneric.cpp')
-rw-r--r--src/client/lua_api/scene/igeneric.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
new file mode 100644
index 0000000..51aaf66
--- /dev/null
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -0,0 +1,70 @@
+/*This file defines some things that all igui stuff can do*/
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "igeneric.hpp"
+#include "../gameparts.hpp"
+
+using namespace irr;
+using namespace core;
+using namespace scene;
+
+static LISceneNode* toiscenenode(lua_State* L, int index){
+ LISceneNode* ret = (LISceneNode*)lua_touserdata(L,index);
+ if(ret == NULL)
+ luaL_typerror(L,index,"LISceneNode");
+ return ret;
+}
+
+int iscenegetpos(lua_State* L){
+ ISceneNode* i = toiscenenode(L,1)->n;
+ vector3df pos = i->getAbsolutePosition();
+
+ lua_createtable(L,3,0);
+
+ lua_pushnumber(L,1);
+ lua_pushnumber(L,pos.X);
+ lua_settable(L,-3);
+
+ lua_pushnumber(L,2);
+ lua_pushnumber(L,pos.Y);
+ lua_settable(L,-3);
+
+ lua_pushnumber(L,3);
+ lua_pushnumber(L,pos.Z);
+ lua_settable(L,-3);
+
+ return 1;
+}
+int iscenesetpos(lua_State* L){
+
+ ISceneNode* i = toiscenenode(L,1)->n;
+
+ lua_pushnumber(L,1);
+ lua_gettable(L,-2);
+ f32 x = (f32)lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushnumber(L,2);
+ lua_gettable(L,-2);
+ f32 y = (f32)lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushnumber(L,3);
+ lua_gettable(L,-2);
+ f32 z = (f32)lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ printf("Trying to set pos of %p to %f %f %f",i,x,y,z);
+
+ i->setPosition(vector3df(x,y,z));
+ i->updateAbsolutePosition();
+ vector3df pos = i->getAbsolutePosition();
+ printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
+
+
+ return 0;
+}