void Scene::read_file(char *filename) { FILE *file = fopen(filename,"r"); int number_of_objects; char type[50]; int i; fscanf(file,"%i",&number_of_objects); printf("number of objects: %i\n",number_of_objects); parse_doubles(file,"amb:",ambient_light); for(i=0;i < number_of_objects;i++) { fscanf(file,"%s\n",type); if (READ_DEBUG) printf("%s\n",type); Vertex v[3]; if(strcasecmp(type,"triangle")==0) { if (READ_DEBUG) printf("found triangle\n"); for(int j=0;j < 3;j++) { v[j].position = parse_glm_vec3(file,"pos:"); parse_doubles(file,"nor:",v[j].normal); parse_doubles(file,"dif:",v[j].color_diffuse); parse_doubles(file,"spe:",v[j].color_specular); parse_shi(file, &v[j].shininess); } triangles.push_back(Triangle(v)); } else if(strcasecmp(type,"sphere")==0) { if (READ_DEBUG) printf("found sphere\n"); Sphere s; s.position = parse_glm_vec3(file,"pos:"); parse_rad(file,&s.radius); parse_doubles(file,"dif:",s.color_diffuse); parse_doubles(file,"spe:",s.color_specular); parse_shi(file,&s.shininess); spheres.push_back(s); } else if(strcasecmp(type,"light")==0) { if (READ_DEBUG) printf("found light\n"); Light light; light.position = parse_glm_vec3(file,"pos:"); parse_doubles(file,"col:",light.color); lights.push_back(light); } else { printf("unknown type in scene description:\n%s\n",type); exit(0); } } }
int loadScene(char *argv) { FILE *file = fopen(argv,"r"); int number_of_objects; char type[50]; int i; Triangle t; Sphere s; Light l; fscanf(file,"%i",&number_of_objects); printf("number of objects: %i\n",number_of_objects); char str[200]; parse_doubles(file,"amb:",ambient_light); for(i=0;i < number_of_objects;i++) { fscanf(file,"%s\n",type); printf("%s\n",type); if(strcasecmp(type,"triangle")==0) { printf("found triangle\n"); int j; for(j=0;j < 3;j++) { parse_doubles(file,"pos:",t.v[j].position); parse_doubles(file,"nor:",t.v[j].normal); parse_doubles(file,"dif:",t.v[j].color_diffuse); parse_doubles(file,"spe:",t.v[j].color_specular); parse_shi(file,&t.v[j].shininess); } if(num_triangles == MAX_TRIANGLES) { printf("too many triangles, you should increase MAX_TRIANGLES!\n"); exit(0); } triangles[num_triangles++] = t; } else if(strcasecmp(type,"sphere")==0) { printf("found sphere\n"); parse_doubles(file,"pos:",s.position); parse_rad(file,&s.radius); parse_doubles(file,"dif:",s.color_diffuse); parse_doubles(file,"spe:",s.color_specular); parse_shi(file,&s.shininess); if(num_spheres == MAX_SPHERES) { printf("too many spheres, you should increase MAX_SPHERES!\n"); exit(0); } spheres[num_spheres++] = s; } else if(strcasecmp(type,"light")==0) { printf("found light\n"); parse_doubles(file,"pos:",l.position); parse_doubles(file,"col:",l.color); if(num_lights == MAX_LIGHTS) { printf("too many lights, you should increase MAX_LIGHTS!\n"); exit(0); } lights[num_lights++] = l; } else { printf("unknown type in scene description:\n%s\n",type); exit(0); } } return 0; }