Ejemplo n.º 1
0
        public override InsertsectResult insertsect(Ray3 ray)
        {
            float a = ray.getDirection.dot(this.n);

            if (a >= 0)
            {
                return(new InsertsectResult());
            }
            float   b         = n.dot(ray.getOrigin.sub(positon));
            float   distance  = -b / a;
            Vector3 nPosition = ray.getPoint(distance);

            return(new InsertsectResult(this, distance, nPosition, n));
        }
Ejemplo n.º 2
0
        public override InsertsectResult insertsect(Ray3 ray)
        {
            Vector3 v  = ray.getOrigin.sub(this.center);
            float   c  = (v.unSqrtLength() - this.sqrtRadius);
            float   dv = ray.getDirection.dot(v);

            if (dv <= 0)
            {
                float dis = dv * dv - c;
                if (c >= 0)
                {
                    float            distance   = -dv - (float)Math.Sqrt(dis);
                    Vector3          position   = ray.getPoint(distance);
                    Vector3          normal     = position.sub(this.center).nor();
                    InsertsectResult insertsect = new InsertsectResult(this, distance, position, normal);
                    return(insertsect);
                }
            }
            return(new InsertsectResult());
        }