Skip to content

Commit dbaf803

Browse files
hollaschUbuntu
andauthored
Quad bbox should consider all four vertices
Resolves #1402 Co-authored-by: Ubuntu <[email protected]>
1 parent 3d5ba74 commit dbaf803

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ then.
2222
yielding a 15-20% speedup (#1007)
2323

2424
### The Next Week
25+
- Change - BBox for `quad` now considers all 4 points (#1402)
2526
- Change - `perlin::turb()` no longer defaults the value for the depth parameter.
2627
- Change - AABB automatically pads to mininmum size for any dimension; no longer requires
2728
primitives to call aabb::pad() function.
@@ -622,4 +623,3 @@ typesetting and source-code cleanup.
622623
# v1.42.0 (2018-08-26)
623624

624625
- New - First GitHub release of _Ray Tracing: The Next Week_.
625-

books/RayTracingTheNextWeek.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@
10311031
At this point, we're ready to use our new BVH code. Let's use it on our random spheres scene.
10321032

10331033
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1034-
#include "bvh.h"
1034+
#include "bvh.h"
10351035
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
10361036
...
10371037

@@ -2452,7 +2452,7 @@
24522452
are parallel) instead of a general quadrilateral. For our purposes, we'll use three geometric
24532453
entities to define a quad:
24542454

2455-
1. $\mathbf{Q}$, the lower-left corner.
2455+
1. $\mathbf{Q}$, the starting corner.
24562456
2. $\mathbf{u}$, a vector representing the first side.
24572457
$\mathbf{Q} + \mathbf{u}$ gives one of the corners adjacent to $\mathbf{Q}$.
24582458
3. $\mathbf{v}$, a vector representing the second side.
@@ -2547,7 +2547,10 @@
25472547
}
25482548

25492549
virtual void set_bounding_box() {
2550-
bbox = aabb(Q, Q + u + v);
2550+
// Compute the bounding box of all four vertices.
2551+
auto bbox_diagonal1 = aabb(Q, Q + u + v);
2552+
auto bbox_diagonal2 = aabb(Q + u, Q + v);
2553+
bbox = aabb(bbox_diagonal1, bbox_diagonal2);
25512554
}
25522555

25532556
aabb bounding_box() const override { return bbox; }
@@ -3580,7 +3583,7 @@
35803583
const aabb aabb::empty = aabb(interval::empty, interval::empty, interval::empty);
35813584
const aabb aabb::universe = aabb(interval::universe, interval::universe, interval::universe);
35823585

3583-
3586+
35843587
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
35853588
aabb operator+(const aabb& bbox, const vec3& offset) {
35863589
return aabb(bbox.x + offset.x(), bbox.y + offset.y(), bbox.z + offset.z());

src/TheNextWeek/quad.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ class quad : public hittable {
2828
}
2929

3030
virtual void set_bounding_box() {
31-
bbox = aabb(Q, Q + u + v);
31+
// Compute the bounding box of all four vertices.
32+
auto bbox_diagonal1 = aabb(Q, Q + u + v);
33+
auto bbox_diagonal2 = aabb(Q + u, Q + v);
34+
bbox = aabb(bbox_diagonal1, bbox_diagonal2);
3235
}
3336

3437
aabb bounding_box() const override { return bbox; }

src/TheRestOfYourLife/quad.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class quad : public hittable {
3030
}
3131

3232
virtual void set_bounding_box() {
33-
bbox = aabb(Q, Q + u + v);
33+
// Compute the bounding box of all four vertices.
34+
auto bbox_diagonal1 = aabb(Q, Q + u + v);
35+
auto bbox_diagonal2 = aabb(Q + u, Q + v);
36+
bbox = aabb(bbox_diagonal1, bbox_diagonal2);
3437
}
3538

3639
aabb bounding_box() const override { return bbox; }

0 commit comments

Comments
 (0)