: 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()
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)
{
- // normal is cross product of spanning vectors
- Vec3f n = (m_c - m_a) % (m_c - m_b);
- n.normalize();
- return n;
+ return m_n;
+}
+
+Box
+Triangle::CalcBounds()
+{
+ Box bounds;
+ bounds.Extend(m_a);
+ bounds.Extend(m_b);
+ bounds.Extend(m_c);
+ return bounds;
+}
+
+bool
+Triangle::InVoxel(const Box& box)
+{
+ return CalcBounds().Overlaps(box);
}