I don't knowhowusefultheyare, buttheycanbeusedforsortofwobblyeffects.
Butcertainlytheabilitytorotateandpositionandscalespriteson a screenisreallyimportant.
AndSointhisvideo, I wanttointroducethecodetoimplementand I findtransform.
Let's getstuffforthisvideo.
I'm goingtousetheoneloneKodapixelgameengine, and I'vealreadycreatedthebirdbonesofwhat's requiredhere.
I'veoverriddenthepixelgameengineclasswith a baseclasscalledSpritetransformsonthatwillprovidetwofunctionsonusercreateonournewsupdateonusercreateiscalledOnceandanuserupdateiscalled.
What I meaniswe'veprovidedinterviewvalueasthefourthargumentofthedrawerSpritefunctiononitwillmodify, aswecanseenowthecaristwiceaslarge, soitisskilledinbothaxesby a factoroftochangeittothreeandit's threetimesbiggerand I candointerviewscalingquitesimply, becausethestripedsharesits X and Y axiswiththe X and Y axisofthescreenintheexampletoshowinsteadofdrawing, onepixelwilldrawthreepixelsinstead.
Solet's say a translationinthe X on a translationinthewhyondependingonhowyouwanttolookatthings, youcouldalsotakethewholelotandmultiplyitby a scalingfactorscale, X orscale.
I'm goingtoextendtherotationmatrixtoaccommodatetheadditionaltermsoitnowbecomes a threebythreematrix.
Andwhenwedoourmultiplicationmultiplyingby X onbywhyonbyoneinthiscase, thethirdtermwouldbeonemultipliedbyzerooronemultipliedbyoneinEitherwayit's irrelevant.
Theresultofthiscombinedtransformisitself a threebythreematrix, whichmeanswecanhave a verycomplicatedtransformation, representedwith a littleamountofdata.
Andthesesortsofcombinetransformsarecalled a finetransforms.
Now I happentoknowthatthespriteis 200 pixelswideby 100 pixelshigh, Soif I translatedbyminus 100 onminus 50 I'llmovethezeropointtothemiddleoftheSprite I stillwanttodotherotation, but I'm goingtostorethatinMatrix B.
Andso I wanttocombinethesetwomatricesintomymatrixfinal.
ItdoesrotatestillgotthesepeskySiondotsallovertheplace, butitseemstobedoingquite a niceandsmoothrotationandcertainlytheperformanceisquitegood, too.
That's a prettyfunkypattern.
ThereasonTheMatrixstuffgets a littlebitcomplicated.
Hismatrixmultiplicationisnotcommuted.
A tive i theordermatters.
That's whywesawatthestart I hadtoswitcharoundthe A and B values.
So I createdtoexclusiveMajorsees.
Wanttotranslateon, wanttorotateondive, multipliedtheminthecorrectordertogiveme a newmatrixmatrix C, andtheywanttotakematrixearsmyalreadyexistingmatrixandmultiplyitby a newmatrix, whichrepresents a translationtothemiddleofthescreen.
Sotakingthetopleftofthesprite, whichwouldbe 00 I canpassthatthroughourforwardfunction, usingourstandardtransformationmatrix.
There's the 00 on.
Theresultisgoingtobeplacedinto P X andPete.
Why?
Well, tostartwith.
That's alltheinformation I have.
So I'm goingtosetmystarting X and Y unending X and Y positionstobe P X and P y, andthengoingtosendthroughintheforwarddirectiontheoppositecornerofoursprite.
Now, ultimately, I wanttotraversethroughtheboundingboxfromthetopleftoftheboundingboxtothebottom.
Right.
So I wanttosortmystarting X and Y positions, which I dohere.
Soformystarting X isalwaysgoingtobetheminimumoffthepointthatwe'vejustcalculatedortheexistingstarting X locationandlikewise, theendingexplicationisalwaysgoingtobethemaximumofmymostrecentlycalculatedpointorwhat I'vealreadygot.
Nowthat I havetheboundingbox, I cannottraversethrougheachpixeloftheboundingboxandusetheinversetransformationtosamplethespiteofthecorrectlocationSoallofthepixelsintheboundingboxisgoingtogetselected.
I'm notgoingtohaveanygapsonthecode.
Looksverysimilartowhatwehadbefore.
I'llusemyforwardcommand, but I'llusetheInvertedMatrixtogivemetonewlocations, and I'llusetheselocationstosampletheSprite.
At a particularpoint.
I'veoffsetan X andend.
Why?
Becausethesearenolongerinterview.
Byaddingno 0.5 tothem, I makesurethat I'm roundingtothecorrectpixel.
Andso I guessthefinalthingtodoistodrawthenewpixelinthe X and Y locationonthescreen.