Add boxes to cornell box

This commit is contained in:
CJSatnarine
2024-07-10 20:57:10 -04:00
parent 1ff91061ba
commit f42d13bbd7
5 changed files with 341684 additions and 341658 deletions

Binary file not shown.

685370
image.ppm

File diff suppressed because it is too large Load Diff

View File

@@ -251,6 +251,10 @@ void cornellBox() {
world.add(make_shared<quad>(point3(555,555,555), vec3(-555,0,0), vec3(0,0,-555), white));
world.add(make_shared<quad>(point3(0,0,555), vec3(555,0,0), vec3(0,555,0), white));
// Boxes.
world.add(box(point3(130, 0, 65), point3(295, 165, 230), white));
world.add(box(point3(265, 0, 295), point3(430, 330, 460), white));
camera cam;
cam.aspectRatio = 1.0;
cam.imageWidth = 600;

22
quad.h
View File

@@ -3,6 +3,7 @@
#include "rayTracer.h"
#include "hittable.h"
#include "hittableList.h"
class quad : public hittable {
public:
@@ -77,5 +78,26 @@ class quad : public hittable {
double D;
};
inline shared_ptr<hittableList> box(const point3& a, const point3& b, shared_ptr<material> mat) {
// Returns the 3D box (six sides) that contains the two opposite vertices a and b.
auto sides = make_shared<hittableList>();
// Construct the two opposite vertices with the minimum and maximum coordinates.
auto min = point3(fmin(a.x(), b.x()), fmin(a.y(), b.y()), fmin(a.z(), b.z()));
auto max = point3(fmax(a.x(), b.x()), fmax(a.y(), b.y()), fmax(a.z(), b.z()));
auto dx = vec3(max.x() - min.x(), 0, 0);
auto dy = vec3(0, max.y() - min.y(), 0);
auto dz = vec3(0, 0, max.z() - min.z());
sides->add(make_shared<quad>(point3(min.x(), min.y(), max.z()), dx, dy, mat)); // front
sides->add(make_shared<quad>(point3(max.x(), min.y(), max.z()), -dz, dy, mat)); // right
sides->add(make_shared<quad>(point3(max.x(), min.y(), min.z()), -dx, dy, mat)); // back
sides->add(make_shared<quad>(point3(min.x(), min.y(), min.z()), dz, dy, mat)); // left
sides->add(make_shared<quad>(point3(min.x(), max.y(), max.z()), dx, -dz, mat)); // top
sides->add(make_shared<quad>(point3(min.x(), min.y(), min.z()), dx, dz, mat)); // bottom
return sides;
}
#endif