added ag::object::setColor()

git-svn-id: svn://anubis/anaglym/trunk@130 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-27 23:59:08 +00:00
parent e5f616b841
commit 9c94186d31
4 changed files with 40 additions and 6 deletions

View File

@ -203,7 +203,16 @@ bool Engine::fileExists(const string & path)
int Engine::addObject(WFObj * obj, bool is_static, float scale) int Engine::addObject(WFObj * obj, bool is_static, float scale)
{ {
int id = m_next_object_index++; 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<float> > args)
{
int id = m_next_object_index++;
Object * o = new Object(is_static, m_world, geom_type, args);
m_objects[id] = o; m_objects[id] = o;
return id; return id;
} }

View File

@ -58,6 +58,12 @@ class Engine
{ {
m_ode_object->setRotation(x, y, z); 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(); void draw();
@ -101,6 +107,8 @@ class Engine
void reportErrors(int status); void reportErrors(int status);
OdeWorld & getWorld() { return m_world; } OdeWorld & getWorld() { return m_world; }
int addObject(WFObj * obj, bool is_static, float scale = 1.0f); int addObject(WFObj * obj, bool is_static, float scale = 1.0f);
int addObject(bool is_static, OdeWorld::GeomType geom_type,
refptr< std::vector<float> > args);
void removeObject(int id); void removeObject(int id);
int cloneObject(const Object * obj); int cloneObject(const Object * obj);
Object * getObject(int id); Object * getObject(int id);
@ -139,11 +147,6 @@ class Engine
void mousebutton_down_event(int button, int x, int y); void mousebutton_down_event(int button, int x, int y);
void mousebutton_up_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); 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, void checkForFunctionFull(const std::string & lua_fn_name,
const std::string & event_name, bool & presentFlag); const std::string & event_name, bool & presentFlag);
void doRegisterHandlerFull(int index, void doRegisterHandlerFull(int index,

21
ag.cc
View File

@ -136,6 +136,8 @@ namespace ag
lua_setfield(L, -2, "addTorque"); lua_setfield(L, -2, "addTorque");
lua_pushcfunction(L, object::addRelTorque); lua_pushcfunction(L, object::addRelTorque);
lua_setfield(L, -2, "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) static int loadModelSpecify(lua_State * L, bool static_data)
@ -519,5 +521,24 @@ namespace ag
} }
return 0; 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;
}
} }
} }

1
ag.h
View File

@ -40,6 +40,7 @@ namespace ag
int addRelForce(lua_State * L); int addRelForce(lua_State * L);
int addTorque(lua_State * L); int addTorque(lua_State * L);
int addRelTorque(lua_State * L); int addRelTorque(lua_State * L);
int setColor(lua_State * L);
} }
} }