debug for Makefile
[MicroTrace.git] / Triangle.cxx
1 #include "Triangle.hxx"
2
3 Triangle::Triangle(const Vec3f& a,
4 const Vec3f& b,
5 const Vec3f& c,
6 Shader* shader)
7 : Primitive(shader),
8 m_a(a),
9 m_b(b),
10 m_c(c)
11 {
12 }
13
14 Triangle::~Triangle()
15 {
16 }
17
18 bool
19 Triangle::Intersect(Ray& ray)
20 {
21 const Vec3f edge1 = m_b-m_a;
22 const Vec3f edge2 = m_c-m_a;
23
24 const Vec3f pvec = ray.direction().cross(edge2);
25
26 const float det = edge1.dot(pvec);
27 if (fabs(det) < Epsilon) return false;
28
29 const float inv_det = 1.0f / det;
30
31 const Vec3f tvec = ray.origin()-m_a;
32 float lambda = tvec.dot( pvec );
33 lambda *= inv_det;
34
35 if (lambda < 0.0f || lambda > 1.0f)
36 return false;
37
38 const Vec3f qvec = tvec.cross(edge1);
39 float mue = ray.direction().dot(qvec);
40 mue *= inv_det;
41
42 if (mue < 0.0f || mue+lambda > 1.0f)
43 return false;
44
45 float f = edge2.dot(qvec);
46 f *= inv_det;
47 if (ray.t() <= f || f < 1e-4 )
48 return false;
49
50 ray.setT(f);
51
52 return true;
53 }
54
55 Vec3f
56 Triangle::GetNormal(Ray& ray)
57 {
58 return Vec3f();
59 }
This page took 0.046665 seconds and 5 git commands to generate.