示例#1
0
        CollisionInfo AreCollisionPointsBehindBegin(Vector2 rightCollP, Vector2 leftCollP, Vector2 rightBeginP, Vector2 leftBeginP)
        {
            var btweenCollP   = rightCollP + (leftCollP - rightCollP) * .5f;
            var extendedRight = FixedStartPosition.Extend(rightCollP, 2000);
            var extendedLeft  = FixedStartPosition.Extend(leftCollP, 2000);

            var intersectionsRight = new Geometry.Polygon.Line(FixedStartPosition.To2D(), extendedRight).
                                     GetIntersectionPointsWithLineSegment(rightBeginP, leftBeginP);
            var intersectionsleft = new Geometry.Polygon.Line(FixedStartPosition.To2D(), extendedLeft).
                                    GetIntersectionPointsWithLineSegment(rightBeginP, leftBeginP);

            bool behind =
                !new Geometry.Polygon.Line(rightBeginP, leftBeginP).IsIntersectingWithLineSegment(
                    FixedStartPosition.To2D(),
                    btweenCollP);

            CollisionInfo info = new CollisionInfo {
                BehindStartLine = behind
            };

            if (intersectionsRight.Any() && intersectionsleft.Any())
            {
                info.New_RightCollPointOnStartLine = intersectionsRight[0];
                info.New_LeftCollPointOnStartLine  = intersectionsleft[0];
            }


            return(info);
        }
示例#2
0
        public override Geometry.Polygon ToPolygon()
        {
            Vector2[] edges     = GetEdgePoints();
            Vector2   rightEdge = edges[0];
            Vector2   leftEdge  = edges[1];

            var     beginPoints     = GetBeginEdgePoints(edges);
            Vector2 rightBeginPoint = beginPoints[0];
            Vector2 leftBeginPoint  = beginPoints.Length == 1 ? Vector2.Zero : beginPoints[1];

            if (leftBeginPoint.IsZero)
            {
                return(new Geometry.Polygon());
            }

            var baseTriangle = new Geometry.Polygon();

            baseTriangle.Points.AddRange(new List <Vector2> {
                FixedStartPosition.To2D(), rightEdge, leftEdge
            });

            var advancedTriangle = new Geometry.Polygon();

            advancedTriangle.Points.AddRange(new List <Vector2> {
                FixedStartPosition.To2D(), rightEdge
            });

            var dummyTriangle = advancedTriangle;

            if (CollisionPoints.Any())
            {
                foreach (var collisionPoint in OrderCollisionPointsHorizontally(rightEdge))
                {
                    var dir       = collisionPoint - FixedStartPosition.To2D();
                    var leftColl  = FixedStartPosition.To2D() + dir + dir.Perpendicular().Normalized() * 25;
                    var rightColl = FixedStartPosition.To2D() + dir + dir.Perpendicular2().Normalized() * 25;

                    var backToLineRight = FixedStartPosition.Extend(rightColl, FixedEndPosition.Distance(FixedStartPosition));
                    var backToLineLeft  = FixedStartPosition.Extend(leftColl, FixedEndPosition.Distance(FixedStartPosition));

                    var earlyCollCheck_Left  = backToLineLeft.Extend(leftColl, FixedEndPosition.Distance(FixedStartPosition));
                    var earlyCollCheck_Right = backToLineRight.Extend(rightColl, FixedEndPosition.Distance(FixedStartPosition));

                    Geometry.Polygon earlyCollisionRectangle = new Geometry.Polygon();
                    earlyCollisionRectangle.Points.AddRange(new List <Vector2>
                    {
                        leftColl, earlyCollCheck_Left, earlyCollCheck_Right, rightColl
                    });
                    bool EarlyCollision =
                        CollisionPoints.Any(x => x != collisionPoint && earlyCollisionRectangle.IsInside(x));

                    Func <Vector2, bool> outsideDummy = point => dummyTriangle.Points.Count < 3 || dummyTriangle.IsOutside(point);

                    if (baseTriangle.IsInside(rightColl) && baseTriangle.IsInside(leftColl) &&
                        outsideDummy(rightColl) && outsideDummy(leftColl) && !EarlyCollision &&
                        backToLineLeft.Distance(backToLineRight) >= OwnSpellData.Radius * 2)
                    {
                        CollisionInfo info = AreCollisionPointsBehindBegin(rightColl, leftColl, rightBeginPoint,
                                                                           leftBeginPoint);

                        if (!info.BehindStartLine)
                        {
                            dummyTriangle.Points.Add(backToLineRight);
                            advancedTriangle.Points.Add(backToLineRight);

                            dummyTriangle.Points.Add(rightColl);
                            advancedTriangle.Points.Add(rightColl);


                            dummyTriangle.Points.Add(leftColl);
                            advancedTriangle.Points.Add(leftColl);

                            dummyTriangle.Points.Add(backToLineLeft);
                            advancedTriangle.Points.Add(backToLineLeft);
                        }
                        else //collision points behind startLine
                        {
                            leftColl  = info.New_LeftCollPointOnStartLine;
                            rightColl = info.New_RightCollPointOnStartLine;

                            backToLineRight = FixedStartPosition.Extend(rightColl, FixedEndPosition.Distance(FixedStartPosition));
                            backToLineLeft  = FixedStartPosition.Extend(leftColl, FixedEndPosition.Distance(FixedStartPosition));

                            dummyTriangle.Points.Add(backToLineRight);
                            advancedTriangle.Points.Add(backToLineRight);

                            dummyTriangle.Points.Add(rightColl);
                            advancedTriangle.Points.Add(rightColl);


                            dummyTriangle.Points.Add(leftColl);
                            advancedTriangle.Points.Add(leftColl);

                            dummyTriangle.Points.Add(backToLineLeft);
                            advancedTriangle.Points.Add(backToLineLeft);
                        }
                    }
                }
            }

            advancedTriangle.Points.Add(leftEdge);
            advancedTriangle.Points.RemoveAt(0);
            advancedTriangle.Points.Insert(0, rightBeginPoint);
            advancedTriangle.Points.Insert(0, leftBeginPoint);

            return(advancedTriangle);
        }