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)
|
static int loadModelSpecify(lua_State * L, bool static_data)
|
||||||
{
|
{
|
||||||
|
float scale = 1.0f;
|
||||||
int argc = lua_gettop(L);
|
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);
|
size_t pos = modelname.find_first_not_of(FILENAME_SAFE_CHARS);
|
||||||
if (pos == string::npos)
|
if (pos == string::npos)
|
||||||
{
|
{
|
||||||
@ -138,7 +143,7 @@ namespace ag
|
|||||||
|
|
||||||
if (obj->load(path))
|
if (obj->load(path))
|
||||||
{
|
{
|
||||||
int id = g_engine->addObject(obj, static_data);
|
int id = g_engine->addObject(obj, static_data, scale);
|
||||||
createLuaObject(L, id);
|
createLuaObject(L, id);
|
||||||
if (physpath != "")
|
if (physpath != "")
|
||||||
{
|
{
|
||||||
@ -179,7 +184,7 @@ namespace ag
|
|||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
if (lua_isnumber(L, -1))
|
||||||
{
|
{
|
||||||
double seconds = lua_tonumber(L, -1);
|
double seconds = lua_tonumber(L, -1);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -248,7 +253,7 @@ namespace ag
|
|||||||
Engine::Object * ret = NULL;
|
Engine::Object * ret = NULL;
|
||||||
|
|
||||||
lua_getfield(L, index, "id");
|
lua_getfield(L, index, "id");
|
||||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
if (lua_isnumber(L, -1))
|
||||||
{
|
{
|
||||||
int id = lua_tointeger(L, -1);
|
int id = lua_tointeger(L, -1);
|
||||||
ret = g_engine->getObject(id);
|
ret = g_engine->getObject(id);
|
||||||
@ -261,7 +266,7 @@ namespace ag
|
|||||||
int draw(lua_State * L)
|
int draw(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(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);
|
Engine::Object * obj = getObject(L, -1);
|
||||||
if (obj != NULL)
|
if (obj != NULL)
|
||||||
@ -282,8 +287,7 @@ namespace ag
|
|||||||
double position[3];
|
double position[3];
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
int type = lua_type(L, i + 2);
|
if (lua_isnumber(L, i + 2))
|
||||||
if (type == LUA_TNUMBER || type == LUA_TSTRING)
|
|
||||||
{
|
{
|
||||||
position[i] = lua_tonumber(L, i + 2);
|
position[i] = lua_tonumber(L, i + 2);
|
||||||
}
|
}
|
||||||
@ -355,7 +359,7 @@ namespace ag
|
|||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
lua_getfield(L, 1, "id");
|
lua_getfield(L, 1, "id");
|
||||||
if (lua_type(L, -1) == LUA_TNUMBER)
|
if (lua_isnumber(L, -1))
|
||||||
{
|
{
|
||||||
int id = lua_tointeger(L, -1);
|
int id = lua_tointeger(L, -1);
|
||||||
g_engine->removeObject(id);
|
g_engine->removeObject(id);
|
||||||
|
@ -204,10 +204,10 @@ bool Engine::fileExists(const string & path)
|
|||||||
return false;
|
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++;
|
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;
|
m_objects[id] = o;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class Engine
|
|||||||
void run();
|
void run();
|
||||||
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);
|
int addObject(WFObj * obj, bool is_static, float scale = 1.0f);
|
||||||
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);
|
||||||
@ -79,9 +79,10 @@ class Engine
|
|||||||
void registerLibraries();
|
void registerLibraries();
|
||||||
bool fileExists(const std::string & path);
|
bool fileExists(const std::string & path);
|
||||||
void update();
|
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;
|
lua_State * m_luaState;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user