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

View File

@@ -36,4 +36,32 @@ class hittable {
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