Instance translation implementation

This commit is contained in:
CJSatnarine
2024-07-11 00:08:56 -04:00
parent efea1517a7
commit 1913ca00b8
5 changed files with 341835 additions and 341799 deletions

Binary file not shown.

View File

@@ -36,4 +36,32 @@ class hittable {
virtual aabb boundingBox() const = 0; virtual aabb boundingBox() const = 0;
}; };
class translate : public hittable {
public:
translate(shared_ptr<hittable> object, const vec3& offset) : object(object), offset(offset) {}
bool hit(const ray& r, interval rayT, hitRecord& rec) const override {
// Move the ray backwards by the offset.
ray offsetR(r.origin() - offset, r.direction(), r.time());
// Determine whether an intersection exists along the offset ray (and if so, where)
if (!object->hit(offsetR, rayT, rec))
return false;
// Move the intersection point forwards by the offset
rec.p += offset;
return true;
}
aabb boundingBox() const override {
return bBox;
}
private:
shared_ptr<hittable> object;
vec3 offset;
aabb bBox;
};
#endif #endif

683598
image.ppm

File diff suppressed because it is too large Load Diff

View File

@@ -47,4 +47,12 @@ class interval {
const interval interval::empty = interval(+infinity, -infinity); const interval interval::empty = interval(+infinity, -infinity);
const interval interval::universe = interval(-infinity, +infinity); const interval interval::universe = interval(-infinity, +infinity);
interval operator+(const interval& ival, double displacement) {
return interval(ival.min + displacement, ival.max + displacement);
}
interval operator+(double displacement, const interval& ival) {
return ival + displacement;
}
#endif #endif