public static void ReAddInverseCutPolygon(Vector2 posComp, BumperEntityPoly bumperEntity, ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 cP1 = posComp, cP2 = posComp;

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, cP1, cP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2, posComp);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            // if the bump is not on the collision course with the rocket
            {
                // Rocket is not on a collision course with the bump, so cut down the del poly area vertically
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, posComp);
                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
            }
        }
        public static void ReAddBlowerBubbleRopeTrajectoryMissingAreas(Vector2 posComp,
                                                                       BumperEntityPoly bumperEntity,
                                                                       ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 cP1 = posComp, cP2 = posComp;

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, cP1, cP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2, posComp);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            {
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, posComp);
                EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                {
                    polyInverseCutVertical
                });
                EntraDrawer.DrawIntoFile(delPolys);

                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
                EntraDrawer.DrawIntoFile(delPolys);
            }
        }
Пример #3
0
        public static void IntersectionWithThreePlanes(Vector2 pinP, Vector2 cP, out Vector2 pWithPlane)
        {
            var pinCookieVec = Vector2.Subtract(cP, pinP);

            pinCookieVec.Normalize();

            pWithPlane = new Vector2(1000, 1000);
            for (int i = 2; i < 7; i += 2)
            {
                var     planeDir = (Direction)i;
                Vector2 pP1, pP2, pInter;
                ProjectionHandler.GetPlanePoints(planeDir, out pP1, out pP2);
                MathHelperModule.FindIntersection(pinP, cP, pP1, pP2, out pInter);
                if (pInter.X >= 0 && pInter.X <= StaticData.LevelFarWidth &&
                    pInter.Y >= 0 && pInter.Y <= StaticData.LevelFarHeight)
                {
                    // if in the same direction with the pin-cookie vector
                    //Vector2 vec = refP1 - pInter;
                    //vec.Normalize();
                    //if (MathHelperModule.GetAngleBetweenTwoVectors(pinCookieVec, vec) <= 90)
                    if (pinP.X < cP.X)
                    {
                        if (cP.X < 900)
                        {
                            if (pInter.X > cP.X)
                            {
                                pWithPlane = pInter;
                            }
                        }
                        else
                        {
                            if (pInter.X < cP.X)
                            {
                                pWithPlane = pInter;
                            }
                        }
                    }
                    else
                    {
                        if (cP.X > 0)
                        {
                            if (pInter.X < cP.X)
                            {
                                pWithPlane = pInter;
                            }
                        }
                        else
                        {
                            if (pInter.X > cP.X)
                            {
                                pWithPlane = pInter;
                            }
                        }
                    }
                }
            }
        }
        public static void ReAddRocketTrajectoryMissingAreas(RocketEntityPoly rocketEntityPoly,
                                                             BumperEntityPoly bumperEntity,
                                                             ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 rP1, rP2;

            ProjectionHandler.FindRocketTwoBorderPoints(rocketEntityPoly, out rP1, out rP2);

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, rP1, rP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2,
                                                     (rocketEntityPoly.CompObj as RocketCarrierService).PositionXNACenter2D);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            // if the bump is not on the collision course with the rocket
            {
                // Rocket is not on a collision course with the bump, so cut down the del poly area vertically
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, rocketEntityPoly);

                EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                {
                    polyInverseCutVertical
                });

                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
                EntraDrawer.DrawIntoFile(delPolys);
            }
        }
        public static void RemoveRocketsPolysIntersectionWithPlanes(RocketCarrierService rocket,
                                                                    ref List <List <IntPoint> > poly)
        {
            Vector2 rP1, rP2;

            ProjectionHandler.FindRocketTwoBorderPoints(rocket, out rP1, out rP2);

            Vector2 rPosCenter = new Vector2((rP1.X + rP2.X) / 2, (rP1.Y + rP2.Y) / 2);

            for (int i = 0; i < 7; i += 2)
            {
                var cDir = (Direction)i;
                //if (CompIsOnDirToBump(compPos, rPosCenter, cDir))
                //{
                Vector2 planeP1, planeP2;
                GetPlanePoints(cDir, out planeP1, out planeP2);

                Vector2 interP;
                MathHelperModule.FindIntersection(planeP1, planeP2, rP1, rP2, out interP);

                if (interP.X <= StaticData.LevelFarWidth && interP.X >= 0 &&
                    interP.Y <= StaticData.LevelFarHeight && interP.Y >= 0)
                {
                    // Rocket is not on a collision course with the bump,
                    // so cut down the del poly area vertically
                    List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(interP, rocket.PositionXNACenter2D);

                    EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                    {
                        polyInverseCutVertical
                    });

                    poly = EntraSolver.GetPolySolution(poly, polyInverseCutVertical,
                                                       ClipType.ctIntersection);
                    EntraDrawer.DrawIntoFile(poly);
                }
                // }
            }
        }
Пример #6
0
        public static List <List <IntPoint> > GetRocketPoly(RocketCarrierService service)
        {
            Vector2 posCenter = service.PositionXNACenter2D;
            float   xUL, xUR, xBL, xBR, yUL, yUR, yBL, yBR;

            xUL = xUR = xBL = xBR = yUL = yUR = yBL = yBR = 0;

            switch (service.Dir)
            {
            case Direction.East:
                xUL = posCenter.X;
                yUL = posCenter.Y;

                xUR = posCenter.X + 900;
                yUR = posCenter.Y;

                xBR = posCenter.X + 900;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X;
                yBL = posCenter.Y + 900;
                break;

            case Direction.SouthEast:
                xUL = posCenter.X;
                yUL = posCenter.Y;

                xUR = posCenter.X + 900;
                yUR = posCenter.Y + 900;

                xBR = posCenter.X + 900;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X;
                yBL = posCenter.Y + 900;
                break;

            case Direction.South:
                xUL = posCenter.X - 20;
                yUL = posCenter.Y - 20;

                xUR = posCenter.X + 20;
                yUR = posCenter.Y - 20;

                xBR = posCenter.X + 20;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X - 20;
                yBL = posCenter.Y + 900;

                break;

            case Direction.SouthWest:
                xUL = posCenter.X;
                yUL = posCenter.Y;

                xUR = posCenter.X;
                yUR = posCenter.Y;

                xBR = posCenter.X;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X - 900;
                yBL = posCenter.Y + 900;
                break;

            case Direction.West:
                xUL = posCenter.X - 900;
                yUL = posCenter.Y;

                xUR = posCenter.X;
                yUR = posCenter.Y;

                xBR = posCenter.X;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X - 900;
                yBL = posCenter.Y + 900;
                break;

            case Direction.NorthWest:
                xUL = posCenter.X - 900;
                yUL = posCenter.Y - 900;

                xUR = posCenter.X;
                yUR = posCenter.Y;

                xBR = posCenter.X;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X - 900;
                yBL = posCenter.Y + 900;
                break;

            case Direction.North:
                xUL = posCenter.X - 20;
                yUL = posCenter.Y - 900;

                xUR = posCenter.X + 20;
                yUR = posCenter.Y - 900;

                xBR = posCenter.X + 20;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X - 20;
                yBL = posCenter.Y + 900;
                break;

            case Direction.NorthEast:
                xUL = posCenter.X;
                yUL = posCenter.Y;

                xUR = posCenter.X + 900;
                yUR = posCenter.Y - 900;

                xBR = posCenter.X + 900;
                yBR = posCenter.Y + 900;

                xBL = posCenter.X;
                yBL = posCenter.Y + 900;
                break;
            }
            List <List <IntPoint> > polys = new List <List <IntPoint> >()
            {
                new List <IntPoint>()
                {
                    new IntPoint((int)xUL, (int)yUL),
                    new IntPoint((int)xUR, (int)yUR),
                    new IntPoint((int)xBR, (int)yBR),
                    new IntPoint((int)xBL, (int)yBL)
                }
            };

            ProjectionHandler.RemoveRocketsPolysIntersectionWithPlanes(service, ref polys);
            return(polys);
        }