static int create_translate_node(lua_State *L) { maybe_insert_default_mv(L); int nargs = am_check_nargs(L, 2); am_translate_node *node = am_new_userdata(L, am_translate_node); node->tags.push_back(L, AM_TAG_TRANSLATE); node->name = am_lookup_param_name(L, 1); switch (am_get_type(L, 2)) { case MT_am_vec2: { glm::vec2 v2 = am_get_userdata(L, am_vec2, 2)->v; node->v = glm::vec3(v2.x, v2.y, 0.0f); break; } case MT_am_vec3: { node->v = am_get_userdata(L, am_vec3, 2)->v; break; } case LUA_TNUMBER: { if (nargs < 3) { return luaL_error(L, "too few arguments"); } else if (nargs == 3) { node->v = glm::vec3((float)luaL_checknumber(L, 2), (float)luaL_checknumber(L, 3), 0.0f); } else if (nargs == 4) { node->v = glm::vec3((float)luaL_checknumber(L, 2), (float)luaL_checknumber(L, 3), (float)luaL_checknumber(L, 4)); } else { return luaL_error(L, "too many arguments"); } break; } default: return luaL_error(L, "expecting a vec2 or vec3 argument"); } return 1; }
static int create_scale_node(lua_State *L) { maybe_insert_default_mv(L); int nargs = am_check_nargs(L, 2); am_scale_node *node = am_new_userdata(L, am_scale_node); node->tags.push_back(L, AM_TAG_SCALE); node->name = am_lookup_param_name(L, 1); switch (am_get_type(L, 2)) { case MT_am_vec2: { glm::dvec2 v2 = am_get_userdata(L, am_vec2, 2)->v; node->v = glm::dvec3(v2.x, v2.y, 1.0); break; } case MT_am_vec3: { node->v = am_get_userdata(L, am_vec3, 2)->v; break; } case LUA_TNUMBER: { if (nargs == 2) { double s = (double)luaL_checknumber(L, 2); node->v = glm::dvec3(s, s, 1.0); } else if (nargs == 3) { node->v = glm::dvec3((double)luaL_checknumber(L, 2), (double)luaL_checknumber(L, 3), 1.0); } else if (nargs == 4) { node->v = glm::dvec3((double)luaL_checknumber(L, 2), (double)luaL_checknumber(L, 3), (double)luaL_checknumber(L, 4)); } else { return luaL_error(L, "too many arguments"); } break; } default: return luaL_error(L, "expecting a vec2 or vec3 argument"); } return 1; }
static int create_lookat_node(lua_State *L) { maybe_insert_default_mv(L); am_check_nargs(L, 4); am_lookat_node *node = am_new_userdata(L, am_lookat_node); node->tags.push_back(L, AM_TAG_LOOKAT); node->name = am_lookup_param_name(L, 1); node->eye = am_get_userdata(L, am_vec3, 2)->v; node->center = am_get_userdata(L, am_vec3, 3)->v; node->up = am_get_userdata(L, am_vec3, 4)->v; return 1; }
static int create_billboard_node(lua_State *L) { maybe_insert_default_mv(L); int nargs = am_check_nargs(L, 1); am_billboard_node *node = am_new_userdata(L, am_billboard_node); node->tags.push_back(L, AM_TAG_BILLBOARD); node->name = am_lookup_param_name(L, 1); node->preserve_uniform_scaling = false; if (nargs > 1) { node->preserve_uniform_scaling = lua_toboolean(L, 2); } return 1; }
static int create_rotate_node(lua_State *L) { maybe_insert_default_mv(L); int nargs = am_check_nargs(L, 2); am_rotate_node *node = am_new_userdata(L, am_rotate_node); node->tags.push_back(L, AM_TAG_ROTATE); node->name = am_lookup_param_name(L, 1); switch (am_get_type(L, 2)) { case MT_am_quat: node->rotation = am_get_userdata(L, am_quat, 2)->q; node->angle = glm::angle(node->rotation); node->axis = glm::axis(node->rotation); break; default: node->angle = luaL_checknumber(L, 2); if (nargs > 2) { node->axis = am_get_userdata(L, am_vec3, 3)->v; } else { node->axis = glm::vec3(0.0f, 0.0f, 1.0f); } node->rotation = glm::angleAxis(node->angle, node->axis); break; } return 1; }