ag::loadModel and ag::loadStaticModel accepting a second optional parameter to specify the scale of the model to load
git-svn-id: svn://anubis/anaglym/trunk@73 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
968a35bc36
commit
6864704d37
22
ag.cc
22
ag.cc
@ -122,11 +122,16 @@ namespace ag
|
||||
|
||||
static int loadModelSpecify(lua_State * L, bool static_data)
|
||||
{
|
||||
float scale = 1.0f;
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
if (argc == 1 && lua_type(L, -1) == LUA_TSTRING)
|
||||
if (argc >= 2 && lua_isnumber(L, 2))
|
||||
{
|
||||
string modelname = lua_tostring(L, -1);
|
||||
scale = lua_tonumber(L, 2);
|
||||
}
|
||||
if (argc >= 1 && lua_isstring(L, 1))
|
||||
{
|
||||
string modelname = lua_tostring(L, 1);
|
||||
size_t pos = modelname.find_first_not_of(FILENAME_SAFE_CHARS);
|
||||
if (pos == string::npos)
|
||||
{
|
||||
@ -138,7 +143,7 @@ namespace ag
|
||||
|
||||
if (obj->load(path))
|
||||
{
|
||||
int id = g_engine->addObject(obj, static_data);
|
||||
int id = g_engine->addObject(obj, static_data, scale);
|
||||
createLuaObject(L, id);
|
||||
if (physpath != "")
|
||||
{
|
||||
@ -179,7 +184,7 @@ namespace ag
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
double seconds = lua_tonumber(L, -1);
|
||||
#ifdef _WIN32
|
||||
@ -248,7 +253,7 @@ namespace ag
|
||||
Engine::Object * ret = NULL;
|
||||
|
||||
lua_getfield(L, index, "id");
|
||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
int id = lua_tointeger(L, -1);
|
||||
ret = g_engine->getObject(id);
|
||||
@ -261,7 +266,7 @@ namespace ag
|
||||
int draw(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_type(L, -1) == LUA_TTABLE)
|
||||
if (argc == 1 && lua_istable(L, -1))
|
||||
{
|
||||
Engine::Object * obj = getObject(L, -1);
|
||||
if (obj != NULL)
|
||||
@ -282,8 +287,7 @@ namespace ag
|
||||
double position[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int type = lua_type(L, i + 2);
|
||||
if (type == LUA_TNUMBER || type == LUA_TSTRING)
|
||||
if (lua_isnumber(L, i + 2))
|
||||
{
|
||||
position[i] = lua_tonumber(L, i + 2);
|
||||
}
|
||||
@ -355,7 +359,7 @@ namespace ag
|
||||
if (argc == 1)
|
||||
{
|
||||
lua_getfield(L, 1, "id");
|
||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
int id = lua_tointeger(L, -1);
|
||||
g_engine->removeObject(id);
|
||||
|
@ -204,10 +204,10 @@ bool Engine::fileExists(const string & path)
|
||||
return false;
|
||||
}
|
||||
|
||||
int Engine::addObject(WFObj * obj, bool is_static)
|
||||
int Engine::addObject(WFObj * obj, bool is_static, float scale)
|
||||
{
|
||||
int id = m_next_object_index++;
|
||||
Object * o = createObject(is_static, obj->render());
|
||||
Object * o = createObject(is_static, obj->render(), scale);
|
||||
m_objects[id] = o;
|
||||
return id;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class Engine
|
||||
void run();
|
||||
void reportErrors(int status);
|
||||
OdeWorld & getWorld() { return m_world; }
|
||||
int addObject(WFObj * obj, bool is_static);
|
||||
int addObject(WFObj * obj, bool is_static, float scale = 1.0f);
|
||||
void removeObject(int id);
|
||||
int cloneObject(const Object * obj);
|
||||
Object * getObject(int id);
|
||||
@ -79,9 +79,10 @@ class Engine
|
||||
void registerLibraries();
|
||||
bool fileExists(const std::string & path);
|
||||
void update();
|
||||
Object * createObject(bool is_static, GLuint display_list)
|
||||
Object * createObject(bool is_static, GLuint display_list,
|
||||
float scale = 1.0f)
|
||||
{
|
||||
return new Object(is_static, m_world, display_list);
|
||||
return new Object(is_static, m_world, display_list, scale);
|
||||
}
|
||||
|
||||
lua_State * m_luaState;
|
||||
|
Loading…
x
Reference in New Issue
Block a user