-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHittableList.java
More file actions
33 lines (26 loc) · 825 Bytes
/
HittableList.java
File metadata and controls
33 lines (26 loc) · 825 Bytes
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
33
import java.util.ArrayList;
import java.util.List;
public class HittableList implements Hittable {
private final List<Hittable> objects = new ArrayList<>();
public HittableList() {}
public void clear() {
objects.clear();
}
public void add(Hittable object) {
objects.add(object);
}
@Override
public boolean hit(Ray r, Interval rayT, HitRecord rec) {
HitRecord tempRec = new HitRecord();
boolean hitAnything = false;
double closestSoFar = rayT.max;
for (Hittable object : objects) {
if (object.hit(r, new Interval(rayT.min, closestSoFar), tempRec)) {
hitAnything = true;
closestSoFar = tempRec.t;
rec.copyFrom(tempRec);
}
}
return hitAnything;
}
}