Project() private method

private Project ( Vector2 axis ) : Vector2
axis Vector2
return Vector2
Beispiel #1
0
        private bool Intersects(CollisionConvexPolygon element)
        {
            // Loop over the axes of this polygon
            for (var i = 0; i < _axes.Count; i++)
            {
                var axis = _axes[i];

                // Project both shapes onto the axis
                var p1 = Project(axis);
                var p2 = element.Project(axis);

                // Do the projections overlap?
                if (!Overlap(p1, p2))
                {
                    // Then we can guarantee that the shapes do not overlap
                    return(false);
                }
            }

            // Loop over element polygon's axes
            List <Vector2> axes = element.GetAxes();

            for (int i = 0; i < axes.Count; i++)
            {
                Vector2 axis = axes[i];

                // Project both shapes onto the axis
                Vector2 p1 = Project(axis);
                Vector2 p2 = element.Project(axis);

                // Do the projections overlap?
                if (!Overlap(p1, p2))
                {
                    // Then we can guarantee that the shapes do not overlap
                    return(false);
                }
            }

            // If we get here then we know that every axis had overlap on it
            // so we can guarantee an intersection
            return(true);
        }
        private bool Intersects(CollisionConvexPolygon element)
        {
            ComputeAxes();

            // loop over the axes of this polygon
            for (int i = 0; i < _axes.Count; i++)
            {
                Vector2 axis = _axes[i];
                // project both shapes onto the axis
                Vector2 p1 = this.Project(axis);
                Vector2 p2 = element.Project(axis);
                // do the projections overlap?
                if (!Overlap(p1, p2))
                {
                    // then we can guarantee that the shapes do not overlap
                    return false;
                }
            }
            // loop over element polygon's axes
            List<Vector2> axes = element.GetAxes();
            for (int i = 0; i < axes.Count; i++)
            {
                Vector2 axis = axes[i];
                // project both shapes onto the axis
                Vector2 p1 = this.Project(axis);
                Vector2 p2 = element.Project(axis);
                // do the projections overlap?
                if (!Overlap(p1, p2))
                {
                    // then we can guarantee that the shapes do not overlap
                    return false;
                }
            }
            // if we get here then we know that every axis had overlap on it
            // so we can guarantee an intersection
            return true;
        }