ccdemos/spheres_shadow.cc
branchpyrit
changeset 40 929aad02c5f2
parent 39 7079dcc3bd74
child 47 320d5d466864
--- a/ccdemos/spheres_shadow.cc	Fri Dec 14 16:51:22 2007 +0100
+++ b/ccdemos/spheres_shadow.cc	Mon Dec 17 22:03:50 2007 +0100
@@ -4,6 +4,55 @@
 #include "image.h"
 #include "common_sdl.h"
 
+Camera cam;
+Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9));
+
+Float lx, ly, lz, cf;
+
+void update_callback()
+{
+	if (lx != 0.0)
+		light.pos.x += lx;
+	if (ly != 0.0)
+		light.pos.y += ly;
+	if (lz != 0.0)
+		light.pos.z += lz;
+	if (cf != 0.0)
+		cam.f += cf;
+}
+
+void key_callback(int key, int down)
+{
+	switch (key)
+	{
+		case SDLK_r:
+			lx = -0.1 * down;
+			break;
+		case SDLK_t:
+			lx = +0.1 * down;
+			break;
+		case SDLK_f:
+			ly = -0.1 * down;
+			break;
+		case SDLK_g:
+			ly = +0.1 * down;
+			break;
+		case SDLK_v:
+			lz = -0.1 * down;
+			break;
+		case SDLK_b:
+			lz = +0.1 * down;
+			break;
+
+		case SDLK_z:
+			cf = -0.02 * down;
+			break;
+		case SDLK_x:
+			cf = +0.02 * down;
+			break;
+	}
+}
+
 int main(int argc, char **argv)
 {
 	Raytracer rt;
@@ -13,16 +62,21 @@
 	Octree top;
 	rt.setTop(&top);
 
-	Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6));
-	rt.addlight(&light1);
+	rt.addlight(&light);
+
+	//Light light2;
+	//light2.colour = Colour(0.7, 0.3, 0.6);
+	//rt.addlight(&light2);
 
-	Light light2(Vector3(-2.0, 10.0, -2.0), Colour(0.4, 0.6, 0.3));
-	rt.addlight(&light2);
+	Material mat0a(Colour(0.7, 0.7, 0.7));
+	mat0a. setReflectivity(0.0);
+	Box box(Vector3(-10.0, -1.2, -20.0), Vector3(10.0, -1.0, 0.0), &mat0a);
+	rt.addshape(&box);
 
-	Material mat0(Colour(0.7, 0.7, 0.7));
-
-	Box box(Vector3(-20.0, -1.2, -20.0), Vector3(20.0, -1.0, 20.0), &mat0);
-	rt.addshape(&box);
+	Material mat0b(Colour(0.1, 0.7, 0.8));
+	mat0b.setReflectivity(0.7);
+	Box box2(Vector3(-10.0, -1.2, -20.0), Vector3(10.0, 10.0, -20.2), &mat0b);
+	rt.addshape(&box2);
 
 	Material mat1(Colour(1.0, 0.0, 0.0));
 	Sphere bigsphere(Vector3(3.0, 2.0, -7.0), 3.0, &mat1);
@@ -33,28 +87,36 @@
 	rt.addshape(&smallsphere);
 
 	Material mat3(Colour(0.0, 0.0, 1.0));
-	Sphere tinysphere(Vector3(-1.2, 0.0, -2.0), 0.5, &mat3);
+	mat3.setReflectivity(0.1);
+	mat3.setTransmissivity(0.8, 1.5);
+	Sphere tinysphere(Vector3(-1.2, 0.0, -2.0), 0.7, &mat3);
 	rt.addshape(&tinysphere);
 
 	top.optimize();
 
-	Camera cam;
-	cam.setEye(Vector3(0,0,15));
+	cam.setEye(Vector3(-2.28908, 4.30992, 12.3051));
+	cam.p = Vector3(0.0988566, -0.139543, -0.985269);
+	cam.u = Vector3(-0.995004, 0, -0.0998334);
+	cam.v = Vector3(0.0139311, 0.990216, -0.138846);
 	rt.setCamera(&cam);
 
 	w = 800;
 	h = 600;
 
-	if (argc == 2 && !strcmp(argv[1], "-i"))
-		loop_sdl(rt, cam);
-	else
+	/* run interactive mode */
+	loop_sdl(rt, cam, update_callback, key_callback);
+
+	/* render image */
+	if (argc == 2 && !strcmp(argv[1], "-r"))
 	{
+		pyrit_verbosity = 2;
 		Float *fdata = (Float *) malloc(w*h*3*sizeof(Float));
+		rt.setOversample(2);
 		rt.render(w, h, fdata);
-	
+
 		struct image *img;
 		new_image(&img, w, h, 3);
-	
+
 		Float *fd = fdata;
 		for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) {
 			if (*fd > 1.0)