Secondly, itmayseemlike a horriblycomplicatedthing.

Convexpolygon, collisiondetection.

Butitisn't.

I wanttofocusonthealgorithmsratherthanthecodeforthisvideo.

Andsothecodingsectionsmaygo a bitquickerthanusual.

However, I encourageyoutodownloadthesourcefilefromthegethubandstudyitforyourselves.

Let's getsomeoftheverybasicsoutofthewayfirst, asmyregularviewerswillknowbynow, I draweverythingbyhand, sotechnicallynothingyou'llseeonthescreenis a polygo.

A polygonisdefinedbypointsconnectedbystraightedges, andasyoucansee, I'm nogoodatdrawingstraightthingsonmyscreen.

onwhat I havehereiscalled a concavepolygonandconcavepolygonpresentsallsortsofproblems I'm notgoingtodiscussinthevideosimplybecausetheyhavesomethinglikethis.

And a concavepolygoncanbeidentifiedbecauseithasatleastoneinternalanglethatisgreaterthan 180 degrees.

Andsoforthisvideo, we'renotinterestedinconqueFalagunswereinterestedinconvexpolygons, whichmeansalloftheinternalanglesarelessthan 100 and 80 degrees.

Now I knowthat a largepartofmyaudiencebuildsimpleto D gamesandsowemustn't forgetthatrectanglesandsquaresarealsoconvexpolygonsonthealgorithms.

Andthismeansgivenanaxisoftheworldinour X and Y directions, thesidesofthequadrilateral a paralleltothoseaxes, checkingtoseeiftwoaxisalignedQuadralateralsoverlapisverytrivialif I labelthisonepeeonthisone.

Q.

Wecanintuitivelyseethatinthe X axis.

Ifthissideof P islessthanthissideof Q, andthisisjustfor X axis, thenthereispotentialforoverlap.

Becauseifthishighlightedsideof P wasgreaterthantherighthandsideof Q, clearlytheywouldn't beoverlapping.

Wecanconfirmthiswithanothercheckthatifthissideoff P isgreaterthanthissideof Q, theninthe X axis, thesetwoQuadralateralsareoverlapping.

Andsoif I labelthisas X on, thispointis X pluswitforthatrectangle, andthesameappliesfor Q.

Weknowthatthere's overlapinthe X axisif P X islessthanque x plus w and p x plus W isgreaterthan Q X onbecauseourquadrilleactualsaxisaligned.

Whateverappliesinthe X axisalsoappliesinthe Y axis.

Sowecansimplyduplicatetheformula, replacingXson W's forwiseon H S.

Andthisisjust a littleprogramthatdemonstratestoalternativemethodsfordetectingoverlapbetweenconvexpolygon.

Sowe'llsee.

We'vegot a selectionofconvexpolygonsonthescreen.

I'vegot a Pentagon, which I canmovearoundThelinefromthemiddleofthePentagontotheoutsidejusthelpswiththedirection, so I knowhowtosteeritwiththearrowkeys.

I couldmovethePentagonaroundwiththe W S and D keys.

I canmovethetrianglearound.

I can't movethesquarearoundinthebottomcornerandwiththefunctionkeys, I canchoosebetweenfourdifferentoptionsofthealgorithms.

ThefirstiscalledseparatedAccessTheoryonAsyou'llseeas I movethePentagonintothesquare, it's changed.

A tallandthisisquiterightbecausethey'reat 90 degreestoeachother.

If, ontheotherhand, wehad a pointgoingto 11 weendupwithonetimesoneplusonetime, zeroclearly a oneonwecanseehereifweweretodrop a shadowdownfromthatparticularpoint.