: 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()
{
const Vec3f edge1 = m_b-m_a;
const Vec3f edge2 = m_c-m_a;
-
+
const Vec3f pvec = ray.direction().cross(edge2);
-
+
const float det = edge1.dot(pvec);
if (fabs(det) < Epsilon) return false;
-
+
const float inv_det = 1.0f / det;
-
+
const Vec3f tvec = ray.origin()-m_a;
float lambda = tvec.dot( pvec );
lambda *= inv_det;
-
- if (lambda < 0.0f || lambda > 1.0f)
+
+ if (lambda < 0.0f || lambda > 1.0f)
return false;
const Vec3f qvec = tvec.cross(edge1);
float mue = ray.direction().dot(qvec);
mue *= inv_det;
-
- if (mue < 0.0f || mue+lambda > 1.0f)
+
+ if (mue < 0.0f || mue+lambda > 1.0f)
return false;
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 Vec3f();
+ return m_n;
+}
+
+Box
+Triangle::CalcBounds()
+{
+ Box bounds;
+ bounds.Extend(m_a);
+ bounds.Extend(m_b);
+ bounds.Extend(m_c);
+ return Box();
+}
+
+bool
+Triangle::InVoxel(const Box& box)
+{
+ return false;
}