Example #1
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            float a = localRay.Direction.X * localRay.Direction.X -
                      localRay.Direction.Y * localRay.Direction.Y +
                      localRay.Direction.Z * localRay.Direction.Z;

            float b = localRay.Origin.X * localRay.Direction.X -
                      localRay.Origin.Y * localRay.Direction.Y +
                      localRay.Origin.Z * localRay.Direction.Z;

            float c = localRay.Origin.X * localRay.Origin.X -
                      localRay.Origin.Y * localRay.Origin.Y +
                      localRay.Origin.Z * localRay.Origin.Z;

            List <Intersection> xs = Intersection.Aggregate();

            if (Abs(a) < Constants.floatEps)
            {
                if (Abs(b) < Constants.floatEps)
                {
                    IntersectCaps(localRay, xs);
                    return(xs);
                }

                xs.Add(new Intersection(-c / 2 * b, this));
            }

            float disc = b * b - a * c;

            if (disc < 0)
            {
                if (Abs(disc) >= Constants.floatEps)
                {
                    return(Intersection.Aggregate());
                }

                disc = 0;
            }

            float t0 = (-b - Sqrt(disc)) / a;
            float t1 = (-b + Sqrt(disc)) / a;

            float y0 = localRay.Origin.Y + t0 * localRay.Direction.Y;

            if (Minimum < y0 && y0 < Maximum)
            {
                xs.Add(new Intersection(t0, this));
            }

            float y1 = localRay.Origin.Y + t1 * localRay.Direction.Y;

            if (Minimum < y1 && y1 < Maximum)
            {
                xs.Add(new Intersection(t1, this));
            }

            IntersectCaps(localRay, xs);
            return(xs);
        }
Example #2
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            (bool success, float t, float u, float v) = TestLocalIntersection(localRay);

            if (success)
            {
                return(Intersection.Aggregate(new IntersectionWithUV(t, this, u, v)));
            }
            else
            {
                return(Intersection.Aggregate());
            }
        }
Example #3
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            List <Intersection> result = Intersection.Aggregate();

            foreach (Shape s in Shapes)
            {
                result.AddRange(s.Intersect(localRay));
            }

            result.Sort(new IntersectionCompare());

            return(result);
        }
Example #4
0
 protected override List <Intersection> LocalIntersect(Ray r)
 {
     if (Abs(r.Direction.Y) < Constants.floatEps)
     {
         return(Intersection.Aggregate());
     }
     else
     {
         return(Intersection.Aggregate(new Intersection(
                                           -r.Origin.Y / r.Direction.Y,
                                           this
                                           )));
     }
 }
Example #5
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            CheckAxis(localRay.Origin.X, localRay.Direction.X, out float xtmin, out float xtmax);
            CheckAxis(localRay.Origin.Y, localRay.Direction.Y, out float ytmin, out float ytmax);
            CheckAxis(localRay.Origin.Z, localRay.Direction.Z, out float ztmin, out float ztmax);

            float tmin = Max(Max(xtmin, ytmin), ztmin);
            float tmax = Min(Min(xtmax, ytmax), ztmax);

            if (tmin > tmax)
            {
                return(Intersection.Aggregate());
            }

            return(Intersection.Aggregate(new Intersection(tmin, this), new Intersection(tmax, this)));
        }
Example #6
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            Tuple sphereToRay = localRay.Origin - Tuple.Point(0, 0, 0);

            float a = localRay.Direction.Dot(localRay.Direction);
            float b = localRay.Direction.Dot(sphereToRay);
            float c = sphereToRay.Dot(sphereToRay) - 1;

            float discriminant = b * b - a * c;

            if (discriminant >= 0)
            {
                float sqrtDisc = System.MathF.Sqrt(discriminant);
                return(Intersection.Aggregate(
                           new Intersection((-b - sqrtDisc) / a, this),
                           new Intersection((-b + sqrtDisc) / a, this)));
            }

            return(Intersection.Aggregate());
        }