Commits

David Jones committed d04e331

foo.

  • Participants
  • Parent commits 2b1e2df

Comments (0)

Files changed (2)

+%module rtrace
+%{
+
+#include "ray_types.h"
+#include "plane.h"
+  // headers
+  %}
+
+
+typedef struct 
+{
+  float x,y,z;
+} Vec3;
+
+
+void 
+vec_subtract(Vec3* a, Vec3* b, Vec3* x) ;
+
+float
+vec_dot(Vec3* a, Vec3* b);
+
+void
+vec_norm(Vec3* a, Vec3* x);
+
+
+void
+vec_print(FILE * file,
+          Vec3* v);
+
+void 
+vec_mult_scalar(float s,
+                Vec3 * v,
+                Vec3 * x);
+
+void 
+vec_add(Vec3 *a,
+        Vec3 *b,
+        Vec3* x);
+
+
+
+typedef struct
+{
+  Vec3 origin;
+  Vec3 direction;
+} Ray;
+
+typedef struct 
+{
+  int width;
+  int height;
+  float * image;
+} Image;
+
+typedef float Color;
+
+typedef struct
+{
+  Vec3 position;
+  Color color;
+} Light;
+
+
+typedef struct 
+{
+  struct Primitive_Ops * ops;
+} Primitive;
+
+
+struct Primitive_Ops{
+  int (*intersects)(Primitive * prim,
+                    Ray * ray,
+                    Vec3 * point);
+  void (*get_normal)(Primitive * prim,
+                     Vec3* point,
+                     Vec3 * normal);
+  Color (*get_color)(Primitive * prim);
+};
+
+
+typedef struct
+{
+  struct Primitive_Ops * ops;
+  Vec3 normal;
+  Vec3 origin;
+  Color color;
+} Plane;
+
+void
+plane_normal(Primitive * s, 
+             Vec3* point,
+             Vec3 * normal);
+
+int 
+plane_intersects(Primitive * plane,
+                 Ray * ray,
+                 Vec3* point);
+
+void 
+plane_init(Plane * s);
+
+Primitive *
+plane_create();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#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"
+
+int main()
+{
+  int bookmark = 0;
+  Primitive * prim = dmalloc(sizeof(Plane));
+  plane_init((Plane*)prim);
+  Plane * tmpp = (Plane *)prim;
+
+
+  tmpp->origin.x = 0;
+  tmpp->origin.y = 0;
+  tmpp->origin.z = 0;
+
+  tmpp->normal.x = 0;
+  tmpp->normal.y = 0;
+  tmpp->normal.z = 1;
+
+
+  tmpp->color = 1.0;
+
+  Ray ray;
+  ray.origin.x = 10;
+  ray.origin.y = 1000;
+  ray.origin.z = 20;
+  ray.direction.x = 0.0;
+  ray.direction.y = 1.0;
+  ray.direction.z = -1.0;
+  Vec3 vec;
+  plane_intersects(prim, &ray, &vec);
+
+  Vec3 tmp;
+  vec_subtract(&ray.origin, &vec, &tmp);
+  printf("\nvec: ");
+  vec_print(stdout, &vec);
+  printf("\n");
+  printf("plane.origin: ");
+  vec_print(stdout, &tmpp->origin);
+  printf("\n");
+  printf("tmp: ");
+  vec_print(stdout, &tmp);
+  printf("\n");
+
+  float n = vec_dot(&tmp, &tmpp->origin);
+  
+  printf("ray dot vec: %f\n", n);
+
+  log_message("done with raytrace main()",1,0);
+
+  check_for_leaks(bookmark, get_bookmark());
+  return 0;
+}