9f1ca7780c6211366cb124a6688377ca6a961ffa
2 #include "InfinitePlane.hxx"
4 Box::Box() : m_min(Infinity
, Infinity
, Infinity
),
5 m_max(-Infinity
, -Infinity
, -Infinity
)
9 Box::Box(Vec3f min
, Vec3f max
) : m_min(min
), m_max(max
)
17 Box::Box(const Box
& b
)
24 Box::operator=(const Box
& b
)
37 Box::Extend(const Vec3f
& a
)
39 // for all three coordinates, move m_max or m_min to the point
40 for(size_t i
= 0; i
< 3; i
++) {
43 } else if(a
[i
] < m_min
[i
]) {
45 } // else: do nothing, coordinate is inside the box
50 Box::Extend(const Box
& box
)
55 Box::Overlaps(const Box
& b
) const
61 Box::Clip(const Ray
& ray
, float& tnear
, float& tfar
) const
63 // Note: equations here are the same as in InfinitePlane::Intersect()
64 // t = ((o-a)*n) / (d*n)
65 // o = ray.origin(), d = ray.direction(),
66 // n = surface normal of plane, a = anchor point of plane
67 Vec3f diff_min
= m_min
- ray
.origin(); // o-a
68 Vec3f diff_max
= m_max
- ray
.origin();
71 float tx_near
, tx_far
;
74 if(cos_theta
= ray
.direction().dot(Vec3f(1,0,0)) != 0) // if not parallel...
75 tx_near
= diff_min
.dot(Vec3f(1,0,0)) / cos_theta
;
76 if(cos_theta
= ray
.direction().dot(Vec3f(1,0,0)) != 0)
77 tx_far
= diff_max
.dot(Vec3f(1,0,0)) / cos_theta
;
80 if(cos_theta
= ray
.direction().dot(Vec3f(0,1,0)) != 0)
81 ty_near
= diff_min
.dot(Vec3f(0,1,0)) / cos_theta
;
82 if(cos_theta
= ray
.direction().dot(Vec3f(0,0,1)) != 0)
83 ty_far
= diff_max
.dot(Vec3f(0,1,0)) / cos_theta
;
85 // ray intersects box iff it intersects projection on xy plane
86 // in this case: tx_near <= ty_near <= tx_far <= ty_far
87 // or: tx_far <= ty_near <= tx_near <= ty_far
88 // or: tx_far <= ty_far <= tx_near <= ty_near
89 // or: tx_near <= ty_far <= tx_far <= ty_near
90 if(tx_near
<= ty_near
&& tx_far
<= ty_near
&&
91 tx_near
<= ty_far
&& tx_far
<= ty_far
) {
94 if (cos_theta
= ray
.direction().dot(Vec3f(0, 1, 0)) != 0)
95 tz_near
= diff_min
.dot(Vec3f(0, 1, 0)) / cos_theta
;
96 if (cos_theta
= ray
.direction().dot(Vec3f(0, 0, 1)) != 0)
97 tz_far
= diff_max
.dot(Vec3f(0, 1, 0)) / cos_theta
;
103 //////////////////////////
This page took 0.057672 seconds and 3 git commands to generate.