X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=triangle.hh;h=9e0f6b9c668c8541b681e08a210339b09828e73d;hb=9f13ae5fe777dd4f7a9302f6dcf3e0d99a1ce65d;hp=8113f9aefb1d211492bda9cf69fad48f41ae3fe5;hpb=a737ad45e690daa3b39b8885e2b6574d2ea48833;p=chaz%2Frasterize diff --git a/triangle.hh b/triangle.hh index 8113f9a..9e0f6b9 100644 --- a/triangle.hh +++ b/triangle.hh @@ -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); + } };