void generate( int polygons ) { double knob_value; vary_node *knobs; vary_node vn; char frame_name[128]; if (first_pass()) { knobs = second_pass(); } else { num_frames = 1; } // Default values char color_type = PNG_RGB, shading = GOROUD; int width = 1000, height = 1000, segments = 20; screen s = make_screen(width, height); vertex_list vlist = new_vlist(100); face_list flist = new_flist(100); edge_list elist = new_elist(100); stack coord_systems = new_stack(5); vector center = new_vector(0, 0, 0); vector eye = new_vector(0, 0, 200); double distance = 200; vertex text0, text1; text0.x = -100; text0.y = 0; text0.z = 0; text1.x = 100; text1.y = 0; text1.z = 0; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb(255, 255, 255); text0.shine = 3; text1.color = rgb(255, 0, 255); text1.shine = 3; uint32_t amb_color = rgb(255, 255, 255), light_color = rgb(0, 255, 255), wire_color = rgb(255, 255, 255); vector light_source = new_vector(0, 100, 200); double amb_ref_constant = 0.1, diff_ref_constant = 1, spec_ref_constant = 1; int frame, i, j; double temp; for (frame = 0; frame < num_frames; frame++) { if (num_frames > 1) { for (vn = knobs[frame]; vn != NULL; vn = vn->next) { set_value(lookup_symbol(vn->name), vn->value); } } for (i = 0; i < lastop; i++) { switch (op[i].opcode) { case TEXTURE: text0.x = op[lastop].op.texture.d0[0]; text0.y = op[lastop].op.texture.d0[1]; text0.z = op[lastop].op.texture.d0[2]; text1.x = op[lastop].op.texture.d1[0]; text1.y = op[lastop].op.texture.d1[1]; text1.z = op[lastop].op.texture.d1[2]; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[2])) ); text0.shine = op[lastop].op.texture.d2[3]; text1.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[2])) ); text1.shine = op[lastop].op.texture.d3[3]; break; case CAMERA: eye.x = op[lastop].op.camera.eye[0]; eye.y = op[lastop].op.camera.eye[1]; eye.z = op[lastop].op.camera.eye[2]; center.x = eye.x + op[lastop].op.camera.aim[0]; center.y = eye.y + op[lastop].op.camera.aim[1]; center.z = eye.z + op[lastop].op.camera.aim[2]; break; case FOCAL: distance = op[lastop].op.focal.value; break; case AMBIENT: amb_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[2])) ); break; case LIGHT: light_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[2])) ); light_source = new_vector( op[lastop].op.light.l[0], op[lastop].op.light.l[1], op[lastop].op.light.l[2] ); break; case SHADING: if (strcmp(op[i].op.shading.p->name, "GOROUD") == 0) { shading = GOROUD; } else { shading = WIRE; } break; case SPHERE: add_sphere( vlist, elist, flist, op[i].op.sphere.d[0], op[i].op.sphere.d[1], op[i].op.sphere.d[2], op[i].op.sphere.r, segments, text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case BOX: add_box( vlist, elist, flist, op[i].op.box.d0[0], op[i].op.box.d0[1], op[i].op.box.d0[2], op[i].op.box.d1[0], op[i].op.box.d1[1], op[i].op.box.d1[2], text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case LINE: add_line( vlist, elist, op[i].op.line.p0[0], op[i].op.line.p0[1], op[i].op.line.p0[2], op[i].op.line.p1[0], op[i].op.line.p1[1], op[i].op.line.p1[2], text0, text1 ); transform(vlist, peek(coord_systems)); draw_edges(s, vlist, elist, center, eye, distance, wire_color); clear_vlist(vlist); clear_elist(elist); break; case MOVE: if (op[i].op.move.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.move.p->s.value; } translate( op[i].op.move.d[0] * knob_value, op[i].op.move.d[1] * knob_value, op[i].op.move.d[2] * knob_value, peek(coord_systems) ); break; case SCALE: if (op[i].op.scale.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.scale.p->s.value; } scale( op[i].op.scale.d[0] * knob_value, op[i].op.scale.d[1] * knob_value, op[i].op.scale.d[2] * knob_value, peek(coord_systems) ); break; case ROTATE: if (op[i].op.rotate.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.rotate.p->s.value; } temp = op[i].op.rotate.axis; if (temp == 0) { rotate_x( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else if (temp == 1) { rotate_y( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else { rotate_z( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } break; case SET: set_value( lookup_symbol(op[i].op.set.p->name), op[i].op.set.val ); break; case SETKNOBS: for (j = 0; j < lastsym; j++) { set_value(&symtab[j], op[j].op.setknobs.value); } break; case PUSH: push(coord_systems); break; case POP: pop(coord_systems); break; case SAVE: make_png(op[i].op.save.p->name, s, color_type); break; case DISPLAY: display_png(s, color_type); break; } } if (num_frames > 1){ sprintf(frame_name, "anim/%s%03d.png", name, frame); make_png(frame_name, s, color_type); clear_screen(s); clear_stack(coord_systems); } } free_screen(s); free_vlist(vlist); free_flist(flist); free_elist(elist); free(coord_systems); }
int parse_index_options(IndexOptions *o, char **argv) { int i,j; SGREPDATA(o); i=0; j=1; while ( *argv!=NULL && *argv[0]=='-' ) { /* option -- means no more options */ if (strcmp(*argv,"--")==0) return i+1; switch((*argv)[j]) { case 'g': { char *arg; arg=get_arg(sgrep,&argv,&i,&j); if ((!arg) || set_scanner_option(o->sgrep,arg)==SGREP_ERROR) { return SGREP_ERROR; } break; } case 'h': print_index_help(); o->index_mode=IM_DONE; break; case 'i': o->sgrep->ignore_case=1; break; case 'l': { char *endptr; char *arg=get_arg(sgrep,&argv,&i,&j); if (!arg) return SGREP_ERROR; o->stop_word_limit=strtol(arg,&endptr,10); if (o->stop_word_limit<0 || *endptr!=0) { sgrep_error(sgrep,"Invalid stop word limit '%s'\n", arg); return SGREP_ERROR; } break; } case 'm': { char *endptr; char *arg=get_arg(sgrep,&argv,&i,&j); if (!arg) return SGREP_ERROR; o->available_memory=strtol(arg,&endptr,10)*1024*1024; if (o->available_memory<0 || *endptr!=0) { sgrep_error(sgrep,"Invalid memory size '%s'\n", arg); return SGREP_ERROR; } break; } case 'L': o->output_stop_word_file=get_arg(sgrep,&argv,&i,&j); if (!o->output_stop_word_file) return SGREP_ERROR; break; case 'S': o->input_stop_word_file=get_arg(sgrep,&argv,&i,&j); if (!o->input_stop_word_file) return SGREP_ERROR; break; case 'V': printf("sgindex version %s compiled at %s\n", VERSION,__DATE__); o->index_mode=IM_DONE; break; case 'v': o->sgrep->progress_output=1; break; case 'T': o->index_stats=1; break; #if 0 case 'C': copyright_notice(); o->index_mode=IM_DONE; break; #endif case 'R': o->sgrep->recurse_dirs=1; sgrep_error(sgrep,"WARNING -R not working (yet)\n"); break; case 'c': o->file_name=get_arg(sgrep,&argv,&i,&j); if (o->file_name==NULL) return SGREP_ERROR; o->index_mode=IM_CREATE; break; case 'x': o->sgrep->index_file=get_arg(sgrep,&argv,&i,&j); if (o->sgrep->index_file==NULL) return SGREP_ERROR; break; case 'q': { const char *arg=get_arg(sgrep,&argv,&i,&j); if (strcmp(arg,"terms")==0) { o->index_mode=IM_TERMS; } else { sgrep_error(sgrep,"Don't know how to query '%s'\n", arg); return SGREP_ERROR; } break; } case 'F': { char *arg; arg=get_arg(sgrep,&argv,&i,&j); if (arg==NULL) return SGREP_ERROR; if (o->file_list_files==NULL) { o->file_list_files=new_flist(sgrep); } flist_add(o->file_list_files,arg); break; } case 'w': o->sgrep->word_chars=get_arg(sgrep,&argv,&i,&j); if (!o->sgrep->word_chars) return SGREP_ERROR; break; default: sgrep_error(sgrep,"Illegal option -%c\n",(*argv)[j]); return SGREP_ERROR; break; } if ((*argv)[++j]==0) { argv++; i++; j=1; } } return i; }