gpuray_glsl
diff src/scene_load.cc @ 4:2ed3da7dc0bc
broken
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 10 Nov 2014 01:26:00 +0200 |
parents | f234630e38ff |
children |
line diff
1.1 --- a/src/scene_load.cc Sun Nov 09 20:13:33 2014 +0200 1.2 +++ b/src/scene_load.cc Mon Nov 10 01:26:00 2014 +0200 1.3 @@ -5,6 +5,7 @@ 1.4 #include "sphere.h" 1.5 #include "plane.h" 1.6 #include "box.h" 1.7 +#include "cone.h" 1.8 #include "light.h" 1.9 #include "camera.h" 1.10 #include "texture.h" 1.11 @@ -13,6 +14,7 @@ 1.12 static Object *parse_sphere(char **argv, const std::map<std::string, Material> &materials); 1.13 static Object *parse_plane(char **argv, const std::map<std::string, Material> &materials); 1.14 static Object *parse_box(char **argv, const std::map<std::string, Material> &materials); 1.15 +static Object *parse_cone(char **argv, const std::map<std::string, Material> &materials); 1.16 static Light *parse_light(char **argv); 1.17 static Camera *parse_camera(char **argv); 1.18 static bool parse_env(char **argv, Scene *scn); 1.19 @@ -77,6 +79,14 @@ 1.20 } 1.21 scn->add_object(obj); 1.22 1.23 + } else if(strstr(line, "cone") == line) { 1.24 + char *args = strip_space(line + strlen("cone")); 1.25 + Object *obj = parse_cone(split_args(args), materials); 1.26 + if(!obj) { 1.27 + goto err; 1.28 + } 1.29 + scn->add_object(obj); 1.30 + 1.31 } else if(strstr(line, "light") == line) { 1.32 char *args = strip_space(line + strlen("light")); 1.33 Light *lt = parse_light(split_args(args)); 1.34 @@ -153,6 +163,7 @@ 1.35 const Sphere *sph; 1.36 const Plane *plane; 1.37 const Box *box; 1.38 + const Cone *cone; 1.39 if((sph = dynamic_cast<const Sphere*>(obj))) { 1.40 fprintf(fp, "sphere -material %s", name); 1.41 fprintf(fp, " -center %.3f %.3f %.3f", sph->pos.x, sph->pos.y, sph->pos.z); 1.42 @@ -165,6 +176,10 @@ 1.43 fprintf(fp, "box -material %s", name); 1.44 fprintf(fp, " -min %.3f %.3f %.3f", box->min.x, box->min.y, box->min.z); 1.45 fprintf(fp, " -max %.3f %.3f %.3f\n", box->max.x, box->max.y, box->max.z); 1.46 + } else if((cone = dynamic_cast<const Cone*>(obj))) { 1.47 + fprintf(fp, "cone -material %s", name); 1.48 + fprintf(fp, " -angle %g", RAD_TO_DEG(cone->angle)); 1.49 + fprintf(fp, " -start %g -end %g\n", cone->ymin, cone->ymax); 1.50 } 1.51 } 1.52 1.53 @@ -374,6 +389,53 @@ 1.54 return box; 1.55 } 1.56 1.57 +static Object *parse_cone(char **argv, const std::map<std::string, Material> &materials) 1.58 +{ 1.59 + char *endp; 1.60 + Cone *cone = new Cone; 1.61 + 1.62 + for(int i=0; argv[i]; i++) { 1.63 + if(strcmp(argv[i], "-name") == 0) { 1.64 + cone->set_name(argv[++i]); 1.65 + 1.66 + } else if(strcmp(argv[i], "-angle") == 0) { 1.67 + cone->angle = DEG_TO_RAD(strtod(argv[++i], &endp)); 1.68 + if(endp == argv[i]) { 1.69 + fprintf(stderr, "failed to parse cone angle\n"); 1.70 + return 0; 1.71 + } 1.72 + 1.73 + } else if(strcmp(argv[i], "-start") == 0) { 1.74 + cone->ymin = strtod(argv[++i], &endp); 1.75 + if(endp == argv[i]) { 1.76 + fprintf(stderr, "failed to parse cone start\n"); 1.77 + return 0; 1.78 + } 1.79 + 1.80 + } else if(strcmp(argv[i], "-end") == 0) { 1.81 + cone->ymax = strtod(argv[++i], &endp); 1.82 + if(endp == argv[i]) { 1.83 + fprintf(stderr, "failed to parse cone end\n"); 1.84 + return 0; 1.85 + } 1.86 + 1.87 + } else if(strcmp(argv[i], "-material") == 0) { 1.88 + auto it = materials.find(argv[++i]); 1.89 + if(it == materials.end()) { 1.90 + fprintf(stderr, "material %s not found\n", argv[i]); 1.91 + return 0; 1.92 + } 1.93 + 1.94 + cone->material = it->second; 1.95 + } else { 1.96 + fprintf(stderr, "invalid box option: %s\n", argv[i]); 1.97 + return 0; 1.98 + } 1.99 + } 1.100 + 1.101 + return cone; 1.102 +} 1.103 + 1.104 static Light *parse_light(char **argv) 1.105 { 1.106 Light *lt = new Light;