David Jones avatar David Jones committed 3f69429

foo.

Comments (0)

Files changed (2)

 tester: all
 #	./test_file
 	# ./test1
-	./ray_trace && display ,output.ppm
+	./ray_trace_main && display ,output.ppm
 
 all: m_exes
 
 local_exe_libs := my_lib.a
 include module.mk
 
-local_exe := ray_trace
+local_exe := ray_trace_main
 local_exe_libs := my_lib.a ray_trace.a
 include module.mk
 
 
 
 local_lib := ray_trace.a
-local_objs:= vec3.o color.o sphere.o plane.o
+local_objs:= vec3.o color.o sphere.o plane.o ray_trace.o
 include module.mk
 
 
 #include "ray_types.h"
 #include "sphere.h"
 #include "plane.h"
-
-typedef struct
-{
-  Vec3 camera_position;
-  Vec3 view_center;
-  int view_height;
-  int view_width;
-
-  Primitive ** primitives;
-  int num_primitives;
-
-} Scene;
-
+#include "ray_trace.h"
 
 /*
   Assumptions:
   fprintf(fp, "P6 %i %i %i\n", ptr->width, ptr->height, max_int);
   
   for(ii = 0; ii < ptr->height; ++ii) {
-    Color * tmp = ptr->image + (ii*ptr->height);
+    Color * tmp = ptr->image + (ii*ptr->width);
     for(jj = 0; jj < ptr->width; ++jj) {
       color_truncate(&tmp[jj]);
       buffer[3*jj] = tmp[jj].r * max_int;
         }
 
         color_scalar_mult( &rcol, reflection, &rcol);
-        color_mult(&rcol, &prim_material->color, &rcol);
+        // color_mult(&rcol, &prim_material->color, &rcol);
         color_add(color, &rcol, color);
 
       }
            
   for(j = 0; j < scene->view_height; ++j) {
    for(i = 0; i < scene->view_width; ++i) {
-     //for(j = 290; j < 310; ++j) {
-     // for(i = 75; i < 100; ++i) {
-      //sprintf(log_buffer, "i: %d, j: %d", i, j);
-      //log_message(log_buffer, 1,0);
+     // if(do_log > 10) {
+     //fprintf(stdout, "i: %d, j: %d  ", i, j);
+       //log_message(log_buffer, 1,0);
+       // }
       {
         Vec3 a;
-        a.x = -(scene->view_width/2) + j; //+ 1.0*rand()/RAND_MAX ;;
-        a.y = (scene->view_height/2) - i;// + 1.0*rand()/RAND_MAX ;
+        a.x = -(scene->view_width/2) + i; //+ 1.0*rand()/RAND_MAX ;;
+        a.y = (scene->view_height/2) - j;// + 1.0*rand()/RAND_MAX ;
         a.z = -0;
         // printf("point: ");
-        // vec_print(stdout, &a);
+        //        vec_print(stdout, &a);
+        //        printf("\n");
         // printf("\n");
         //printf("point:%f %f %f\n", a.x, a.y, a.z);
         // printf("origin:%f %f %f\n", ray.origin.x, ray.origin.y,
       color.b = 0;
       Vec3 point;
       ray_trace(scene, &ray, &color, 1, &point);
-      im.image[i*scene->view_width + j] = color;
+      im.image[j*scene->view_width + i] = color;
     }
   }
   write_image(&im, filename);
   dfree(im.image);
 }
-
-int main()
-{
-  
-  Scene scene;
-  int bookmark = get_bookmark();
-  scene.camera_position.x = 0;
-  scene.camera_position.y = 0;
-  scene.camera_position.z = -500;
-  scene.view_center.x = 0;
-  scene.view_center.y = 0;
-  scene.view_center.z = 0;
-  
-  scene.view_height = 400;
-  scene.view_width = 400;
-
-  scene.num_primitives = 6;
-  scene.primitives = dmalloc(scene.num_primitives*sizeof(Primitive*));
-
-  scene.primitives[4] = dmalloc(sizeof(Sphere));
-  sphere_init((Sphere*)scene.primitives[4]);
-  Sphere * tmps = (Sphere *) scene.primitives[4];
-  tmps->light = 1;
-
-  tmps->center.y = 2000;
-  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 = 0;
-  tmps->center.x = 10000;
-  tmps->center.y = 10000;
-  tmps->center.z = 5000;
-  tmps->radius = 1000;
-  tmps->material.color.r = .9;
-  tmps->material.color.g = .4;
-  tmps->material.color.b = .4;
-
-  scene.primitives[0] = dmalloc(sizeof(Sphere));
-  sphere_init((Sphere*)scene.primitives[0]);
-  tmps = (Sphere *) scene.primitives[0];
-  tmps->center.x = 5000;
-  tmps->center.y = 2000;
-  tmps->center.z = 15000;
-  tmps->radius = 3000.0;
-  tmps->material.color.r = .9;
-  tmps->material.color.g = .9;
-  tmps->material.color.b = .9;
-  tmps->material.diffuse = .8;
-  tmps->material.specular = .1;
-  tmps->material.reflection = 1.0;
-
-  scene.primitives[1] = dmalloc(sizeof(Sphere));
-  sphere_init((Sphere*)scene.primitives[1]);
-  tmps = (Sphere *) scene.primitives[1];
-
-  tmps->center.y = 1000;
-  tmps->center.x = -3000;
-  tmps->center.z = 15000;
-  tmps->radius =   3000;
-  tmps->material.color.r = .1;
-  tmps->material.color.g = .1;
-  tmps->material.color.b = .9;
-  tmps->material.diffuse = .8;
-  tmps->material.specular =1 ;
-  tmps->material.reflection = 1.0;
-
-  scene.primitives[2] = dmalloc(sizeof(Sphere));
-  sphere_init((Sphere*)scene.primitives[2]);
-  tmps = (Sphere *) scene.primitives[2];
-  tmps->light = 0;
-  tmps->center.y = -4800;
-  tmps->center.x = -4000;
-  tmps->center.z = 17000;
-  tmps->radius =   50;
-  tmps->material.color.r = 0;
-  tmps->material.color.g = .9;
-  tmps->material.color.b = 0;
-  tmps->material.diffuse = 1;
-  tmps->material.specular = .1;
-  tmps->material.reflection = 1;
-
-
-  scene.primitives[3] = dmalloc(sizeof(Plane));
-  plane_init((Plane*)scene.primitives[3]);
-  Plane * tmpp = (Plane *) scene.primitives[3];
-
-  tmpp->origin.y = 0;
-  tmpp->origin.x = -40000;
-  tmpp->origin.z = 0;
-
-  tmpp->normal.y = 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 = 1;
-  tmpp->material.reflection = 0;
-  printf("------------\n");
-
-  render(&scene, ",output.ppm");
-  /* 
-  im.width = 256;
-  im.height = 256;
-  
-  im.image = dmalloc(sizeof(float) * im.width * im.height);
-
-  {
-    int i;
-    n = im.width * im.height;
-,    for(i = 0; i < (im.width * im.height); ++i) {
-      im.image[i] = i / n;
-      // printf("%f\n", im.image[i]);
-    }
-  }
-
-  printf("image[0] = %f\n", im.image[0]);
-
-  write_image(&im, ",output.pgm");
-  */
-  log_message("done with raytrace main()",1,0);
-
-  check_for_leaks(bookmark, get_bookmark());
-  return 0;
-}
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.