ffddbc8a2643f5f0f1cbac14b2dcf6bf3fe4def3
1 #include "Triangle.hxx"
3 Triangle::Triangle(const Vec3f
& a
,
17 Triangle::Intersect(Ray
& ray
)
19 const Vec3f edge1
= m_b
-m_a
;
20 const Vec3f edge2
= m_c
-m_a
;
22 const Vec3f pvec
= ray
.direction().cross(edge2
);
24 const float det
= edge1
.dot(pvec
);
25 if (fabs(det
) < Epsilon
) return false;
27 const float inv_det
= 1.0f
/ det
;
29 const Vec3f tvec
= ray
.origin()-m_a
;
30 float lambda
= tvec
.dot( pvec
);
33 if (lambda
< 0.0f
|| lambda
> 1.0f
)
36 const Vec3f qvec
= tvec
.cross(edge1
);
37 float mue
= ray
.direction().dot(qvec
);
40 if (mue
< 0.0f
|| mue
+lambda
> 1.0f
)
43 float f
= edge2
.dot(qvec
);
45 if (ray
.t() <= f
|| f
< 1e-4 )
This page took 0.042403 seconds and 3 git commands to generate.