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); } }
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 List <List <IntPoint> > SetProperBumpersEffect(List <List <IntPoint> > spaceSoFar, List <CompEntityPoly> adders, List <CompEntityPoly> allEntitiesList, bool withAdd) { //foreach (CompEntityPoly adder in adders) { List <BumperEntityPoly> processedBumps = new List <BumperEntityPoly>(); while (true) { List <BumperEntityPoly> allRechableBumpers = GetReachableBumpers(spaceSoFar, allEntitiesList); allRechableBumpers.Sort(BumpersComparator); List <BumperEntityPoly> rBumpersNew = GetNewBumps(allRechableBumpers, processedBumps); rBumpersNew.Sort(BumpersComparator); //foreach (BumperEntityPoly rBump in rBumpersNew) { if (rBumpersNew.Count == 0) { break; } else { BumperEntityPoly rBumper = //rBump;// rBumpersNew.First(); processedBumps.Add(rBumper); spaceSoFar = rBumper.ApplyEffectPref(spaceSoFar, adders, withAdd); //EntraDrawer.DrawIntoFileTesting(spaceSoFar); } } } } return(spaceSoFar); }
public List <List <IntPoint> > ProjectCompOntoBumper(Vector2 compPos, BumperEntityPoly bumperEntity) { Vector2 bP1, bP2; FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2); // Intersection with all planes var result = IntersectWithPlanes(compPos, bP1, bP2); return(result); }
public static CookieDirection GetABCookieDirection(CompEntityPoly entity, BumperEntityPoly bumper) { var refPos = entity.PositionXNACenter2D; var bumpPos = bumper.PositionXNACenter2D; if (refPos.Y < bumpPos.Y) { return(CookieDirection.FromAbove); } else { return(CookieDirection.FromBottom); } }
private static int GroupSorter(BumperEntityPoly b1, BumperEntityPoly b2) { if (b1.PositionXNACenter2D.X > b2.PositionXNACenter2D.X) { return(1); } else { if (b1.PositionXNACenter2D.X == b2.PositionXNACenter2D.X) { return(0); } else { return(-1); } } }
//private static void RemoveNewlyAddedBumpsDelPolys(ref List<List<IntPoint>> initialPoly, CompEntityPoly entity) //{ // //List<BumperEntityPoly> rBumpers = entity.EntraAgentSimple.BumpersHandler.GetReachableBumpers(initialPoly, // // entity.EntraAgentSimple // // .AllCompsEntities); // var coveredBumps = GetCoveredBumpers(entity, initialPoly); // foreach (BumperEntityPoly bumper in coveredBumps) // { // //this.EntraAgentSimple.BumpersHandler.processedBumps.Remove(bumperEntityPoly); // List<List<IntPoint>> bumperDelPolys = bumper.GetDelPolys(initialPoly, // new List<CompEntityPoly>() { entity }); // EntraDrawer.DrawIntoFile(bumperDelPolys); // List<List<IntPoint>> delIntersection = BumpersHandler.GetDelPolysIntersection(bumperDelPolys); // EntraDrawer.DrawIntoFile(delIntersection); // //var originalAreaToBeAdded = EntraSolver.GetPolySolution(result, delIntersection, ClipType.ctIntersection); // EntraDrawer.DrawIntoFile(bumperDelPolys); // if (delIntersection != null) // { // initialPoly = EntraSolver.GetPolySolution(initialPoly, delIntersection, ClipType.ctDifference); // EntraDrawer.DrawIntoFile(initialPoly); // if (!entity.EntraAgentSimple.BumpersHandler.processedBumps.Contains(bumper)) // { // entity.EntraAgentSimple.BumpersHandler.processedBumps.Add(bumper); // } // } // } //} //public static void ReAddNewlyAddedBumpsAreas(ref List<List<IntPoint>> initialPoly, CompEntityPoly adder) //{ // List<BumperEntityPoly> allBumpers = // adder.EntraAgentSimple.AllCompsEntities.Where(e => e is BumperEntityPoly).Cast<BumperEntityPoly>().ToList(); // List<BumperEntityPoly> rBumpers = adder.EntraAgentSimple.BumpersHandler.GetReachableBumpers(initialPoly, // adder.EntraAgentSimple // .AllCompsEntities); // EntraDrawer.DrawIntoFile(initialPoly); // var coveredBumps = GetCoveredBumpers(adder, initialPoly); // foreach (BumperEntityPoly bumper in coveredBumps) // { // // for debug // var pos = adder.PositionXNACenter2D; // var b = bumper.CompObj as BumpRigid; // var vPos = b.PositionXNACenter2D; // var bumperCoveringPoly = bumper.GetAreaPoly(adder.PositionXNACenter2D); // EntraDrawer.DrawIntoFile(bumperCoveringPoly); // // GO RECURSION for Coverd bumpers by the covered bumper // List<BumperEntityPoly> coveredByBumpBumpers = GetAnotherBumperIsCovered(bumperCoveringPoly, bumper, // allBumpers); // List<CompEntityPoly> covered = coveredByBumpBumpers.Cast<CompEntityPoly>().ToList(); // coveredByBumpBumpers = GetBumperCloseOnYToOthers(bumper, coveredByBumpBumpers); // if (coveredByBumpBumpers.Count > 0) // { // foreach (CompEntityPoly entityPoly in covered) // { // ReAddNewlyAddedBumpsAreas(ref initialPoly, entityPoly); // } // } // // //List<BumperEntityPoly> coveredByBumpBumpers = GetBumperCloseOnYToOthers(bumper, allBumpers); // // List<Polygon> delPolys = new Polygons(); // // foreach (BumperEntityPoly compEntityPoly in covered) // // { // // delPolys.AddRange(BumperEntityPoly.GetDelPolys(compEntityPoly, bumperCoveringPoly, // // new List<CompEntityPoly>() {bumper})); // // } // // EntraDrawer.DrawIntoFile(delPolys); // // delPolys = BumpersHandler.GetDelPolysIntersection(delPolys); // // EntraDrawer.DrawIntoFile(delPolys); // // if (delPolys != null) // // bumperCoveringPoly = EntraSolver.GetPolySolution(bumperCoveringPoly, delPolys, ClipType.ctDifference); // // PolysHelper.RemoveNewlyAddedBumpsDelPolys(ref bumperCoveringPoly, entity); // // entity.EntraAgentSimple.PolysLogger.Log(new PolyLog(bumper, bumperCoveringPoly)); // // initialPoly = EntraSolver.GetPolySolution(initialPoly, bumperCoveringPoly, ClipType.ctUnion); // //} // //else // { // //EntraDrawer.DrawIntoFileTesting(bumperCoveringPoly); // initialPoly = EntraSolver.GetPolySolution(initialPoly, bumperCoveringPoly, ClipType.ctUnion); // BumpersHandler.RemoveNewlyAddedBumpsDelPolys(ref initialPoly, adder); // EntraDrawer.DrawIntoFile(initialPoly); // //EntraDrawer.DrawIntoFileTesting(bumperCoveringPoly); // BumpersHandler.RemoveNewlyAddedBumpsDelPolys(ref bumperCoveringPoly, adder); // EntraDrawer.DrawIntoFile(bumperCoveringPoly); // adder.EntraAgentSimple.PolysLogger.Log(new PolyLog(bumper, bumperCoveringPoly, adder)); // //initialPoly = EntraSolver.GetPolySolution(initialPoly, bumperCoveringPoly, ClipType.ctUnion); // } // } //} //private static List<BumperEntityPoly> GetAnotherBumperIsCovered(List<List<IntPoint>> coveringArea, BumperEntityPoly bRef, // List<BumperEntityPoly> allBumpers) //{ // List<BumperEntityPoly> result = new List<BumperEntityPoly>(); // foreach (BumperEntityPoly b in allBumpers) // { // if (bRef != b) // { // if (EntraSolver.IsPolyOperation(coveringArea, b.GetDefPoly(), ClipType.ctIntersection)) // { // result.Add(b); // } // } // } // result.Sort(BumpersHandler.BumpersComparator); // return result; //} private static List <BumperEntityPoly> GetBumperCloseOnYToOthers(BumperEntityPoly bRef, List <BumperEntityPoly> allBumpers) { List <BumperEntityPoly> result = new List <BumperEntityPoly>(); foreach (BumperEntityPoly b in allBumpers) { if (bRef != b) { var bRefPos = bRef.PositionXNACenter2D; var bPos = b.PositionXNACenter2D; //if (Vector2.Distance(bRefPos, bPos) < 120) if (Math.Abs(bRefPos.Y - bPos.Y) < 30) { result.Add(b); } } } return(result); }
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); } }
private static void AddToProperList(BumperEntityPoly bRef, BumperEntityPoly bNew, ref List <BumperEntityPoly> bRefList, ref List <List <BumperEntityPoly> > result) { var list = result.Find(delegate(List <BumperEntityPoly> bList) { return(bList.Contains(bRef)); }); if (list == null) { list = result.Find(delegate(List <BumperEntityPoly> bList) { return(bList.Contains(bNew)); }); if (list == null) { if (!bRefList.Contains(bNew)) { bRefList.Add(bNew); } return; } } if (!list.Contains(bNew)) { list.Add(bNew); } }
public static void FindBumperTwoBorderPoints(BumperEntityPoly bumperEntity, out Vector2 pb1, out Vector2 pb2) { BumpRigid bump = (bumperEntity.CompObj as BumpRigid); Vector2 bXNA = bump.PositionXNA2D; Vector2 bXNACenter = bump.PositionXNACenter2D; int halfBumpWidth = bump.Width / 2 - 5; switch (bump.Dir) { case Direction.East: case Direction.West: pb1 = bXNA + new Vector2(0, bump.Height / 2); pb2 = bXNA + new Vector2(bump.Width, bump.Height / 2); break; case Direction.SouthEast: case Direction.NorthWest: pb1 = bXNACenter + new Vector2(-halfBumpWidth, -halfBumpWidth); pb2 = bXNACenter + new Vector2(+halfBumpWidth, +halfBumpWidth); break; case Direction.South: case Direction.North: pb1 = bXNACenter + new Vector2(0, -halfBumpWidth); pb2 = bXNACenter + new Vector2(0, bump.Width - halfBumpWidth); break; case Direction.SouthWest: case Direction.NorthEast: pb1 = bXNACenter + new Vector2(-halfBumpWidth, +halfBumpWidth); pb2 = bXNACenter + new Vector2(+halfBumpWidth, -halfBumpWidth); break; default: throw new ArgumentOutOfRangeException(); } }
public void AddShouldBeProcessedBumper(BumperEntityPoly bumperEntityPoly) { shouldBeProcessedBumps.Add(bumperEntityPoly); }
public static void AddBumpsAreaForBubble(ref List <List <IntPoint> > initialPoly, BumperEntityPoly bumper, BubbleEntityPoly bubble) { BubbleService bubbleService = bubble.CompObj as BubbleService; Vector2 bubblePos = bubbleService.PositionXNACenter; //var coveredBumps = BumpersHandler.GetCoveredBumpers(bubble, initialPoly); int fR = AreaCompPolyHandler.fR; int nR = AreaCompPolyHandler.nR; int dfR = AreaCompPolyHandler.dfR; //foreach (BumperEntityPoly bumper in coveredBumps) { BumpRigid bump = bumper.CompObj as BumpRigid; Vector2 bPos = bump.PositionXNACenter2D; CookieDirection abDir = AreaCompPolyHandler.GetABCookieDirection(bubblePos, bPos); CookieDirection rlDir = AreaCompPolyHandler.GetRLCookieDirection(bubblePos, bPos); switch (bump.Dir) { case Direction.East: case Direction.West: if (abDir == CookieDirection.FromBottom) { if (rlDir == CookieDirection.FromRight) { initialPoly = EntraSolver.GetPolySolution(initialPoly, new List <IntPoint>() { new IntPoint((int)bPos.X, (int)bPos.Y + 900), new IntPoint((int)bPos.X - fR, (int)bPos.Y + 900), new IntPoint((int)bPos.X - fR, (int)bPos.Y - 900), new IntPoint((int)bPos.X, (int)bPos.Y - 900) }, ClipType.ctUnion); } else { //initialPoly = EntraSolver.GetPolySolution(initialPoly, // new Polygon() // { // new IntPoint((int) bPos.X, // (int) bPos.Y - 900), // new IntPoint((int) bPos.X + fR, // (int) bPos.Y - 900), // new IntPoint((int) bPos.X + fR, // (int) bPos.Y + nR), // new IntPoint((int) bPos.X - 20, // (int) bPos.Y + nR), // new IntPoint((int) bPos.X - 20, // (int) bPos.Y + 20), // }, // ClipType.ctUnion); initialPoly = EntraSolver.GetPolySolution(initialPoly, new List <IntPoint>() { new IntPoint((int)bPos.X, (int)bPos.Y - 900), new IntPoint((int)bPos.X + fR, (int)bPos.Y - 900), new IntPoint((int)bPos.X + fR, (int)bPos.Y + 900), new IntPoint((int)bPos.X, (int)bPos.Y + 900) }, ClipType.ctUnion); } } else { // the bubble is above the bumps so don't add anything } break; case Direction.South: case Direction.North: break; case Direction.NorthWest: case Direction.SouthEast: if (abDir == CookieDirection.FromBottom) // From Right and Left are the same { initialPoly = EntraSolver.GetPolySolution(initialPoly, new List <IntPoint>() { new IntPoint((int)bPos.X, (int)bPos.Y + 900), new IntPoint((int)bPos.X - fR, (int)bPos.Y + 900), new IntPoint((int)bPos.X - fR, (int)bPos.Y - 900), new IntPoint((int)bPos.X, (int)bPos.Y - 900) }, ClipType.ctUnion); } break; case Direction.NorthEast: case Direction.SouthWest: if (abDir == CookieDirection.FromBottom) // From Right and Left are the same { //var poly = new Polygon() // { // new IntPoint((int) bPos.X, (int) bPos.Y - 900), // new IntPoint((int) bPos.X + fR, // (int) bPos.Y - 900), // new IntPoint((int) bPos.X + fR, (int) bPos.Y), // new IntPoint((int) bPos.X, (int) bPos.Y), // }; //EntraDrawer.DrawIntoFile(poly); //initialPoly = EntraSolver.GetPolySolution(initialPoly, // poly, // ClipType.ctUnion); var poly = new List <IntPoint>() { new IntPoint((int)bPos.X, (int)bPos.Y - 900), new IntPoint((int)bPos.X + fR, (int)bPos.Y - 900), new IntPoint((int)bPos.X + fR, (int)bPos.Y + 900), new IntPoint((int)bPos.X, (int)bPos.Y + 900), }; initialPoly = EntraSolver.GetPolySolution(initialPoly, poly, ClipType.ctUnion); EntraDrawer.DrawIntoFile(poly); } break; default: throw new ArgumentOutOfRangeException(); } } }