public bool Intersects(
            AdnRay ray,
            ref AdnPoint point)
        {
            point = null;

            // Perform intersection test on bounding box
            // first for performances
            if (!_boundingBox.Intersects(ray))
                return false;

            double mindist = double.PositiveInfinity;

            for (int idx = 0; idx < _vertexBuffer.ElementCount; idx += 3)
            {
                AdnPoint p = null;

                if (ray.Intersect(
                    _vertices[idx],
                    _vertices[idx + 1],
                    _vertices[idx + 2],
                    out p))
                {
                    double dist = ray.Origin.SquaredDistanceTo(p);

                    if (dist < mindist)
                    {
                        mindist = dist;
                        point = p;
                    }
                }
            }

            return (point != null);
        }
Beispiel #2
0
        public bool Intersects(AdnRay ray)
        {
            if (ray.Intersect(_vertices[0], _vertices[1], _vertices[2]))
                return true;

            if (ray.Intersect(_vertices[2], _vertices[3], _vertices[0]))
                return true;

            if (ray.Intersect(_vertices[1], _vertices[5], _vertices[4]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[2], _vertices[1]))
                return true;

            if (ray.Intersect(_vertices[3], _vertices[2], _vertices[4]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[7], _vertices[3]))
                return true;

            if (ray.Intersect(_vertices[0], _vertices[7], _vertices[7]))
                return true;

            if (ray.Intersect(_vertices[7], _vertices[0], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[0], _vertices[1], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[1], _vertices[5], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[7], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[6], _vertices[5], _vertices[4]))
                return true;

            return false;
        }