void World::build(void) { int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); Pinhole* camera_ptr = new Pinhole; camera_ptr->set_eye(0, 7, 10); camera_ptr->set_lookat(0, -1.5, 0); camera_ptr->set_view_distance(1200); camera_ptr->compute_uvw(); set_camera(camera_ptr); PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(3, 10, 2); light_ptr1->set_color(1, 0, 0); // red light_ptr1->scale_radiance(12.0); light_ptr1->set_shadows(true); add_light(light_ptr1); PointLight* light_ptr2 = new PointLight; light_ptr2->set_location(-3, 10, 2); light_ptr2->set_color(0, 1, 0); // green light_ptr2->scale_radiance(12.0); light_ptr2->set_shadows(true); add_light(light_ptr2); PointLight* light_ptr3 = new PointLight; light_ptr3->set_location(0, 10, -3); light_ptr3->set_color(0, 0, 1); // blue light_ptr3->scale_radiance(12.0); light_ptr3->set_shadows(true); add_light(light_ptr3); // sphere Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(0.6); matte_ptr1->set_kd(0.2); matte_ptr1->set_cd(0.5); Sphere* sphere_ptr1 = new Sphere; sphere_ptr1->set_material(matte_ptr1); add_object(sphere_ptr1); // ground plane Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(0.0); matte_ptr2->set_kd(0.35); matte_ptr2->set_cd(0.7); Plane* plane_ptr = new Plane(Point3D(0, -3, 0), Normal(0, 1, 0)); plane_ptr->set_material(matte_ptr2); add_object(plane_ptr); }
void load_scene5_lights(t_scene *scene) { scene->amb_intensity = 0.3; scene->amb_color = new_color(BLUE); add_light(scene, new_light(SPOT, 1, new_vector(-20, 15, 10), new_color(WHITE))); add_light(scene, new_light(DIR, 0.5, new_vector(0, -1, -1), new_color(WHITE))); }
void World::build(void) { int num_samples = 16; vp.set_hres(400); vp.set_vres(400); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(100, 0, 100); pinhole_ptr->set_lookat(0, 1, 0); pinhole_ptr->set_view_distance(8000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); PointLight* light_ptr = new PointLight; light_ptr->set_location(50, 50, 1); light_ptr->scale_radiance(3.0); add_light(light_ptr); Phong* phong_ptr = new Phong; phong_ptr->set_ka(0.25); phong_ptr->set_kd(0.8); phong_ptr->set_cd(0.75); phong_ptr->set_ks(0.15); phong_ptr->set_exp(50.0); Sphere* sphere_ptr = new Sphere; sphere_ptr->set_material(phong_ptr); add_object(sphere_ptr); }
void SDFloader::read(std::string file) { // delete eventually existing scene scene_.materials.clear(); scene_.shapes.clear(); scene_.cameras.clear(); scene_.lights.clear(); std::ifstream f; std::string s; f.open(file, std::ios::in); while (!f.eof()) { // Solange noch Daten vorliegen getline(f, s); // Lese eine Zeile std::istringstream iss(s); std::string sub; iss >> sub; if(sub == "define"){ iss >> sub; if(sub == "material") add_material(iss); else if(sub == "shape") add_shape(iss); else if(sub == "camera") add_camera(iss); else if(sub == "light") add_light(iss); } else if(sub == "transform")
void parse_caster(t_scene *scene, t_tds_block *block, t_sub_func sub_func, int type) { t_caster *caster; t_tds_var *var; caster = xmalloc(sizeof(t_caster)); var = block->var_list; init_caster(caster); while (var) { tds_bind(&caster->pos.x, var, TDS_TYPE_FLT64, "pos_x"); tds_bind(&caster->pos.y, var, TDS_TYPE_FLT64, "pos_y"); tds_bind(&caster->pos.z, var, TDS_TYPE_FLT64, "pos_z"); tds_bind(&caster->vec.x, var, TDS_TYPE_FLT64, "vec_x"); tds_bind(&caster->vec.y, var, TDS_TYPE_FLT64, "vec_y"); tds_bind(&caster->vec.z, var, TDS_TYPE_FLT64, "vec_z"); var = var->next; } if (sub_func) { sub_func(caster, block); add_light(scene, caster); } else scene->eye = caster; }
int place_light(int lx, int ly, int bright) { if (game[0].lightsourcing == 0) return 0; if (bright <= 0) return 0; add_light(lx, ly, bright, bright, 1); if (arena[0].need_actor_lit == 1) { int i; for (i = 0; i < NO_ACTORS; i ++) { if (actor[i].aclass == ACLASS_PLAYER && actor[i].lit == 0) { if (actor[i].x > lx - (bright * GRAIN) && actor[i].x < lx + (bright * GRAIN) && actor[i].y > ly - (bright * GRAIN) && actor[i].y < ly + (bright * GRAIN)) actor[i].lit = 10; } } } return 1; }
int place_dark(int lx, int ly, int bright) { if (bright <= 0) return 0; add_light(lx, ly, bright, bright, 0); return 1; }
static scene_t create_sphereflake_scene(int recursion_limit) { scene_t scene; Vec3 color; sphere_t* sphere; init_scene(&scene); add_light(&scene, 2, 5, 0, 0.92, 0.76, 0.771); add_light(&scene, -5, 3, -5, 0.96, 0.93, 0.88); int max_sphere_count = 2 + powl(6, recursion_limit + 2); scene.spheres = realloc(scene.spheres, max_sphere_count*sizeof(sphere_t)); if (!scene.spheres) { fprintf(stderr, "Failed to get memory for sphereflake. aborting.\n"); exit(-1); } // sphere = &(scene.spheres[0]); // set( sphere->org, -0.5, -1.0, 0 ); // sphere->rad = 0.75; // set( color, 0.85, 0.25, 0.25 ); // copy( sphere->color, color ); // sphere->shader = mirror_shader; /* center sphere is special, child inherent shader and color */ sphere = &(scene.spheres[0]); scene.sphere_count++; set(sphere->org, 0, -1, 0); sphere->rad = 0.75; set(color, 0.75, 0.75, 0.75); copy(sphere->color, color); sphere->shader = mirror_shader; recursive_add_sphereflake(&scene, 0, /* parent is the first sphere */ -1, /* -1 means no dir, make all children */ 1, /* next free sphere index */ 2, /* starting dir */ 0, /* starting recursion level */ recursion_limit); return scene; }
static void init_light(t_data *d) { t_light *l; l = add_light(NULL, VEC3(0, 0, 0), VEC3(0, 0, 0), RGB(50,50,50)); d->l = l; l->type = OMNI; l = add_light(l, VEC3(3, 1, 10), VEC3(0, 0, 0), CRED); l->type = SPOT; l = add_light(l, VEC3(-3, -1, 10), VEC3(0, 0, 0), CBLUE); l->type = SPOT; l = add_light(l, VEC3(-MAX_DIST, 0, 0), VEC3(1, 0, 0), CBLUE); l->type = DIR; l = add_light(l, VEC3(5, 1, 10), VEC3(0, 0, 1), CGREEN); l->type = SPOTLIGHT; }
static void light_add(Widget w, XtPointer data, XmAnyCallbackStruct *cbs) { extern void add_light(); if (light_count() > 8) { OOGLError(0, "Can't have more than 8 lights\n"); return; } add_light(); }
void clone_light(int object_id) { float z_pos,r,g,b; z_pos=lights_list[object_id]->pos_z; r=lights_list[object_id]->r; g=lights_list[object_id]->g; b=lights_list[object_id]->b; selected_light=add_light(scene_mouse_x,scene_mouse_y,z_pos,r,g,b,1.0f,lights_list[object_id]->locked); cur_tool=tool_select;//change the current tool }
void World::build(void){ int num_samples = 1; vp.set_hres(400); vp.set_vres(400); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 20); pinhole_ptr->set_lookat(0, 0, 0); pinhole_ptr->set_view_distance(3600); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr = new Directional; light_ptr->set_direction(-10, 20, 20); light_ptr->scale_radiance(3.0); light_ptr->set_shadows(false); add_light(light_ptr); int num_spheres = 1000; // for Figure 22.11(a) // int num_spheres = 10000; // for Figure 22.11(b) // int num_spheres = 100000; // for Figure 22.11(c) // int num_spheres = 1000000; // for Figure 22.11(d) float volume = 0.1 / num_spheres; float radius = pow(0.75 * volume / 3.14159, 0.333333); set_rand_seed(15); Grid* grid_ptr = new Grid; for (int j = 0; j < num_spheres; j++) { Matte* matte_ptr = new Matte; matte_ptr->set_ka(0.25); matte_ptr->set_kd(0.75); matte_ptr->set_cd(rand_float(), rand_float(), rand_float()); Sphere* sphere_ptr = new Sphere; sphere_ptr->set_radius(radius); sphere_ptr->set_center( 1.0 - 2.0 * rand_float(), 1.0 - 2.0 * rand_float(), 1.0 - 2.0 * rand_float()); sphere_ptr->set_material(matte_ptr); grid_ptr->add_object(sphere_ptr); } grid_ptr->setup_cells(); add_object(grid_ptr); }
void rt_light(void * tex, vector ctr, apiflt rad) { point_light * li; li=newlight(tex, (vector) ctr, rad); li->tex->islight=1; li->tex->shadowcast=1; li->tex->diffuse=0.0; li->tex->specular=0.0; li->tex->opacity=1.0; add_light(li); add_object((object *)li); }
void World::build(void) { int num_samples = 25; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(60, 40, 80); pinhole_ptr->set_lookat(0.0); pinhole_ptr->set_view_distance(12000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); PointLight* light_ptr = new PointLight; light_ptr->set_location(100, 100, 60); light_ptr->scale_radiance(3.0); light_ptr->set_shadows(true); add_light(light_ptr); SphereChecker* checker_ptr = new SphereChecker; checker_ptr->set_num_vertical_checkers(20); checker_ptr->set_num_horizontal_checkers(20); checker_ptr->set_vertical_line_width(0.15); checker_ptr->set_horizontal_line_width(0.04); checker_ptr->set_color1(white); checker_ptr->set_color2(white); checker_ptr->set_line_color(black); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.2); sv_matte_ptr->set_kd(0.6); sv_matte_ptr->set_cd(checker_ptr); Sphere* sphere_ptr = new Sphere; sphere_ptr->set_material(sv_matte_ptr); Instance* ellipsoid_ptr = new Instance(sphere_ptr); ellipsoid_ptr->scale(0.25, 2.5, 0.25); add_object(ellipsoid_ptr); }
void World::build(void) { int num_samples = 1; vp.set_hres(650); vp.set_vres(300); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 100); pinhole_ptr->set_lookat(0, 0, 0); pinhole_ptr->set_view_distance(6000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr2 = new Directional; light_ptr2->set_direction(20, 0, 20); light_ptr2->scale_radiance(3.0); add_light(light_ptr2); // beveled cylinder float bottom = -2.0; float top = 2.0; float radius = 1.0; float bevel_radius = 0.2; BeveledCylinder* cylinder_ptr1 = new BeveledCylinder(bottom, top, radius, bevel_radius); for (int j = 0; j < 4; j++) { Matte* matte_ptr = new Matte; matte_ptr->set_ka(0.25); matte_ptr->set_kd(0.1 + 0.3 * j); matte_ptr->set_cd(0.5); Instance* cylinder_ptr2 = new Instance(cylinder_ptr1); cylinder_ptr2->translate(-3.75 + 2.5 * j, 0, 0); cylinder_ptr2->set_material(matte_ptr); add_object(cylinder_ptr2); } }
void World::build(void) { int num_samples = 4; vp.set_hres(400); vp.set_vres(400); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); background_color = black; Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 40, 100); //pinhole_ptr->set_lookat(-0.5, 0, 0); //for golden-fish; pinhole_ptr->set_lookat(-2, 8, 0); //for bunny; pinhole_ptr->set_view_distance(1600); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* directional_ptr = new Directional; directional_ptr->set_direction(0.75, 0.5, -0.15); directional_ptr->scale_radiance(2.0); directional_ptr->set_shadows(true); add_light(directional_ptr); Phong* phong_ptr1 = new Phong; phong_ptr1->set_ka(0.4); phong_ptr1->set_kd(0.8); phong_ptr1->set_cd(1.0, 0.2, 0.0); phong_ptr1->set_ks(0.5); phong_ptr1->set_cs(1.0, 1.0, 0.0); phong_ptr1->set_exp(50.0); char* file_name = "c:\\bunny.ply"; // const char* file_name = "goldfish_high_res.ply"; Grid* grid_ptr = new Grid(new Mesh); // grid_ptr->read_flat_triangles(file_name); grid_ptr->read_smooth_triangles(file_name); grid_ptr->set_material(phong_ptr1); grid_ptr->setup_cells(); add_object(grid_ptr); }
light_patch *make_patch_list(int width, int height, int32_t screenx, int32_t screeny) { light_patch *first=new light_patch(0,0,width-1,height-1,NULL); for (light_source *f=first_light_source; f; f=f->next) // determine which lights will have effect { int32_t x1=f->x1-screenx,y1=f->y1-screeny, x2=f->x2-screenx,y2=f->y2-screeny; if (x1<0) x1=0; if (y1<0) y1=0; if (x2>=width) x2=width-1; if (y2>=height) y2=height-1; if (x1<=x2 && y1<=y2) add_light(first,x1,y1,x2,y2,f); } reduce_patches(first); return first; }
void World::build(void) { int num_samples = 16; vp.set_hres(400); vp.set_vres(400); vp.set_samples(num_samples); vp.set_max_depth(0); background_color = RGBColor(0.5); tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(2, 3.5, 5); pinhole_ptr->set_lookat(0,0,0); pinhole_ptr->set_view_distance(800.0); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr = new Directional; light_ptr->set_direction(14, 20, 25); light_ptr->scale_radiance(1.75); light_ptr->set_shadows(true); add_light(light_ptr); Image* image_ptr = new Image; image_ptr->read_ppm_file("F:/Documents/Visual Studio 2005/Projects/Rytracer/TextureFiles/ppm/CountryScene.ppm"); CylindricalMap* map_ptr = new CylindricalMap; ImageTexture* texture_ptr = new ImageTexture(image_ptr); texture_ptr->set_mapping(map_ptr); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.40); sv_matte_ptr->set_kd(0.95); sv_matte_ptr->set_cd(texture_ptr); OpenCylinder* cylinder_ptr = new OpenCylinder; cylinder_ptr->set_material(sv_matte_ptr); add_object(cylinder_ptr); }
void World::build(void) { int num_samples = 64; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); tracer_ptr = new AreaLighting(this); background_color = RGBColor(0.5,0.5,0.5); AmbientOccluder* ambient_occluder_ptr = new AmbientOccluder; ambient_occluder_ptr->set_sampler(new MultiJittered(num_samples)); ambient_occluder_ptr->set_min_amount(0.5); set_ambient_light(ambient_occluder_ptr); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(100, 45, 100); pinhole_ptr->set_lookat(-10, 40, 0); pinhole_ptr->set_view_distance(400); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr3 = new Directional; light_ptr3->set_direction(150, 50, -50); light_ptr3->scale_radiance(4.0); light_ptr3->set_color(1.0, 0.25, 0.0); // orange light_ptr3->set_shadows(true); add_light(light_ptr3); Emissive* emissive_ptr = new Emissive; emissive_ptr->scale_radiance(0.90); emissive_ptr->set_ce(1.0, 1.0, 0.5); // yellow //ConcaveSphere* sphere_ptr = new ConcaveSphere; //sphere_ptr->set_radius(1000000.0); //sphere_ptr->set_material(emissive_ptr); //sphere_ptr->set_shadows(false); //add_object(sphere_ptr); EnvironmentLight* environment_light_ptr = new EnvironmentLight; environment_light_ptr->set_material(emissive_ptr); environment_light_ptr->set_sampler(new MultiJittered(num_samples)); environment_light_ptr->set_shadows(true); add_light(environment_light_ptr); float ka = 0.2; // commom ambient reflection coefficient // large sphere Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(ka); matte_ptr1->set_kd(0.60); matte_ptr1->set_cd(0.75); Sphere* sphere_ptr1 = new Sphere(Point3D(38, 20, -24), 20); sphere_ptr1->set_material(matte_ptr1); add_object(sphere_ptr1); // small sphere Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(ka); matte_ptr2->set_kd(0.5); matte_ptr2->set_cd(0.85); Sphere* sphere_ptr2 = new Sphere(Point3D(34, 12, 13), 12); sphere_ptr2->set_material(matte_ptr2); add_object(sphere_ptr2); // medium sphere Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(ka); matte_ptr3->set_kd(0.5); matte_ptr3->set_cd(0.75); Sphere* sphere_ptr3 = new Sphere(Point3D(-7, 15, 42), 16); sphere_ptr3->set_material(matte_ptr3); add_object(sphere_ptr3); // cylinder // //Matte* matte_ptr4 = new Matte; //matte_ptr4->set_ka(ka); //matte_ptr4->set_kd(0.5); //matte_ptr4->set_cd(0.60); // //float bottom = 0.0; //float top = 85; //float radius = 22; //SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius); //cylinder_ptr->set_material(matte_ptr4); //add_object(cylinder_ptr); // cylinder Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(ka); matte_ptr4->set_kd(0.5); matte_ptr4->set_cd(0.60); float bottom = 0.0; float top = 85; float radius = 22; SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius); cylinder_ptr->set_material(matte_ptr4); add_object(cylinder_ptr); // box Matte* matte_ptr5 = new Matte; matte_ptr5->set_ka(ka); matte_ptr5->set_kd(0.5); matte_ptr5->set_cd(0.95); Box* box_ptr = new Box(Point3D(-35, 0, -110), Point3D(-25, 60, 65)); box_ptr->set_material(matte_ptr5); add_object(box_ptr); // ground plane Matte* matte_ptr6 = new Matte; matte_ptr6->set_ka(0.15); matte_ptr6->set_kd(0.5); matte_ptr6->set_cd(0.7); Plane* plane_ptr = new Plane(Point3D(0, 0.01, 0), Normal(0, 1, 0)); plane_ptr->set_material(matte_ptr6); add_object(plane_ptr); }
//@builds the world of objects and background color, // lights, and camera with depth of reflections //@post objects and lights now exist in the world with camera and associated viewplane assigned //@usage world_ptr -> build(); void World::build(void) { background_color = black; depth = 4; // levels of reflection. 0 for no reflections. camera_ptr = new Camera(); camera_ptr -> loc = Vector3D(3,15,6); camera_ptr -> v = Vector3D(0,1,-5); camera_ptr -> n = Vector3D(0,.3,1); camera_ptr -> calculateUVN(camera_ptr -> n, camera_ptr -> v); camera_ptr -> u = Vector3D(1,0,-10); camera_ptr -> calculateUVN(camera_ptr -> n, camera_ptr -> u); Sphere* sphere_ptr = new Sphere; sphere_ptr -> set_center(-3, 1, -45); sphere_ptr -> set_radius(2.0); Material* mat_ptr = new Material(); mat_ptr -> kr = .8; mat_ptr -> setAllColor(1,0,0); // red sphere_ptr -> set_material(mat_ptr); add_object(sphere_ptr); sphere_ptr = new Sphere(Vector3D(6, 3, -45), 2); sphere_ptr -> set_radius(1.0); mat_ptr = new Material(); mat_ptr -> kr = .6; mat_ptr -> setAllColor(0,1,1); // teal sphere_ptr -> set_material(mat_ptr); add_object(sphere_ptr); sphere_ptr = new Sphere(Vector3D(2, -1, -35), 2); mat_ptr = new Material(); mat_ptr -> kr = 0; mat_ptr -> setAllColor(0,1,0); // green sphere_ptr -> set_material(mat_ptr); add_object(sphere_ptr); Cube new_cube(5, .5, -60); Square* array_of_squares[6]; new_cube.populate_squares(array_of_squares); for (int i = 0; i < 6; i++) { add_object(array_of_squares[i]); } Plane* plane_ptr = new Plane(Vector3D(0, -2, 0), Vector3D(0, 1, 0)); mat_ptr = new Material(); mat_ptr -> kr = .8; mat_ptr -> setAllColor(1, 1, 1); // green plane_ptr -> set_material(mat_ptr); add_object(plane_ptr); CheckeredPlane* pattern_pointer = new CheckeredPlane(Vector3D(0, -1.9999, 0), Vector3D(0, 1, 0)); mat_ptr = new Material(); mat_ptr -> kr = .4; mat_ptr -> setAllColor(1, 0, 1); // green pattern_pointer -> set_material(mat_ptr); add_object(pattern_pointer); PointLight* light_ptr = new PointLight(); light_ptr -> set_color(1,1,1); light_ptr -> set_intensity(1); light_ptr -> set_location(100,40,10); add_light(light_ptr); }
int load_map (const char* file_name) { int i; map_header cur_map_header; char* mem_map_header=(char *)&cur_map_header; #if defined CLUSTER_INSIDES || defined NEW_LIGHT_FORMAT unsigned char version; #endif object3d_io cur_3d_obj_io; int obj_3d_no=0; int obj_3d_io_size; obj_2d_io cur_2d_obj_io; int obj_2d_no=0; int obj_2d_io_size; light_io cur_light_io; int lights_no=0; int lights_io_size; particles_io cur_particles_io; int particles_no=0; int particles_io_size; #ifdef ZLIB gzFile f = NULL; f= my_gzopen(file_name, "rb"); #else //ZLIB FILE *f = NULL; f= fopen(file_name, "rb"); #endif //ZLIB if(!f)return 0; #ifdef ZLIB gzread(f, mem_map_header, sizeof(cur_map_header));//header only #else //ZLIB fread(mem_map_header, 1, sizeof(cur_map_header), f);//header only #endif //ZLIB //verify if we have a valid file if(cur_map_header.file_sig[0]!='e')return 0; if(cur_map_header.file_sig[1]!='l')return 0; if(cur_map_header.file_sig[2]!='m')return 0; if(cur_map_header.file_sig[3]!='f')return 0; destroy_map();//Only destroy the map now.... //get the map size tile_map_size_x=cur_map_header.tile_map_x_len; tile_map_size_y=cur_map_header.tile_map_y_len; //allocate memory for the tile map (it was destroyed) tile_map=(unsigned char *)calloc(tile_map_size_x*tile_map_size_y, 1); //allocates the memory for the heights now height_map=(unsigned char *)calloc(tile_map_size_x*tile_map_size_y*6*6, 1); //get the sizes of structures (they might change in the future) obj_3d_io_size=cur_map_header.obj_3d_struct_len; obj_2d_io_size=cur_map_header.obj_2d_struct_len; lights_io_size=cur_map_header.lights_struct_len; particles_io_size=cur_map_header.particles_struct_len; //get the number of objects and lights obj_3d_no=cur_map_header.obj_3d_no; obj_2d_no=cur_map_header.obj_2d_no; lights_no=cur_map_header.lights_no; particles_no=cur_map_header.particles_no; //get the type of map, and the ambient light dungeon=cur_map_header.dungeon; #if defined CLUSTER_INSIDES || defined NEW_LIGHT_FORMAT version = cur_map_header.version; #endif ambient_r=cur_map_header.ambient_r; ambient_g=cur_map_header.ambient_g; ambient_b=cur_map_header.ambient_b; //this is useful if we go in/out a dungeon new_minute(); //read the tiles map #ifdef ZLIB gzread(f, tile_map, tile_map_size_x*tile_map_size_y); #else //ZLIB fread(tile_map, 1, tile_map_size_x*tile_map_size_y, f); #endif //ZLIB //load the tiles in this map, if not already loaded load_map_tiles(); //read the heights map #ifdef ZLIB gzread(f, height_map, tile_map_size_x*tile_map_size_y*6*6); #else //ZLIB fread(height_map, 1, tile_map_size_x*tile_map_size_y*6*6, f); #endif //ZLIB //read the 3d objects for(i=0; i < obj_3d_no; i++) { char *cur_3do_pointer = (char *)&cur_3d_obj_io; #ifdef ZLIB gzread (f, cur_3do_pointer, obj_3d_io_size); #else //ZLIB fread (cur_3do_pointer, 1, obj_3d_io_size, f); #endif //ZLIB add_e3d_keep_deleted (cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos, cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot, cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended, cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b); } //read the 2d objects for(i=0;i<obj_2d_no;i++) { char * cur_2do_pointer=(char *)&cur_2d_obj_io; #ifdef ZLIB gzread(f, cur_2do_pointer, obj_2d_io_size); #else //ZLIB fread(cur_2do_pointer, 1, obj_2d_io_size, f); #endif //ZLIB add_2d_obj(cur_2d_obj_io.file_name,cur_2d_obj_io.x_pos,cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos,cur_2d_obj_io.x_rot,cur_2d_obj_io.y_rot,cur_2d_obj_io.z_rot); } //read the lights for (i = 0; i < lights_no; i++) { char* cur_light_pointer = (char *)&cur_light_io; #ifdef ZLIB gzread(f, cur_light_pointer, lights_io_size); #else //ZLIB fread(cur_light_pointer, 1, lights_io_size, f); #endif //ZLIB #ifdef NEW_LIGHT_FORMAT if (version == 0) { // Old map format, insert default values for // extended light parameters cur_light_io.spec_r = 255; cur_light_io.spec_g = 255; cur_light_io.spec_b = 255; cur_light_io.light_dir_z_sign = 0; cur_light_io.quadric_attenuation = 0; cur_light_io.range = 0; cur_light_io.cutoff = -32768; cur_light_io.exponent = 0; cur_light_io.light_dir_x = 0; cur_light_io.light_dir_y = 0; } #endif // NEW_LIGHT_FORMAT add_light (cur_light_io.pos_x, cur_light_io.pos_y, cur_light_io.pos_z, cur_light_io.r, cur_light_io.g, cur_light_io.b, 1.0f, 0); } //read particle systems for(i=0;i<particles_no;i++) { char *cur_particles_pointer=(char *)&cur_particles_io; #ifdef ZLIB gzread(f, cur_particles_pointer,particles_io_size); #else //ZLIB fread(cur_particles_pointer,1,particles_io_size,f); #endif //ZLIB if (!strncmp(cur_particles_io.file_name, "ec://", 5)) { #ifdef EYE_CANDY printf("Deserializing eye candy.\n"); deserialize_eye_candy_effect(&cur_particles_io); #else LOG_ERROR("Map contains eye candy effect, but map editor is compiled without eye candy support"); #endif } else { add_particle_sys(cur_particles_io.file_name,cur_particles_io.x_pos,cur_particles_io.y_pos,cur_particles_io.z_pos); if(particles_list[i]) particles_list[i]->ttl=-1;//Fail-safe if things f**k up... } } #ifdef ZLIB gzclose(f); #else //ZLIB fclose(f); #endif //ZLIB return 1; }
void World::build(void) { int num_samples = 1; // view plane vp.set_hres(400); vp.set_vres(400); vp.set_pixel_size(0.5); vp.set_samples(num_samples); // the ambient light here is the same as the default set in the World // constructor, and can therefore be left out Ambient* ambient_ptr = new Ambient; ambient_ptr->scale_radiance(1.0); set_ambient_light(ambient_ptr); background_color = black; // default color - this can be left out tracer_ptr = new RayCast(this); // camera Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 500); pinhole_ptr->set_lookat(0.0); pinhole_ptr->set_view_distance(600.0); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); // light Directional* light_ptr1 = new Directional; light_ptr1->set_direction(100, 100, 200); light_ptr1->scale_radiance(3.0); add_light(light_ptr1); // colors RGBColor yellow(1, 1, 0); // yellow RGBColor brown(0.71, 0.40, 0.16); // brown RGBColor darkGreen(0.0, 0.41, 0.41); // darkGreen RGBColor orange(1, 0.75, 0); // orange RGBColor green(0, 0.6, 0.3); // green RGBColor lightGreen(0.65, 1, 0.30); // light green RGBColor darkYellow(0.61, 0.61, 0); // dark yellow RGBColor lightPurple(0.65, 0.3, 1); // light purple RGBColor darkPurple(0.5, 0, 1); // dark purple RGBColor grey(0.25); // grey // Matte material reflection coefficients - common to all materials float ka = 0.25; float kd = 0.75; // spheres Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(ka); matte_ptr1->set_kd(kd); matte_ptr1->set_cd(yellow); Sphere* sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); sphere_ptr1->set_material(matte_ptr1); // yellow add_object(sphere_ptr1); Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(ka); matte_ptr2->set_kd(kd); matte_ptr2->set_cd(brown); Sphere* sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); sphere_ptr2->set_material(matte_ptr2); // brown add_object(sphere_ptr2); Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(ka); matte_ptr3->set_kd(kd); matte_ptr3->set_cd(darkGreen); Sphere* sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); sphere_ptr3->set_material(matte_ptr3); // dark green add_object(sphere_ptr3); Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(ka); matte_ptr4->set_kd(kd); matte_ptr4->set_cd(orange); Sphere* sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); sphere_ptr4->set_material(matte_ptr4); // orange add_object(sphere_ptr4); Matte* matte_ptr5 = new Matte; matte_ptr5->set_ka(ka); matte_ptr5->set_kd(kd); matte_ptr5->set_cd(green); Sphere* sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); sphere_ptr5->set_material(matte_ptr5); // green add_object(sphere_ptr5); Matte* matte_ptr6 = new Matte; matte_ptr6->set_ka(ka); matte_ptr6->set_kd(kd); matte_ptr6->set_cd(lightGreen); Sphere* sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); sphere_ptr6->set_material(matte_ptr6); // light green add_object(sphere_ptr6); Matte* matte_ptr7 = new Matte; matte_ptr7->set_ka(ka); matte_ptr7->set_kd(kd); matte_ptr7->set_cd(green); Sphere* sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); sphere_ptr7->set_material(matte_ptr7); // green add_object(sphere_ptr7); Matte* matte_ptr8 = new Matte; matte_ptr8->set_ka(ka); matte_ptr8->set_kd(kd); matte_ptr8->set_cd(brown); Sphere* sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15); sphere_ptr8->set_material(matte_ptr8); // brown add_object(sphere_ptr8); Matte* matte_ptr9 = new Matte; matte_ptr9->set_ka(ka); matte_ptr9->set_kd(kd); matte_ptr9->set_cd(lightGreen); Sphere* sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); sphere_ptr9->set_material(matte_ptr9); // light green add_object(sphere_ptr9); Matte* matte_ptr10 = new Matte; matte_ptr10->set_ka(ka); matte_ptr10->set_kd(kd); matte_ptr10->set_cd(darkGreen); Sphere* sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); sphere_ptr10->set_material(matte_ptr10); // dark green add_object(sphere_ptr10); Matte* matte_ptr11 = new Matte; matte_ptr11->set_ka(ka); matte_ptr11->set_kd(kd); matte_ptr11->set_cd(darkYellow); Sphere* sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); sphere_ptr11->set_material(matte_ptr11); // dark yellow add_object(sphere_ptr11); Matte* matte_ptr12 = new Matte; matte_ptr12->set_ka(ka); matte_ptr12->set_kd(kd); matte_ptr12->set_cd(darkYellow); Sphere* sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); sphere_ptr12->set_material(matte_ptr12); // dark yellow add_object(sphere_ptr12); Matte* matte_ptr13 = new Matte; matte_ptr13->set_ka(ka); matte_ptr13->set_kd(kd); matte_ptr13->set_cd(darkYellow); Sphere* sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); sphere_ptr13->set_material(matte_ptr13); add_object(sphere_ptr13); // dark yellow (hidden) Matte* matte_ptr14 = new Matte; matte_ptr14->set_ka(ka); matte_ptr14->set_kd(kd); matte_ptr14->set_cd(darkGreen); Sphere* sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); sphere_ptr14->set_material(matte_ptr14); // dark green add_object(sphere_ptr14); Matte* matte_ptr15 = new Matte; matte_ptr15->set_ka(ka); matte_ptr15->set_kd(kd); matte_ptr15->set_cd(brown); Sphere* sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); sphere_ptr15->set_material(matte_ptr15); // brown add_object(sphere_ptr15); Matte* matte_ptr16 = new Matte; matte_ptr16->set_ka(ka); matte_ptr16->set_kd(kd); matte_ptr16->set_cd(lightPurple); Sphere* sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); sphere_ptr16->set_material(matte_ptr16); // light purple add_object(sphere_ptr16); Matte* matte_ptr17 = new Matte; matte_ptr17->set_ka(ka); matte_ptr17->set_kd(kd); matte_ptr17->set_cd(brown); Sphere* sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); sphere_ptr17->set_material(matte_ptr17); // browm add_object(sphere_ptr17); Matte* matte_ptr18 = new Matte; matte_ptr18->set_ka(ka); matte_ptr18->set_kd(kd); matte_ptr18->set_cd(darkPurple); Sphere* sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); sphere_ptr18->set_material(matte_ptr18); // dark purple add_object(sphere_ptr18); Matte* matte_ptr19 = new Matte; matte_ptr19->set_ka(ka); matte_ptr19->set_kd(kd); matte_ptr19->set_cd(darkGreen); Sphere* sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); sphere_ptr19->set_material(matte_ptr19); // dark green add_object(sphere_ptr19); Matte* matte_ptr20 = new Matte; matte_ptr20->set_ka(ka); matte_ptr20->set_kd(kd); matte_ptr20->set_cd(brown); Sphere* sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); sphere_ptr20->set_material(matte_ptr20); // browm add_object(sphere_ptr20); Matte* matte_ptr21 = new Matte; matte_ptr21->set_ka(ka); matte_ptr21->set_kd(kd); matte_ptr21->set_cd(lightPurple); Sphere* sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); sphere_ptr21->set_material(matte_ptr21); // light purple add_object(sphere_ptr21); Matte* matte_ptr22 = new Matte; matte_ptr22->set_ka(ka); matte_ptr22->set_kd(kd); matte_ptr22->set_cd(lightPurple); Sphere* sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); sphere_ptr22->set_material(matte_ptr22); // light purple add_object(sphere_ptr22); Matte* matte_ptr23 = new Matte; matte_ptr23->set_ka(ka); matte_ptr23->set_kd(kd); matte_ptr23->set_cd(darkPurple); Sphere* sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); sphere_ptr23->set_material(matte_ptr23); // dark purple add_object(sphere_ptr23); Matte* matte_ptr24 = new Matte; matte_ptr24->set_ka(ka); matte_ptr24->set_kd(kd); matte_ptr24->set_cd(lightPurple); Sphere* sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); sphere_ptr24->set_material(matte_ptr24); // light purple add_object(sphere_ptr24); Matte* matte_ptr25 = new Matte; matte_ptr25->set_ka(ka); matte_ptr25->set_kd(kd); matte_ptr25->set_cd(green); Sphere* sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); sphere_ptr25->set_material(matte_ptr25); // green add_object(sphere_ptr25); Matte* matte_ptr26 = new Matte; matte_ptr26->set_ka(ka); matte_ptr26->set_kd(kd); matte_ptr26->set_cd(lightPurple); Sphere* sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); sphere_ptr26->set_material(matte_ptr26); // light purple add_object(sphere_ptr26); Matte* matte_ptr27 = new Matte; matte_ptr27->set_ka(ka); matte_ptr27->set_kd(kd); matte_ptr27->set_cd(lightPurple); Sphere* sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); sphere_ptr27->set_material(matte_ptr27); // light purple add_object(sphere_ptr27); Matte* matte_ptr28 = new Matte; matte_ptr28->set_ka(ka); matte_ptr28->set_kd(kd); matte_ptr28->set_cd(darkPurple); Sphere* sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); sphere_ptr28->set_material(matte_ptr28); // dark purple add_object(sphere_ptr28); Matte* matte_ptr29 = new Matte; matte_ptr29->set_ka(ka); matte_ptr29->set_kd(kd); matte_ptr29->set_cd(darkPurple); Sphere* sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); sphere_ptr29->set_material(matte_ptr29); // dark purple add_object(sphere_ptr29); Matte* matte_ptr30 = new Matte; matte_ptr30->set_ka(ka); matte_ptr30->set_kd(kd); matte_ptr30->set_cd(darkPurple); Sphere* sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15); sphere_ptr30->set_material(matte_ptr30); // dark purple add_object(sphere_ptr30); Matte* matte_ptr31 = new Matte; matte_ptr31->set_ka(ka); matte_ptr31->set_kd(kd); matte_ptr31->set_cd(lightPurple); Sphere* sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); sphere_ptr31->set_material(matte_ptr31); // light purple add_object(sphere_ptr31); Matte* matte_ptr32 = new Matte; matte_ptr32->set_ka(ka); matte_ptr32->set_kd(kd); matte_ptr32->set_cd(green); Sphere* sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11); sphere_ptr32->set_material(matte_ptr32); // green add_object(sphere_ptr32); Matte* matte_ptr33 = new Matte; matte_ptr33->set_ka(ka); matte_ptr33->set_kd(kd); matte_ptr33->set_cd(green); Sphere* sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); sphere_ptr33->set_material(matte_ptr33); // green add_object(sphere_ptr33); Matte* matte_ptr34 = new Matte; matte_ptr34->set_ka(ka); matte_ptr34->set_kd(kd); matte_ptr34->set_cd(lightPurple); Sphere* sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); sphere_ptr34->set_material(matte_ptr34); // light purple add_object(sphere_ptr34); Matte* matte_ptr35 = new Matte; matte_ptr35->set_ka(ka); matte_ptr35->set_kd(kd); matte_ptr35->set_cd(lightPurple); Sphere* sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); sphere_ptr35->set_material(matte_ptr35); // light purple add_object(sphere_ptr35); // vertical plane Matte* matte_ptr36 = new Matte; matte_ptr36->set_ka(ka); matte_ptr36->set_kd(kd); matte_ptr36->set_cd(grey); Plane* plane_ptr = new Plane(Point3D(0, 0, -150), Normal(0, 0, 1)); plane_ptr->set_material(matte_ptr36); add_object (plane_ptr); }
void update_game(Game* G) { float delta_time = (float)get_delta_time(G->timer); int ii; _control_camera(G, delta_time); set_view_matrix(G->graphics, mat4_inverse(transform_get_matrix(G->camera))); /* Dynamic Lights */ if(G->dynamic_lights) { G->sun_light.position = mat3_mul_vector(vec3_create(5,5,0), mat3_rotation_y((float)get_running_time(G->timer)*0.5f)); G->light_transform += delta_time; for(ii=0;ii<NUM_LIGHTS;++ii) { if(ii % 2) G->lights[ii].position.z = sinf((G->light_transform + ii * 1.0f)/2.0f) * 10.0f; else G->lights[ii].position.x = sinf((G->light_transform + ii * 1.0f)/2.0f) * 10.0f; } } add_light(G->graphics, G->sun_light); for(ii=0;ii<NUM_LIGHTS;++ii) { add_light(G->graphics, G->lights[ii]); } render_scene(G->scene, G->graphics); G->tap_timer += delta_time; /* Calculate FPS */ G->fps_time += delta_time; G->fps_count++; if(G->fps_time >= 1.0f) { G->fps = G->fps_count/G->fps_time; system_log("FPS: %f\n", G->fps); G->fps_time -= 1.0f; G->fps_count = 0; } { int width, height; float scale = 50.0f; float x = -G->width/2.0f; float y = G->height/2.0f-scale; char buffer[256] = {0}; // FPS sprintf(buffer, "FPS: %.2f", G->fps); add_string(G->ui, x, y, scale, buffer); y -= scale; // Renderer switch(renderer_type(G->graphics)) { case kForward: add_string(G->ui, x, y, scale, "Forward renderer"); break; case kLightPrePass: add_string(G->ui, x, y, scale, "Deferred Lighting"); break; case kDeferred: add_string(G->ui, x, y, scale, "Deferred Shading"); break; default: assert(!"Invalid renderer"); break; } y -= scale; // Resolution graphics_size(G->graphics, &width, &height); sprintf(buffer, "%dx%d", width, height); add_string(G->ui, x, y, scale, buffer); } }
void World::build(void) { int num_samples = 4; // at max_depth = 10, this renders very slowly vp.set_hres(600); vp.set_vres(600); vp.set_max_depth(10); vp.set_samples(num_samples); Ambient* ambient_ptr = new Ambient; ambient_ptr->scale_radiance(0.25); set_ambient_light(ambient_ptr); background_color = RGBColor(0.0, 0.3, 0.25); tracer_ptr = new Whitted(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(1, 7.5, 20); pinhole_ptr->set_lookat(0, -0.35, 0); pinhole_ptr->set_view_distance(5250.0); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); PointLight* light_ptr = new PointLight; light_ptr->set_location(20, 20, 15); light_ptr->scale_radiance(2.75); light_ptr->set_shadows(true); add_light(light_ptr); // transparent bowl Transparent* glass_ptr = new Transparent; glass_ptr->set_ks(0.5); glass_ptr->set_exp(2000.0); glass_ptr->set_ior(1.5); glass_ptr->set_kr(0.05); glass_ptr->set_kt(0.9); double inner_radius = 0.9; double outer_radius = 1.0; //FlatRimmedBowl* bowl_ptr = new FlatRimmedBowl(inner_radius, outer_radius); //bowl_ptr->set_material(glass_ptr); //add_object(bowl_ptr); RoundRimmedBowl* bowl_ptr = new RoundRimmedBowl(inner_radius, outer_radius, Point3D(0)); bowl_ptr->set_material(glass_ptr); add_object(bowl_ptr); // the two spheres in the bowl just touch its inner surface // red sphere /*Reflective* reflective_ptr1 = new Reflective; reflective_ptr1->set_ka(0.6); reflective_ptr1->set_kd(0.4); reflective_ptr1->set_cd(red); reflective_ptr1->set_ks(0.5); reflective_ptr1->set_exp(2000.0); reflective_ptr1->set_kr(0.25); double radius = 0.4; double theta = 55.0; theta = 3.1415926 * theta / 180.0; double xc = -(0.9 - radius) * cos(theta); double yc = -(0.9 - radius) * sin(theta); Sphere* sphere_ptr2 = new Sphere(Point3D(xc, yc, 0), radius); sphere_ptr2->set_material(reflective_ptr1); add_object(sphere_ptr2); // yellow sphere Reflective* reflective_ptr2 = new Reflective; reflective_ptr2->set_ka(0.6); reflective_ptr2->set_kd(0.4); reflective_ptr2->set_cd(1, 1, 0); // yellow reflective_ptr2->set_ks(0.5); reflective_ptr2->set_exp(2000.0); reflective_ptr2->set_kr(0.5); radius = 0.35; theta = 35.0; theta = 3.1415926 * theta / 180.0; xc = (0.9 - radius) * cos(theta); yc = -(0.9 - radius) * sin(theta); Sphere* sphere_ptr3 = new Sphere(Point3D(xc, yc, 0), radius); sphere_ptr3->set_material(reflective_ptr2); add_object(sphere_ptr3); */ // rectangle Checker3D* checker_ptr = new Checker3D; checker_ptr->set_size(1.0); checker_ptr->set_color1(white); checker_ptr->set_color2(0.5); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.8); sv_matte_ptr->set_kd(0.85); sv_matte_ptr->set_cd(checker_ptr); Point3D p0(-2, -1, -5); Vector3D a(0, 0, 9); Vector3D b(4, 0, 0); Rectangle* rectangle_ptr = new Rectangle(p0, a, b); rectangle_ptr->set_material(sv_matte_ptr); add_object(rectangle_ptr); }
//28.5 折射测试图,同16,不同可能是加入了菲涅尔系数变化 void World::build(void){ int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(5); background_color = RGBColor(0.0, 0.3, 0.25); tracer_ptr = new Whitted(this); Ambient* ambient_ptr = new Ambient; ambient_ptr->scale_radiance(0.25); set_ambient_light(ambient_ptr); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(-8, 5.5, 40); pinhole_ptr->set_lookat(1, 4, 0); pinhole_ptr->set_view_distance(2400.0); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); // point light PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(40, 50, 0); light_ptr1->scale_radiance(4.5); light_ptr1->set_shadows(true); add_light(light_ptr1); // point light PointLight* light_ptr2 = new PointLight; light_ptr2->set_location(-10, 20, 10); light_ptr2->scale_radiance(4.5); light_ptr2->set_shadows(true); add_light(light_ptr2); // directional light Directional* light_ptr3 = new Directional; light_ptr3->set_direction(-1, 0, 0); light_ptr3->scale_radiance(4.5); light_ptr3->set_shadows(true); add_light(light_ptr3); // transparent sphere Dielectric* dielectic_ptr = new Dielectric; dielectic_ptr->set_ks(0.2); dielectic_ptr->set_exp(2000.0); // dielectic_ptr->set_eta_in(1.5); // for Figure 28.5(a) dielectic_ptr->set_eta_in(0.75); // for Figure 28.5(b) dielectic_ptr->set_eta_out(1.0); dielectic_ptr->set_cf_in(white); dielectic_ptr->set_cf_out(white); Sphere* sphere_ptr1 = new Sphere(Point3D(0.0, 4.5, 0.0), 3.0); sphere_ptr1->set_material(dielectic_ptr); add_object(sphere_ptr1); // red sphere Reflective* reflective_ptr = new Reflective; reflective_ptr->set_ka(0.3); reflective_ptr->set_kd(0.3); reflective_ptr->set_cd(red); reflective_ptr->set_ks(0.2); reflective_ptr->set_exp(2000.0); reflective_ptr->set_kr(0.25); Sphere* sphere_ptr2 = new Sphere(Point3D(4, 4, -6), 3); sphere_ptr2->set_material(reflective_ptr); add_object(sphere_ptr2); Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(0.15); matte_ptr3->set_kd(0.5); matte_ptr3->set_cd(0, 0.4, 0.2); // dark green // rectangle Point3D p0(-20, 0, -100); Vector3D a(0, 0, 120); Vector3D b(40, 0, 0); Rectangle* rectangle_ptr = new Rectangle(p0, a, b); rectangle_ptr->set_material(matte_ptr3); add_object(rectangle_ptr); }
void World::build(void) { int num_samples = 100; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(19); tracer_ptr = new AreaLighting(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(7.5, 3, 9.5); pinhole_ptr->set_lookat(5, 2.5, 0); pinhole_ptr->set_view_distance(800); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); // four point lights near the ceiling // these don't use distance attenuation PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(10, 10, 0); light_ptr1->scale_radiance(2.0); light_ptr1->set_shadows(true); add_light(light_ptr1); PointLight* light_ptr2 = new PointLight; light_ptr2->set_location(0, 10, 10); light_ptr2->scale_radiance(2.0); light_ptr2->set_shadows(true); add_light(light_ptr2); PointLight* light_ptr3 = new PointLight; light_ptr3->set_location(-10, 10, 0); light_ptr3->scale_radiance(2.0); light_ptr3->set_shadows(true); add_light(light_ptr3); PointLight* light_ptr4 = new PointLight; light_ptr4->set_location(0, 10, -10); light_ptr4->scale_radiance(2.0); light_ptr4->set_shadows(true); add_light(light_ptr4); // sphere // this is the only reflective object with a direct illumination shading component Reflective* reflective_ptr1 = new Reflective; reflective_ptr1->set_ka(0.1); reflective_ptr1->set_kd(0.4); reflective_ptr1->set_cd(0, 0, 1); // blue reflective_ptr1->set_ks(0.25); reflective_ptr1->set_exp(100.0); reflective_ptr1->set_kr(0.85); reflective_ptr1->set_cr(0.75, 0.75, 1); // blue Sphere* sphere_ptr1 = new Sphere(Point3D(0, 0.5, 0), 4); sphere_ptr1->set_material(reflective_ptr1); add_object(sphere_ptr1); // the walls, the ceiling, and the floor of the room are defined as planes // the shape is a cube double room_size = 11.0; // floor (-ve yw) Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(0.1); matte_ptr1->set_kd(0.50); matte_ptr1->set_cd(0.25); // medium grey Plane* floor_ptr = new Plane(Point3D(0, -room_size, 0), Normal(0, 1, 0)); floor_ptr->set_material(matte_ptr1); add_object(floor_ptr); // ceiling (+ve yw) Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(0.35); matte_ptr2->set_kd(0.50); matte_ptr2->set_cd(white); Plane* ceiling_ptr = new Plane(Point3D(0, room_size, 0), Normal(0, -1, 0)); ceiling_ptr->set_material(matte_ptr2); add_object(ceiling_ptr); // back wall (-ve zw) Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(0.15); matte_ptr3->set_kd(0.60); matte_ptr3->set_cd(0.5, 0.75, 0.75); // cyan Plane* backWall_ptr = new Plane(Point3D(0, 0, -room_size), Normal(0, 0, 1)); backWall_ptr->set_material(matte_ptr3); add_object(backWall_ptr); // front wall (+ve zw) Plane* frontWall_ptr = new Plane(Point3D(0, 0, room_size), Normal(0, 0, -1)); frontWall_ptr->set_material(matte_ptr3); add_object(frontWall_ptr); // left wall (-ve xw) Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(0.15); matte_ptr4->set_kd(0.60); matte_ptr4->set_cd(0.71, 0.40, 0.20); // orange Plane* leftWall_ptr = new Plane(Point3D(-room_size, 0, 0), Normal(1, 0, 0)); leftWall_ptr->set_material(matte_ptr4); add_object(leftWall_ptr); // right wall (+ve xw) Plane* rightWall_ptr = new Plane(Point3D(room_size, 0, 0), Normal(-1, 0, 0)); rightWall_ptr->set_material(matte_ptr4); add_object(rightWall_ptr); // mirrors on the walls // the right wall has no mirror double mirror_size = 8; // the mirror size double offset = 1.0; // the mirror offset from the walls // mirror reflection material for the left wall mirror Reflective* reflective_ptr2 = new Reflective; reflective_ptr2->set_ka(0); reflective_ptr2->set_kd(0); reflective_ptr2->set_cd(black); reflective_ptr2->set_ks(0); reflective_ptr2->set_kr(0.9); reflective_ptr2->set_cr(0.9, 1.0, 0.9); // light green // glossy reflector material for the back and front mirrors float exp = 25000.0; GlossyReflector* glossy_reflector_ptr = new GlossyReflector; glossy_reflector_ptr->set_samples(num_samples, exp); glossy_reflector_ptr->set_ka(0.0); glossy_reflector_ptr->set_kd(0.0); glossy_reflector_ptr->set_ks(0.0); glossy_reflector_ptr->set_exp(exp); glossy_reflector_ptr->set_cd(black); glossy_reflector_ptr->set_kr(0.9); glossy_reflector_ptr->set_exponent(exp); glossy_reflector_ptr->set_cr(0.9, 1.0, 0.9); // light green // back wall mirror (-ve zw) Point3D p0; Vector3D a, b; p0 = Point3D(-mirror_size, -mirror_size, -(room_size - offset)); a = Vector3D(2.0 * mirror_size, 0, 0); b = Vector3D(0, 2.0 * mirror_size, 0); Normal n(0, 0, 1); Rectangle* rectangle_ptr1 = new Rectangle(p0, a, b, n); // rectangle_ptr1->set_material(reflective_ptr2); rectangle_ptr1->set_material(glossy_reflector_ptr); add_object(rectangle_ptr1); // front wall mirror (+ve zw) p0 = Point3D(-mirror_size, -mirror_size, +(room_size - offset)); n = Normal(0, 0, -1); Rectangle* rectangle_ptr2 = new Rectangle(p0, a, b, n); // rectangle_ptr2->set_material(reflective_ptr2); rectangle_ptr2->set_material(glossy_reflector_ptr); add_object(rectangle_ptr2); // left wall mirror (-ve xw) p0 = Point3D(-(room_size - offset), -mirror_size, +mirror_size); a = Point3D(0, 0, -2.0 * mirror_size); n = Normal(1, 0, 0); Rectangle* rectangle_ptr3 = new Rectangle(p0, a, b, n); rectangle_ptr3->set_material(reflective_ptr2); add_object(rectangle_ptr3); // horizontal mirror underneath the sphere // this has no direct illumination and a lemon color Reflective* reflective_ptr3 = new Reflective; reflective_ptr3->set_ka(0); reflective_ptr3->set_kd(0); reflective_ptr3->set_cd(black); reflective_ptr3->set_ks(0); reflective_ptr3->set_kr(1); reflective_ptr3->set_cr(1, 1, 0.5); // lemon double yw = -4.0; // the yw location of the mirror p0 = Point3D(-mirror_size, yw, -mirror_size); a = Vector3D(0, 0, 2.0 * mirror_size); b = Vector3D(2.0 * mirror_size, 0, 0); n = Normal(0, 1, 0); Rectangle* rectangle_ptr4 = new Rectangle(p0, a, b, n); rectangle_ptr4->set_material(reflective_ptr3); add_object(rectangle_ptr4); }
void World::build(void) { int num_samples = 25; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(1); tracer_ptr = new AreaLighting(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(-150, 75, 500); pinhole_ptr->set_lookat(-6, 50, 0); pinhole_ptr->set_view_distance(3000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(250, 500, 250); light_ptr1->scale_radiance(2.0); light_ptr1->set_shadows(true); add_light(light_ptr1); // float exp = 1.0; // for Figure 25.30(a) // float exp = 10.0; // for Figure 25.30(b) // float exp = 100.0; // for Figure 25.30(c) // float exp = 1000.0; // for Figure 25.30(d) // float exp = 10000.0; // for Figure 25.30(e) float exp = 100000.0; // for Figure 25.30(f) GlossyReflector* glossy_ptr = new GlossyReflector; glossy_ptr->set_samples(num_samples, exp); glossy_ptr->set_ka(0.0); glossy_ptr->set_kd(0.0); glossy_ptr->set_ks(0.0); glossy_ptr->set_exp(exp); glossy_ptr->set_cd(1.0, 1.0, 0.3); glossy_ptr->set_kr(0.9); glossy_ptr->set_exponent(exp); glossy_ptr->set_cr(1.0, 1.0, 0.3); // lemon Sphere* sphere_ptr1 = new Sphere(Point3D(-6, 55, 0), 40); sphere_ptr1->set_material(glossy_ptr); add_object(sphere_ptr1); //cylinder Matte* matte_ptr = new Matte; matte_ptr->set_ka(0.15); matte_ptr->set_kd(0.75); matte_ptr->set_cd(0.5, 1.0, 0.5); // green double bottom = -100; double top = 15; double radius = 30; Instance* cylinder_ptr = new Instance(new SolidCylinder(bottom, top, radius)); cylinder_ptr->translate(-6, 0, 0); cylinder_ptr->set_material(matte_ptr); add_object(cylinder_ptr); Image* image_ptr = new Image; image_ptr->read_ppm_file("F:/Documents/Visual Studio 2005/Projects/Rytracer/TextureFiles/ppm/uffizi_probe_small.ppm"); // for testing // image_ptr->read_ppm_file("uffizi_probe_large.ppm"); // for production LightProbe* light_probe_ptr = new LightProbe; light_probe_ptr->set_map_type(panoramic); ImageTexture* image_texture_ptr = new ImageTexture(image_ptr); image_texture_ptr->set_mapping(light_probe_ptr); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(1); sv_matte_ptr->set_kd(0.85); sv_matte_ptr->set_cd(image_texture_ptr); Sphere* unit_sphere_ptr = new Sphere; unit_sphere_ptr->set_shadows(false); Instance* sphere_ptr2 = new Instance(unit_sphere_ptr); sphere_ptr2->scale(1000000.0); sphere_ptr2->set_material(sv_matte_ptr); add_object(sphere_ptr2); }
void World::build(void) { int num_samples = 1; vp.set_hres(300); vp.set_vres(300); vp.set_samples(num_samples); vp.set_max_depth(0); background_color = black; tracer_ptr = new AreaLighting(this); Ambient* ambient_ptr = new Ambient; ambient_ptr->scale_radiance(0.0); set_ambient_light(ambient_ptr); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(27.6, 27.4, -80.0); pinhole_ptr->set_lookat(27.6, 27.4, 0.0); pinhole_ptr->set_view_distance(400); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Point3D p0; Vector3D a, b; Normal normal; // box dimensions double width = 55.28; // x direction double height = 54.88; // y direction double depth = 55.92; // z direction Emissive* emissive_ptr = new Emissive; emissive_ptr->set_ce(1.0, 0.73, 0.4); emissive_ptr->scale_radiance(100.0); p0 = Point3D(21.3, height - 0.001, 22.7); a = Vector3D(0.0, 0.0, 10.5); b = Vector3D(13.0, 0.0, 0.0); normal = Normal(0.0, -1.0, 0.0); Rectangle* light_ptr = new Rectangle(p0, a, b, normal); light_ptr->set_material(emissive_ptr); light_ptr->set_sampler(new MultiJittered(num_samples)); light_ptr->set_shadows(false); add_object(light_ptr); AreaLight* ceiling_light_ptr = new AreaLight; ceiling_light_ptr->set_object(light_ptr); ceiling_light_ptr->set_shadows(true); add_light(ceiling_light_ptr); // left wall Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(0.0); matte_ptr1->set_kd(0.6); matte_ptr1->set_cd(0.57, 0.025, 0.025); // red p0 = Point3D(width, 0.0, 0.0); a = Vector3D(0.0, 0.0, depth); b = Vector3D(0.0, height, 0.0); normal = Normal(-1.0, 0.0, 0.0); Rectangle* left_wall_ptr = new Rectangle(p0, a, b, normal); left_wall_ptr->set_material(matte_ptr1); add_object(left_wall_ptr); // right wall Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(0.0); matte_ptr2->set_kd(0.6); matte_ptr2->set_cd(0.37, 0.59, 0.2); // green p0 = Point3D(0.0, 0.0, 0.0); a = Vector3D(0.0, 0.0, depth); b = Vector3D(0.0, height, 0.0); normal = Normal(1.0, 0.0, 0.0); Rectangle* right_wall_ptr = new Rectangle(p0, a, b, normal); right_wall_ptr->set_material(matte_ptr2); add_object(right_wall_ptr); // back wall Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(0.0); matte_ptr3->set_kd(0.6); matte_ptr3->set_cd(white); p0 = Point3D(0.0, 0.0, depth); a = Vector3D(width, 0.0, 0.0); b = Vector3D(0.0, height, 0.0); normal = Normal(0.0, 0.0, -1.0); Rectangle* back_wall_ptr = new Rectangle(p0, a, b, normal); back_wall_ptr->set_material(matte_ptr3); add_object(back_wall_ptr); // floor p0 = Point3D(0.0, 0.0, 0.0); a = Vector3D(0.0, 0.0, depth); b = Vector3D(width, 0.0, 0.0); normal = Normal(0.0, 1.0, 0.0); Rectangle* floor_ptr = new Rectangle(p0, a, b, normal); floor_ptr->set_material(matte_ptr3); add_object(floor_ptr); // ceiling p0 = Point3D(0.0, height, 0.0); a = Vector3D(0.0, 0.0, depth); b = Vector3D(width, 0.0, 0.0); normal = Normal(0.0, -1.0, 0.0); Rectangle* ceiling_ptr = new Rectangle(p0, a, b, normal); ceiling_ptr->set_material(matte_ptr3); add_object(ceiling_ptr); // the two boxes defined as 5 rectangles each // short box // top p0 = Point3D(13.0, 16.5, 6.5); a = Vector3D(-4.8, 0.0, 16.0); b = Vector3D(16.0, 0.0, 4.9); normal = Normal(0.0, 1.0, 0.0); Rectangle* short_top_ptr = new Rectangle(p0, a, b, normal); short_top_ptr->set_material(matte_ptr3); add_object(short_top_ptr); // side 1 p0 = Point3D(13.0, 0.0, 6.5); a = Vector3D(-4.8, 0.0, 16.0); b = Vector3D(0.0, 16.5, 0.0); Rectangle* short_side_ptr1 = new Rectangle(p0, a, b); short_side_ptr1->set_material(matte_ptr3); add_object(short_side_ptr1); // side 2 p0 = Point3D(8.2, 0.0, 22.5); a = Vector3D(15.8, 0.0, 4.7); Rectangle* short_side_ptr2 = new Rectangle(p0, a, b); short_side_ptr2->set_material(matte_ptr3); add_object(short_side_ptr2); // side 3 p0 = Point3D(24.2, 0.0, 27.4); a = Vector3D(4.8, 0.0, -16.0); Rectangle* short_side_ptr3 = new Rectangle(p0, a, b); short_side_ptr3->set_material(matte_ptr3); add_object(short_side_ptr3); // side 4 p0 = Point3D(29.0, 0.0, 11.4); a = Vector3D(-16.0, 0.0, -4.9); Rectangle* short_side_ptr4 = new Rectangle(p0, a, b); short_side_ptr4->set_material(matte_ptr3); add_object(short_side_ptr4); // tall box // top p0 = Point3D(42.3, 33.0, 24.7); a = Vector3D(-15.8, 0.0, 4.9); b = Vector3D(4.9, 0.0, 15.9); normal = Normal(0.0, 1.0, 0.0); Rectangle* tall_top_ptr = new Rectangle(p0, a, b, normal); tall_top_ptr->set_material(matte_ptr3); add_object(tall_top_ptr); // side 1 p0 = Point3D(42.3, 0.0, 24.7); a = Vector3D(-15.8, 0.0, 4.9); b = Vector3D(0.0, 33.0, 0.0); Rectangle* tall_side_ptr1 = new Rectangle(p0, a, b); tall_side_ptr1->set_material(matte_ptr3); add_object(tall_side_ptr1); // side 2 p0 = Point3D(26.5, 0.0, 29.6); a = Vector3D(4.9, 0.0, 15.9); Rectangle* tall_side_ptr2 = new Rectangle(p0, a, b); tall_side_ptr2->set_material(matte_ptr3); add_object(tall_side_ptr2); // side 3 p0 = Point3D(31.4, 0.0, 45.5); a = Vector3D(15.8, 0.0, -4.9); Rectangle* tall_side_ptr3 = new Rectangle(p0, a, b); tall_side_ptr3->set_material(matte_ptr3); add_object(tall_side_ptr3); // side 4 p0 = Point3D(47.2, 0.0, 40.6); a = Vector3D(-4.9, 0.0, -15.9); Rectangle* tall_side_ptr4 = new Rectangle(p0, a, b); tall_side_ptr4->set_material(matte_ptr3); add_object(tall_side_ptr4); }
void World::build(void) { int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(4); background_color = RGBColor(0.5, 0.5, 1.0); // light blue tracer_ptr = new Whitted(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 2); pinhole_ptr->set_lookat(0, 0, 10); pinhole_ptr->set_view_distance(200.0); pinhole_ptr->set_exposure_time(0.17); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr1 = new Directional; light_ptr1->set_direction(0, 1, 0); // straight down light_ptr1->scale_radiance(3.0); light_ptr1->set_shadows(true); add_light(light_ptr1); Directional* light_ptr2 = new Directional; light_ptr2->set_direction(0, -1, 0); // straight up light_ptr2->scale_radiance(2.5); light_ptr2->set_shadows(false); add_light(light_ptr2); // transparent sphere Dielectric* dielectric_ptr = new Dielectric; dielectric_ptr->set_eta_in(2.42); // diamond dielectric_ptr->set_eta_out(1.0); // air dielectric_ptr->set_cf_in(white); dielectric_ptr->set_cf_out(white); Sphere* sphere_ptr1 = new Sphere(Point3D(0.0), 4.0); sphere_ptr1->set_material(dielectric_ptr); add_object(sphere_ptr1); // a ring of spheres around the transparent sphere double scaling_factor = 2.0; // used to scale the radii of the ring and spheres double sphere_radius = 1.75 * scaling_factor; double ring_radius = 10.0 * scaling_factor; int num_spheres = 20; int delta_theta = 20; RGBColor color1(1, 0.5, 0); // orange RGBColor color2(0.0, 0.5, 0.25); // cyan // Phong material for top half of each sphere Phong* phong_ptr1 = new Phong; phong_ptr1->set_ka(0.2); phong_ptr1->set_kd(1.0); phong_ptr1->set_cd(color1); phong_ptr1->set_exp(100.0); phong_ptr1->set_ks(0.5); phong_ptr1->set_cs(1, 1, 0); // reflective material for bottom half of each sphere Reflective* reflective_ptr2 = new Reflective; reflective_ptr2->set_ka(0.2); reflective_ptr2->set_kd(1.0); reflective_ptr2->set_cd(color2); reflective_ptr2->set_exp(100.0); reflective_ptr2->set_ks(0.5); reflective_ptr2->set_cs(1, 1, 0); reflective_ptr2->set_kr(0.2); for (int j = 0; j < num_spheres; j++) { double xc = ring_radius * sin (j * delta_theta * PI / 180.0); double zc = ring_radius * cos (j * delta_theta * PI / 180.0); Point3D center(xc, 0, zc); ConvexPartSphere* top_half_ptr = new ConvexPartSphere(center, sphere_radius, 0, 360, 0, 90); top_half_ptr->set_material(phong_ptr1); add_object(top_half_ptr); ConvexPartSphere* bottom_half_ptr = new ConvexPartSphere(center, sphere_radius, 0, 360, 90, 180); bottom_half_ptr->set_material(reflective_ptr2); add_object(bottom_half_ptr); } // ground plane with checker Checker3D* checker3D_ptr = new Checker3D; checker3D_ptr->set_size(4.2); checker3D_ptr->set_color1(white); checker3D_ptr->set_color2(0.5); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.4); sv_matte_ptr->set_kd(0.6); sv_matte_ptr->set_cd(checker3D_ptr); Plane* plane_ptr = new Plane(Point3D(0, -4.5, 0), Normal(0, 1, 0)); plane_ptr->set_material(sv_matte_ptr); add_object(plane_ptr); }
void World::build(void) { int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_pixel_size(0.5); vp.set_samples(num_samples); // vp.set_gamut_display(true); // for Figure 14.23(b) tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 10000); pinhole_ptr->set_lookat(0.0); pinhole_ptr->set_view_distance(15000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr = new Directional; light_ptr->set_direction(100, 100, 200); light_ptr->set_color(1.0, 1.0, 1.0); light_ptr->scale_radiance(4.5); add_light(light_ptr); // colors RGBColor yellow(1, 1, 0); // yellow RGBColor brown(0.71, 0.40, 0.16); // brown RGBColor dark_green(0.0, 0.41, 0.41); // dark_green RGBColor orange(1, 0.75, 0); // orange RGBColor green(0, 0.6, 0.3); // green RGBColor light_green(0.65, 1, 0.30); // light green RGBColor dark_yellow(0.61, 0.61, 0); // dark yellow RGBColor light_purple(0.65, 0.3, 1); // light purple RGBColor dark_purple(0.5, 0, 1); // dark purple // Matt material reflection coefficients float ka = 0.25; float kd = 0.75; // spheres Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(ka); matte_ptr1->set_kd(kd); matte_ptr1->set_cd(yellow); Sphere* sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); sphere_ptr1->set_material(matte_ptr1); // yellow add_object(sphere_ptr1); Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(ka); matte_ptr2->set_kd(kd); matte_ptr2->set_cd(brown); Sphere* sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); sphere_ptr2->set_material(matte_ptr2); // brown add_object(sphere_ptr2); Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(ka); matte_ptr3->set_kd(kd); matte_ptr3->set_cd(dark_green); Sphere* sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); sphere_ptr3->set_material(matte_ptr3); // dark green add_object(sphere_ptr3); Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(ka); matte_ptr4->set_kd(kd); matte_ptr4->set_cd(orange); Sphere* sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); sphere_ptr4->set_material(matte_ptr4); // orange add_object(sphere_ptr4); Matte* matte_ptr5 = new Matte; matte_ptr5->set_ka(ka); matte_ptr5->set_kd(kd); matte_ptr5->set_cd(green); Sphere* sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); sphere_ptr5->set_material(matte_ptr5); // green add_object(sphere_ptr5); Matte* matte_ptr6 = new Matte; matte_ptr6->set_ka(ka); matte_ptr6->set_kd(kd); matte_ptr6->set_cd(light_green); Sphere* sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); sphere_ptr6->set_material(matte_ptr6); // light green add_object(sphere_ptr6); Matte* matte_ptr7 = new Matte; matte_ptr7->set_ka(ka); matte_ptr7->set_kd(kd); matte_ptr7->set_cd(green); Sphere* sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); sphere_ptr7->set_material(matte_ptr7); // green add_object(sphere_ptr7); Matte* matte_ptr8 = new Matte; matte_ptr8->set_ka(ka); matte_ptr8->set_kd(kd); matte_ptr8->set_cd(brown); Sphere* sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15); sphere_ptr8->set_material(matte_ptr8); // brown add_object(sphere_ptr8); Matte* matte_ptr9 = new Matte; matte_ptr9->set_ka(ka); matte_ptr9->set_kd(kd); matte_ptr9->set_cd(light_green); Sphere* sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); sphere_ptr9->set_material(matte_ptr9); // light green add_object(sphere_ptr9); Matte* matte_ptr10 = new Matte; matte_ptr10->set_ka(ka); matte_ptr10->set_kd(kd); matte_ptr10->set_cd(dark_green); Sphere* sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); sphere_ptr10->set_material(matte_ptr10); // dark green add_object(sphere_ptr10); Matte* matte_ptr11 = new Matte; matte_ptr11->set_ka(ka); matte_ptr11->set_kd(kd); matte_ptr11->set_cd(dark_yellow); Sphere* sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); sphere_ptr11->set_material(matte_ptr11); // dark yellow add_object(sphere_ptr11); Matte* matte_ptr12 = new Matte; matte_ptr12->set_ka(ka); matte_ptr12->set_kd(kd); matte_ptr12->set_cd(dark_yellow); Sphere* sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); sphere_ptr12->set_material(matte_ptr12); // dark yellow add_object(sphere_ptr12); Matte* matte_ptr13 = new Matte; matte_ptr13->set_ka(ka); matte_ptr13->set_kd(kd); matte_ptr13->set_cd(dark_yellow); Sphere* sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); sphere_ptr13->set_material(matte_ptr13); add_object(sphere_ptr13); // dark yellow (hidden) Matte* matte_ptr14 = new Matte; matte_ptr14->set_ka(ka); matte_ptr14->set_kd(kd); matte_ptr14->set_cd(dark_green); Sphere* sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); sphere_ptr14->set_material(matte_ptr14); // dark green add_object(sphere_ptr14); Matte* matte_ptr15 = new Matte; matte_ptr15->set_ka(ka); matte_ptr15->set_kd(kd); matte_ptr15->set_cd(brown); Sphere* sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); sphere_ptr15->set_material(matte_ptr15); // brown add_object(sphere_ptr15); Matte* matte_ptr16 = new Matte; matte_ptr16->set_ka(ka); matte_ptr16->set_kd(kd); matte_ptr16->set_cd(light_purple); Sphere* sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); sphere_ptr16->set_material(matte_ptr16); // light purple add_object(sphere_ptr16); Matte* matte_ptr17 = new Matte; matte_ptr17->set_ka(ka); matte_ptr17->set_kd(kd); matte_ptr17->set_cd(brown); Sphere* sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); sphere_ptr17->set_material(matte_ptr17); // browm add_object(sphere_ptr17); Matte* matte_ptr18 = new Matte; matte_ptr18->set_ka(ka); matte_ptr18->set_kd(kd); matte_ptr18->set_cd(dark_purple); Sphere* sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); sphere_ptr18->set_material(matte_ptr18); // dark purple add_object(sphere_ptr18); Matte* matte_ptr19 = new Matte; matte_ptr19->set_ka(ka); matte_ptr19->set_kd(kd); matte_ptr19->set_cd(dark_green); Sphere* sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); sphere_ptr19->set_material(matte_ptr19); // dark green add_object(sphere_ptr19); Matte* matte_ptr20 = new Matte; matte_ptr20->set_ka(ka); matte_ptr20->set_kd(kd); matte_ptr20->set_cd(brown); Sphere* sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); sphere_ptr20->set_material(matte_ptr20); // browm add_object(sphere_ptr20); Matte* matte_ptr21 = new Matte; matte_ptr21->set_ka(ka); matte_ptr21->set_kd(kd); matte_ptr21->set_cd(light_purple); Sphere* sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); sphere_ptr21->set_material(matte_ptr21); // light purple add_object(sphere_ptr21); Matte* matte_ptr22 = new Matte; matte_ptr22->set_ka(ka); matte_ptr22->set_kd(kd); matte_ptr22->set_cd(light_purple); Sphere* sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); sphere_ptr22->set_material(matte_ptr22); // light purple add_object(sphere_ptr22); Matte* matte_ptr23 = new Matte; matte_ptr23->set_ka(ka); matte_ptr23->set_kd(kd); matte_ptr23->set_cd(dark_purple); Sphere* sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); sphere_ptr23->set_material(matte_ptr23); // dark purple add_object(sphere_ptr23); Matte* matte_ptr24 = new Matte; matte_ptr24->set_ka(ka); matte_ptr24->set_kd(kd); matte_ptr24->set_cd(light_purple); Sphere* sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); sphere_ptr24->set_material(matte_ptr24); // light purple add_object(sphere_ptr24); Matte* matte_ptr25 = new Matte; matte_ptr25->set_ka(ka); matte_ptr25->set_kd(kd); matte_ptr25->set_cd(green); Sphere* sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); sphere_ptr25->set_material(matte_ptr25); // green add_object(sphere_ptr25); Matte* matte_ptr26 = new Matte; matte_ptr26->set_ka(ka); matte_ptr26->set_kd(kd); matte_ptr26->set_cd(light_purple); Sphere* sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); sphere_ptr26->set_material(matte_ptr26); // light purple add_object(sphere_ptr26); Matte* matte_ptr27 = new Matte; matte_ptr27->set_ka(ka); matte_ptr27->set_kd(kd); matte_ptr27->set_cd(light_purple); Sphere* sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); sphere_ptr27->set_material(matte_ptr27); // light purple add_object(sphere_ptr27); Matte* matte_ptr28 = new Matte; matte_ptr28->set_ka(ka); matte_ptr28->set_kd(kd); matte_ptr28->set_cd(dark_purple); Sphere* sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); sphere_ptr28->set_material(matte_ptr28); // dark purple add_object(sphere_ptr28); Matte* matte_ptr29 = new Matte; matte_ptr29->set_ka(ka); matte_ptr29->set_kd(kd); matte_ptr29->set_cd(dark_purple); Sphere* sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); sphere_ptr29->set_material(matte_ptr29); // dark purple add_object(sphere_ptr29); Matte* matte_ptr30 = new Matte; matte_ptr30->set_ka(ka); matte_ptr30->set_kd(kd); matte_ptr30->set_cd(dark_purple); Sphere* sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15); sphere_ptr30->set_material(matte_ptr30); // dark purple add_object(sphere_ptr30); Matte* matte_ptr31 = new Matte; matte_ptr31->set_ka(ka); matte_ptr31->set_kd(kd); matte_ptr31->set_cd(light_purple); Sphere* sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); sphere_ptr31->set_material(matte_ptr31); // light purple add_object(sphere_ptr31); Matte* matte_ptr32 = new Matte; matte_ptr32->set_ka(ka); matte_ptr32->set_kd(kd); matte_ptr32->set_cd(green); Sphere* sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11); sphere_ptr32->set_material(matte_ptr32); // green add_object(sphere_ptr32); Matte* matte_ptr33 = new Matte; matte_ptr33->set_ka(ka); matte_ptr33->set_kd(kd); matte_ptr33->set_cd(green); Sphere* sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); sphere_ptr33->set_material(matte_ptr33); // green add_object(sphere_ptr33); Matte* matte_ptr34 = new Matte; matte_ptr34->set_ka(ka); matte_ptr34->set_kd(kd); matte_ptr34->set_cd(light_purple); Sphere* sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); sphere_ptr34->set_material(matte_ptr34); // light purple add_object(sphere_ptr34); Matte* matte_ptr35 = new Matte; matte_ptr35->set_ka(ka); matte_ptr35->set_kd(kd); matte_ptr35->set_cd(light_purple); Sphere* sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); sphere_ptr35->set_material(matte_ptr35); // light purple add_object(sphere_ptr35); }