Fixed a lot of bugs in triangle ray tracing code

--- Work_in_Progress/triangle_intersect.c
+++ Work_in_Progress/triangle_intersect.c
@@ -18,6 +18,7 @@
 typedef struct{
     vector start;
     vector dir;
+    float refract;
 }ray;

 /*This is a fast inverse square root function.
@@ -172,20 +173,30 @@

 	// determine if given point lies above
 	// or below plane defined by triangle
-	float dv1 = dotProduct(&v1, &fplane1);
-	float dv2 = dotProduct(&v2, &fplane2);
-	float dv3 = dotProduct(&v3, &fplane3);
+	float dv1 = dotProduct(&cv1, &fplane1);
+	float dv2 = dotProduct(&cv2, &fplane2);
+	float dv3 = dotProduct(&cv3, &fplane3);

 	// if all three have positive directions
 	// point does lies within inside triangle
 	// and so returns true (which returns 1)
-	if ((dv1 < 0) && (dv2 < 0) && (dv3 < 0)) {
+	if ((dv1 >= 0) && (dv2 >= 0) && (dv3 >= 0)) {
 		return true;
 	}
 	else {
 		return false;
 	}
 }
+/*Returns a vector in the direction of the reflected
+ray given by the normal of the surface and the initial
+ray.*/
+vector reflectedRay(ray *d, vector *n){
+	float dn = 2*(dotProduct(&d->dir, n));
+	vector c = vecScale(n, &dn);
+	vector r = vecSub(&d->dir, &c);
+	return r;
+}
+

 int main()
 {
@@ -200,14 +211,14 @@

     t.p3.x = 3;
     t.p3.y = 0;
-    t.p3.z = 3;
+    t.p3.z = 6;

     ray r;
     r.start.x = 0;
-    /*r.start.y = 0;
-    r.start.z = 0;*/
-
-    r.dir.x = 1;
+    r.start.y = 0;
+    r.start.z = 0;
+
+    r.dir.x = 4;
     r.dir.y = 0;
     r.dir.z = 0;

@@ -228,20 +239,31 @@
     int y,z;
     bool inside;

-    for (y=-10;y<10;y++){
-        r.start.y=y;
+    for (z=10;z>-11;z--){
+        r.dir.z=z;
         printf("\n");
-        for (z=-10; z<10;z++){
-            r.start.z = z;
+        for (y=-10; y<11;y++){
+            r.dir.y = y;
             vector intersect = triangleIntersect(&t, &r);
             inside = inTri(&t,&intersect);
             if (inside){
                 printf("++");
             }else{
                 printf("--");
-            };
+            }
         }
     }
-
+    r.start.x = 0;
+    r.start.y = 0;
+    r.start.z = 0;
+
+    r.dir.x = 4;
+    r.dir.y = 0;
+    r.dir.z = 0;
+    vector norm = triangleNormal(&t);
+    vector Ref = reflectedRay(&r, &norm);
+    printf("\nNormal:      \n%f, %f, %f\n", norm.x, norm.y, norm.z);
+    printf("Unreflected: \n%f, %f, %f\n", r.dir.x, r.dir.y, r.dir.z);
+    printf("Reflected:   \n%f, %f, %f\n", Ref.x, Ref.y, Ref.z);
     return 0;
 }