diff --git a/Engine.cc b/Engine.cc index 32609b5..29a9e2b 100644 --- a/Engine.cc +++ b/Engine.cc @@ -203,7 +203,16 @@ bool Engine::fileExists(const string & path) int Engine::addObject(WFObj * obj, bool is_static, float scale) { int id = m_next_object_index++; - Object * o = createObject(is_static, obj->render(), scale); + Object * o = new Object(is_static, m_world, obj->render(), scale); + m_objects[id] = o; + return id; +} + +int Engine::addObject(bool is_static, OdeWorld::GeomType geom_type, + refptr< vector > args) +{ + int id = m_next_object_index++; + Object * o = new Object(is_static, m_world, geom_type, args); m_objects[id] = o; return id; } diff --git a/Engine.h b/Engine.h index 0d4e2e7..d8b185a 100644 --- a/Engine.h +++ b/Engine.h @@ -58,6 +58,12 @@ class Engine { m_ode_object->setRotation(x, y, z); } + void setColor(float r, float g, float b) + { + m_color[0] = r; + m_color[1] = g; + m_color[2] = b; + } void draw(); @@ -101,6 +107,8 @@ class Engine void reportErrors(int status); OdeWorld & getWorld() { return m_world; } int addObject(WFObj * obj, bool is_static, float scale = 1.0f); + int addObject(bool is_static, OdeWorld::GeomType geom_type, + refptr< std::vector > args); void removeObject(int id); int cloneObject(const Object * obj); Object * getObject(int id); @@ -139,11 +147,6 @@ class Engine void mousebutton_down_event(int button, int x, int y); void mousebutton_up_event(int button, int x, int y); void mouse_motion_event(int x, int y, int xrel, int yrel); - Object * createObject(bool is_static, GLuint display_list, - float scale = 1.0f) - { - return new Object(is_static, m_world, display_list, scale); - } void checkForFunctionFull(const std::string & lua_fn_name, const std::string & event_name, bool & presentFlag); void doRegisterHandlerFull(int index, diff --git a/ag.cc b/ag.cc index fb1de98..5dbf72d 100644 --- a/ag.cc +++ b/ag.cc @@ -136,6 +136,8 @@ namespace ag lua_setfield(L, -2, "addTorque"); lua_pushcfunction(L, object::addRelTorque); lua_setfield(L, -2, "addRelTorque"); + lua_pushcfunction(L, object::setColor); + lua_setfield(L, -2, "setColor"); } static int loadModelSpecify(lua_State * L, bool static_data) @@ -519,5 +521,24 @@ namespace ag } return 0; } + + int setColor(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL && + lua_isnumber(L, 2) && + lua_isnumber(L, 3) && + lua_isnumber(L, 4)) + { + obj->setColor(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } } } diff --git a/ag.h b/ag.h index c4b5c85..a236a28 100644 --- a/ag.h +++ b/ag.h @@ -40,6 +40,7 @@ namespace ag int addRelForce(lua_State * L); int addTorque(lua_State * L); int addRelTorque(lua_State * L); + int setColor(lua_State * L); } }