I'm gonnatake a quickbreakfromtheroleplayinggame, Siri's tohave a look.
ATTprogrammingpseudothreedimensionalplanes.
Andthiswas a techniquemadepopularbytheSuperNintendo, and I'm goingtouse a superMarioKartisanexamplewhereanimageistakenasthegroundplaneanditisrotatedandscaledandtranslatedaroundthecameraisnecessarytogivetheimpressionoverthreedimensionalenvironment.
ThiswasknownasModeseven, whichfortheSuperNintendowasjustreallyimplementingan F finetransforminhardware.
I'm notgoingtobeusingAfricantransformeddirectlybecause I wanttoplaywithsomeoftheparametersandseewhathappens.
Andsothisiswhatwe'regoingtobedeveloping.
Ofcourse, it's intheconsolenow.
Tothoseof a certainage, thismaylookveryfamiliar.
Thisisindeedthefirsttrack, I believefromSuperMarioKart, andforthoseexpectinganotherepisodeoftheroleplayinggame, youcanseeit's vaguelyrelated.
We'reusingexactlythistechnologyfortheworldmap.
What I thinkisreallyneedsaboutthisprogramisthatisit.
There's barelyanythingtoit.
A toss.
Thereshouldbe a nice, short, quickvideoshowingsomethinginterestingwemightbeabletouseinothergamesandtechnologies.
Soasweusuallydoonthischannel, let's take a quicklooktojustexplorewhatitisthatwe'regoingtodoandtryandunderstandthatsomeoftheconceptsandprinciplesbehindthealgorithm I'm goingtocreate a bigolseasprite, andweknowthatthesebehavedjustliketexturesonthatwecansamplefromthem.
Assumingthatthetopleftis 00 on, theextremitiesare 1.0 on 1.0, andifyourememberfromthecodeityourselffirstpersonshooters, thismakessamplingthetexturescale.
I'm here, and I'm goingtousethosecoordinatestogiveme a regionwhich I willbeSampleytodisplaytotheuser.
Andthisismyfirsttime.
Oncewe'vegotthefirst, um, wecannowdeterminethemappingbetweenwhattheplayercanseeonthetwo d planeversuswhattheycanseeonthisscreennowinthecouncilwindowweknowthatthe Y axisgoesinthisdirectiononthe X axisgoesinthisdirection.
Whyaccessandthisbecomesour X axiswillnoticethatthe X axischangeslengthdependingonwhereitisinthe Y axiswhenwe'refaraway.
We'relookingat a lotmoreexthanwearewhenwe'reclosetoit.
Thismeanswecantakeany X Y coordinatesinthecommandpromptwindowworkoutwhereitliesinsideourfirst, um, andthatbecomesthesampledpointthatwewilldisplayonthescreen.
Itwouldappearthatthere's quite a degreeofinterpellationhappeningontherace, so I'm goingtoputsomenamingconventionsinsowecanfollowthecode.
Thispointuphereisgoingtobeknownasfar X oneonwhyonethisonedownhereisgoingtobeknownasnear X oneonwhyonethisoneisfar X two, andwhy, too, andThisoneisnear X twoonWhitey.
Whenweextract a pixellocationfromtheconsolescreen, wewillbenormalizingitversusthescreenwithandscreenheightsowell, gettingin a valuebetweenzeroandone.
Well, weknowthatthe Y coordinateisgoingtobereasonablyconsistentfornow.
Thosewhoarethinkingaheadwe'llcomebacktothatlater.
No 0.5 willbesomewherehalfwayalongthelinebetweennearandfar.
Andbecauseweknowthevectorbetweenfar X oneandnear X oneonthevectorbetweenfartstoo, andnear x two, wecanworkoutwherethosetwopointsare.
Andonceyou'vegotthosetwopoints, wecreate a newline.
I'm goingtogoseethemiddle.
So I'lljustflagthatinnormalizedspace.
Thisishalfwayalongandthen, ofcourse, becausewe'vegotthislinewecandoexactlythesametothisnewlinetoeworkout, the X location, whichishalfwayacrossthisnewline, whichwithdrawninalreadyit's there.
Youmayhavenoticedthat I subtlyhintedsomething's notquiterightwiththisapproach, butwe'llcomebacktothatwhenwestartwritingsomecode.
Solet's getstartedwiththecode.
I'vealreadycreated a subclasscalledonelonecode, a fakemodsevenon I'vecreated a mainfunctionwhichcreatesaninstanceofthisclassconstructingtheconsultobe 3 20 wideby 2 40 Highoneachcharacterisgoingtobefourbyfourpixels.
Notethatthisisquite a highresolutiononindeed, maynotworkoncertainscreens.
Ifyou'renotusing a 10 80 p screen, it's notgoingtofitonthatdesktops.
You'llhavetouse a smallerconsolesize.
Well, let's startbyaddingtheverybasics I know I'm goingtoneed a SpritethatrepresentsthegroundlaterwillshowhowtoloadtheSprite.
Buttobeginwith, I'm goingtocreateitAlgorithmicLee, because I wantedtobe a spriteoflinessowecansee.
Howdoesthethree D effectsstarttodistortwhattheusercanseeonOnthewhole, I knowthatmymapisgoingtobesquareonbothsidesaregoingtobe 1024 soit's goingtobelike a onemegapixeltexture, quite a bigthingfortheconsolegameengine.
Sointheonusercreatefunction, I'm goingtocreateit.
Andherewego.
I'vedefineditasbeing a squarespriteofsize, mapsizebymapsize.
I wanttopopulatethismapbyhandsomewheretocreatetwonestedfourloopstodrawlinesgoingfromonesideofthemaptotheotherinboththeaccent.
Whydirections?
And I wantedtoleave a gapoff 32 pixelsbetweeneachlinefortheopposingaccess.
I wanttodrawineverysinglepixel, soweskipbyonepixelat a time.
Now, eventhough I'veusedthenamingconventions X andwhyhere?
I canactuallybothdrawboththehorizontalandverticallinesatthesametime, andthat's becausethemapwillbereflectedalongthe X Y axis.
I'm goingtocallthissimpledepth, andit's justsimplythewhyvaluedividedbythetotalrangeofthe Y valueinthiscase, knowinghowfarintothefirstroomweneedtobay, wecancreatetwopointsthatrepresentthisscanlinegoingacrossthefirstroom.
Soonthelefthandside, the X oneside, I getthedirectionvectoroffthelineofthesideofthefirst, Um, I multipliedbymynormalizedvaluetocreate a samplingpoint, and I offsetitbythenearplane, I guessanendpointforthescanlinebydoingexactlythesamething.
Nowweknowwherethescanlinebeginsandends.
Inourfirstroom.
Wecanusethe X componentofthescreencoordinatetoeworkoutwerealongthatline.
Weshouldsamplethepixelincolor.
Soinexactlythesameway, I'm goingtocreate a normalizedpointbetweenzeroandonesamplewit, and I'm goingtofindthesamplelocationbyinterplatingalongthatline.
Once I havemysamplecoordinates, I cangoandextractthemfromtheOLCSprite, usingthesamplecliffandsamplecoolerfunctions.
Nowthesefunctionswilloperateon a nearestneighborprinciple, whichmeanswedon't reallycareaboutthespatialscale.
If I orientatethecamera, sowegetverticalandhorizontallinessomewhereinourscene, wecanseethattheybehavekindofappropriately, butitlookslikeourscenehasitsperspective, firstlyinthewrongdirectionandupsidedown.
We'vemade a rathernaiveassumptionthatourinterpellationalongthefirstroomcentralaxisawayfromthecameraislinear.
Anditisn't perspectiveassumesthatwe'vegotthreecomponentstoanimage X, y andZed.
Where's thatisequaltothedeath, andweintuitivelyknowthatthingsthat a furtherawaymovelessandhavelesssignificance.
Andsoifweweretolookattherelationshipbetweendepthon X andwhy, whatwemightbeabletoassumeisthatsomenewPosition X isequaltosomePosition X dividedbydepth, andthesamegoesforthe Y axison.
Thisimpliesthathassaid, approachesinfinity.
Anychangestoactsbecomeminuscule.
Where's ifZeddapproached?
Zero?
Thechangesbecomeverylargeindeed, andinmanyways.
I supposethisiswhythestarsinthenightskydon't appeartomoveasyoumoveyourheadaroundyettothetreesandlamppostsinfrontofthemdo.
Butwhat's interestinghereisthatwe'reseeingthatdepthiscertainly a oneoverdepthrelationshipto X and Y.
I thoughtitmightbeusefultoquicklyexplorewhythismightbethecase.
I wantyoutoimaginefor a minutethatthecameraistheman's headon.
Sohere I'veprojectedtoraisefromtheplayers I intothedistance.
Andifweweretoattributehowmuchofthisdistantscanlinecanbeseenbytheplayer, wemightwanttoestimateitbydrawing a littlearrowbetweenthetwo.
Wecanseeit's quitesmall.
Let's drawinsomemorelines, andnow, ifwelookattheproportionofwhatcanbeseenforeachskinline, wemightbeabletoidentify a bitof a trend, and I'llverycarefullytryanddrawthislineinjoiningallofthepointsoftheseup.
Lookatthat.
I'm gettingsomewhatbetterwiththeolddrawingtablet.
Wecanseeveryclearlythatwehaveindeedgotta y equalsoneover X relationshiphere.
I thinkit's timetosaygoodbyenowtoourhandsgeneratedmaponuse, a preloadedtexture.
So I'llcommentthatout.
Unloadthetexturedirectly.
Now I wentonlinetohave a lookatMarioKartmapsandfound a fantasticwebsitewhichhadthemasPNGfilesondhe A.
Someofyoumayknownow, fromquite a fewvideos, theFantasticKingfromtheDiscordServerhasbeencreatinglotsofalgorithmstoturnPNGfilesinto a consolegameengineformatsprites.
Andso I convertedthePNGinto a sprite, readytouseinthegameengine.
Solet's have a look.
WecanseeWell, we'vecertainlygot a map.
Itlooks a bitdistortedandparallellinesaren't quiteright.
Butthat's whywe'vegotadjustableparameters.
Sofirstly, itlookslike I'm floatingintheair, so I'm goingtoadjustthefarviewpointdown a littlebit, soitbringsmeclosertotheground.
I'm goingtobringinthenearparametertotryandtakeoutsomeofthecurvatureso I canputinlotsofcurvature.
Itjustmakesitlooklikewe'realwaysgoingdownhill.
I wanttotryandironthatout a littlebituntilitlooksaboutright.
Therewego.
That's nottoobad.
Thefieldofviewseemsreasonableanyway.
Wecanmakeitwider.
Wecouldmakeitnarrower.
I thinkinracinggamesyoucanchangethefieldofyoutogiveyoudifferentperceptionsofspeed.
Soas I makethefieldofviewwider, I'lljusttryandzoomalongin a particulardirection.
Thefieldisgettingverywide, butif I bringitinandcome a bitnarrower, yes, I thinkitstartstolooklikewe'respeedingup.
Maybe I don't know.
TheyneedsomeplayingwithOnething I amcurioustoseeishowdoestheMarioKartmaplook?