Beispiel #1
0
        public dynamic intersect(dynamic r, dynamic tmax)
        {
            dynamic nhits = 0;
            dynamic temp  = new Isect();

            temp.t     = 1e9;
            this.inter = temp;
            int i = 0;

            while (i < this.prim.Length)
            {
                dynamic tp = this.prim[i].intersect(r);
                bool    sw = (tp != null);
                if (sw)
                {
                    dynamic isect = new Isect();
                    isect.t     = tp.t;
                    isect.prim  = tp.prim;
                    isect.surf  = tp.surf;
                    isect.enter = tp.enter;
                    this.inter  = isect;
                    nhits       = nhits + 1;
                }
                i = i + 1;
            }
            return(nhits > 0 ? true : false);
        }
Beispiel #2
0
        public override Isect intersect(Ray ry)
        {
            dynamic p = ry.P;
            dynamic d = ry.D;

            v.sub2(c, p);
            dynamic b     = Vec.dot(v, d);
            dynamic dotVV = Vec.dot(v, v);
            dynamic disc  = b * b - dotVV + r2;

            if (disc < 0.0)
            {
                return(null);
            }
            disc = Math.Sqrt(disc);
            dynamic t = (b - disc < 1e-6) ? b + disc : b - disc;

            if (t < 1e-6)
            {
                return(null);
            }
            dynamic ip = new Isect();

            ip.t     = t;
            ip.enter = dotVV > r2 + 1e-6 ? 1.0 : 0.0;
            ip.prim  = this;
            ip.surf  = this.surf;
            return(ip);
        }