|
1123 | 1123 | straight-forward, but we'll add a few things to the `aabb` class in the process.
|
1124 | 1124 |
|
1125 | 1125 | The first task is to construct an axis-aligned bounding box of the span of objects in the BVH
|
1126 |
| -constructor. Basically, we'll construct the `bvh_node`s bounding box from this span by initializing |
1127 |
| -the bounding box to empty, and then augmenting it with each bounding box in the span of objects. |
| 1126 | +constructor. Basically, we'll construct the bounding box of the `bvh_node` from this span by |
| 1127 | +initializing the bounding box to empty (we'll define `aabb::empty` shortly), and then augment it |
| 1128 | +with each bounding box in the span of objects. |
1128 | 1129 |
|
1129 |
| -We don't have a way yet to express an empty bounding box, so we'll imagine one for now and |
1130 |
| -implementing it shortly. |
| 1130 | +Once we have the bounding box, set the splitting axis to the one with the longest side. We'll |
| 1131 | +imagine a function that does that for us: `aabb::longest_axis()`. Finally, since we're computing the |
| 1132 | +bounding box of the object span up front, we can delete the original line that computed it as the |
| 1133 | +union of the left and right sides. |
1131 | 1134 |
|
1132 | 1135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1133 | 1136 | class bvh_node : public hittable {
|
1134 | 1137 | public:
|
1135 | 1138 | ...
|
1136 |
| - |
1137 | 1139 | bvh_node(std::vector<shared_ptr<hittable>>& objects, size_t start, size_t end) {
|
1138 | 1140 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1139 | 1141 | // Build the bounding box of the span of source objects.
|
1140 | 1142 | bbox = aabb::empty;
|
1141 | 1143 | for (size_t object_index=start; object_index < end; object_index++)
|
1142 | 1144 | bbox = aabb(bbox, objects[object_index]->bounding_box());
|
1143 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1144 |
| - |
1145 |
| - ... |
1146 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1147 |
| - [Listing [object-span-bbox]: <kbd>[bvh.h]</kbd> Building the bbox for the span of BVH objects] |
1148 |
| - |
1149 |
| -Now that we have the bounding box, set the splitting axis to the one with the longest side. Again, |
1150 |
| -we'll imagine a function that does that for us: `aabb::longest_axis()`. Finally, since we're |
1151 |
| -computing the bounding box of the object span up front, we can delete the original line that |
1152 |
| -computed it as the union of the left and right sides. |
1153 | 1145 |
|
1154 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1155 |
| - class bvh_node : public hittable { |
1156 |
| - public: |
1157 |
| - ... |
1158 |
| - bvh_node(std::vector<shared_ptr<hittable>>& objects, size_t start, size_t end) { |
1159 |
| - // Build the bounding box of the span of source objects. |
1160 |
| - bbox = aabb::empty; |
1161 |
| - for (size_t object_index=start; object_index < end; object_index++) |
1162 |
| - bbox = aabb(bbox, objects[object_index]->bounding_box()); |
1163 |
| - |
1164 |
| - |
1165 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1166 | 1146 | int axis = bbox.longest_axis();
|
1167 | 1147 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1168 | 1148 |
|
|
0 commit comments