1 #include "Triangle.hxx"
3 Triangle::Triangle(const Vec3f
& a
,
19 Triangle::Intersect(Ray
& ray
)
21 const Vec3f edge1
= m_b
-m_a
;
22 const Vec3f edge2
= m_c
-m_a
;
24 const Vec3f pvec
= ray
.direction().cross(edge2
);
26 const float det
= edge1
.dot(pvec
);
27 if (fabs(det
) < Epsilon
) return false;
29 const float inv_det
= 1.0f
/ det
;
31 const Vec3f tvec
= ray
.origin()-m_a
;
32 float lambda
= tvec
.dot( pvec
);
35 if (lambda
< 0.0f
|| lambda
> 1.0f
)
38 const Vec3f qvec
= tvec
.cross(edge1
);
39 float mue
= ray
.direction().dot(qvec
);
42 if (mue
< 0.0f
|| mue
+lambda
> 1.0f
)
45 float f
= edge2
.dot(qvec
);
47 if (ray
.t() <= f
|| f
< 1e-4 )
56 Triangle::GetNormal(Ray
& ray
)
This page took 0.048552 seconds and 5 git commands to generate.