ag.pickObjects() now sets pick_dist, pick_pos, and pick_normal attributes on the selected objects

git-svn-id: svn://anubis/anaglym/trunk@307 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-09-17 02:44:25 +00:00
parent d768feb8b4
commit 7c7609045d

45
ag.cc
View File

@ -104,19 +104,44 @@ namespace ag
it != objects->end();
it++)
{
lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */
lua_getfield(L, -1, "_objects"); /* pushes 1 */
lua_pushinteger(L, (*it)->id); /* pushes 1 */
lua_gettable(L, -2); /* replace top */
lua_remove(L, -3); /* remove 1 */
lua_remove(L, -2); /* remove 1 */
lua_getfield(L, LUA_GLOBALSINDEX, "ag");/* {ag} */
lua_getfield(L, -1, "_objects"); /* {ag,_objects} */
lua_pushinteger(L, (*it)->id); /* {ag,_objects,id} */
lua_gettable(L, -2); /* {ag,_objects,obj} */
lua_remove(L, -3); /* {_objects,obj} */
lua_remove(L, -2); /* {obj} */
if (!lua_isnil(L, -1))
{
lua_pushinteger(L, next_index++); /* push key */
lua_pushvalue(L, -2); /* push value */
lua_settable(L, argc + 1); /* pop 2 */
lua_pushinteger(L, next_index++); /* {obj,index} */
lua_pushvalue(L, -2); /* {obj,index,obj} */
lua_settable(L, argc + 1); /* {obj} */
}
lua_pop(L, 1); /* pop 1 */
lua_pushstring(L, "pick_dist"); /* {obj,"pick_dist"} */
lua_pushnumber(L, (*it)->dist); /* {obj,"pick_dist",dist} */
lua_settable(L, -3); /* {obj} */
lua_createtable(L, 3, 0); /* {obj,arr} */
for (int i = 0; i < 3; i++)
{
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
lua_pushnumber(L, (*it)->pos[i]);/* {obj,arr,index,pos_x} */
lua_settable(L, -3); /* {obj,arr} */
}
lua_pushstring(L, "pick_pos"); /* {obj,arr,"pick_pos"} */
lua_pushvalue(L, -2); /* {obj,arr,"pick_pos",arr} */
lua_settable(L, -4); /* {obj,arr} */
lua_pop(L, 1); /* {obj} */
lua_createtable(L, 3, 0); /* {obj,arr} */
for (int i = 0; i < 3; i++)
{
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
lua_pushnumber(L, (*it)->normal[i]);/* {obj,arr,index,n} */
lua_settable(L, -3); /* {obj,arr} */
}
lua_pushstring(L, "pick_normal"); /* {obj,arr,"pick_normal"} */
lua_pushvalue(L, -2); /* {obj,arr,"pick_normal",arr} */
lua_settable(L, -4); /* {obj,arr} */
lua_pop(L, 1); /* {obj} */
lua_pop(L, 1); /* {} */
}
}
else