Esempio n. 1
0
        public bool ObjectsIntersectRay(
            int[] objectIndexArray, int firstIndex, int indexCount,
            FastRay3d fastRay,
            Func <IIntersectableObjectSet, int, bool> objectFilter,
            Func <IIntersectableObjectSet, int, int, RayHit3d, bool> hitFilter,
            double tmin, double tmax,
            ref ObjectRayHit hit)
        {
            bool result = false;

            if (objectFilter == null)
            {
                for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
                {
                    var index = objectIndexArray[i];
                    if (fastRay.Ray.Hits(Lines[index], tmin, tmax, ref hit.RayHit))
                    {
                        // Report.Line("hit shell of cylinder " + index + " at " + hit.RayHit.Point);
                        if (hitFilter == null)
                        {
                            result = hit.Set(this, index);
                            break;
                        }

                        if (!hitFilter(this, index, 0, hit.RayHit))
                        {
                            result = hit.Set(this, index);
                            break;
                        }
                        else
                        {
                            //continue shooting
                            //Report.Line("Filtered");

                            hit.RayHit.T = tmax;
                        }
                    }
                }
            }
            else
            {
                foreach (int index in objectIndexArray)
                {
                    if (objectFilter(this, index))
                    {
                        if (fastRay.Ray.Hits(Lines[index], tmin, tmax, ref hit.RayHit) &&
                            (hitFilter == null || !hitFilter(this, index, 0, hit.RayHit)))
                        {
                            result = hit.Set(this, index);
                        }
                    }
                }
            }
            return(result);
        }
        public bool ObjectsIntersectRay(
            int[] objectIndexArray, int firstIndex, int indexCount,
            FastRay3d fastRay,
            Func <IIntersectableObjectSet, int, bool> objectFilter,
            Func <IIntersectableObjectSet, int, int, RayHit3d, bool> hitFilter,
            double tmin, double tmax,
            ref ObjectRayHit hit
            )
        {
            var  plist  = Position3dList;
            bool result = false;

            if (objectFilter == null)
            {
                for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
                {
                    var index  = objectIndexArray[i];
                    int pi     = index * 3;
                    var rawHit = hit.RayHit;
                    if (fastRay.Ray.HitsTriangle(
                            plist[pi], plist[pi + 1], plist[pi + 2], tmin, tmax,
                            ref rawHit) &&
                        (hitFilter == null || !hitFilter(this, index, 0, rawHit)))
                    {
                        hit.RayHit = rawHit;
                        result     = hit.Set(this, index);
                    }
                }
            }
            else
            {
                for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
                {
                    var index = objectIndexArray[i];
                    if (objectFilter(this, index))
                    {
                        int pi     = index * 3;
                        var rawHit = hit.RayHit;
                        if (fastRay.Ray.HitsTriangle(
                                plist[pi], plist[pi + 1], plist[pi + 2], tmin, tmax,
                                ref rawHit) &&
                            (hitFilter == null || !hitFilter(this, index, 0, rawHit)))
                        {
                            hit.RayHit = rawHit;
                            result     = hit.Set(this, index);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        public bool ObjectsIntersectRay(
            int[] objectIndexArray, int firstIndex, int indexCount,
            FastRay3d fastRay,
            Func <IIntersectableObjectSet, int, bool> objectFilter,
            Func <IIntersectableObjectSet, int, int, RayHit3d, bool> hitFilter,
            double tmin, double tmax,
            ref ObjectRayHit hit)
        {
            bool result = false;

            if (objectFilter == null)
            {
                for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
                {
                    var index  = objectIndexArray[i];
                    var rawHit = hit.RayHit;
                    if (fastRay.Ray.Hits(Sphere3ds[index], tmin, tmax,
                                         ref rawHit) &&
                        (hitFilter == null || !hitFilter(this, index, 0, rawHit)))
                    {
                        hit.RayHit = rawHit;
                        result     = hit.Set(this, index);
                    }
                }
            }
            else
            {
                for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
                {
                    var index = objectIndexArray[i];
                    if (objectFilter(this, index))
                    {
                        var rawHit = hit.RayHit;
                        if (fastRay.Ray.Hits(Sphere3ds[index], tmin, tmax,
                                             ref rawHit) &&
                            (hitFilter == null || !hitFilter(this, index, 0, rawHit)))
                        {
                            hit.RayHit = rawHit;
                            result     = hit.Set(this, index);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// The intersection of a polygon with a ray is performed using the
        /// intersection with the constituting triangles of the polygon. This
        /// only works for convex polygons, and the part number in the hit is
        /// used to store the number of the triangle within the polygon.
        /// </summary>
        public bool ObjectsIntersectRay(int[] objectIndexArray, int firstIndex, int indexCount,
                                        FastRay3d fastRay,
                                        Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter,
                                        Func <IIntersectableObjectSet, int, int, RayHit3d, bool> hitFilter,
                                        double tmin, double tmax, ref ObjectRayHit hit)
        {
            bool result = false;

            int[] fia = FirstIndexArray, via = VertexIndexArray;
            var   pa  = PositionArray;

            for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
            {
                var oi = objectIndexArray[i];
                if (ios_index_objectFilter != null &&
                    !ios_index_objectFilter(this, oi))
                {
                    continue;
                }
                int fvi = fia[oi], fve = fia[oi + 1];
                V3d p0 = pa[via[fvi++]], e0 = pa[via[fvi++]] - p0;
                int fvi0 = fvi;
                while (fvi < fve)
                {
                    var e1     = pa[via[fvi]] - p0;
                    var rawHit = hit.RayHit;
                    if (fastRay.Ray.HitsTrianglePointAndEdges(
                            p0, e0, e1, tmin, tmax, ref rawHit))
                    {
                        int part = fvi - fvi0;
                        if (hitFilter == null || !hitFilter(this, oi, part, rawHit))
                        {
                            hit.RayHit = rawHit;
                            result     = hit.Set(this, oi, part);
                            break;
                        }
                    }
                    ++fvi; e0 = e1;
                }
            }
            return(result);
        }