mmh, there was something missing for assignment 3
[MicroTrace.git] / Triangle.cxx
index ffddbc8..498757e 100644 (file)
@@ -2,11 +2,15 @@
 
 Triangle::Triangle(const Vec3f& a,
                   const Vec3f& b,
-                  const Vec3f& c)
-  : m_a(a),
+                  const Vec3f& c,
+                  Shader* shader)
+  : Primitive(shader),
+    m_a(a),
     m_b(b),
-    m_c(c)
+    m_c(c),
+    m_n( (b-a).cross(c-a) )
 {
+  m_n.normalize();
 }
 
 Triangle::~Triangle()
@@ -42,10 +46,17 @@ Triangle::Intersect(Ray& ray)
 
   float f = edge2.dot(qvec);
   f *= inv_det;
-  if (ray.t() <= f || f <  1e-4  ) 
+  if (ray.t() <= f || f < Epsilon ) 
     return false;
   
   ray.setT(f);
-    
+  ray.setHit(this);
+
   return true;
 }
+
+Vec3f
+Triangle::GetNormal(Ray& ray)
+{
+  return m_n;
+}
This page took 0.026524 seconds and 4 git commands to generate.