Commits

David Jones committed 5f1334f

foo.

Comments (0)

Files changed (2)

+#ifndef HEADER_GUARD_RAY_TRACE_H
+#define HEADER_GUARD_RAY_TRACE_H
+
+typedef struct
+{
+  Vec3 camera_position;
+  Vec3 view_center;
+  int view_height;
+  int view_width;
+
+  Primitive * primitives[128];
+  int num_primitives;
+
+} Scene;
+
+
+void write_image(Image * ptr, 
+                 const char * filename);
+Primitive *
+ray_trace(Scene * scene, Ray * ray, 
+          Color * color, int depth, Vec3 * point);
+
+
+#endif
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "dmem.h"
+#include "dlog.h"
+
+#include "ray_types.h"
+#include "sphere.h"
+#include "plane.h"
+#include "ray_trace.h"
+
+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 = 600;
+  scene.view_width = 800;
+
+  scene.num_primitives = 6;
+  // scene.primitives = dmalloc(scene.num_primitives*sizeof(Primitive*));
+
+  int i = 4;
+  scene.primitives[i] = dmalloc(sizeof(Sphere));
+  sphere_init((Sphere*)scene.primitives[i]);
+  Sphere * tmps = (Sphere *) scene.primitives[i];
+  tmps->light = 1;
+
+  tmps->center.y = 20000;
+  tmps->center.x =  -2000;
+  tmps->center.z = -5000;
+  tmps->radius = 1000;
+  tmps->material.color.r = .8;
+  tmps->material.color.g = .7;
+  tmps->material.color.b = .7;
+
+  i = 5;
+  
+  scene.primitives[i] = dmalloc(sizeof(Sphere));
+  sphere_init((Sphere*)scene.primitives[i]);
+  tmps = (Sphere *) scene.primitives[i];
+  tmps->light = 1;
+  tmps->center.x = 20000;
+  tmps->center.y = 20000;
+  tmps->center.z = 5000;
+  tmps->radius = 1000;
+  tmps->material.color.r = .7;
+  tmps->material.color.g = .7;
+  tmps->material.color.b = .8;
+
+  i = 0;
+  
+  scene.primitives[i] = dmalloc(sizeof(Sphere));
+  sphere_init((Sphere*)scene.primitives[i]);
+  tmps = (Sphere *) scene.primitives[i];
+  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 = 1;
+  tmps->material.specular = .1;
+  tmps->material.reflection = .70;
+
+  i = 1;
+  
+  scene.primitives[i] = dmalloc(sizeof(Sphere));
+  sphere_init((Sphere*)scene.primitives[i]);
+  tmps = (Sphere *) scene.primitives[i];
+
+  tmps->center.y = 6000;
+  tmps->center.x = -3000;
+  tmps->center.z = 25000;
+  tmps->radius =   3000;
+  tmps->material.color.r = .1;
+  tmps->material.color.g = .1;
+  tmps->material.color.b = .9;
+  tmps->material.diffuse = 1;
+  tmps->material.specular =.5 ;
+  tmps->material.reflection = .6;
+
+  i = 2;
+  
+  scene.primitives[i] = dmalloc(sizeof(Sphere));
+  sphere_init((Sphere*)scene.primitives[i]);
+  tmps = (Sphere *) scene.primitives[i];
+  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;
+
+  i = 3;
+  
+  scene.primitives[i] = dmalloc(sizeof(Plane));
+  plane_init((Plane*)scene.primitives[i]);
+  Plane * tmpp = (Plane *) scene.primitives[i];
+
+  tmpp->origin.x = 0;
+  tmpp->origin.y = -4000;
+  tmpp->origin.z = 0;
+
+  tmpp->normal.y = 1;
+  tmpp->normal.x = 0;
+  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 = .3;
+  tmpp->material.reflection = .2;
+  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;
+}