diff options
Diffstat (limited to 'src/client/lua_api/scene/icamera.cpp')
| -rw-r--r-- | src/client/lua_api/scene/icamera.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp index 2dd5a67..ce54ef2 100644 --- a/src/client/lua_api/scene/icamera.cpp +++ b/src/client/lua_api/scene/icamera.cpp @@ -13,11 +13,13 @@ extern "C" { #include <irrlicht.h> #include "../gameparts.hpp" #include "icamera.hpp" +#include "igeneric.hpp" using namespace irr; using namespace scene; +using namespace core; -//IrrlichtDevice* guidevice; +extern IrrlichtDevice* device; static LISceneNode* checkiscenecamera(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"scene.icamera"); @@ -36,8 +38,10 @@ static int newiscenecamera(lua_State* L){ //The position of the camera int startx = luaL_optint(L,1,0); int starty = luaL_optint(L,2,0); - int endx = luaL_optint(L,3,startx+100); - int endy = luaL_optint(L,4,starty+100); + int startz = luaL_optint(L,3,0); + int endx = luaL_optint(L,4,startx+100); + int endy = luaL_optint(L,5,starty+100); + int endz = luaL_optint(L,6,startz+100); //Label and tooltip wchar_t* label; @@ -48,65 +52,73 @@ static int newiscenecamera(lua_State* L){ printf("Got the string option\n"); //If the element has a parrent - int parent = 0; + int parent = -1; if(nargs >= 6){ - parent = luaL_optint(L,6,0); + parent = luaL_optint(L,7,0); printf("got the parrent\n"); } - //Create the button - IGUIEnvironment* env = guidevice->getGUIEnvironment(); + //Create the camera + ISceneManager* smgr = device->getSceneManager(); + //IGUIEnvironment* env = device->getGUIEnvironment(); //printf("Createing button with data %d %d %d %d, %p, %d, %s, %s\n", startx,starty,endx,endy,guielements[parent],gui_elenum,button_label,button_tooltip); //Create the label - IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false); - printf("Created the button\n"); + //IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false); + ICameraSceneNode* cam = smgr->addCameraSceneNode(0, vector3df(startx,starty,startz), vector3df(endx,endy,endz)); + printf("Registered the camera!\n"); //Register it's callback - registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); + //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); //Create it's lua representation - LIGUIElement* ltext = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement)); + LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode)); int tref = luaL_ref(L,LUA_REGISTRYINDEX); - iguielements[llabel] = tref; - lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. + //iguielements[lcam] = tref; + //lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. //Set it's metatable - luaL_getmetatable(L, "gui.iguilabel"); + luaL_getmetatable(L, "scene.iscenecamera"); lua_setmetatable(L, -2); //Create the struct - ltext->e = llabel; - ltext->funcmap = hashmap_new(); - ltext->type = "iguilabel"; + lcam->n = cam; + lcam->funcmap = hashmap_new(); + lcam->type = "iscenecamera"; //Free up anything made in this function - free(label); + //free(label); //Put it on top and return it lua_rawgeti(L,LUA_REGISTRYINDEX,tref); return 1; } -static const luaL_reg iguilabel_f[] = { - {"new", newiguilabel}, - {"gethandeler", guigethandeler}, - {"sethandeler", guisethandeler}, +static const luaL_reg icamera_f[] = { + {"new", newiscenecamera}, +// {"gethandeler", guigethandeler}, +// {"sethandeler", guisethandeler}, {0,0}, }; -static const luaL_reg iguilabel_m[] = { - {"move", moveiguielement}, - {"settext", setiguitext}, - {"remove", removeiguielement}, +static const luaL_reg icamera_m[] = { + {"getpos", iscenegetpos}, + {"setpos", iscenesetpos}, +// {"move", moveiguielement}, +// {"settext", setiguitext}, +// {"remove", removeiguielement}, {0, 0}, }; -int iguilabel_register(lua_State* L, IrrlichtDevice* d){ +int icamera_register(lua_State* L, IrrlichtDevice* d){ - luaL_newmetatable(L, "gui.iguilabel"); + device = d; - luaL_register(L,"iguilabel",iguilabel_f); + printf("icamera registered\n"); + + luaL_newmetatable(L, "scene.icamera"); + + luaL_register(L,"icamera",icamera_f); lua_pushstring(L,"__index"); lua_pushstring(L,"gethandeler"); @@ -118,7 +130,7 @@ int iguilabel_register(lua_State* L, IrrlichtDevice* d){ lua_gettable(L,-3); lua_settable(L,-4); - luaL_register(L, NULL, iguilabel_m); + luaL_register(L, NULL, icamera_m); return 1; } |
