void 												
World::build(void) {
	int num_samples = 1;   		// for Figure 18.4(a)
//	int num_samples = 100;   	// for Figure 18.4(b) & (c)
	
	Sampler* sampler_ptr = new MultiJittered(num_samples);

	vp.set_hres(600);
	vp.set_vres(600);
	vp.set_sampler(sampler_ptr);	

	background_color = RGBColor(0.5);

	tracer_ptr = new AreaLighting(this);

	Pinhole* camera = new Pinhole;
	camera->set_eye(-20, 10, 20);
	camera->set_lookat(0, 2, 0); 	
	camera->set_view_distance(1080);          
	camera->compute_uvw();     
	set_camera(camera); 

	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->scale_radiance(40.0);
	emissive_ptr->set_ce(white);
	
	
	// define a rectangle for the rectangular light
	
	float width = 4.0;				// for Figure 18.4(a) & (b)
	float height = 4.0;
//	float width = 2.0;				// for Figure 18.4(c)
//	float height = 2.0;
	Point3D center(0.0, 7.0, -7.0);	// center of each area light (rectangular, disk, and spherical)
	Point3D p0(-0.5 * width, center.y - 0.5 * height, center.z);
	Vector3D a(width, 0.0, 0.0);
	Vector3D b(0.0, height, 0.0);
	Normal normal(0, 0, 1);
	
	Rectangle* rectangle_ptr = new Rectangle(p0, a, b, normal);
	rectangle_ptr->set_material(emissive_ptr);
	rectangle_ptr->set_sampler(sampler_ptr);
	rectangle_ptr->set_shadows(false);
	add_object(rectangle_ptr);

	
	AreaLight* area_light_ptr = new AreaLight;
	area_light_ptr->set_object(rectangle_ptr);
	area_light_ptr->set_shadows(true);
	add_light(area_light_ptr);
	
	
	// Four axis aligned boxes
		
	float box_width 	= 1.0; 		// x dimension
	float box_depth 	= 1.0; 		// z dimension
	float box_height 	= 4.5; 		// y dimension
	float gap			= 3.0; 
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.25); 
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(0.4, 0.7, 0.4);     // green
	
	Box* box_ptr0 = new Box(Point3D(- 1.5 * gap - 2.0 * box_width, 0.0, -0.5 * box_depth), 
							Point3D(-1.5 * gap  - box_width, box_height, 0.5 * box_depth)); 
	box_ptr0->set_material(matte_ptr1);
	add_object(box_ptr0);
	
	Box* box_ptr1 = new Box(Point3D(- 0.5 * gap - box_width, 0.0, -0.5 * box_depth), 
							Point3D(-0.5 * gap, box_height, 0.5 * box_depth)); 
	box_ptr1->set_material(matte_ptr1);
	add_object(box_ptr1);
		
	Box* box_ptr2 = new Box(Point3D(0.5 * gap, 0.0, -0.5 * box_depth), 
							Point3D(0.5 * gap + box_width, box_height, 0.5 * box_depth));
	box_ptr2->set_material(matte_ptr1);
	add_object(box_ptr2);
	
	Box* box_ptr3 = new Box(Point3D(1.5 * gap + box_width, 0.0, -0.5 * box_depth), 
							Point3D(1.5 * gap + 2.0 * box_width, box_height, 0.5 * box_depth));
	box_ptr3->set_material(matte_ptr1);
	add_object(box_ptr3);

		
	// ground plane
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.1); 
	matte_ptr2->set_kd(0.90);
	matte_ptr2->set_cd(white);
		
	Plane* plane_ptr = new Plane(Point3D(0.0), Normal(0, 1, 0)); 
	plane_ptr->set_material(matte_ptr2);
	add_object(plane_ptr);	
}
void 												
World::build(void) {
	int num_samples = 25;
	
	vp.set_hres(600);      
	vp.set_vres(600);
	vp.set_max_depth(3);
	vp.set_samples(num_samples);
	
	background_color = RGBColor(0.5, 0.6666, 0.5);  // light green
	
	tracer_ptr = new Whitted(this);	

	FishEye* fisheye_ptr = new FishEye;
	fisheye_ptr->set_eye(0.0, 0.1, 0.0);
	fisheye_ptr->set_lookat(0, 10, 0);
//	fisheye_ptr->set_rectangular(true);
	fisheye_ptr->set_fov(265.0);
	fisheye_ptr->compute_uvw();  
	set_camera(fisheye_ptr);
	
		
	Directional* light_ptr1 = new Directional; 
	light_ptr1->set_direction(0, 1, 0);
	light_ptr1->scale_radiance(5.0);
	light_ptr1->set_shadows(false);
	add_light(light_ptr1);
	
	
	Transparent* glass_ptr = new Transparent;
	glass_ptr->set_ks(0.0);
	glass_ptr->set_exp(1.0);
	glass_ptr->set_ior(1.5);			
	glass_ptr->set_kr(0.1);     
	glass_ptr->set_kt(0.9);   
	
	Dielectric* dielectric_ptr = new Dielectric;
	dielectric_ptr->set_cd(0);
	dielectric_ptr->set_ka(0.0);
	dielectric_ptr->set_kd(0.0);
	dielectric_ptr->set_ks(0.0);
	dielectric_ptr->set_exp(1.0);
	dielectric_ptr->set_eta_in(1.5);
	dielectric_ptr->set_eta_out(1.0);
	
	double radius 	= 250.0;
	double bottom 	= 10.0;
	double top 		= 10.1;
	SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius);
	cylinder_ptr->set_material(glass_ptr);				// for Figure 28.7(a)
//	cylinder_ptr->set_material(dielectric_ptr);			// for Figure 28.7(b)
	add_object(cylinder_ptr);
	
	
	// plane with checker
	
	Checker3D* checker_ptr = new Checker3D;
	checker_ptr->set_size(10.0);
	checker_ptr->set_color1(black);  
	checker_ptr->set_color2(1.0, 0.7, 0.2);  // orange	
	
	SV_Matte* sv_matte_ptr5 = new SV_Matte;		
	sv_matte_ptr5->set_ka(0.25);
	sv_matte_ptr5->set_kd(0.5);
	sv_matte_ptr5->set_cd(checker_ptr);

	Plane* plane_ptr2 = new Plane(Point3D(0.0), Normal(0, 1, 0));
	plane_ptr2->set_material(sv_matte_ptr5);
	plane_ptr2->set_shadows(false);
	add_object(plane_ptr2);	
}
void 												
World::build(void) {
	int num_samples = 16;

	vp.set_hres(500);	  		
	vp.set_vres(400);
	vp.set_samples(num_samples);
	
	tracer_ptr = new RayCast(this);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(50, 40, 30);			
	pinhole_ptr->set_lookat(0.25, 0.25, 0);
	pinhole_ptr->set_view_distance(4000);   
	pinhole_ptr->compute_uvw();
	set_camera(pinhole_ptr);
	
	Directional* light_ptr2 = new Directional;
	light_ptr2->set_direction(20, 30, 30);
	light_ptr2->scale_radiance(2.5);   
	light_ptr2->set_shadows(true);
	add_light(light_ptr2);
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.25);    
	matte_ptr1->set_kd(0.65);
	matte_ptr1->set_cd(0.5, 1, 0.5);	  // green
	
	// wedge1 parameters
	
	float y0 = -1.0;		// minimum y value
	float y1 = 2;			// maximum y value
	float r0 = 1.5;			// inner radius
	float r1 = 3;			// outer radius
	float rb = 0.25;		// bevel radius
	float phi0 = 140;		// minimum azimuth angle in degrees
	float phi1 = 350;		// maximum azimuth angle in degrees
	
	BeveledWedge* wedge_ptr1 = new BeveledWedge(y0, y1, r0, r1, rb, phi0, phi1);
	wedge_ptr1->set_material(matte_ptr1);
	add_object(wedge_ptr1);
	
		
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.25);    
	matte_ptr2->set_kd(0.85);
	matte_ptr2->set_cd(1.0, 0.5, 0.0);	// orange
	
	// wedge2 parameters
	
	y0 = -1.5;		// minimum y value
	y1 = 1.25;		// minimum y value
	r0 = 0.5;		// inner radius
	r1 = 4.0;		// outer radius
	rb = 0.075;		// bevel radius
	phi0 = 110;		// minimum azimuth angle in degrees
	phi1 = 130;		// maximum azimuth angle in degrees
		
	BeveledWedge* wedge_ptr2 = new BeveledWedge(y0, y1, r0, r1, rb, phi0, phi1);
	wedge_ptr2->set_material(matte_ptr2);
	add_object(wedge_ptr2);	
		
	
	Matte* matte_ptr3 = new Matte;			
	matte_ptr3->set_cd(1, 1, 0.0);	// yellow
	matte_ptr3->set_ka(0.25);    
	matte_ptr3->set_kd(0.85);
	
	// wedge3 parameters
	
	y0 = -0.75;		// minimum y value
	y1 = 0.5;		// minimum y value
	r0 = 1.25;		// inner radius
	r1 = 3.75;		// outer radius
	rb = 0.1;		// bevel radius
	phi0 = 0;		// minimum azimuth angle in degrees
	phi1 = 90;		// maximum azimuth angle in degrees
		
	BeveledWedge* wedge_ptr3 = new BeveledWedge(y0, y1, r0, r1, rb, phi0, phi1);
	wedge_ptr3->set_material(matte_ptr3);
	add_object(wedge_ptr3);		
}
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);  
	
	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);
	
	
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(100, 100, 200);
	light_ptr->scale_radiance(3.0);
	light_ptr->set_shadows(true); 			
	add_light(light_ptr);
	
		
	// colors

	float a = 0.75;  // scaling factor for yellow, orange, and light green
	
	RGBColor yellow(a * 1, a * 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(a * 1, a * 0.75, 0);							// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor light_green(a * 0.65, a * 1, a * 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
	
	
	// Phong materials' reflection coefficients
	
	float ka 	= 0.25;
	float kd 	= 0.75;
	float ks 	= 0.12;
	float exp 	= 20;
	
	
	// spheres
	
	Phong* phong_ptr1 = new Phong;
	phong_ptr1->set_ka(ka);	
	phong_ptr1->set_kd(kd);
	phong_ptr1->set_ks(ks);
	phong_ptr1->set_exp(exp);
	phong_ptr1->set_cd(yellow);
					
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(phong_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	
	Phong* phong_ptr2 = new Phong;
	phong_ptr2->set_ka(ka);	
	phong_ptr2->set_kd(kd);
	phong_ptr2->set_ks(ks);
	phong_ptr2->set_exp(exp);
	phong_ptr2->set_cd(brown);
	
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(phong_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Phong* phong_ptr3 = new Phong;
	phong_ptr3->set_ka(ka);	
	phong_ptr3->set_kd(kd);
	phong_ptr3->set_ks(ks);
	phong_ptr3->set_exp(exp);
	phong_ptr3->set_cd(dark_green);
		
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(phong_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	
	Phong* phong_ptr4 = new Phong;
	phong_ptr4->set_ka(ka);	
	phong_ptr4->set_kd(kd);
	phong_ptr4->set_ks(ks);
	phong_ptr4->set_exp(exp);
	phong_ptr4->set_cd(orange);
	
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(phong_ptr4);								// orange
	add_object(sphere_ptr4);
	
	
	Phong* phong_ptr5 = new Phong;
	phong_ptr5->set_ka(ka);	
	phong_ptr5->set_kd(kd);
	phong_ptr5->set_ks(ks);
	phong_ptr5->set_exp(exp);
	phong_ptr5->set_cd(green);
	
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(phong_ptr5);								// green
	add_object(sphere_ptr5);
	
	
	Phong* phong_ptr6 = new Phong;
	phong_ptr6->set_ka(ka);	
	phong_ptr6->set_kd(kd);
	phong_ptr6->set_ks(ks);
	phong_ptr6->set_exp(exp);
	phong_ptr6->set_cd(light_green);
	
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(phong_ptr6);								// light green
	add_object(sphere_ptr6);
	
	
	Phong* phong_ptr7 = new Phong;
	phong_ptr7->set_ka(ka);	
	phong_ptr7->set_kd(kd);
	phong_ptr7->set_ks(ks);
	phong_ptr7->set_exp(exp);
	phong_ptr7->set_cd(green);
	
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(phong_ptr7);   							// green
	add_object(sphere_ptr7);
	
	
	Phong* phong_ptr8 = new Phong;
	phong_ptr8->set_ka(ka);	
	phong_ptr8->set_kd(kd);
	phong_ptr8->set_ks(ks);
	phong_ptr8->set_exp(exp);
	phong_ptr8->set_cd(brown);
	
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(phong_ptr8);								// brown
	add_object(sphere_ptr8);
	
	
	Phong* phong_ptr9 = new Phong;
	phong_ptr9->set_ka(ka);	
	phong_ptr9->set_kd(kd);
	phong_ptr9->set_ks(ks);
	phong_ptr9->set_exp(exp);
	phong_ptr9->set_cd(light_green);
	
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(phong_ptr9);								// light green
	add_object(sphere_ptr9);
	
	
	Phong* phong_ptr10 = new Phong;
	phong_ptr10->set_ka(ka);	
	phong_ptr10->set_kd(kd);
	phong_ptr10->set_ks(ks);
	phong_ptr10->set_exp(exp);
	phong_ptr10->set_cd(dark_green);
			
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(phong_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	
	Phong* phong_ptr11 = new Phong;
	phong_ptr11->set_ka(ka);	
	phong_ptr11->set_kd(kd);
	phong_ptr11->set_ks(ks);
	phong_ptr11->set_exp(exp);
	phong_ptr11->set_cd(dark_yellow);
	
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(phong_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	
	Phong* phong_ptr12 = new Phong;
	phong_ptr12->set_ka(ka);	
	phong_ptr12->set_kd(kd);
	phong_ptr12->set_ks(ks);
	phong_ptr12->set_exp(exp);
	phong_ptr12->set_cd(dark_yellow);
	
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(phong_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	
	Phong* phong_ptr13 = new Phong;
	phong_ptr13->set_ka(ka);	
	phong_ptr13->set_kd(kd);
	phong_ptr13->set_ks(ks);
	phong_ptr13->set_exp(exp);
	phong_ptr13->set_cd(dark_yellow);
			
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(phong_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	
	Phong* phong_ptr14 = new Phong;
	phong_ptr14->set_ka(ka);	
	phong_ptr14->set_kd(kd);
	phong_ptr14->set_ks(ks);
	phong_ptr14->set_exp(exp);
	phong_ptr14->set_cd(dark_green);
		
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(phong_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	
	Phong* phong_ptr15 = new Phong;
	phong_ptr15->set_ka(ka);	
	phong_ptr15->set_kd(kd);
	phong_ptr15->set_ks(ks);
	phong_ptr15->set_exp(exp);
	phong_ptr15->set_cd(brown);
		
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(phong_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	
	Phong* phong_ptr16 = new Phong;
	phong_ptr16->set_ka(ka);	
	phong_ptr16->set_kd(kd);
	phong_ptr16->set_ks(ks);
	phong_ptr16->set_exp(exp);
	phong_ptr16->set_cd(light_purple);
	
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(phong_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	
	Phong* phong_ptr17 = new Phong;
	phong_ptr17->set_ka(ka);	
	phong_ptr17->set_kd(kd);
	phong_ptr17->set_ks(ks);
	phong_ptr17->set_exp(exp);
	phong_ptr17->set_cd(brown);
	
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(phong_ptr17);							// browm
	add_object(sphere_ptr17);
	
	
	Phong* phong_ptr18 = new Phong;
	phong_ptr18->set_ka(ka);	
	phong_ptr18->set_kd(kd);
	phong_ptr18->set_ks(ks);
	phong_ptr18->set_exp(exp);
	phong_ptr18->set_cd(dark_purple);
	
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(phong_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	
	Phong* phong_ptr19 = new Phong;
	phong_ptr19->set_ka(ka);	
	phong_ptr19->set_kd(kd);
	phong_ptr19->set_ks(ks);
	phong_ptr19->set_exp(exp);
	phong_ptr19->set_cd(dark_green);
	
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(phong_ptr19);							// dark green
	add_object(sphere_ptr19);
	
	
	Phong* phong_ptr20 = new Phong;
	phong_ptr20->set_ka(ka);	
	phong_ptr20->set_kd(kd);
	phong_ptr20->set_ks(ks);
	phong_ptr20->set_exp(exp);
	phong_ptr20->set_cd(brown);

	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(phong_ptr20);							// browm
	add_object(sphere_ptr20);
	
	
	Phong* phong_ptr21 = new Phong;
	phong_ptr21->set_ka(ka);	
	phong_ptr21->set_kd(kd);
	phong_ptr21->set_ks(ks);
	phong_ptr21->set_exp(exp);
	phong_ptr21->set_cd(light_purple);
	 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(phong_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	
	Phong* phong_ptr22 = new Phong;
	phong_ptr22->set_ka(ka);	
	phong_ptr22->set_kd(kd);
	phong_ptr22->set_ks(ks);
	phong_ptr22->set_exp(exp);
	phong_ptr22->set_cd(light_purple);
	
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(phong_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	
	Phong* phong_ptr23 = new Phong;
	phong_ptr23->set_ka(ka);	
	phong_ptr23->set_kd(kd);
	phong_ptr23->set_ks(ks);
	phong_ptr23->set_exp(exp);
	phong_ptr23->set_cd(dark_purple);
	
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(phong_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	
	Phong* phong_ptr24 = new Phong;
	phong_ptr24->set_ka(ka);	
	phong_ptr24->set_kd(kd);
	phong_ptr24->set_ks(ks);
	phong_ptr24->set_exp(exp);
	phong_ptr24->set_cd(light_purple);
	 
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(phong_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	
	Phong* phong_ptr25 = new Phong;
	phong_ptr25->set_ka(ka);	
	phong_ptr25->set_kd(kd);
	phong_ptr25->set_ks(ks);
	phong_ptr25->set_exp(exp);
	phong_ptr25->set_cd(green);
	
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(phong_ptr25);					 		// green
	add_object(sphere_ptr25);
	
	
	Phong* phong_ptr26 = new Phong;
	phong_ptr26->set_ka(ka);	
	phong_ptr26->set_kd(kd);
	phong_ptr26->set_ks(ks);
	phong_ptr26->set_exp(exp);
	phong_ptr26->set_cd(light_purple);
	  
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(phong_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	
	Phong* phong_ptr27 = new Phong;
	phong_ptr27->set_ka(ka);	
	phong_ptr27->set_kd(kd);
	phong_ptr27->set_ks(ks);
	phong_ptr27->set_exp(exp);
	phong_ptr27->set_cd(light_purple);
	
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(phong_ptr27);							// light purple
	add_object(sphere_ptr27);
	
		
	Phong* phong_ptr28 = new Phong;
	phong_ptr28->set_ka(ka);	
	phong_ptr28->set_kd(kd);
	phong_ptr28->set_ks(ks);
	phong_ptr28->set_exp(exp);
	phong_ptr28->set_cd(dark_purple);
	 
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(phong_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	
	
	Phong* phong_ptr29 = new Phong;
	phong_ptr29->set_ka(ka);	
	phong_ptr29->set_kd(kd);
	phong_ptr29->set_ks(ks);
	phong_ptr29->set_exp(exp);
	phong_ptr29->set_cd(dark_purple);
	
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(phong_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	
	Phong* phong_ptr30 = new Phong;
	phong_ptr30->set_ka(ka);	
	phong_ptr30->set_kd(kd);
	phong_ptr30->set_ks(ks);
	phong_ptr30->set_exp(exp);
	phong_ptr30->set_cd(dark_purple);
	
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(phong_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	
	Phong* phong_ptr31 = new Phong;
	phong_ptr31->set_ka(ka);	
	phong_ptr31->set_kd(kd);
	phong_ptr31->set_ks(ks);
	phong_ptr31->set_exp(exp);
	phong_ptr31->set_cd(light_purple);
	
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(phong_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
		
	Phong* phong_ptr32 = new Phong;
	phong_ptr32->set_ka(ka);	
	phong_ptr32->set_kd(kd);
	phong_ptr32->set_ks(ks);
	phong_ptr32->set_exp(exp);
	phong_ptr32->set_cd(green);
	
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(phong_ptr32);							//  green
	add_object(sphere_ptr32);
	
	
	Phong* phong_ptr33 = new Phong;
	phong_ptr33->set_ka(ka);	
	phong_ptr33->set_kd(kd);
	phong_ptr33->set_ks(ks);
	phong_ptr33->set_exp(exp);
	phong_ptr33->set_cd(green);
	
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(phong_ptr33);							// green 
	add_object(sphere_ptr33);
	
	
	Phong* phong_ptr34 = new Phong;
	phong_ptr34->set_ka(ka);	
	phong_ptr34->set_kd(kd);
	phong_ptr34->set_ks(ks);
	phong_ptr34->set_exp(exp);
	phong_ptr34->set_cd(light_purple);
	
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(phong_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	
	Phong* phong_ptr35 = new Phong;
	phong_ptr35->set_ka(ka);	
	phong_ptr35->set_kd(kd);
	phong_ptr35->set_ks(ks);
	phong_ptr35->set_exp(exp);
	phong_ptr35->set_cd(light_purple);
	
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(phong_ptr35);							// light purple
	add_object(sphere_ptr35);
}
Esempio n. 5
0
		TITANIUM_PROPERTY_SETTER(View, camera)
		{
			TITANIUM_ASSERT(argument.IsObject());
			set_camera(static_cast<JSObject>(argument).GetPrivate<Camera>());
			return true;
		}
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
	
	Transparent* glass_ptr = new Transparent;
	glass_ptr->set_ks(0.2);
	glass_ptr->set_exp(2000.0);
	glass_ptr->set_ior(1.1);			// for Figure 27.14(a)	
//	glass_ptr->set_ior(1.5);			// for Figure 27.14(b)
	glass_ptr->set_kr(0.1);
	glass_ptr->set_kt(0.9);
	
	Sphere* sphere_ptr1 = new Sphere(Point3D(0.0, 4.5, 0.0), 3.0);
	sphere_ptr1->set_material(glass_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);

		
	Checker3D* checker_ptr = new Checker3D;
	checker_ptr->set_size(4);
	checker_ptr->set_color1(0.75);  
	checker_ptr->set_color2(white);	
	
	SV_Matte* sv_matte_ptr = new SV_Matte;		
	sv_matte_ptr->set_ka(0.5);
	sv_matte_ptr->set_kd(0.35);
	sv_matte_ptr->set_cd(checker_ptr);	
	
	// 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(sv_matte_ptr);
	add_object(rectangle_ptr);		
}
Esempio n. 7
0
void
mouse_moved( int x, int y)
{
  usleep(100);

  camera_pose_t * camera_pose = get_camera_pose();
  int window_width = get_window_width();
  int window_height = get_window_height();

  switch (mouse_rotation.button)
  {
  case GLUT_LEFT_BUTTON: // rotate
  {
    camera_pose->phi   -= ((float)( mouse_rotation.x0 - x ))/((float)(window_width))*2.0*3.14;
    camera_pose->theta -= ((float)( mouse_rotation.y0 - y ))/((float)(window_height))*2.0*3.14;
    if (camera_pose->theta > 0.5*3.14)
      camera_pose->theta = 0.5*3.14;
    if (camera_pose->theta < -0.5*3.14f)
      camera_pose->theta = -0.5*3.14f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
  case GLUT_RIGHT_BUTTON: // pan
  {
    camera_pose->focus_x += 500.0f*cos(camera_pose->phi)*((float)(y - mouse_rotation.y0))/((float)(window_height));
    camera_pose->focus_y += 500.0f*sin(camera_pose->phi)*((float)(y - mouse_rotation.y0))/((float)(window_height));;

    camera_pose->focus_x += 500.0f*sin(camera_pose->phi)*((float)(x - mouse_rotation.x0))/((float)(window_width));
    camera_pose->focus_y -= 500.0f*cos(camera_pose->phi)*((float)(x - mouse_rotation.x0))/((float)(window_width));;

    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;

    set_camera();
    break;
  }
/*
  case GLUT_MIDDLE_BUTTON: // zoom
  {
    camera_pose->rho += 1000.0f*((float)(y - mouse_rotation.y0))/((float)(window_height));
    if (camera_pose->rho < 1.0f)
      camera_pose->rho = 1.0f;
    if (camera_pose->rho > 2000.0f)
      camera_pose->rho = 2000.0f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
*/
  case GLUT_MIDDLE_BUTTON: // move camera focus
  {
    camera_pose->focus_z += 500.0f*((float)(y - mouse_rotation.y0))/((float)(window_height));
    if (camera_pose->focus_z > 0.0f)
      camera_pose->focus_z = 0.0f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
  default:
    break;
  }// switch (mouse_rotation.button)
}
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(4, 3.25, 5);
	pinhole_ptr->set_lookat(0.85, 0.0, 0);
	pinhole_ptr->set_view_distance(900); 
	pinhole_ptr->compute_uvw();
	set_camera(pinhole_ptr);
		
	PointLight* light_ptr1 = new PointLight;
	light_ptr1->set_location(20, 10, 15);
	light_ptr1->scale_radiance(2.0);
	light_ptr1->set_shadows(true);
	add_light(light_ptr1);
			
	
	// ring parameters	
		
	Point3D centre(0);
	float y0 = -0.25;
	float y1 = 0.25;
	float inner_radius = 0.5;
	float outer_radius = 1.0;
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.3);    
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(0, 1, 1);  // cyan
	
	Annulus* bottom_ptr = new Annulus(Point3D(0, y0, 0), Normal(0, -1, 0), inner_radius, outer_radius); 
	bottom_ptr->set_material(matte_ptr1);
	
	Annulus* top_ptr = new Annulus(Point3D(0, y1, 0),  Normal(0, 1, 0), inner_radius, outer_radius); 
	top_ptr->set_material(matte_ptr1);
	
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.4);    
	matte_ptr2->set_kd(0.75);
	matte_ptr2->set_cd(1, 1, 0);   // yellow
	
	OpenCylinder* outer_wall_ptr = new OpenCylinder(y0, y1, outer_radius); 
	outer_wall_ptr->set_material(matte_ptr2);
	
		
	Matte* matte_ptr3 = new Matte;			
	matte_ptr3->set_ka(0.4);    
	matte_ptr3->set_kd(0.75);
	matte_ptr3->set_cd(1, 1, 0);   // yellow
	
	OpenCylinder* inner_wall_ptr = new OpenCylinder(y0, y1, inner_radius); 
	inner_wall_ptr->set_material(matte_ptr3);
	
	
	// construct the ring as a compound object
	
	Compound* ring_ptr = new Compound;
	ring_ptr->add_object(bottom_ptr); 
	ring_ptr->add_object(top_ptr);
	ring_ptr->add_object(outer_wall_ptr);
	ring_ptr->add_object(inner_wall_ptr);
	
	// use nested instances for the transformed ring
	
	Instance* rotated_ring_ptr = new Instance(ring_ptr);
	rotated_ring_ptr->rotate_z(-45);
	
	Instance* translated_ring_ptr = new Instance(rotated_ring_ptr);
	translated_ring_ptr->translate(1, 0, 0);
	add_object(translated_ring_ptr);
	
	// sphere
	
	Matte* matte_ptr4 = new Matte;			
	matte_ptr4->set_ka(0.15);    
	matte_ptr4->set_kd(0.9);
	matte_ptr4->set_cd(1, 0.75, 0);
	
	Sphere* sphere_ptr = new Sphere(Point3D(2, 1, 0.5), 0.2);
	sphere_ptr->set_material(matte_ptr4);
	add_object(sphere_ptr);
	
	// ground plane
	
	Matte* matte_ptr5 = new Matte;			
	matte_ptr5->set_ka(0.15);    
	matte_ptr5->set_kd(0.75);
	matte_ptr5->set_cd(1.0);
	
	Plane* plane_ptr = new Plane(Point3D(0, -2, 0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr5);
	add_object(plane_ptr);
}
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(12);
	
	background_color = RGBColor(0.9, 0.9, 1);  // pale blue
	
	tracer_ptr = new Whitted(this);
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(0.5);
	set_ambient_light(ambient_ptr);
	
		
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 3); 
	pinhole_ptr->set_lookat(0.0); 
	pinhole_ptr->set_view_distance(450.0);		// for Figure 28.44(a)
//	pinhole_ptr->set_view_distance(1800.0);		// for Figure 28.44(b)
	pinhole_ptr->compute_uvw();
	set_camera(pinhole_ptr);
	
		
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(10, 20, 20);
	light_ptr->scale_radiance(15.0);
	light_ptr->set_shadows(false);
	add_light(light_ptr);
	
	
	// reflective sphere inside cube
		
	Reflective*	reflective_ptr = new Reflective;
	reflective_ptr->set_ka(0.3);	
	reflective_ptr->set_kd(0.25); 
	reflective_ptr->set_cd(0, 0.25, 1);  
	reflective_ptr->set_kr(0.65); 
	
	Sphere*	sphere_ptr1 = new Sphere(Point3D(0.0), 0.75);
	sphere_ptr1->set_material(reflective_ptr); 
	add_object(sphere_ptr1);
	
	
	// transparent cube
	
	RGBColor glass_color(0.64, 0.98, 0.88);	// light cyan
	
	Dielectric* glass_ptr = new Dielectric;
	glass_ptr->set_exp(2000.0);  
	glass_ptr->set_eta_in(1.5);					// glass
	glass_ptr->set_eta_out(1.0);				// air
	glass_ptr->set_cf_in(glass_color);
	glass_ptr->set_cf_out(white); 
//	glass_ptr->set_shadows(false);
		
	Box* box_ptr = new Box(Point3D(-1.0), Point3D(1.0));
	box_ptr->set_material(glass_ptr);
	add_object(box_ptr);
		
	
	// plane
	
	Checker3D* checker_ptr = new Checker3D;
	checker_ptr->set_size(4.0); 
	checker_ptr->set_color1(1, 1, 0.4);    		// yellow
	checker_ptr->set_color2(1, 0.5, 0);   		// orange
	
	SV_Matte* sv_matte_ptr = new SV_Matte;		
	sv_matte_ptr->set_ka(0.5);
	sv_matte_ptr->set_kd(0.1);
	sv_matte_ptr->set_cd(checker_ptr);
	
	Plane* plane_ptr = new Plane(Point3D(0, -10.1, 0), Normal(0, 1, 0)); 
	plane_ptr->set_material(sv_matte_ptr);	
	add_object(plane_ptr);
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    int i;
    float r = 0;
	int f = -15;
	int g = 0;
	int l = 0;
	int y = 0;
	int u = 15;
	int q = 0;
	int gamestate=0;
	int PlayerHP=15, Bosshealth=30, enemy1health=5, enemy2health=5, Bigtimer=600, CD;
	int SpawnLemon1=0, SpawnLemon2=0, SpawnLemon3=0, SpawnBigLemon=0, enemybullet=0;
	float Lemonx1=0, Lemonx2=0, Lemonx3=0, LemonxBig=0, enemybulletx=0;
	int Lemony1=0, Lemony2=0, Lemony3=0, LemonyBig=0, enemybullety=0;
	int a=0, b=0, c=0, d=0, count, Goomba_attack1=0, Goomba_attack2=0, Goomba_move1, Goomba_move2;
    Space *space;
    Entity *cube1,*cube2, *Actor;
    char bGameLoopRunning = 1;
	Vec3D Bosspos = {u, y, 2};
	Vec3D enemy1pos = {5, 10, 2};
	Vec3D enemy2pos = {5, -10, 2};
    Vec3D cameraPosition = {0,0,70.3};
    Vec3D cameraRotation = {0,0,360};
    SDL_Event e;
    Obj *megaman,*boss, *mapp, *mape, *lemon, *BossHPBar, *PlayerHPBar, *Goomba;
    Sprite *megamantexture, *bosstexture, *maptexture1, *maptexture2, *lemontexture, *BosstextureHP, *PlayertextureHP, *Goombatexture;
    
    init_logger("gametest3d.log");
    if (graphics3d_init(1024,768,1,"gametest3d",33) != 0)
    {
        return -1;
    }
    model_init();
    obj_init();
    entity_init(255);
    
   //load objects, models here, replace cube with megaman
    megaman = obj_load("models/MPU.obj");
	//load his uv map "texture file"
    megamantexture = LoadSprite("models/MegaManBody1.png",1024,1024);

	PlayerHPBar = obj_load("models/cube.obj");
	PlayertextureHP = NULL;


	boss = obj_load("models/Fireman.obj");
	bosstexture = LoadSprite("models/FireManBody1.png",1024,1024);

	BossHPBar = obj_load("models/cube.obj");
	BosstextureHP = NULL;

	Goomba = obj_load("models/goomba.obj");
	Goombatexture = LoadSprite("models/goomba_tex.png",1024,1024);

    mapp = obj_load("models/MidtermMapSingle.obj");
	maptexture1 = LoadSprite("models/PlayerTile(Red).png",1024,1024);

	mape = obj_load("models/MidtermMapSingle.obj");
	maptexture2 = LoadSprite("models/BossTile(Blue).png",1024,1024);
    
    lemon = obj_load("models/cube.obj");
	lemontexture = NULL;//LoadSprite("models/cube_text.png",1024,1024);
    
	    
    while (bGameLoopRunning)
    {
        entity_think_all();

        while ( SDL_PollEvent(&e) ) 
        {
            if (e.type == SDL_QUIT)
            {
                bGameLoopRunning = 0;
            }
            else if (e.type == SDL_KEYDOWN)
            {
                if (e.key.keysym.sym == SDLK_ESCAPE)
                {
                    bGameLoopRunning = 0;
                }
                else if (e.key.keysym.sym == SDLK_x)
                {
                    cameraPosition.z++;
                }
                else if (e.key.keysym.sym == SDLK_z)
                {
                    cameraPosition.z--;
                }
                else if (e.key.keysym.sym == SDLK_h)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -sin(cameraRotation.z * DEGTORAD),
                            cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_y)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            sin(cameraRotation.z * DEGTORAD),
                            -cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_j)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            cos(cameraRotation.z * DEGTORAD),
                            sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_g)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -cos(cameraRotation.z * DEGTORAD),
                            -sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
				else if (e.key.keysym.sym == SDLK_d)
                {
                   
				   
				   if(f >= -5)
				   {
					   f = -5;
				   }
				   else
				   {
					   f += 10;
				   }
                }
				else if (e.key.keysym.sym == SDLK_a)
                {
                   
				   
				   if(f <= -20)
				   {
					   f = -25;
				   }
				   else
				   {
					   f -= 10;
				   }
				  			
                }
				else if (e.key.keysym.sym == SDLK_w)
                {
                   
				   if(g >= 5)
				   {
					   g = 10;
				   }
				   else
				   {
					   g += 10;
				   }
			
                }
				else if (e.key.keysym.sym == SDLK_s)
                {
                   
				   g -= 10;
				    if(g <= -5)
				   {
					   g = -10;
				   }
			
                }
                else if (e.key.keysym.sym == SDLK_LEFT)
                {
                    cameraRotation.z += 1;
                }
                else if (e.key.keysym.sym == SDLK_RIGHT)
                {
                    cameraRotation.z -= 1;
                }
                else if (e.key.keysym.sym == SDLK_UP)
                {
                    cameraRotation.x += 1;
                }
                else if (e.key.keysym.sym == SDLK_DOWN)
                {
                    cameraRotation.x -= 1;
                }
                else if (e.key.keysym.sym == SDLK_SPACE)
                {
                    
					CD = TIME + Bigtimer;					
					
                }
				else if (e.key.keysym.sym == SDLK_n)
                {
                   
				   if (enemy1health <= 0 && enemy2health <= 0)
				   {
					   gamestate=1;
				   }
			
                }
				else if (e.key.keysym.sym == SDLK_n)
                {
                   
				   if (enemy1health <= 0 && enemy2health <= 0)
				   {
					   gamestate=1;
				   }
			
                }
            }
			else if (e.type == SDL_KEYUP)
			{
				if (e.key.keysym.sym == SDLK_SPACE)
				{
					
					if (TIME >= CD && SpawnBigLemon !=1)
					{
						SpawnBigLemon = 1;
						LemonxBig = f;
						LemonyBig = g;
					}
					else if (SpawnLemon1 != 1)
					{
						SpawnLemon1 = 1;
						Lemonx1 = f;
						Lemony1 = g;
					}
					else if (SpawnLemon2 != 1)
					{
						SpawnLemon2 = 1;
						Lemonx2 = f;
						Lemony2 = g;
					}
					else if (SpawnLemon3 != 1)
					{
						SpawnLemon3 = 1;
						Lemonx3 = f;
						Lemony3 = g;
					}
					
				}
			}
				
        }

                
        graphics3d_frame_begin();
        
        glPushMatrix();
        set_camera(
            cameraPosition,
            cameraRotation);
        
        //entity_draw_all();
      
		if (PlayerHP > 0 )
		{
		//Megaman
        obj_draw(
            megaman,
            vec3d(f, g, 2),
            vec3d(90,90,0),
            vec3d(0.5,0.5,0.5),
            vec4d(1,1,1,1),
            megamantexture
        );

		//Megaman HP BAR
		obj_draw(
            PlayerHPBar,
            vec3d(-30+PlayerHP/(2),20,2),
            vec3d(90,-90,0),
            vec3d(.9,.9,PlayerHP/(2)),
            vec4d(0,1,0,1),
			PlayertextureHP
        );
		}

		//Megaman Projectiles
		//Lemon1
		if (SpawnLemon1 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx1 + a*(.4), Lemony1, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			a++;
				if (Lemonx1 + a*(.4) >=30)
				{
					SpawnLemon1 = 0;
					a=0;
				}
				else if (Lemonx1 + a*(.4) == enemy1pos.x && Lemony1 == enemy1pos.y)
				{
					SpawnLemon1 = 0;
					a=0;
					enemy1health -= 1;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx1 + a*(.4) == enemy2pos.x && Lemony1 == enemy2pos.y)
				{
					SpawnLemon1 = 0;
					a=0;
					enemy2health -= 1;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx1 + a*(.4) == Bosspos.x && Lemony1 == Bosspos.y)
				{
				SpawnLemon1 = 0;
				a=0;
				Bosshealth -= 1;
				//slog("Boss Health %d",Bosshealth);
				}
		}
		//Lemon2
		if (SpawnLemon2 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx2 + b*(.4), Lemony2, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			b++;
				if (Lemonx2 + b*(.4) >=30)
				{
					SpawnLemon2 = 0;
					b=0;
				}
				else if (Lemonx2 + b*(.4) == enemy1pos.x && Lemony2 == enemy1pos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					enemy1health -= 1;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx2 + b*(.4) == enemy2pos.x && Lemony2 == enemy2pos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					enemy2health -= 1;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx2 + b*(.4) == Bosspos.x && Lemony2 == Bosspos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					Bosshealth -= 1;
					//slog("Boss Health %d",Bosshealth);
				}
		}
		if (SpawnLemon3 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx3 + c*(.4), Lemony3, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			c++;
				//lemons fly off staege
				if (Lemonx3 + c*(.4) >=30)
				{
					SpawnLemon3 = 0;
					c=0;
				}
				//lemons collide with enemies
				else if (Lemonx3 + c*(.4) == enemy1pos.x && Lemony3 == enemy1pos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					enemy1health -= 1;
					slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx3 + c*(.4) == enemy2pos.x && Lemony3 == enemy2pos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					enemy2health -= 1;
					slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx3 + c*(.4) == Bosspos.x && Lemony3 == Bosspos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					Bosshealth -= 1;
					//slog("Boss Health %d",Bosshealth);
				}
		}
		if (SpawnBigLemon != 0)
		{
			obj_draw(
			lemon,
            vec3d(LemonxBig + d*(.4), LemonyBig, 4),
            vec3d(90,90,0),
            vec3d(2,2,4),
            vec4d(.9,.3,.1,1),
		    lemontexture
		);
			d++;
				if (LemonxBig + d*(.4) >=30)
				{
					SpawnBigLemon = 0;
					d=0;
				}
				else if (LemonxBig + d*(.4) == enemy1pos.x && LemonyBig == enemy1pos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					enemy1health -= 5;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (LemonxBig + d*(.4) == enemy2pos.x && LemonyBig == enemy2pos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					enemy2health -= 5;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && LemonxBig + d*(.4) == Bosspos.x && LemonyBig == Bosspos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					Bosshealth -= 5;
					slog("Boss Health %d",Bosshealth);
				}
		}

		
		//MAP
		obj_draw(
            mapp,
            vec3d(-15,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
		    maptexture1
		);
		obj_draw(
            mape,
            vec3d(15,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
		    maptexture2
		);
		

		//Enemies
		if (gamestate == 0)
		{

			if (enemy1health > 0)
			{
			//enemy_move(enemypos.x,enemypos.y, &enemypos);
			//enemy_attack1(Goomba_attack1, &enemy1pos);

			obj_draw(
            Goomba,
            vec3d(enemy1pos.x,enemy1pos.y,2),
            vec3d(90,-90,0),
            vec3d(0.1,0.1,0.1),
            vec4d(1,1,1,1),
            Goombatexture
			);
						
			if (Goomba_attack1 == 0)
			{
				Goomba_attack1 = rand_ranged( 1, 5); //start to (end - 1)
				if (Goomba_attack1 == 2)
				{
					Goomba_attack1 = 1;
				}
		
			};

			if (Goomba_attack1 == 1)
			{
				enemy1pos.x -=.1;
				if (enemy1pos.x <= -30)
				{
					Goomba_attack1 = 0;
					enemy1pos.x = 5;
				}
			}

			}
			else
			{
				enemy1pos.x = 50;
				enemy1pos.y = 50;
			}

			if (enemy2health > 0)
			{
			//enemy_move(enemypos.x,enemypos.y, &enemypos);
			//enemy_attack2(Goomba_attack2, &enemy2pos);
			obj_draw(
            Goomba,
            vec3d(enemy2pos.x,enemy2pos.y,2),
            vec3d(90,-90,0),
            vec3d(0.1,0.1,0.1),
            vec4d(1,1,1,1),
            Goombatexture
			);

			//bottom Goomba won't attack

			if (Goomba_attack2 == 0)
			{
				Goomba_attack2 = rand_ranged( 1, 5); //start to (end - 1)
				if (Goomba_attack2 == 2)
				{
					Goomba_attack2 = 1;
				}
		
			};

			if (Goomba_attack2 == 1)
			{
				enemy2pos.x -=.1;
				if (enemy2pos.x <= -30)
				{
					Goomba_attack2 = 0;
					enemy2pos.x = 5;
				}
			}

			
			}
			else
			{
				enemy2pos.x = 50;
				enemy2pos.y = 50;
			}
			
		}
		if (gamestate != 0)
		{
		if (Bosshealth > 0)
		{
			Boss_move(Bosspos.x,Bosspos.y, &Bosspos);      	    
			//Fire man
			obj_draw(
				boss,
				vec3d(Bosspos.x,Bosspos.y,2),
				vec3d(90,-90,0),
				vec3d(0.5,0.5,0.5),
				vec4d(1,1,1,1),
				bosstexture
				);

				obj_draw(
				BossHPBar,
				vec3d(30-Bosshealth/(2.5),20,2),
				vec3d(90,-90,0),
				vec3d(.9,.9,Bosshealth/(2.5)),
				vec4d(1,0,0,1),
				BosstextureHP
			);

		}
		else
		{
			obj_free(boss);

			Bosspos.x = 50;
			Bosspos.y = 50;
			slog("You WIN!");
		}
		

		}
        
        if (r > 360)r -= 360;
        glPopMatrix();
        /* drawing code above here! */
        graphics3d_next_frame();
	} 
	return 0;
	}
void 												
World::build(void) {
	int num_samples = 5041;
	
	vp.set_hres(600);	  		
	vp.set_vres(400);
	vp.set_samples(num_samples); 
	vp.set_max_depth(5);
		
	tracer_ptr = new PathTrace(this);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 100, 2);		
	pinhole_ptr->set_lookat(0, 0, 2);
	pinhole_ptr->set_view_distance(5000);	
	pinhole_ptr->compute_uvw();     
	set_camera(pinhole_ptr);

	
	// emissive sphere
	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->set_ce(0.75, 1, 0.75);
	emissive_ptr->scale_radiance(30.0);   
		
	Sphere* sphere_ptr = new Sphere(Point3D(-2, 7, 6), 1); 
	sphere_ptr->set_material(emissive_ptr);
	sphere_ptr->set_sampler(new MultiJittered(num_samples));
	add_object(sphere_ptr);
		
	
	// reflective open half cylinder
	
	Reflective* reflective_ptr = new Reflective;
	reflective_ptr->set_ka(0.0); 
	reflective_ptr->set_kd(0.4); 
	reflective_ptr->set_ks(0.0);      
	reflective_ptr->set_exp(1.0);
	reflective_ptr->set_kr(0.95); 
	reflective_ptr->set_cr(1.0, 0.5, 0.25);  // orange 
	
	double y0 		= -1.0;
	double y1 		= 3.0;
	double radius 	= 3.0;
	double phi_min 	= 90.0;
	double phi_max 	= 270.0;
	
	ConcavePartCylinder* cylinder_ptr = new ConcavePartCylinder(y0, y1, radius, phi_min, phi_max); 
	cylinder_ptr->set_material(reflective_ptr);
	add_object(cylinder_ptr);	
	
	
	// plane

	Matte* matte_ptr = new Matte;			
	matte_ptr->set_ka(0.0);		
	matte_ptr->set_kd(0.75);
	matte_ptr->set_cd(1);
	matte_ptr->set_sampler(new MultiJittered(num_samples));
	
	Plane* plane_ptr = new Plane(Point3D(0, -1.0, 0), Normal(0, 1, 0)); 	
	plane_ptr->set_material(matte_ptr);
	add_object(plane_ptr);
}
Esempio n. 12
0
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(2);	
	
	tracer_ptr = new Whitted(this);
	background_color = black;
	
	MultiJittered* sampler_ptr = new MultiJittered(num_samples);
		
	AmbientOccluder* occluder_ptr = new AmbientOccluder;
	occluder_ptr->set_min_amount(0.25);		
	occluder_ptr->set_sampler(sampler_ptr);
	set_ambient_light(occluder_ptr);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(-6, 5, 11);    	
	pinhole_ptr->set_lookat(0 , 0, 0);
	pinhole_ptr->set_view_distance(5200);  
	pinhole_ptr->compute_uvw();     
	set_camera(pinhole_ptr); 

	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(10, 5, 20);		
	light_ptr->scale_radiance(2.0);
	light_ptr->set_shadows(true);
	add_light(light_ptr);
	
	
	Phong* phong_ptr = new Phong;			
	phong_ptr->set_ka(0.2); 
	phong_ptr->set_kd(0.95); 
	phong_ptr->set_cd(1, 0.6, 0);   // orange
	phong_ptr->set_ks(0.5);  
	phong_ptr->set_exp(20); 
	phong_ptr->set_cs(1, 0.6, 0);   // orange   
		
	const char* file_name = "plyFiles/Horse97K.ply";		
	Grid* horse_ptr = new Grid(new Mesh);
	horse_ptr->read_smooth_triangles(file_name);
	horse_ptr->set_material(phong_ptr); 
	horse_ptr->setup_cells();
	add_object(horse_ptr);

	
	Reflective*	reflective_ptr = new Reflective;			
	reflective_ptr->set_ka(0.2); 
	reflective_ptr->set_kd(0.75);
	reflective_ptr->set_cd(0.5);
	reflective_ptr->set_ks(0.0);
	reflective_ptr->set_exp(20);
	reflective_ptr->set_kr(0.5);  
	reflective_ptr->set_cr(0.8, 1.0, 0.8);    
	
	Plane* plane_ptr = new Plane(Point3D(0, -.3, 0), Normal(0, 1, 0)); 	
	plane_ptr->set_material(reflective_ptr);
	add_object(plane_ptr);	
}
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(10);
	
	tracer_ptr = new Whitted(this);	
	background_color = RGBColor(0.15); 
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(0.5);
	set_ambient_light(ambient_ptr);
	
			
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(2000, 4000, -1000);
	pinhole_ptr->set_lookat(38, 75, -20);
	pinhole_ptr->set_view_distance(45000);
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
		
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(150, 150, 0);  
	light_ptr->scale_radiance(3.0);
	light_ptr->set_shadows(true);
	add_light(light_ptr);

	
	// yellow-green reflective sphere
	
	Reflective* reflective_ptr1 = new Reflective;			
	reflective_ptr1->set_ka(0.25); 
	reflective_ptr1->set_kd(0.5);
	reflective_ptr1->set_cd(0.75, 0.75, 0);    	// yellow
	reflective_ptr1->set_ks(0.15);
	reflective_ptr1->set_exp(100.0);
	reflective_ptr1->set_kr(0.75);
	reflective_ptr1->set_cr(white); 			// default color
	
	float radius = 23.0;
	Sphere* sphere_ptr1 = new Sphere(Point3D(38, radius, -25), radius); 
	sphere_ptr1->set_material(reflective_ptr1);
	add_object(sphere_ptr1);
	
	
	// orange non-reflective sphere
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.45); 
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(0.75, 0.25, 0);   // orange
	
	Sphere* sphere_ptr2 = new Sphere(Point3D(-7, 10, 42), 20);
	sphere_ptr2->set_material(matte_ptr1);      
	add_object(sphere_ptr2);
	
	
	// sphere on top of box

	Reflective* reflective_ptr2 = new Reflective;			
	reflective_ptr2->set_ka(0.35); 
	reflective_ptr2->set_kd(0.75);
	reflective_ptr2->set_cd(black); 
	reflective_ptr2->set_ks(0.0);		// default value
	reflective_ptr2->set_exp(1.0);		// default value, but irrelevant in this case
	reflective_ptr2->set_kr(0.75);
	reflective_ptr2->set_cr(white); 

	Sphere* sphere_ptr3 = new Sphere(Point3D(-30, 59, 35), 20);
	sphere_ptr3->set_material(reflective_ptr2);     
	add_object(sphere_ptr3);

	
	// cylinder
	
	Reflective* reflective_ptr3 = new Reflective;			
	reflective_ptr3->set_ka(0.35); 
	reflective_ptr3->set_kd(0.5);
	reflective_ptr3->set_cd(0, 0.5, 0.75);   // cyan
	reflective_ptr3->set_ks(0.2);
	reflective_ptr3->set_exp(100.0);
	reflective_ptr3->set_kr(0.75);
	reflective_ptr3->set_cr(white);
	
	double bottom 			= 0.0;
	double top 				= 85;   
	double cylinder_radius	= 22;
	SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, cylinder_radius);
	cylinder_ptr->set_material(reflective_ptr3);
	add_object(cylinder_ptr);
	
	
	// box
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.15); 
	matte_ptr2->set_kd(0.5);
	matte_ptr2->set_cd(0.75, 1.0, 0.75);   // light green
	
	Box* box_ptr = new Box(Point3D(-35, 0, -110), Point3D(-25, 60, 65));
	box_ptr->set_material(matte_ptr2);
	add_object(box_ptr);

	
	// ground plane
	
	PlaneChecker* checker_ptr = new PlaneChecker;
	checker_ptr->set_size(20.0);		
	checker_ptr->set_outline_width(2.0);
	checker_ptr->set_color1(white);
	checker_ptr->set_color2(white);
	checker_ptr->set_outline_color(black); 
	
	SV_Matte* sv_matte_ptr = new SV_Matte;		
	sv_matte_ptr->set_ka(0.30);
	sv_matte_ptr->set_kd(0.9);
	sv_matte_ptr->set_cd(checker_ptr); 
	
	Plane* plane_ptr = new Plane(Point3D(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(400);
	vp.set_samples(num_samples);
	
	tracer_ptr = new RayCast(this);
			
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(0.5);
	set_ambient_light(ambient_ptr);
	
	float a = 0.75;
	background_color = RGBColor(0.0, 0.3 * a, 0.25 * a);  // torquise
			
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(7.5, 4, 10); 
	pinhole_ptr->set_lookat(-1, 3.7, 0);  
	pinhole_ptr->set_view_distance(340);		
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
		
		
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.25);
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(0.75, 0.75, 0);    	// dark yellow
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.45); 
	matte_ptr2->set_kd(0.75);
	matte_ptr2->set_cd(0.75, 0.25, 0);  	 // orange
	
	Matte* matte_ptr3 = new Matte;			
	matte_ptr3->set_ka(0.4); 
	matte_ptr3->set_kd(0.75);
	matte_ptr3->set_cd(1, 0.5, 1);  		// mauve
	
	Matte* matte_ptr4 = new Matte;			
//	matte_ptr4->set_ka(ka);
	matte_ptr4->set_ka(0.15);
	matte_ptr4->set_kd(0.5);
	matte_ptr4->set_cd(0.75, 1.0, 0.75);   	// light green
	
	Matte* matte_ptr5 = new Matte;			
	matte_ptr5->set_ka(0.20); 
	matte_ptr5->set_kd(0.97);	
	matte_ptr5->set_cd(white);  
	
	
	
	// spheres
	
	Sphere* sphere_ptr1 = new Sphere(Point3D(3.85, 2.3, -2.55), 2.3);
	sphere_ptr1->set_material(matte_ptr1);
	add_object(sphere_ptr1);
	
	Sphere* sphere_ptr2 = new Sphere(Point3D(-0.7, 1, 4.2), 2);
	sphere_ptr2->set_material(matte_ptr2);     
	add_object(sphere_ptr2);

	// cylinder 
	
	float bottom 	= 0.0;
	float top 		= 8.5;   
	float radius	= 2.2;
	SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius);
	cylinder_ptr->set_material(matte_ptr3);
	add_object(cylinder_ptr);
	
	// box
		
	Box* box_ptr = new Box(Point3D(-3.5, 0, -11), Point3D(-2.5, 6, 6.5));
	box_ptr->set_material(matte_ptr4);
	add_object(box_ptr);
	
	// ground plane
	
	Plane* plane_ptr = new Plane(Point3D(0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr5);
	add_object(plane_ptr);
}
void 												
World::build(void) {
	int num_samples = 16;
	Sampler* sampler_ptr = new MultiJittered(num_samples);

	vp.set_hres(400);
	vp.set_vres(400);
	vp.set_max_depth(1);
	vp.set_sampler(sampler_ptr);	

	background_color = black;

	tracer_ptr = new AreaLighting(this);

	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(30, 13, 20);
	pinhole_ptr->set_lookat(0, -2, 0); 
	pinhole_ptr->set_view_distance(12000); 
	pinhole_ptr->compute_uvw();     
	set_camera(pinhole_ptr); 

	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->scale_radiance(3.0);
	emissive_ptr->set_ce(white);
	
	Rectangle* rectangle_ptr = new Rectangle(Point3D(-1, -0.5, -1), Vector3D(2, 0, 0), Vector3D(0, 0, 2), Normal(0, -1, 0));
	rectangle_ptr->set_material(emissive_ptr);
	rectangle_ptr->set_sampler(sampler_ptr);
	add_object(rectangle_ptr);
	
	AreaLight* rectangularLight_ptr = new AreaLight;
	rectangularLight_ptr->set_object(rectangle_ptr);
	rectangularLight_ptr->set_shadows(true);
	add_light(rectangularLight_ptr);
	
	
	Reflective* reflective_ptr1 = new Reflective;
	reflective_ptr1->set_ka(0.2); 
	reflective_ptr1->set_kd(0.1); 
	reflective_ptr1->set_cd(0, 1, 0.2);  // green
	reflective_ptr1->set_ks(0.0);     
	reflective_ptr1->set_exp(1);
	reflective_ptr1->set_kr(0.85); 
	reflective_ptr1->set_cr(0.75, 0.75, 1);  // blue 

	Sphere* sphere_ptr1 = new Sphere(Point3D(0, -2, 0), 0.5); 	
	sphere_ptr1->set_material(reflective_ptr1);
	add_object(sphere_ptr1);

		
	Checker3D* checker_ptr = new Checker3D;
	checker_ptr->set_size(1);		
	checker_ptr->set_color1(1.0);  
	checker_ptr->set_color2(0.9);
	
	SV_Matte* sv_matte_ptr = new SV_Matte;		
	sv_matte_ptr->set_ka(0.25);
	sv_matte_ptr->set_kd(0.75);
	sv_matte_ptr->set_cd(checker_ptr);
	
	Plane* plane_ptr = new Plane(Point3D(0, -2.75, 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(400); 
	vp.set_samples(num_samples);	
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(0.5);
	set_ambient_light(ambient_ptr);
	
	tracer_ptr = new RayCast(this);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(10, 15, 20);
	pinhole_ptr->set_lookat(-0.5, -0.5, 0); 
	pinhole_ptr->set_view_distance(800);
	pinhole_ptr->compute_uvw();
	set_camera(pinhole_ptr);
	
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(30, 30, 25);  
	light_ptr->scale_radiance(3.0);  
	light_ptr->set_shadows(true);
	add_light(light_ptr);
	
	
	// ellipsoids
				
	float 	x0 					= -5.0;					// minimum x center coordinate
	float 	z0 					= -5.0;					// minimum z center coordinate
	float 	x1 					= 5.0;					// maximum x center coordinate
	float 	z1 					= 5.0;					// maximum z center coordinate
	int 	num_x_ellipsoids	= 5;					// number of ellipsoids in the x direction
	int 	num_z_ellipsoids	= 5;  					// number of ellipsoids in the z direction
	float 	radius 				= 1.0;   				// common sphere radius
	float	x_spacing			= (x1 - x0) / (num_x_ellipsoids - 1); // center spacing in x direction
	float	z_spacing			= (z1 - z0) / (num_z_ellipsoids - 1); // center spacing in x direction
	
	Sphere* sphere_ptr = new Sphere;
	set_rand_seed(1000);
	
	for (int iz = 0; iz < num_z_ellipsoids; iz++) {
		for (int ix = 0; ix < num_x_ellipsoids; ix++) {
			Phong* phong_ptr = new Phong;	
			phong_ptr->set_ka(0.35);  
			phong_ptr->set_kd(0.75);
			phong_ptr->set_ks(0.1);  
			phong_ptr->set_exp(20.0);
			phong_ptr->set_cd(rand_float(), rand_float(), rand_float());
			
			float xc = x0 + ix * x_spacing;  	// ellipsoid center x coordinate
			float zc = z0 + iz * z_spacing;		// ellipsoid center z coordinate
			
			Instance* ellipsoid_ptr = new Instance(sphere_ptr);
			ellipsoid_ptr->scale(1.0, 4.0 * rand_float(), 1.0);
			ellipsoid_ptr->translate(xc, 0, zc);
			ellipsoid_ptr->set_material(phong_ptr);
			add_object(ellipsoid_ptr);
		}
	}
	
	// ground plane 
	
	Matte* matte_ptr = new Matte;		
	matte_ptr->set_ka(0.75);
	matte_ptr->set_kd(0.5);
	matte_ptr->set_cd(0.85);  
	
	Plane* plane_ptr = new Plane(Point3D(0, -1, 0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr);
	add_object(plane_ptr);
}
void 												
World::build(void) {
	int num_samples = 100;

	vp.set_hres(600);
	vp.set_vres(400);
	vp.set_samples(num_samples);
	
	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(100, 45, 100);  
	pinhole_ptr->set_lookat(-10, 40, 0);  
	pinhole_ptr->set_view_distance(400);  	
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->set_ce(white);  
	emissive_ptr->scale_radiance(1.5);   
							
	EnvironmentLight* environmentLight_ptr = new EnvironmentLight;
	environmentLight_ptr->set_material(emissive_ptr);
	environmentLight_ptr->set_sampler(new MultiJittered(num_samples));
	environmentLight_ptr->set_shadows(true);
	add_light(environmentLight_ptr);
	
	
	ConcaveSphere* sphere_ptr = new ConcaveSphere;		// centered on the origin
	sphere_ptr->set_radius(1000000.0);
	sphere_ptr->set_shadows(false);
	sphere_ptr->set_material(emissive_ptr);
	add_object(sphere_ptr);	
	
		
	float ka = 0.2;  // common 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(white);
	
	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);				// gray
	
	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.75);
	matte_ptr3->set_cd(0.73, 0.22, 0.0);    // orange
	
	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.75);
	matte_ptr4->set_cd(0.60);				// gray
			
	double bottom 	= 0.0;
	double top 		= 85.0;
	double radius	= 22.0;
	SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius);
	cylinder_ptr->set_material(matte_ptr4);
	add_object(cylinder_ptr);

	
	// box
	
	MultiJittered* sampler_ptr5 = new MultiJittered(num_samples);
	
	Matte* matte_ptr5 = new Matte;			
	matte_ptr5->set_ka(ka); 
	matte_ptr5->set_kd(0.75);
	matte_ptr5->set_cd(0.95);				// gray
	
	Box* box_ptr = new Box(Point3D(-55, 0, -110), Point3D(-25, 60, 65));  // thicker
	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.95);	
	matte_ptr6->set_cd(0.37, 0.43, 0.08);     // olive green
	
	Plane* plane_ptr = new Plane(Point3D(0, 0.01, 0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr6);
	add_object(plane_ptr);
}
void 												
World::build(void) {
	int num_samples = 100;
	
	vp.set_hres(600);
	vp.set_vres(400);
	vp.set_samples(num_samples);
		
	tracer_ptr = new AreaLighting(this);	
		
	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);

	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->scale_radiance(0.90);
	emissive_ptr->set_ce(white);   	
		
	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
	float ks = 1.0;  		// commom specular reflection coefficient
	float exp = 10.0;   	// for Figure 18.11(a)
//	float exp = 50.0;   	// for Figure 18.11(b)
//	float exp = 200.0;   	// for Figure 18.11(c)
	RGBColor cs(1, 0, 0); 	// common specular color
	
	// large sphere
	
	Phong* phong_ptr1 = new Phong;			
	phong_ptr1->set_ka(ka); 
	phong_ptr1->set_kd(0.6);
	phong_ptr1->set_cd(0.75);
	phong_ptr1->set_ks(ks);
	phong_ptr1->set_exp(exp);
	phong_ptr1->set_cs(cs);
	
	Sphere* sphere_ptr1 = new Sphere(Point3D(38, 20, -24), 20);
	sphere_ptr1->set_material(phong_ptr1);
	add_object(sphere_ptr1);
	
	
	// small sphere
		
	Phong* phong_ptr2 = new Phong;			
	phong_ptr2->set_ka(ka); 
	phong_ptr2->set_kd(0.5);
	phong_ptr2->set_cd(0.95);
	phong_ptr2->set_ks(ks);
	phong_ptr2->set_exp(exp);
	phong_ptr2->set_cs(cs);
	
	Sphere* sphere_ptr2 = new Sphere(Point3D(34, 12, 13), 12);
	sphere_ptr2->set_material(phong_ptr2);
	add_object(sphere_ptr2);
	
	
	// medium sphere
	
	Phong* phong_ptr3 = new Phong;			
	phong_ptr3->set_ka(ka); 
	phong_ptr3->set_kd(0.5);
	phong_ptr3->set_cd(0.75);
	phong_ptr3->set_ks(ks);
	phong_ptr3->set_exp(exp);
	phong_ptr3->set_cs(cs);
	
	Sphere* sphere_ptr3 = new Sphere(Point3D(-7, 15, 42), 16);
	sphere_ptr3->set_material(phong_ptr3);
	add_object(sphere_ptr3);
	
	
	// cylinder
	
	Phong* phong_ptr4 = new Phong;			
	phong_ptr4->set_ka(ka); 
	phong_ptr4->set_kd(0.5);
	phong_ptr4->set_cd(0.60);
	phong_ptr4->set_ks(ks);
	phong_ptr4->set_exp(exp);
	phong_ptr4->set_cs(cs);
	
	float bottom 	= 0.0;
	float top 		= 85; 
	float radius	= 22;
	SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius);
	cylinder_ptr->set_material(phong_ptr4);
	add_object(cylinder_ptr);

	
	// box
	
	Phong* phong_ptr5 = new Phong;			
	phong_ptr5->set_ka(ka); 
	phong_ptr5->set_kd(0.5);
	phong_ptr5->set_cd(0.95);
	phong_ptr5->set_ks(ks);
	phong_ptr5->set_exp(exp);
	phong_ptr5->set_cs(cs);
	
	Box* box_ptr = new Box(Point3D(-35, 0, -110), Point3D(-25, 60, 65));
	box_ptr->set_material(phong_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);
}
Esempio n. 19
0
/**
 to initialize the scene with the default one.
 */
void make_test_scene (int xsize, int ysize) {
    //camera
    set_camera (0.f, 4.f, -4.f,
                0.f, 0.f, 0.f,
                0.f, 1.f, 0.f,
                90.f, xsize, ysize);
    //objects
    Material * plastic = create_plastic_mat (0.6f, 0.5f, 0.5f,
                                             0.6f, 0.5f, 0.5f,
                                             100.f);
	
    // ground plane
    Geometry * plane = create_plane (0.f, -1.f, 0.f,
                                     0.f, 1.f, 0.f);
    add_object (plane, plastic);

    // Up row
    // base objects
    Geometry *boxLeft = create_box (-2.f, 3.f, 0.f,
                                    1.f, 0.f, 0.f,
                                    0.f, 0.25f, 1.f,
                                    1.f, 1.f, 1.f);
    Geometry *sphereLeft = create_sphere (-2.f, 3.f, 0.f,
                                          0.65f);
    Geometry *boxCenter = create_box (0.f, 3.25f, 0.f,
                                      1.f, 0.f, 0.f,
                                      0.f, 0.25f, 1.f,
                                      1.f, 1.f, 1.f);
    Geometry *sphereCenter = create_sphere (0.f, 3.25f, 0.f,
                                            0.65f);
    Geometry *boxRight = create_box (2.f, 3.f, 0.f,
                                     1.f, 0.f, 0.f,
                                     0.f, 0.25f, 1.f,
                                     1.f, 1.f, 1.f);
    Geometry *sphereRight = create_sphere (2.f, 3.f, 0.f,
                                           0.65f);
    // CSG objects
    Geometry *unionUp = create_csg_union (boxLeft, sphereLeft);
    Geometry *intersectionUp = create_csg_intersection(boxCenter, sphereCenter);
    Geometry *differenceUp = create_csg_difference(boxRight, sphereRight);
	
    add_object (unionUp, plastic);
    add_object (intersectionUp, plastic);
    add_object (differenceUp, plastic);
	
    // Middle row
    // base objects
    Geometry *coneLeft = create_cone(-2.25f, 1.f, -1.25f,
                                     -2.25f, 3.f, -1.25f,
                                     0.5f);
    Geometry *cylinderLeft = create_cylinder(-2.25f, 1.75f, -1.25f,
                                             0.5f, 0.f, 1.f,
                                             0.25f, 1.5f);
    Geometry *coneCenter = create_cone(0.f, 1.5f, -0.75f,
                                       0.f, 3.5f, -0.75f,
                                       0.5f);
    Geometry *cylinderCenter = create_cylinder(0.f, 2.25f, -0.75f,
                                               0.5f, 0.f, 1.f,
                                               0.25f, 1.5f);
    Geometry *coneRight = create_cone(2.25f, 1.f, -1.25f,
                                      2.25f, 3.f, -1.25f,
                                      0.5f);
    Geometry *cylinderRight = create_cylinder(2.25f, 1.75f, -1.25f,
                                              0.5f, 0.f, 1.f,
                                              0.25f, 1.5f);
    // CSG objects
    Geometry * unionDown = create_csg_union (coneLeft, cylinderLeft);
    Geometry * intersectionDown = create_csg_intersection(coneCenter, cylinderCenter);
    Geometry * differenceDown = create_csg_difference(coneRight, cylinderRight);
	
    add_object (unionDown, plastic);
    add_object (intersectionDown, plastic);
    add_object (differenceDown, plastic);
	
    // front object
    char complex_tree[] = "(- (* (bo 0. 2.5 -3.25 1. 0. 0. 0. 0. 1. 1.0 1.0 1.0) (sp 0. 2.5 -3.25 0.65) ) (+ (cy 0. 2.5 -3.25 1.0 0.0 0.0 0.3 1.75) (+ (cy 0. 2.5 -3.25 0.0 1.0 0.0 0.3 1.75) (cy 0. 2.5 -3.25 0.0 0.0 1.0 0.3 1.75) ) ) )";
    Geometry *tree = csg_parse(complex_tree);
    if (tree)
        add_object (tree, plastic);

    //lights
	// Front light -- white
    add_light (0.f, 5.f, -1.5f, 1.5f, 1.5f, 1.5f);
	// Back light -- blue
    add_light (4.f, 2.f, 10.f, 0.1f, 0.1f, 0.9f);
	// Left light -- red
    add_light (-4.f, 5.f, -2.f, 0.9f, 0.1f, 0.1f);
}
void 												
World::build(void) {
	int num_samples = 16;
	
	vp.set_hres(600);
	vp.set_vres(300);
	vp.set_samples(num_samples);
	
	tracer_ptr = new RayCast(this);	
				
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 25, 100);  
	pinhole_ptr->set_lookat(0);   
	pinhole_ptr->set_view_distance(6500);	 
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
	
	Directional* light_ptr = new Directional;
	light_ptr->set_direction(200, 250, 300);  
//	light_ptr->set_color(white);  			// for Figure 14.24(a)
	light_ptr->set_color(0, 0, 1);  		// for Figure 14.24(b)
	light_ptr->scale_radiance(3.0);			
	light_ptr->set_shadows(true);    // see Chapter 16
	add_light(light_ptr);
	
	
	// four spheres centered on the x axis
	
	float radius = 1.0;
	float gap = 0.2;	 // gap between spheres
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.0); 
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(1, 0, 0);		// red
	
	Sphere* sphere_ptr1 = new Sphere(Point3D(-3.0 * radius - 1.5 * gap, 0.0, 0.0), radius);
	sphere_ptr1->set_material(matte_ptr1);
	add_object(sphere_ptr1);
	
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.0); 
	matte_ptr2->set_kd(0.75);
	matte_ptr2->set_cd(1, 0.5, 0);		// orange
	
	Sphere* sphere_ptr2 = new Sphere(Point3D(-radius - 0.5 * gap, 0.0, 0.0), radius);
	sphere_ptr2->set_material(matte_ptr2);
	add_object(sphere_ptr2);
	
	
	Matte* matte_ptr3 = new Matte;			
	matte_ptr3->set_ka(0.0); 
	matte_ptr3->set_kd(0.75);
	matte_ptr3->set_cd(1, 1, 0);		// yellow
	
	Sphere* sphere_ptr3 = new Sphere(Point3D(radius + 0.5 * gap, 0.0, 0.0), radius);
	sphere_ptr3->set_material(matte_ptr3);
	add_object(sphere_ptr3);
	
	
	Matte* matte_ptr4 = new Matte;			
	matte_ptr4->set_ka(0.0); 
	matte_ptr4->set_kd(0.75);
	matte_ptr4->set_cd(0, 1, 0);		// green
	
	Sphere* sphere_ptr4 = new Sphere(Point3D(3.0 * radius + 1.5 * gap, 0.0, 0.0), radius);
	sphere_ptr4->set_material(matte_ptr4);
	add_object(sphere_ptr4);
		
	
	// ground plane
	
	Matte* matte_ptr5 = new Matte;			
	matte_ptr5->set_ka(0.25); 
	matte_ptr5->set_kd(0.5);	
	matte_ptr5->set_cd(1.0);    
	
	Plane* plane_ptr = new Plane(Point3D(0, -1, 0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr5);
	add_object(plane_ptr);
}
Esempio n. 21
0
/* The function called whenever a key is pressed. */
void
key_pressed(unsigned char key, int x, int y)
{
  // supress unused variable warnings
  (void)x;
  (void)y;
  /* avoid thrashing this call */
  usleep(100);

  camera_pose_t * camera_pose = get_camera_pose();
  
  switch(key)
  {
  case 'w':
  {
    camera_pose->focus_x += 10.0f*cos(camera_pose->phi);
    camera_pose->focus_y += 10.0f*sin(camera_pose->phi);
    set_camera();
    break;
  }
  case 's':
  {
    camera_pose->focus_x -= 10.0f*cos(camera_pose->phi);
    camera_pose->focus_y -= 10.0f*sin(camera_pose->phi);
    set_camera();
    break;
  }
  case 'd':
  {
    camera_pose->focus_x -= 10.0f*sin(camera_pose->phi);
    camera_pose->focus_y += 10.0f*cos(camera_pose->phi);
    set_camera();
    break;
  }
  case 'a':
  {
    camera_pose->focus_x += 10.0f*sin(camera_pose->phi);
    camera_pose->focus_y -= 10.0f*cos(camera_pose->phi);
    set_camera();
    break;
  }
  case 'r':
  {
    camera_pose->theta += 10.0f*3.14159f/180.0f;
    if (camera_pose->theta > 80.0f*3.14159f/180.0f)
      camera_pose->theta = 80.0f*3.14159f/180.0f;

    set_camera();
    break;
  }
  case 'f':
  {
    camera_pose->theta -= 10.0f*3.14159f/180.0f;
    if (camera_pose->theta < -80.0f*3.14159f/180.0f)
      camera_pose->theta = -80.0f*3.14159f/180.0f;

    set_camera();
    break;
  }
  case 'q':
  {
    camera_pose->phi += 10.0f*3.14159f/180.0f;
    set_camera();
    break;
  }
  case 'e':
  {
    camera_pose->phi -= 10.0f*3.14159f/180.0f;
    set_camera();
    break;
  }
  case 'x':
  {
    camera_pose->rho -= 10.0f;
    if (camera_pose->rho < 10.0f)
      camera_pose->rho = 10.0f;
    if (camera_pose->rho > 4000.0f)
      camera_pose->rho = 4000.0f;
    set_camera();
    break;
  }
  case 'z':
  {
    camera_pose->rho += 10.0f;
    set_camera();
    break;
  }

  case ESCAPE:
  {
  /* If escape is pressed, kill everything. */
    // glutDestroyWindow(window);
    exit(0);
    printf("ignoring ESCAPE key glutDestroyWindow call\n");
    break;
  }
  default:
    break;
  }// switch(key)

}
Esempio n. 22
0
void 												
World::build(void) {
	int num_samples = 1;

	vp.set_hres(200);	
	vp.set_vres(200);
	vp.set_pixel_size(0.05);		
	vp.set_samples(num_samples);	
	
	tracer_ptr = new RayCast(this);			

	float vpd = 100;  // view plane distance for 200 x 200 pixel images

	Pinhole* left_camera_ptr = new Pinhole;  
	left_camera_ptr->set_view_distance(vpd);
	
	Pinhole* right_camera_ptr = new Pinhole; 
	right_camera_ptr->set_view_distance(vpd);
	
	StereoCamera* stereo_ptr = new StereoCamera;		
	stereo_ptr->set_left_camera(left_camera_ptr);
	stereo_ptr->set_right_camera(right_camera_ptr);
	stereo_ptr->use_parallel_viewing();
//	stereo_ptr->use_transverse_viewing();
	stereo_ptr->set_pixel_gap(5);       // in pixels
	stereo_ptr->set_eye(5, 0, 100);
	stereo_ptr->set_lookat(0,0,0);
	stereo_ptr->compute_uvw();
	stereo_ptr->set_stereo_angle(0.75);  // in degrees
	stereo_ptr->setup_cameras(); 
	set_camera(stereo_ptr);
	
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(100, 100, 100);
	light_ptr->scale_radiance(3);
	light_ptr->set_shadows(true);
	add_light(light_ptr);
	
	
	// sphere materials
	
	Phong* phong_ptr1 = new Phong;			
	phong_ptr1->set_cd(0, 0.5, 0.5);   	// cyan
	phong_ptr1->set_ka(0.4); 
	phong_ptr1->set_kd(0.6);
	phong_ptr1->set_ks(0.2); 
	phong_ptr1->set_exp(20); 
	
	Phong*	phong_ptr2 = new Phong;
	phong_ptr2->set_cd(0.85, 0.6, 0.2); 	// brown				
	phong_ptr2->set_ka(0.3); 
	phong_ptr2->set_kd(0.7);
	phong_ptr2->set_ks(0.08);
	phong_ptr2->set_exp(20);  
	
	Phong*	phong_ptr3 = new Phong;			
	phong_ptr3->set_cd(1, 1, 0);     		// yellow
	phong_ptr3->set_ka(0.2); 
	phong_ptr3->set_kd(0.6);
	phong_ptr3->set_ks(0.08); 
	phong_ptr3->set_exp(20);   
	
	// the spheres
	
	Sphere* sphere1 = new Sphere(Point3D(0, 0, 35), 0.75);
	sphere1->set_material(phong_ptr1);
	add_object(sphere1);
	
	Sphere* sphere2 = new Sphere(Point3D(), 2);
	sphere2->set_material(phong_ptr2);
	add_object(sphere2);
	
	Sphere* sphere3 = new Sphere(Point3D(1.5, 0, -80), 2);
	sphere3->set_material(phong_ptr3);
	add_object(sphere3);	
}
Esempio n. 23
0
void
World::build(void) { 
	//int num_samples = 1;		// for Figure 26.7(a)
	int num_samples = 100;		// for Figure 26.7(b)
//	int num_samples = 1024;		// for Figure 26.7(c)
//	int num_samples = 10000;	// for Figure 26.7(d)
		
	vp.set_hres(1000);	  		
	vp.set_vres(1000);
	vp.set_samples(num_samples); 
	vp.set_max_depth(12);
	
	background_color = black;
	
	tracer_ptr = new PathTrace(this);
	
	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
	
	
	// the ceiling light - doesn't need samples
	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->set_ce(1.0, 0.73, 0.4);   
	emissive_ptr->scale_radiance(100);
	
	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);
	add_object(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
	matte_ptr1->set_sampler(new MultiJittered(num_samples));
	
	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   from Photoshop
	matte_ptr2->set_sampler(new MultiJittered(num_samples));
	
	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(1.0);	 // white
	matte_ptr3->set_sampler(new MultiJittered(num_samples));
	
	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 = 25;
	
	vp.set_hres(600);	  		
	vp.set_vres(600);
	vp.set_max_depth(3);      
	vp.set_samples(num_samples);
	
	background_color = RGBColor(0.75);
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(0.5);
	set_ambient_light(ambient_ptr);
	
	tracer_ptr = new Whitted(this);
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 20);
	pinhole_ptr->set_lookat(0.0);
	pinhole_ptr->set_view_distance(4500); 
	pinhole_ptr->compute_uvw();
	set_camera(pinhole_ptr);
	
		
	PointLight* light_ptr1 = new PointLight;
	light_ptr1->set_location(0, 50, 0);
	light_ptr1->scale_radiance(4.5);
	light_ptr1->set_shadows(false);
	add_light(light_ptr1);
	
	
	// transparent sphere
	
	Dielectric* glass_ptr = new Dielectric;
	glass_ptr->set_ks(0.15);
	glass_ptr->set_exp(100.0);
	glass_ptr->set_eta_in(1.5);
	glass_ptr->set_eta_out(1.0);
	glass_ptr->set_cf_in(0.47, 0.86, 0.74);
	glass_ptr->set_cf_out(white);
			
	Sphere* sphere_ptr = new Sphere;
	sphere_ptr->set_material(glass_ptr);
	add_object(sphere_ptr);                
	
	
	// plane with checker
		
	Checker3D* checker_ptr = new Checker3D;
	checker_ptr->set_size(4.0);		
	checker_ptr->set_color1(white);  	
	checker_ptr->set_color2(black);
	
	SV_Matte* sv_matte_ptr = new SV_Matte;		
	sv_matte_ptr->set_ka(0.25);
	sv_matte_ptr->set_kd(0.65);
	sv_matte_ptr->set_cd(checker_ptr);
	
	Plane* plane_ptr = new Plane(Point3D(0, -5, 0), Normal(0, 1, 0));  
	plane_ptr->set_material(sv_matte_ptr);
	add_object(plane_ptr);	
}
Esempio n. 25
0
void 												
World::build(void) {
	int num_samples = 64;
	
	vp.set_hres(600);			
	vp.set_vres(400);
	vp.set_samples(num_samples);
	
	tracer_ptr = new RayCast(this);	
	
	AmbientOccluder* ambient_occluder_ptr = new AmbientOccluder;
	ambient_occluder_ptr->set_sampler(new MultiJittered(num_samples));
	ambient_occluder_ptr->set_min_amount(1.0);   	// for Figure 17.13(a)
//	ambient_occluder_ptr->set_min_amount(0.25);		// for Figure 17.13(b)
	set_ambient_light(ambient_occluder_ptr);
	
	
	Orthographic* orthographic_ptr = new Orthographic;
	vp.set_pixel_size(0.31);	
	orthographic_ptr->set_eye(100, 100, 50);  
	orthographic_ptr->set_lookat(0, 10, 0);
	orthographic_ptr->compute_uvw(); 
	set_camera(orthographic_ptr);

	
	PointLight* light_ptr = new PointLight;
	light_ptr->set_location(150, 500, 300); 
	light_ptr->scale_radiance(3.75);
	light_ptr->set_shadows(true);
	add_light(light_ptr);
	
	
	// city parameters
	
	float 	a					= 10;   // city block width:  xw extent
	float 	b   				= 12;	// city block length:  yw extent
	int 	num_rows			= 10;  	// number of blocks in the xw direction
	int 	num_columns			= 12; 	// number of blocks in the zw direction
	float	width				= 7;	// building width: xw extent in range [min, a - offset]
	float 	length				= 7;	// building length: zw extent in range [min, b - offset]
	float 	min_size			= 6;	// mininum building extent in xw and yw directions
	float 	offset				= 1.0;	// half the minimum distance between buildings
	float 	min_height			= 0.0; 	// minimum building height
	float 	max_height			= 30; 	// maximum bulding height
	float 	height;						// the building height in range [min_height, max_height]
	int		num_park_rows		= 4;  	// number of blocks of park in xw direction
	int		num_park_columns	= 6;  	// number of blocks of park in xw direction
	int 	row_test;					// there are no buildings in the park
	int 	column_test;				// there are no buildings in the park
	float 	min_color			= 0.1;  // prevents black buildings
	float 	max_color			= 0.9;	// prevents white buildings
		
	set_rand_seed(15);  				// as the buildings' dimensions and colors are random, it's necessary to 
										// seed rand to keep these quantities the same at each run
										// if you leave this out, and change the number of samples per pixel,
										// these will change
	
	// the buildings are stored in a grid
	
	Grid* grid_ptr = new Grid;
	
	for (int r = 0; r < num_rows; r++)  			// xw direction
		for (int c = 0; c < num_columns; c++) {		// zw direction
			// determine if the block is in the park
		
			if ((r - num_rows / 2) >= 0)
				row_test = r -  num_rows / 2;
			else
				row_test = r -  num_rows / 2 + 1;
				
			if ((c - num_columns / 2) >= 0)
				column_test = c - num_columns / 2;
			else
				column_test = c - num_columns / 2 + 1;
			
			if (abs(row_test) >= (num_park_rows / 2) || abs(column_test) >= (num_park_columns / 2)) {
		
				Matte* matte_ptr = new Matte;
				matte_ptr->set_ka(0.4); 
				matte_ptr->set_kd(0.6);			
				matte_ptr->set_cd(	min_color + rand_float() * (max_color - min_color), 
									min_color + rand_float() * (max_color - min_color), 
									min_color + rand_float() * (max_color - min_color));    
			
				// block center coordinates
				
				float xc = a * (r - num_rows / 2.0 + 0.5);
				float zc = b * (c - num_columns / 2.0 + 0.5);
				
				width = min_size + rand_float() * (a - 2 * offset - min_size);
				length = min_size + rand_float() * (b - 2 * offset - min_size);	
				
				// minimum building coordinates
				
				float xmin = xc - width / 2.0;
				float ymin = 0.0;
				float zmin = zc - length / 2.0;
				
				// maximum building coordinates
				
				height = min_height + rand_float() * (max_height - min_height);
				
				// The following is a hack to make the middle row and column of buildings higher
				// on average than the other buildings. 
				// This only works properly when there are three rows and columns of buildings
				
				if (r == 1 || r == num_rows - 2 || c == 1 || c == num_columns - 2)
					height *= 1.5;
				
				float xmax = xc + width / 2.0;
				float ymax = height;
				float zmax = zc + length / 2.0;
				
				Box* building_ptr = new  Box(Point3D(xmin, ymin, zmin), Point3D(xmax, ymax, zmax));
				building_ptr->set_material(matte_ptr);
				grid_ptr->add_object(building_ptr);
			}
		}
		
	grid_ptr->setup_cells();
	add_object(grid_ptr);
		
	// render the park green
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.4); 
	matte_ptr1->set_kd(0.5);
	matte_ptr1->set_cd(0.3, 0.5, 0.3);     // green 
											
	Box* park_ptr = new Box( 	Point3D(-a * num_park_rows / 2, 0.0, -b * num_park_columns / 2), 
								Point3D(a * num_park_rows / 2, 0.1, b * num_park_columns / 2)  );										
	park_ptr->set_material(matte_ptr1);
	add_object(park_ptr);
					
	
	// ground plane 
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.3); 
	matte_ptr2->set_kd(0.5); 
	matte_ptr2->set_cd(0.85); 
		
	Plane* plane_ptr = new Plane(Point3D(0, 0.01, 0), Normal(0, 1, 0));
	plane_ptr->set_material(matte_ptr2);
	add_object(plane_ptr);
}
void 												
World::build(void) {
	int num_samples = 100;   
	
	Sampler* sampler_ptr = new MultiJittered(num_samples);

	vp.set_hres(600);
	vp.set_vres(600);
	vp.set_max_depth(0);
	vp.set_sampler(sampler_ptr);	

	background_color = RGBColor(0.5);

	tracer_ptr = new AreaLighting(this);

	Pinhole* camera = new Pinhole;
	camera->set_eye(-20, 10, 20);
	camera->set_lookat(0, 2, 0); 	
	camera->set_view_distance(1080);          
	camera->compute_uvw();     
	set_camera(camera); 

	
	Emissive* emissive_ptr = new Emissive;
	emissive_ptr->scale_radiance(40.0);
	emissive_ptr->set_ce(white);
	
	
	// disk for the disk light
	
	Point3D center(0.0, 7.0, -7.0);
	float width = 4.0;
	float radius = 0.56 * width;
	Normal normal(0, 0, 1);
		
	
	Disk* disk_ptr = new Disk(center, normal, radius);
	disk_ptr->set_material(emissive_ptr);
	disk_ptr->set_sampler(sampler_ptr);
	disk_ptr->set_shadows(false);
//	disk_ptr->compute_uvw();
	add_object(disk_ptr);
	
		
	AreaLight* area_light_ptr = new AreaLight;
	area_light_ptr->set_object(disk_ptr);
	area_light_ptr->set_shadows(true);
	add_light(area_light_ptr);
	
	
	// Four axis aligned boxes
		
	float box_width 	= 1.0; 		// x dimension
	float box_depth 	= 1.0; 		// z dimension
	float box_height 	= 4.5; 		// y dimension
	float gap			= 3.0; 
	
	Matte* matte_ptr1 = new Matte;			
	matte_ptr1->set_ka(0.25); 
	matte_ptr1->set_kd(0.75);
	matte_ptr1->set_cd(0.4, 0.7, 0.4);     // green
	
	Box* box_ptr0 = new Box(Point3D(- 1.5 * gap - 2.0 * box_width, 0.0, -0.5 * box_depth), 
							Point3D(-1.5 * gap  - box_width, box_height, 0.5 * box_depth)); 
	box_ptr0->set_material(matte_ptr1);
	add_object(box_ptr0);
	
	Box* box_ptr1 = new Box(Point3D(- 0.5 * gap - box_width, 0.0, -0.5 * box_depth), 
							Point3D(-0.5 * gap, box_height, 0.5 * box_depth)); 
	box_ptr1->set_material(matte_ptr1);
	add_object(box_ptr1);
		
	Box* box_ptr2 = new Box(Point3D(0.5 * gap, 0.0, -0.5 * box_depth), 
							Point3D(0.5 * gap + box_width, box_height, 0.5 * box_depth));
	box_ptr2->set_material(matte_ptr1);
	add_object(box_ptr2);
	
	Box* box_ptr3 = new Box(Point3D(1.5 * gap + box_width, 0.0, -0.5 * box_depth), 
							Point3D(1.5 * gap + 2.0 * box_width, box_height, 0.5 * box_depth));
	box_ptr3->set_material(matte_ptr1);
	add_object(box_ptr3);

		
	// ground plane
	
	Matte* matte_ptr2 = new Matte;			
	matte_ptr2->set_ka(0.1); 
	matte_ptr2->set_kd(0.90);
	matte_ptr2->set_cd(white);
		
	Plane* plane_ptr = new Plane(Point3D(0.0), Normal(0, 1, 0)); 
	plane_ptr->set_material(matte_ptr2);
	add_object(plane_ptr);	
}