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);
            }
        }
Beispiel #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;
                            }
                        }
                    }
                }
            }
        }
        private List <Vector2> GetIntersection(Vector2 compPos, Vector2 bP1, Vector2 bP2,
                                               Vector2 planeP1, Vector2 planeP2)
        {
            Vector2 pInter1, pInter2;

            MathHelperModule.FindIntersection(compPos, bP1, planeP1, planeP2, out pInter1);
            MathHelperModule.FindIntersection(compPos, bP2, planeP1, planeP2, out pInter2);
            List <Vector2> shadowPoints = new List <Vector2>()
            {
                bP1, bP2, pInter1, pInter2
            };

            return(shadowPoints);
        }
        //private void UpdateCookieFrogDistance()
        //{
        //    float dist =
        //        (StaticData.EngineManager.CookieRB.PositionXNACenter2D -
        //         StaticData.EngineManager.FrogRB.PositionXNACenter2D).Length();
        //    if (dist < CookieFrogMinDist)
        //    {
        //        CookieFrogMinDist = (int)dist;
        //    }
        //}

        private bool IsPathIntersected()
        {
            for (int i = 0; i < _placedCompSoFar.Count - 1; i++)
            {
                for (int j = 1; j < _placedCompSoFar.Count - 1; j++)
                {
                    Vector2 pInter = Vector2.Zero;
                    Vector2 p1     = _placedCompSoFar[i],
                            p2     = _placedCompSoFar[i + 1],
                            p3     = _placedCompSoFar[j],
                            p4     = _placedCompSoFar[j + 1];

                    if (_placedCompSoFar[i].X > 543 && _placedCompSoFar[i].X < 544)
                    {
                        int lk123 = 10;
                    }

                    if (_placedCompSoFar[j].X > 558 && _placedCompSoFar[j].X < 559)
                    {
                        int lk123 = 10;
                    }

                    if (MathHelperModule.IsIntersecting(p1, p2, p4, p3))
                    {
                        MathHelperModule.FindIntersection(p1, p2, p3, p4, out pInter);
                        if ((pInter != Vector2.Zero) &&
                            (pInter != p1) &&
                            (pInter != p2) &&
                            (pInter != p3) &&
                            (pInter != p4))
                        {
                            IsPathIntersection = true;
                            //if (IsReallyIntersection(pInter, new Vector2[] { p1, p2, p3, p4 }))
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        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);
                }
                // }
            }
        }