David Jones avatar David Jones committed 95520e4

fixed problem in specular calculation....

a lot of this stuff depends on unit vectors, which I did not have.

Comments (0)

Files changed (2)

   vec_add(&diff, &ray->origin, point);
 
   vec_subtract(point, &plane->origin, &diff);
-  float t = fabs(vec_dot(&diff, &plane->normal));
+  float t = fabs(vec_dot(&diff, &plane->normal)) /
+    vec_dot(&diff, &diff);
   if(t > 1) {
     vec_print(stdout, point);
-    assert(1 == 0);
+    printf("\n");
+    vec_print(stdout, &diff);
+    printf("\n");
+    vec_print(stdout, &plane->normal);
+    printf("\n");
+    printf("t: %f\n", t);
+    // assert(1 == 0);
   }
   return 1;
 }
         Vec3 reflection;
         vec_mult_scalar(2.0*vec_dot(&to_light, &normal), &normal, &reflection);
         vec_subtract(&to_light, &reflection, &reflection);
-        float dot = vec_dot(&ray->direction, &reflection);
+        float dot = vec_dot(&ray->direction, &reflection) /
+          vec_dot(&ray->direction, &ray->direction) /
+          vec_dot(&reflection,&reflection);
         if (dot > 0) {
           dot = dot * dot;
           dot = dot * dot;
   tmps->light = 1;
 
   tmps->center.y = 2000;
-  tmps->center.x =  -20000;
-  tmps->center.z = -5000;
-  tmps->radius = 1000;
+  tmps->center.x =  -2000;
+  tmps->center.z = -500000;
+  tmps->radius = 100;
   tmps->material.color.r = .9;
   tmps->material.color.g = .9;
   tmps->material.color.b = .9;
   scene.primitives[5] = dmalloc(sizeof(Sphere));
   sphere_init((Sphere*)scene.primitives[5]);
   tmps = (Sphere *) scene.primitives[5];
-  tmps->light = 1;
+  tmps->light = 0;
   tmps->center.x = 10000;
   tmps->center.y = 10000;
   tmps->center.z = 5000;
   tmps->material.color.g = .1;
   tmps->material.color.b = .9;
   tmps->material.diffuse = .8;
-  tmps->material.specular =.1 ;
+  tmps->material.specular =1 ;
   tmps->material.reflection = 1.0;
 
   scene.primitives[2] = dmalloc(sizeof(Sphere));
   Plane * tmpp = (Plane *) scene.primitives[3];
 
   tmpp->origin.y = 0;
-  tmpp->origin.x = 0;
-  tmpp->origin.z = 40000;
+  tmpp->origin.x = -40000;
+  tmpp->origin.z = 0;
 
   tmpp->normal.y = 0;
-  tmpp->normal.x = 0;
+  tmpp->normal.x = 1;
   tmpp->normal.z = -1;
 
   tmpp->material.color.r = .1;
   tmpp->material.color.g = .7;
   tmpp->material.color.b = .6;
   tmpp->material.diffuse = .9;
-  tmpp->material.specular = .09;
+  tmpp->material.specular = 1;
   tmpp->material.reflection = 0;
   printf("------------\n");
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.