Search in sources :

Example 1 with RayIntersection

use of suite.rt.RayTracer.RayIntersection 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();
}
Also used : R3(suite.math.R3) RayHit(suite.rt.RayTracer.RayHit) RayIntersection(suite.rt.RayTracer.RayIntersection)

Aggregations

R3 (suite.math.R3)1 RayHit (suite.rt.RayTracer.RayHit)1 RayIntersection (suite.rt.RayTracer.RayIntersection)1