diff --git a/ag.cc b/ag.cc index 5dbf72d..138c83c 100644 --- a/ag.cc +++ b/ag.cc @@ -286,6 +286,138 @@ namespace ag return g_engine->clearEventHandler(L); } + static int addManagedObject(lua_State * L, bool is_static, + OdeWorld::GeomType geom_type, refptr< vector > args) + { + int id = g_engine->addObject(is_static, geom_type, args); + createLuaObject(L, id); + } + + static int createBoxSpecify(lua_State * L, bool is_static) + { + int argc = lua_gettop(L); + if (argc == 3 && + lua_isnumber(L, 1) && + lua_isnumber(L, 2) && + lua_isnumber(L, 3)) + { + refptr< vector > args = new vector(); + args.push_back(lua_tonumber(L, 1)); + args.push_back(lua_tonumber(L, 2)); + args.push_back(lua_tonumber(L, 3)); + addManagedObject(L, is_static, OdeWorld::BOX, args); + } + else + lua_pushnil(L); + return 1; + } + + int createBox(lua_State * L) + { + return createBoxSpecify(L, false); + } + + int createStaticBox(lua_State * L) + { + return createBoxSpecify(L, true); + } + + static int createSphereSpecify(lua_State * L, bool is_static) + { + int argc = lua_gettop(L); + if (argc == 1 && lua_isnumber(L, 1)) + { + refptr< vector > args = new vector(); + args.push_back(lua_tonumber(L, 1)); + addManagedObject(L, is_static, OdeWorld::SPHERE, args); + } + else + lua_pushnil(L); + return 1; + } + + int createSphere(lua_State * L) + { + return createSphereSpecify(L, false); + } + + int createStaticSphere(lua_State * L) + { + return createSphereSpecify(L, true); + } + + static int createPlaneSpecify(lua_State * L, bool is_static) + { + int argc = lua_gettop(L); + if (argc == 3 && + lua_isnumber(L, 1) && + lua_isnumber(L, 2) && + lua_isnumber(L, 3)) + { + refptr< vector > args = new vector(); + args.push_back(lua_tonumber(L, 1)); + args.push_back(lua_tonumber(L, 2)); + args.push_back(lua_tonumber(L, 3)); + addManagedObject(L, is_static, OdeWorld::BOX, args); + } + else + lua_pushnil(L); + return 1; + } + + int createPlane(lua_State * L) + { + return createPlaneSpecify(L, false); + } + + int createStaticPlane(lua_State * L) + { + return createPlaneSpecify(L, true); + } + + static int createCylinderSpecify(lua_State * L, bool is_static) + { + int argc = lua_gettop(L); + if (argc == 3 && + lua_isnumber(L, 1) && + lua_isnumber(L, 2) && + lua_isnumber(L, 3)) + { + refptr< vector > args = new vector(); + args.push_back(lua_tonumber(L, 1)); + args.push_back(lua_tonumber(L, 2)); + args.push_back(lua_tonumber(L, 3)); + addManagedObject(L, is_static, OdeWorld::BOX, args); + } + else + lua_pushnil(L); + return 1; + } + + int createCylinder(lua_State * L) + { + return createCylinderSpecify(L, false); + } + + int createStaticCylinder(lua_State * L) + { + return createCylinderSpecify(L, true); + } + + static int createCCylinderSpecify(lua_State * L, bool is_static) + { + } + + int createCCylinder(lua_State * L) + { + return createCCylinderSpecify(L, false); + } + + int createStaticCCylinder(lua_State * L) + { + return createCCylinderSpecify(L, true); + } + namespace object { static Engine::Object * getObject(lua_State * L, int index) diff --git a/ag.h b/ag.h index a236a28..760eb33 100644 --- a/ag.h +++ b/ag.h @@ -27,6 +27,17 @@ namespace ag int registerEventHandler(lua_State * L); int clearEventHandler(lua_State * L); + int createBox(lua_State * L); + int createStaticBox(lua_State * L); + int createSphere(lua_State * L); + int createStaticSphere(lua_State * L); + int createPlane(lua_State * L); + int createStaticPlane(lua_State * L); + int createCylinder(lua_State * L); + int createStaticCylinder(lua_State * L); + int createCCylinder(lua_State * L); + int createStaticCCylinder(lua_State * L); + namespace object { int draw(lua_State * L);