|
1999 | 1999 |
|
2000 | 2000 | It is a hit if $x_0 < x < x_1$ and $y_0 < y < y_1$.
|
2001 | 2001 |
|
| 2002 | +Because our rectangles are axis-aligned, their bounding boxes will have an infinitely-thin side. |
| 2003 | +This can be a problem when dividing them up with our axis-aligned bounding volume hierarchy. To |
| 2004 | +counter this, all hittable objects should get a bounding box that has finite width along every |
| 2005 | +dimension. For our rectangles, we'll just pad the box a bit on the infnitely-thin side. |
| 2006 | + |
2002 | 2007 | <div class='together'>
|
2003 | 2008 | The actual `xy_rect` class is thus:
|
2004 | 2009 |
|
|
2013 | 2018 | virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
|
2014 | 2019 |
|
2015 | 2020 | virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
|
2016 |
| - output_box = aabb(point3(x0,y0, k-0.0001), point3(x1, y1, k+0.0001)); |
| 2021 | + // The bounding box must have non-zero width in each dimension, so pad the Z |
| 2022 | + // dimension a small amount. |
| 2023 | + output_box = aabb(point3(x0,y0, k-0.0001), point3(x1, y1, k+0.0001)); |
2017 | 2024 | return true;
|
2018 | 2025 | }
|
2019 | 2026 |
|
|
2117 | 2124 | virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
|
2118 | 2125 |
|
2119 | 2126 | virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
|
2120 |
| - output_box = aabb(point3(x0,k-0.0001,z0), point3(x1, k+0.0001, z1)); |
| 2127 | + // The bounding box must have non-zero width in each dimension, so pad the Y |
| 2128 | + // dimension a small amount. |
| 2129 | + output_box = aabb(point3(x0,k-0.0001,z0), point3(x1, k+0.0001, z1)); |
2121 | 2130 | return true;
|
2122 | 2131 | }
|
2123 | 2132 |
|
|
2136 | 2145 | virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
|
2137 | 2146 |
|
2138 | 2147 | virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
|
2139 |
| - output_box = aabb(point3(k-0.0001, y0, z0), point3(k+0.0001, y1, z1)); |
| 2148 | + // The bounding box must have non-zero width in each dimension, so pad the X |
| 2149 | + // dimension a small amount. |
| 2150 | + output_box = aabb(point3(k-0.0001, y0, z0), point3(k+0.0001, y1, z1)); |
2140 | 2151 | return true;
|
2141 | 2152 | }
|
2142 | 2153 |
|
|
0 commit comments