498757e28895115e480af318ef1a91553cad670b
1 #include "Triangle.hxx"
3 Triangle::Triangle(const Vec3f
& a
,
11 m_n( (b
-a
).cross(c
-a
) )
21 Triangle::Intersect(Ray
& ray
)
23 const Vec3f edge1
= m_b
-m_a
;
24 const Vec3f edge2
= m_c
-m_a
;
26 const Vec3f pvec
= ray
.direction().cross(edge2
);
28 const float det
= edge1
.dot(pvec
);
29 if (fabs(det
) < Epsilon
) return false;
31 const float inv_det
= 1.0f
/ det
;
33 const Vec3f tvec
= ray
.origin()-m_a
;
34 float lambda
= tvec
.dot( pvec
);
37 if (lambda
< 0.0f
|| lambda
> 1.0f
)
40 const Vec3f qvec
= tvec
.cross(edge1
);
41 float mue
= ray
.direction().dot(qvec
);
44 if (mue
< 0.0f
|| mue
+lambda
> 1.0f
)
47 float f
= edge2
.dot(qvec
);
49 if (ray
.t() <= f
|| f
< Epsilon
)
59 Triangle::GetNormal(Ray
& ray
)
This page took 0.03786 seconds and 3 git commands to generate.