use of suite.rt.RayTracer.RayHit in project suite by stupidsing.
the class RayHit_ method join.
public static List<RayHit> join(List<RayHit> rayHits0, List<RayHit> rayHits1, Fun<Pair<Boolean, Boolean>, Boolean> fun) {
List<RayHit> rayHits2 = new ArrayList<>();
int size0 = rayHits0.size(), size1 = rayHits1.size();
int index0 = 0, index1 = 0;
boolean b0, b1;
boolean isInsideNow = false;
while ((b0 = index0 < size0) | (b1 = index1 < size1)) {
RayHit rayHit0 = b0 ? rayHits0.get(index0) : null;
RayHit rayHit1 = b1 ? rayHits1.get(index1) : null;
boolean isAdvance0 = b0 && (!b1 || rayHit0.advance() < rayHit1.advance());
if (isAdvance0)
index0++;
else
index1++;
boolean isInsideBefore = isInsideNow;
isInsideNow = fun.apply(Pair.of(index0 % 2 == 1, index1 % 2 == 1));
if (isInsideBefore != isInsideNow)
rayHits2.add(isAdvance0 ? rayHit0 : rayHit1);
}
return removeDuplicates(rayHits2);
}
use of suite.rt.RayTracer.RayHit in project suite by stupidsing.
the class Sphere method hit.
@Override
public List<RayHit> hit(Ray ray) {
R3 start0 = R3.sub(ray.startPoint, center);
double a = ray.dir.abs2();
double b = 2f * R3.dot(start0, ray.dir);
double c = start0.abs2() - radius * radius;
double discriminant = b * b - 4f * a * c;
List<RayHit> rayHits;
if (0 < discriminant) {
// hit?
double sqrt = Math.sqrt(discriminant);
double denom = 1d / (2d * a);
rayHits = List.of(rayHit(ray, (-b - sqrt) * denom), rayHit(ray, (-b + sqrt) * denom));
} else
rayHits = List.of();
return rayHits;
}
use of suite.rt.RayTracer.RayHit in project suite by stupidsing.
the class Planar method hit.
@Override
public List<RayHit> hit(Ray ray) {
List<RayHit> rayHits = new ArrayList<>();
for (RayHit rayHit : plane.hit(ray)) {
R3 planarDir = R3.sub(rayHit.intersection().hitPoint(), origin);
double x = R3.dot(planarDir, axis0) * invAxis0;
double y = R3.dot(planarDir, axis1) * invAxis1;
if (isHit.isHit(x, y))
rayHits.add(rayHit);
}
return rayHits;
}
use of suite.rt.RayTracer.RayHit in project suite by stupidsing.
the class RayHit_ method removeDuplicates.
private static List<RayHit> removeDuplicates(List<RayHit> rayHits0) {
List<RayHit> rayHits1 = new ArrayList<>();
int size = rayHits0.size();
RayHit rayHit;
for (int i = 0; i < size; i++) if (i != size - 1)
if ((rayHit = rayHits0.get(i)) != rayHits0.get(i + 1))
rayHits1.add(rayHit);
else
// skips same hit
i++;
else
rayHits1.add(rayHits0.get(i));
return rayHits1;
}
use of suite.rt.RayTracer.RayHit in project suite by stupidsing.
the class Plane method hit.
@Override
public List<RayHit> hit(Ray ray) {
double denum = R3.dot(normal, ray.dir);
double adv;
if (MathUtil.epsilon < Math.abs(denum))
adv = (originIndex - R3.dot(normal, ray.startPoint)) / denum;
else
// treats as not-hit
adv = -1d;
double advance = adv;
if (RayTracer.negligibleAdvance < advance) {
RayHit rayHit = new RayHit() {
public double advance() {
return advance;
}
public RayIntersection intersection() {
R3 hitPoint = ray.hitPoint(advance);
return new RayIntersection() {
public R3 hitPoint() {
return hitPoint;
}
public R3 normal() {
return normal;
}
public Material material() {
return material;
}
};
}
};
return List.of(rayHit);
} else
return List.of();
}
Aggregations