Exemple #1
0
        /// <summary>
        /// Gets a list of geometries and their intersectionpoints that the line intersects.
        /// </summary>
        /// <param name="point1">The point1.</param>
        /// <param name="point2">The point2.</param>
        /// <param name="simulator">The simulator.</param>
        /// <param name="detectUsingAABB">if set to <c>true</c> [detect using AABB].</param>
        /// <returns></returns>
        public static List <GeomPointPair> LineSegmentAllGeomsIntersect(ref Vector2 point1, ref Vector2 point2, PhysicsSimulator simulator, bool detectUsingAABB)
        {
            List <Vector2>       intSecPoints = new List <Vector2>();
            List <GeomPointPair> geoms        = new List <GeomPointPair>();

            foreach (Geom geom in simulator.GeomList)
            {
                intSecPoints.Clear();

                if (detectUsingAABB)
                {
                    LineSegmentAABBIntersect(ref point1, ref point2, geom.AABB, ref intSecPoints);
                }
                else
                {
                    LineSegmentVerticesIntersect(ref point1, ref point2, geom.WorldVertices, ref intSecPoints);
                }

                if (intSecPoints.Count > 0)
                {
                    _tempPair        = new GeomPointPair();
                    _tempPair.Geom   = geom;
                    _tempPair.Points = new List <Vector2>(intSecPoints);
                    geoms.Add(_tempPair);
                }
            }

            return(geoms);
        }
        /// <summary>
        /// Gets a list of geometries and their intersectionpoints that the line intersects.
        /// </summary>
        /// <param name="point1">The point1.</param>
        /// <param name="point2">The point2.</param>
        /// <param name="simulator">The simulator.</param>
        /// <param name="detectUsingAABB">if set to <c>true</c> [detect using AABB].</param>
        /// <returns></returns>
        public static List<GeomPointPair> LineSegmentAllGeomsIntersect(ref Vector2 point1, ref Vector2 point2, PhysicsSimulator simulator, bool detectUsingAABB)
        {
            List<Vector2> intSecPoints = new List<Vector2>();
            List<GeomPointPair> geoms = new List<GeomPointPair>();

            foreach (Geom geom in simulator.GeomList)
            {
                intSecPoints.Clear();

                if (detectUsingAABB)
                {
                    LineSegmentAABBIntersect(ref point1, ref point2, geom.AABB, ref intSecPoints);
                }
                else
                {
                    LineSegmentVerticesIntersect(ref point1, ref point2, geom.WorldVertices, ref intSecPoints);
                }

                if (intSecPoints.Count > 0)
                {
                    _tempPair = new GeomPointPair();
                    _tempPair.Geom = geom;
                    _tempPair.Points = new List<Vector2>(intSecPoints);
                    geoms.Add(_tempPair);
                }
            }

            return geoms;
        }