-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.h
32 lines (29 loc) · 851 Bytes
/
translate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
#include "hitable.h"
class translate : public hitable
{
public:
translate(){};
translate(hitable *hit_ptr, vec::vec3 offset) : hit_ptr(hit_ptr), offset(offset){};
virtual bool hit(const ray &_ray, float t_min, float t_max, hit_record &rec) const override
{
ray moved_ray(_ray.origin() - offset, _ray.direction(), _ray.get_time());
if (hit_ptr->hit(moved_ray, t_min, t_max, rec))
{
rec.point += offset;
return true;
}
return false;
}
virtual bool bounding_box(float t0, float t1, aabb &bbox) const override
{
if (hit_ptr->bounding_box(t0, t1, bbox))
{
bbox = aabb(bbox.min() + offset, bbox.max() + offset);
return true;
}
return false;
}
hitable *hit_ptr;
vec::vec3 offset;
};