add cornell box
parent
3be855cffd
commit
ebbf711403
@ -0,0 +1,35 @@
|
||||
package eu.jonahbauer.raytracing.scene.util;
|
||||
|
||||
import eu.jonahbauer.raytracing.math.Vec3;
|
||||
import eu.jonahbauer.raytracing.render.material.Material;
|
||||
import eu.jonahbauer.raytracing.scene.Hittable;
|
||||
import eu.jonahbauer.raytracing.scene.hittable2d.Parallelogram;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class Hittables {
|
||||
private Hittables() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static @NotNull Hittable box(@NotNull Vec3 a, @NotNull Vec3 b, @NotNull Material material) {
|
||||
var sides = new ArrayList<Hittable>();
|
||||
|
||||
var min = Vec3.min(a, b);
|
||||
var max = Vec3.max(a, b);
|
||||
|
||||
var dx = new Vec3(max.x() - min.x(), 0, 0);
|
||||
var dy = new Vec3(0, max.y() - min.y(), 0);
|
||||
var dz = new Vec3(0, 0, max.z() - min.z());
|
||||
|
||||
sides.add(new Parallelogram(new Vec3(min.x(), min.y(), max.z()), dx, dy, material)); // front
|
||||
sides.add(new Parallelogram(new Vec3(max.x(), min.y(), max.z()), dz.neg(), dy, material)); // right
|
||||
sides.add(new Parallelogram(new Vec3(max.x(), min.y(), min.z()), dx.neg(), dy, material)); // back
|
||||
sides.add(new Parallelogram(new Vec3(min.x(), min.y(), min.z()), dz, dy, material)); // left
|
||||
sides.add(new Parallelogram(new Vec3(min.x(), max.y(), max.z()), dx, dz.neg(), material)); // top
|
||||
sides.add(new Parallelogram(new Vec3(min.x(), min.y(), min.z()), dx, dz, material)); // bottom
|
||||
|
||||
return new HittableList(sides);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue