void LTSor::produceOutput() { // wait for the input producer to flag us. tuple* tmpFlag = make_tuple("s", SOR_FLAG); tuple* flag = get_tuple(tmpFlag, &ctx); // grab the solution tuple and copy it to the output tuple *templateSolutionTuple = make_tuple("s?", SOLUTION_VECTOR); tuple *solutionTuple = read_tuple(templateSolutionTuple, &ctx); memcpy(outputs[0], solutionTuple->elements[1].data.s.ptr, solutionTuple->elements[1].data.s.len); // remove the tuple synch lock from tuple space tuple *synchLock = make_tuple("s", SYNCH_LOCK); get_tuple(synchLock, &ctx); // clean-up destroy_tuple(tmpFlag); destroy_tuple(flag); destroy_tuple(templateSolutionTuple); destroy_tuple(solutionTuple); destroy_tuple(synchLock); }
int gr_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; int n = lua_gettop(L); gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; double kd[3], ks[3]; get_tuple(L, 1, kd, 3); get_tuple(L, 2, ks, 3); double shininess = luaL_checknumber(L, 3); double reflect_ratio = luaL_checknumber(L, 4); double refract_ratio = 0.0; if (n == 4) { data->material = new PhongMaterial(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio); } else if (n == 5) { refract_ratio = luaL_checknumber(L, 5); data->material = new PhongMaterial(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio); } else if (n > 5) { refract_ratio = luaL_checknumber(L, 5); std::string nm = luaL_checkstring(L, 6); if (nm == "pNormalMap") { double scale = luaL_checknumber(L, 7); double amount = luaL_checknumber(L, 8); data->material = new PhongMaterial(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio, new pNormalMap(scale, amount)); } else if (nm == "imgNormalMap") { std::string nmName = luaL_checkstring(L, 7); data->material = new PhongMaterial(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio, new imgNormalMap(nmName)); } } luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int gr_light_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_light_ud* data = (gr_light_ud*)lua_newuserdata(L, sizeof(gr_light_ud)); data->light = 0; double pos[3]; double col[3]; double falloff[3]; get_tuple(L, 1, pos, 3); get_tuple(L, 2, col, 3); get_tuple(L, 3, falloff, 3); AttentuationCoefficients att; att.quadraticAttenuation = falloff[0]; att.linearAttenuation = falloff[1]; att.constantAttenuation = falloff[3]; data->light = new Light(*(new Colour(col[0], col[1], col[2])), *(new Point(pos[0], pos[1], pos[2])), att); luaL_newmetatable(L, "gr.light"); lua_setmetatable(L, -2); return 1; }
int gr_plane_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); Point3D pos; get_tuple(L, 2, &pos[0], 3); Vector3D v1; get_tuple(L, 3, &v1[0], 3); Vector3D v2; get_tuple(L, 4, &v2[0], 3); double width = luaL_checknumber(L, 5); double height = luaL_checknumber(L, 6); data->node = new GeometryNode(name, new Plane(pos, v1, v2, width, height)); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
int gr_cylinder_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); Point3D pos; Vector3D direction; get_tuple(L, 2, &pos[0], 3); get_tuple(L, 3, &direction[0], 3); double radius = luaL_checknumber(L, 4); Ray ray; ray.p = pos; ray.d = direction; data->node = new GeometryNode(name, new Cylinder(ray, radius)); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
void LTRandmat::produceOutput() { // tuple template tuple *recv = make_tuple("s??", "randmat done"); // grab output pointer locally. IntMatrix output = (IntMatrix) outputs[0]; // grab all of the mandelbrot computations from the workers, // in an unspecified order. int computations = RANDMAT_NR; while (computations > 0) { // get the tuple and copy it into the matrix. tuple* received = get_tuple(recv, &ctx); memcpy( &MATRIX_RECT_NC(output, received->elements[1].data.i, 0, RANDMAT_NC), received->elements[2].data.s.ptr, received->elements[2].data.s.len); computations--; destroy_tuple(received); } // get rid of randmat state from tuple space tuple *tmpInit = make_tuple("s?", "randmat state"); destroy_tuple(get_tuple(tmpInit, &ctx)); // destroy the template tuple destroy_tuple(recv); }
int gr_perlin_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; double kd1[3], kd2[3], ks[3]; get_tuple(L, 1, kd1, 3); get_tuple(L, 2, kd2, 3); get_tuple(L, 3, ks, 3); double shininess = luaL_checknumber(L, 4); double scale = luaL_checknumber(L, 5); double reflectivity = luaL_checknumber(L, 6); double refraction = luaL_checknumber(L, 7); int type = luaL_checknumber(L, 8); double bumpScale = luaL_checknumber(L, 9); double bumpAmount = luaL_checknumber(L, 10); data->material = new Texture(glm::vec3(kd1[0], kd1[1], kd1[2]), glm::vec3(kd2[0], kd2[1], kd2[2]), glm::vec3(ks[0], ks[1], ks[2]), shininess, scale, reflectivity, refraction, type, bumpScale, bumpAmount); luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int gr_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; double kd[3], ks[3]; get_tuple(L, 1, kd, 3); get_tuple(L, 2, ks, 3); double shininess = luaL_checknumber(L, 3); double reflectivity = luaL_checknumber(L, 4); double refraction = luaL_checknumber(L, 5); double refractiveIndex = luaL_checknumber(L, 6); double bumpScale = luaL_checknumber(L, 7); double bumpAmount = luaL_checknumber(L, 8); data->material = new PhongMaterial(glm::vec3(kd[0], kd[1], kd[2]), glm::vec3(ks[0], ks[1], ks[2]), shininess, reflectivity, refraction, refractiveIndex, bumpScale, bumpAmount); luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int gr_render_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* root = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node"); luaL_argcheck(L, root != 0, 1, "Root node expected"); const char* filename = luaL_checkstring(L, 2); int width = luaL_checknumber(L, 3); int height = luaL_checknumber(L, 4); glm::vec3 eye; glm::vec3 view, up; get_tuple(L, 5, &eye[0], 3); get_tuple(L, 6, &view[0], 3); get_tuple(L, 7, &up[0], 3); double fov = luaL_checknumber(L, 8); double ambient_data[3]; get_tuple(L, 9, ambient_data, 3); glm::vec3 ambient(ambient_data[0], ambient_data[1], ambient_data[2]); luaL_checktype(L, 10, LUA_TTABLE); int light_count = lua_rawlen(L, 10); int aaMode = luaL_checknumber(L, 11); int partition = luaL_checknumber(L, 12); int threadCount = luaL_checknumber(L, 13); //Error checking if(threadCount <= 0) threadCount = 1; if(partition < 2) partition = 2; if(aaMode < 0 || aaMode > 2) aaMode = 0; luaL_argcheck(L, light_count >= 1, 10, "Tuple of lights expected"); std::list<Light*> lights; for (int i = 1; i <= light_count; i++) { lua_rawgeti(L, 10, i); gr_light_ud* ldata = (gr_light_ud*)luaL_checkudata(L, -1, "gr.light"); luaL_argcheck(L, ldata != 0, 10, "Light expected"); lights.push_back(ldata->light); lua_pop(L, 1); } Image im( width, height, 3 ); a4_render( root->node, im, eye, view, up, fov, ambient, lights, aaMode, partition, threadCount); im.savePng( filename ); return 0; }
int gr_mesh_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); std::vector<Point3D> verts; std::vector< std::vector<int> > faces; luaL_checktype(L, 2, LUA_TTABLE); int vert_count = luaL_getn(L, 2); luaL_argcheck(L, vert_count >= 1, 2, "Tuple of vertices expected"); for (int i = 1; i <= vert_count; i++) { lua_rawgeti(L, 2, i); Point3D vertex; get_tuple(L, -1, &vertex[0], 3); verts.push_back(vertex); lua_pop(L, 1); } luaL_checktype(L, 3, LUA_TTABLE); int face_count = luaL_getn(L, 3); luaL_argcheck(L, face_count >= 1, 3, "Tuple of faces expected"); faces.resize(face_count); for (int i = 1; i <= face_count; i++) { lua_rawgeti(L, 3, i); luaL_checktype(L, -1, LUA_TTABLE); int index_count = luaL_getn(L, -1); luaL_argcheck(L, index_count >= 3, 3, "Tuple of indices expected"); faces[i - 1].resize(index_count); get_tuple(L, -1, &faces[i - 1][0], index_count); lua_pop(L, 1); } Mesh* mesh = new Mesh(verts, faces); GRLUA_DEBUG(*mesh); data->node = new GeometryNode(name, mesh); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
int scene_m_light_area_cmd(lua_State *L) { GRLUA_DEBUG_CALL; LightNode *light = get_light_node(L); Vector3D uvec, vvec; get_tuple(L, 2, &uvec[0], 3); get_tuple(L, 3, &vvec[0], 3); light->jitter.set_uvec(uvec); light->jitter.set_vvec(vvec); light->jitter.set_shape(JITTER_RECTANGLE); return 0; }
int gr_render_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* root = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node"); luaL_argcheck(L, root != 0, 1, "Root node expected"); const char* filename = luaL_checkstring(L, 2); int width = luaL_checknumber(L, 3); int height = luaL_checknumber(L, 4); Point3D eye; Vector3D view, up; get_tuple(L, 5, &eye[0], 3); get_tuple(L, 6, &view[0], 3); get_tuple(L, 7, &up[0], 3); double fov = luaL_checknumber(L, 8); double ambient_data[3]; get_tuple(L, 9, ambient_data, 3); Colour ambient(ambient_data[0], ambient_data[1], ambient_data[2]); luaL_checktype(L, 10, LUA_TTABLE); int light_count = luaL_getn(L, 10); luaL_argcheck(L, light_count >= 1, 10, "Tuple of lights expected"); std::list<Light*> lights; for (int i = 1; i <= light_count; i++) { lua_rawgeti(L, 10, i); gr_light_ud* ldata = (gr_light_ud*)luaL_checkudata(L, -1, "gr.light"); luaL_argcheck(L, ldata != 0, 10, "Light expected"); lights.push_back(ldata->light); lua_pop(L, 1); } double aperature = luaL_checknumber(L, 11); double dof = luaL_checknumber(L, 12); a4_render(root->node, filename, width, height, eye, view, up, fov, ambient, lights, aperature, dof); return 0; }
w_rc_t table_man_t<T>::print_table(ostream& os, int num_lines) { table_row_t* row = get_tuple(); rep_row_t rep(ts()); rep_row_t repkey(ts()); rep.set(table()->maxsize()); repkey.set(table()->maxsize()); row->_rep = &rep; row->_rep_key = &repkey; table_scan_iter_impl<T> scanner(this); scanner.open_scan(); bool eof = false; size_t i = 0; while (true) { scanner.next(eof, *row); if (eof) break; if (num_lines > 0 && i++ > num_lines) break; row->print_values(os); } give_tuple(row); return RCOK; }
void MergeJoin::create_merge_stack() { Tuple t; t.schema(m_tuple[TLEFT|PROJ].schema()); t.m_data = m_data; // merged_data > left.proj_data m_merge_stack.clear(); // get first item of merge stack for future comparisons. m_tsr[LEFT]->read(t); m_tsr[LEFT]->rewind(1); // rewind to push first item unto stack. while (!m_eof[LEFT] && get_tuple(LEFT, TLEFT|PROJ, false) && compare(t, m_joinCols[TLEFT|PROJ], m_tuple[TLEFT|PROJ], m_joinCols[TLEFT|PROJ]) == 0) { // push item unto merge stack. byte * data = new byte[m_tuple[TLEFT|PROJ].schema()->rsize()]; memcpy(data, m_tuple[LEFT].m_data, m_tuple[TLEFT|PROJ].schema()->rsize()); m_merge_stack.push_back(data); if (m_tsr[LEFT]->isEndOfStream()) { m_consumed[LEFT] = true; m_eof[LEFT] = isEmpty(LEFT); } } // rewind to retrieve next item for subsequent processing. if (!m_eof[LEFT]) m_tsr[LEFT]->rewind(1); }
static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) { int i = pcmcia_get_next_tuple(handle, tuple); if (i != CS_SUCCESS) return i; return get_tuple(handle, tuple, parse); }
w_rc_t table_man_t<T>::print_index(unsigned ind, ostream& os, int num_lines, bool need_tuple) { table_row_t* row = get_tuple(); rep_row_t rep(ts()); rep_row_t repkey(ts()); rep.set(table()->maxsize()); repkey.set(table()->maxsize()); row->_rep = &rep; row->_rep_key = &repkey; index_desc_t* pindex = table()->get_indexes()[ind]; w_assert0(pindex); index_scan_iter_impl<T> scanner(pindex, this, need_tuple); scanner.open_scan(); bool eof = false; size_t i = 0; while (true) { scanner.next(eof, *row); if (eof) break; if (num_lines > 0 && i++ > num_lines) break; row->print_values(os); } give_tuple(row); return RCOK; }
int gr_rt_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; gr_texture_ud* aData = (gr_texture_ud*)luaL_checkudata(L, 1, "gr.texture"); luaL_argcheck(L, aData != 0, 1, "Node expected"); Texture *tD = dynamic_cast<Texture *>(aData->texture); ASSERT(tD); double kS[3]; get_tuple(L, 2, kS, 3); double shininess = luaL_checknumber(L, 3); double reflectivity = min(max(luaL_checknumber(L, 4), 0.0), 1.0); double opacity = min(max(luaL_checknumber(L, 5), 0.0), 1.0); double indexOfRefraction = max(luaL_checknumber(L, 6), 0.0); data->material = new RTMaterial(tD, Colour(kS[0], kS[1], kS[2]), shininess, reflectivity, opacity, indexOfRefraction); luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) { int i = pcmcia_get_next_tuple(handle, tuple); if (i != CS_SUCCESS) return i; return get_tuple(handle, tuple, parse); }
int gr_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; gr_texture_ud* tData = (gr_texture_ud*)luaL_checkudata(L, 1, "gr.texture"); luaL_argcheck(L, tData != 0, 1, "Texture expected"); Texture *tD = dynamic_cast<Texture *>(tData->texture); ASSERT(tD); double kS[3]; get_tuple(L, 2, kS, 3); double shininess = luaL_checknumber(L, 3); data->material = new RTMaterial(tD, Colour(kS[0], kS[1], kS[2]), shininess); luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int scene_m_light_falloff_cmd(lua_State *L) { GRLUA_DEBUG_CALL; LightNode *light = get_light_node(L); get_tuple(L, 2, light->falloff, 3); return 0; }
int scene_m_cam_view_cmd(lua_State *L) { GRLUA_DEBUG_CALL; CameraNode *cam = get_cam_node(L); get_tuple(L, 2, &cam->view[0], 3); cam->rel_view = lua_toboolean(L, 3); return 0; }
void LTSor::consumeInput() { // create a tuple synch lock tuple *synchLock = make_tuple("s", SYNCH_LOCK); put_tuple(synchLock, &ctx); // Initialise. note that as these can run in processes, the // solution vector must live in tuple space to be communicated // between the workers. Setting the solution variable is LOCAL ONLY Matrix matrix = (Matrix) inputs[0]; Vector target = (Vector) inputs[1]; Vector solution = (Vector) outputs[0]; for (index_t r = 0; r < SOR_N; ++r) { VECTOR(solution, r) = 1.0; } // put a tuple for the solution vector into tuple space tuple *solutionTuple = make_tuple("ss", SOLUTION_VECTOR); solutionTuple->elements[1].data.s.len = sizeof(solution); solutionTuple->elements[1].data.s.ptr = (char*) solution; // loop until we get the desired tolerance real maxDiff = (real)(2 * SOR_TOLERANCE); for (index_t t = 0; (t < SOR_MAX_ITERS) && (maxDiff >= SOR_TOLERANCE); t++) { maxDiff = 0.0; for (index_t r = 0; r < SOR_N; ++r) { // compute sum real sum = solutionSum(r); // calculate new solution real oldSolution = VECTOR(solution, r); VECTOR(solution, r) = (real)( (1.0 - SOR_OMEGA) * oldSolution + SOR_OMEGA * (VECTOR(target, r) - sum) / MATRIX_SQUARE_N(matrix, r, r, SOR_N) ); // refresh the solution vector in tuple-space tuple *solutionBlank = make_tuple("s?", SOLUTION_VECTOR); get_tuple(solutionBlank, &ctx); put_tuple(solutionTuple, &ctx); destroy_tuple(solutionBlank); // compute difference real diff = (real) fabs((double)(oldSolution - VECTOR(solution, r))); if (diff > maxDiff) { maxDiff = diff; } } } // flag the output producer. put_tuple(make_tuple("s", SOR_FLAG), &ctx); }
int gr_turb_cmd(lua_State* L) { GRLUA_DEBUG_CALL; int n = lua_gettop(L); gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; double kd[3], ks[3]; get_tuple(L, 1, kd, 3); get_tuple(L, 2, ks, 3); double shininess = luaL_checknumber(L, 3); double reflect_ratio = luaL_checknumber(L, 4); double refract_ratio = luaL_checknumber(L, 5); int scale = luaL_checknumber(L, 6); int level = luaL_checknumber(L, 7); if (n > 7) { double c1[3], c2[3]; get_tuple(L, 8, c1, 3); get_tuple(L, 9, c2, 3); data->material = new Turbulence(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio, scale, level, Colour(c1[0], c1[1], c1[2]), Colour(c2[0], c2[1], c2[2]) ); } else { data->material = new Turbulence(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess, reflect_ratio, refract_ratio, scale, level); } luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int scene_m_light_pos_cmd(lua_State *L) { GRLUA_DEBUG_CALL; LightNode *light = get_light_node(L); Point3D pos; get_tuple(L, 2, &pos[0], 3); light->jitter.set_pos(pos); return 0; }
int gr_light_cmd(lua_State* L) { GRLUA_DEBUG_CALL; int n = lua_gettop(L); gr_light_ud* data = (gr_light_ud*)lua_newuserdata(L, sizeof(gr_light_ud)); data->light = 0; Point3D pos; double col[3]; double falloff[3]; get_tuple(L, 1, &pos[0], 3); get_tuple(L, 2, col, 3); get_tuple(L, 3, falloff, 3); Colour c = Colour(col[0], col[1], col[2]); if (n == 3) { data->light = new Light(pos, c, falloff[0], falloff[1], falloff[2]); // std::cout << "light" << std::endl; } else { if (n > 6) { Vector3D v1, v2; get_tuple(L, 4, &v1[0], 3); get_tuple(L, 5, &v2[0], 3); double width = luaL_checknumber(L, 6); double height = luaL_checknumber(L, 7); data->light = new AreaLight(pos, c, falloff[0], falloff[1], falloff[2], v1, v2, width, height); } else { Vector3D dir; get_tuple(L, 4, &dir[0], 3); int power = luaL_checknumber(L, 5); if (n > 5) { float gamma = luaL_checknumber(L, 6); data->light = new ConeLight(pos, c, falloff[0], falloff[1], falloff[2], dir, power, gamma); // std::cout << "conelight" << std::endl; } else // n==5 { data->light = new DirectedLight(pos, c, falloff[0], falloff[1], falloff[2], dir, power); } } } luaL_newmetatable(L, "gr.light"); lua_setmetatable(L, -2); return 1; }
int gr_cone_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); glm::vec3 pos,up; get_tuple(L, 2, &pos[0], 3); get_tuple(L, 3, &up[0], 3); double radius = luaL_checknumber(L, 4); double height = luaL_checknumber(L, 5); data->node = new GeometryNode(name, new Cone(pos, up, radius, height)); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
int gr_material_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud)); data->material = 0; double kd[3], ks[3]; get_tuple(L, 1, kd, 3); get_tuple(L, 2, ks, 3); double shininess = luaL_checknumber(L, 3); data->material = new PhongMaterial(Colour(kd[0], kd[1], kd[2]), Colour(ks[0], ks[1], ks[2]), shininess); luaL_newmetatable(L, "gr.material"); lua_setmetatable(L, -2); return 1; }
int gr_torus_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); glm::vec3 pos,axis; get_tuple(L, 2, &pos[0], 3); get_tuple(L, 3, &axis[0], 3); double a = luaL_checknumber(L, 4); double b = luaL_checknumber(L, 5); data->node = new GeometryNode(name, new Torus(pos, axis, a,b)); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
int scene_m_translate_cmd(lua_State *L) { GRLUA_DEBUG_CALL; scene_node_ud *me = (scene_node_ud*)luaL_checkudata(L, 1, SCENE_META); luaL_argcheck(L, me != 0, 1, "Node expected"); SceneNode *node = me->node; Vector3D trans; get_tuple(L, 2, &trans[0], 3); node->translate(trans); return 0; }
int gr_light_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_light_ud* data = (gr_light_ud*)lua_newuserdata(L, sizeof(gr_light_ud)); data->light = 0; Light l; double col[3]; get_tuple(L, 1, &l.position[0], 3); get_tuple(L, 2, col, 3); get_tuple(L, 3, l.falloff, 3); l.colour = Colour(col[0], col[1], col[2]); data->light = new Light(l); double v1[3], v2[3]; get_tuple(L, 4, v1, 3); get_tuple(L, 5, v2, 3); double theta_limit = luaL_checknumber(L, 6); data->light->v1 = Vector3D(v1[0], v1[1], v1[2]); data->light->v2 = Vector3D(v2[0], v2[1], v2[2]); data->light->n = data->light->v1.cross(data->light->v2); data->light->cos_theta_limit_squared = cos((theta_limit * M_PI) / 180) * cos((theta_limit * M_PI) / 180); luaL_newmetatable(L, "gr.light"); lua_setmetatable(L, -2); return 1; }