]> Dogcows Code - chaz/rasterize/blobdiff - triangle.hh
added texturing
[chaz/rasterize] / triangle.hh
index 8113f9aefb1d211492bda9cf69fad48f41ae3fe5..9e0f6b9c668c8541b681e08a210339b09828e73d 100644 (file)
@@ -8,7 +8,6 @@
 #ifndef _TRIANGLE_HH_
 #define _TRIANGLE_HH_
 
-#include "color.hh"
 #include "element.hh"
 
 
@@ -20,15 +19,14 @@ namespace rt {
  */
 class triangle : public element
 {
-public:
-
-    color_t material;
     vec_t   a;
     vec_t   b;
     vec_t   c;
 
-    triangle(vec_t a, vec_t b, vec_t c, color_t color = COLOR_WHITE) :
-        a(a), b(b), c(c), material(color)
+public:
+
+    triangle(vec_t a, vec_t b, vec_t c) :
+        a(a), b(b), c(c)
     {}
 
     virtual ~triangle()
@@ -42,16 +40,17 @@ public:
         }
 
         scal_t bc[3];
-        if (barycentric(bc, hit.p)) {
-            return true;
+        if (!barycentric(bc, hit.p)) {
+            return false;
         }
 
-        return false;
-    }
+#if QUIRKS
+        if (vec_dot(p.normal(), hit.n) < S(0.0)) {
+            hit.n = vec_neg(hit.n);
+        }
+#endif
 
-    virtual color_t color(vec_t point) const
-    {
-        return material;
+        return true;
     }
 
     /*
@@ -70,6 +69,16 @@ public:
         }
         return false;
     }
+
+    virtual vec_t txcoord(vec_t point) const
+    {
+        vec_t t1 = vec_new(S(0.0), S(0.0), S(0.0));
+        vec_t t2 = vec_new(S(1.0), S(0.0), S(0.0));
+        vec_t t3 = vec_new(S(1.0), S(1.0), S(0.0));
+        scal_t bc[3];
+        barycentric(bc, point);
+        return vec_interp(t1, t2, t3, bc);
+    }
 };
 
 
This page took 0.021231 seconds and 4 git commands to generate.