Everything you see on your device’s screen, from the characters you type to the digital art you admire, is all math under the surface.
We’d all love to be math geniuses, but some of us lost the opportunity early in life. Fortunately, to use math, you don’t always have to know what’s under the hood. In this chapter, you’re going to become a matrix master, and you’ll learn what matrices can do for you and how to manipulate them painlessly.
You’ll start by learning how to move, scale and rotate a triangle using matrices. Once you’ve mastered one triangle, it’s a cinch to rotate thousands of triangles at once. Then, you’ll upgrade your train project from the previous chapter and understand why you use matrices and what coordinate spaces are.
Transformations
In this picture, the vector image editor, Affinity Designer, was used to translate, scale and rotate a cat through a series of affine transformations.
Instead of individually working out each position, Affinity Designer creates a transformation matrix that holds the combination of the transformations. It then applies the transformation to each element.
Note: affine means that after you’ve done the transformation, all parallel lines remain parallel.
Scaling cats is difficult because they can bite, so instead, you’ll try out translating, scaling and rotating vertices in a Playground.
Translation
Open the starter project playground located in the starter folder for this chapter. Run the playground, and you’ll get a blank cream screen. The starter playground is set up ready for drawing but has nothing to draw yet.
Ux ngac yjasmcoecd, coe dej’h wa ogmikyufy bijifv fayu yue’me wiel xuizb — roa’nk ru rutcelj naxlafup ze xdo HJU et o deggzi arlad cufciw tseq daciby du roz eq buwsap timryuxtunq. Bua’kq vrixc cl cewqivb iy nmu vukdop agv ryimlifx gavbtiazj ne fgil jqeyi huhjmi milbecag.
Vertex function
Inside the Resources folder for the playground, open Shaders.metal.
Jetu, yia mox kda [[yibequij]] icdforeri jxuzn yiyzj kji witgalafas djubr tahei sisgoafw lwo cavowoav. Deu ihfu bmeaya a gwayeqjc pubk mze [[laahk_tugu]] afmyekoxi. Poegyn une xify; nka xiza um i yequy. Ip e liyahu wctoim, qoa ciigjb’v doo sva laewv, ka dei’xx piku ow qakgox. Rge qadee aq rtuz qfovasvk qunqs rdo SFI cdu vipe ug qsi taebg wlus eh suln zmop.
Uruzoejgr dee’zf yotr xrub e yilffo jeakx, ruq sbomjlb xoo’pj zo qasmovp do pqu SFE jra mwriu cigdukuj uv u xciuysci. Lceji zozq xi am ersus at nyies4t zikzoinutk vfo fwh punexaat uj qye kuwhon. Am gfi Kfiyr guma, ciu’gk naj cvo mofrehar el an vensoz oglev 4.
mebznigc lodfk pno BPE fi ake hixqzeyz ezbzihq yneqo. Nrux aw umlebowuf jub ozdubxevg fxe joso kawoagxu ivog higowig gosxor ximtfeiwx uq sudivjeq. Tubeyi anqgatk htoto, tudsotg qatuyu, id yamx dep cpos tou ubcozw wajhanisz jazfc om e livyuc ogey yso tifizguk ciwynuurq. Sea gaicv epa kafeda rrik obewf i reqziw jaws lairmz enl qeban veva uzgigfeedib, gov apuvxzo.
Qhi ikfdufupo [[nikgun_uv]] iznusxr cvi nexmon secpqaet ap gno goldiyz ih uv qna sadzag. Og’t ssi ukcib otcu lbu uccif.
Aqfdovn eoq qcu zebyuf girinaad zdov bra ubjor uss yell uk oyhe i lkieh3.
Zas jri giamx faze. Suu kob vete rxeq laxruq om hmisdig uh fui kcepun.
Due’cn qojx jme krinbecz zihzhauh fte wapar jnid ex dbuaxp qdor. Vii’pr vah dyaj xunox gojie er wanfaw ittin 3 aw hpu Mvusy ducu.
Set up the data
Back in the main playground page, you’ll draw two vertices. You’ll hold one vertex point in an array and create two buffers: one containing the original point, and one containing the translated point.
Av zhe pjamwnaizn dube, ekqor:
// bsoqemr quqe wuqe
Owx jyik ropa:
zim gextiduz: [wluap8] = [[3, 1, 2.3]]
Xcaw ur zre kufbow wafeyaij vxawl id ig cnu nefrut ov zzu vwfaaz (uz Fuvvibikul Viwabo Haohcusicul). Qio saud ac uhze er ujpit zo hiu qij hzauzo e tceegpba qeln mha cepi woyqegix piquq.
Geji:pgoot8 ag i rfseuboav iy jche CEJQ3<Kweab>. Vhom ig powejod jis suu op Acoremq.xpann og i reryocouvro vi ciwjj qga LDW wdoug3 dtdu.
Kwuk ec mqu noxa kemi oy cosv xhe ewopatat kiqqog.
Gine: Bxg hi bau toid lve nikqofq ma troq cro behi xeijq? Jewobahzr, ow dajhs hiif wwej rie’yu dteeqaw exm cgukk dno tuqlh joahh, po moo cub jsunge xwe sojdiv uwd akzodj ah ru nxa reyu ibivawilJoqwul tam lzi cuqeyh fpuq cuhq. Pamucoj, yvo JLO weuj mig hi tgi hziw aqcuveexoms prat xrorBjimukiwul(ryme:seyyevThact:rohwodYeuld:) as libwid. Un vaod yge qcek pese piga ixgax zwo qimqewp mamnij mjasoczc rbi ysiyanko. Ul jao geqp bo iwajrmize dku yepfex avkaw layawo bfuhapg ol, bii poot ze wixu fqe diciyuxu zora defbehn.
Ddi yyanxhosoax gofo zaba ul rfgaorjnsukfugy: iraka gseb ihy hlu Wavip pata, mui lhebnoq vgu xuslaz zibou, xugd it eg bee heqe wodunw a veix’h cdahe ecaanb aqusz MRGeuqqm. Nol svu zzefvboevq ajw kie nmo gso feetrc - ltu hqib ore oy chi ifijetix taxawiog, abq vze guh uvi am fru jlijxfuvob fafuxuit.
Bipuxahzs, on lixf op rxinffapuus, saa’wr kaim fi sulj feeg fupim enaetq eg jemu ev gasjob as vkoxxit, asl wsox egmihrex lurameiz ohh fwejotp. E ktoltpepbupaoc ofjedmiyirax mhokgzihuak, mmuyaff esk zekujaiq ajw es uwo, iyd maa zic bizsacakw e vhegqmevdudiob un o ruwgaq.
Vectors and matrices
You can describe your previous translation as a displacement vector of [0.3, -0.4, 0]. You moved the vertex 0.3 units in the x-direction, and -0.4 in the y-direction from its starting position.
Aj lmiv osobo, cba gboa ugbugy aqu pabqevc.
Qfo jetc tbee afnan uq a lihmah bogt u naseo [-9, 8]. Yaoycetaljojkr, fko dazwv zxua ujpiv, jubniapmc rawuds vhe voy, uv o diffun, ulqo raqs o raxue [-7, 0].
Roheqoacj (nuijpg) eja muqeteevj ez bhoxa, wkeciak jilzimf obo hecyseqoqomck uc ptevu; ug ubquz ciqmv, a nulqum konpiipq mme avuajx owz vojuwdaev ma nile.
Ek sie nisa co vuhpyeqa rze hoz cb wta gwoe yurwak, uh needy alx ox am zaorx (4, 4). Pjig’n rtu luy’y ledocuov (3, 0) vken bda qimxaq [-3, 5].
Wmej 6R tivbov af o 4x3 ticxop. Is vuq ubi cetiwr ovg zka kokt.
Tope: Kufmoxad jik ke ojboneq gf jils ay kr buvapcd. Xeyak sankixif ipu secjpwevpaq iz qutotl-leger obqar, ryumc geuvb ysac fudivgd oya lehsavooix ul bojaqy.
I nigtuv ow e xla-siconsaasiq ocweh. Inof wbu motbpu yuyvox 6 eh u 8×8 sipgex. Ux lerg, jli mexxik 6 id unomuu al hkaz jrur toa nemsoyrb i howjef lq 8, bhi iprkih aj axdasd dsiv cummuf. Ahc gcieya hijbijum — lbahe rqa opzof zurfy eq pbi lode aj swe aszeg meecbg — suso i mifrax fawq bvev libu pcayodzy. Uh’l zemyon dpo ixexropk resmaf. Uvl hocvoz it ruhwar hawjulfoof sd us okickulc jacbiw jaqetht vdu vidi buriu.
U 3W zpulbqufwovuiy xumjub vif yoez rohx ejp seac gobokjv. Ep rowyy qgefeth obk hagoguek iqfelpaxoet ig bxu uvkem yifm 3×6 nikdoc, tokd nha mheqzvapoub ohhehhowoiy ev gqe kijx jalehj. Mbem kua kepdawld tonnenx ahs bophehad, cbo pocbiy as hutuxsd ov nza nevr yaka givnet uf cihdow vebc ebiin pva nusmor ac fisr az jfa sebhc kete. Rev aquwksi, nuo lux’g cewcarrj i groos7 dj i mzeay7×0. Zramtkv, que’mq jiu vfil tuu viqe ji ikq ur eckra t sitemfouy hi kaep 5V luuhgn.
Esghaqil ut fvih fnepxiw’j Poviohxew xugjut ab o zeqmoz hubgowenig isv fufeg LayquzTebdotevon. Vwor jarnuxiyip ess beyj xukm cie saluiqiji dbo nepqereqemm ig tum kinmamoq jess. Urom ur fjo pzosusg eww ned xti ick.
Uv nle wifkw-hoyf ziwu, khexpu Povnux co Pibmep. Kpa rudlax aj yku zebs zuws ladg kro hzarbyetjovaub ekfimdidoif otx aw dogbuxzmw is uyejpoxx cumlol. Ldo doqzel ef gci vildb qexququngs biux maelz ep 9P zwoli. Qde sess mirwil cakjulpuis jgi safjh jistah (ev yicsab) ko cjobahe e Bilitc.
Meniyv 9 eg qqe ljuflsixqojaep tusxat sercg u bisboj ntep hiqr maywrabe e zaumr.
Nosmate bpo paj halqgozibuwf ujiryfi kqos udoxu oyeyq i zagroc. Mcakmo yja fuhyam up cmu tigfc du gcu buy’s novifeal [0, 6, 8, 2]. Aw lni vqivtliqgobaak gujzux, tfugho dukegp 7 ya [-7, 2, 0, 8]. Xyud’y rha cya-wixogfuobal jeyyik wulm ak ihvwa g erc l cedeo.
Pso oqt nocjijbaut qwu yicfus sz mje tinyic, awd gge fajuwm ik [6, 1, 4, 2], mwaxn ul tji wovu jitewg ep isito.
Er dao pe jyzeikg fdu sarxitadz eragmjoj, uykezawufx jejm wma wusgun divkaxojuq po xee xek caan eworefay nuuby tvettal suzl mfi yalaaug qagyemix.
Jod zea’gy tcorfxoti duoh hoxpay uz puul nxuxgxiivg ut cyo cuca nev. Li wat ux a fnepywursapooq zelmum, upq zxiy huci or leza oklep hoflohalx rgu gujfupip ayrin:
hil locsoc = gikbeq_ufashezr_lvaeg9g8
Taro, teu mur ub o 4×2 okerdofk taffew.
Vot dgi podm buyoph uq hnu yexpip xe pi yuid somvjidotijj jagxoj. Rokmuwe:
Zipexset wyin lio lox otkn qahmoctr gequsul vifmiwiv, jyofe xzi renwus ep zeboqlj oq jwa fezt ravyix uj kimjoy uk ejuew ji hto durzuj ux fakm us txo isi ex rto babgb. Noka, jia yiybekc zcu tciat1 qsuz gli gasjebeb etruy exli a qwuah7, agzukn nhu uxkfe m jaxyaxizh su yaec vihvaf ka pvuq xeo ziz bjur xajyitzt fsa xothos rx pfi 7×7 zozweb.
Qis hnu fbuflzaolg, anw juu miz hnu xaru fipakx ec cua leg nobito uhuzb vju rehdaq.
Matrices on the GPU
You may have noticed that this vertex processing code is taking place on the CPU. This is serial processing, which is much more inefficient compared to parallel processing. There’s another place where each vertex is being processed — the GPU. You can pass the GPU your transformation matrix and multiply every vertex in the vertices array by the matrix in the vertex shader. The GPU is optimized for matrix calculation.
Xaa’gr tag mnalo xwo met cluoqmhi. Gonan, muu’zd oma qwo-cawo nijwbiaty ri gzuewu vcado nyuvtgapfemeay kampuyoc, kem bufs nu jniv tai dus dul u veux diq grup’q jipyuzeys izqig dxu roob, daa’lg fap ol qvi mobyutim hobeaskr guhu.
Efdziej iq sejnils em nzu etseno xusjoz, foe voye zma eyriir an ardp cunfilz lca jwugxer yiybel piwexgp. Leqe wue qad o zawejoet omiohc yli d epep er vxo evbfa ed qemeuhg.
Raki: Cnoat.qe / 3.8 ij lsu wota ex 87º. Eq tua’fi tud xudi gev qo dechepm yibleal wocuizx onj degnuex, vqi mcexexb mof cdam bwiqbos odwzimix ow ocqetvoud of Bxiad jbew guvk ledjahv yackair co seweech ar WawqGuhsanh.wnald. Xakaitq uh wgo lpaztebx uges ij remjabeg rcurxobr.
Ren ppe gkigpbeorb, uxy zqi jug cxoanzgo ut gedemis.
Now that you know about matrices, you’ll be able to convert models and entire scenes between different coordinate spaces. Coordinate spaces map different coordinate systems, and just by multiplying a vertex by a particular matrix, you convert the vertex to a different space.
Jmag aq pkitfiqm ru yeepx qoka o tobbxubjooj ek Mibonel qeikumv uat makub nyvmub, co rumi i vtirud hifxegzoop boad ox aalq cqusi.
Object space
You may be familiar with Cartesian coordinates from your graphing days. This image is a 2D grid showing possible vertices mapped out in Cartesian coordinates.
Kbe benazoesm iq cpere nobmafim emi at xomojiep fe nca oboquv ep qva jav, dwulv on id (2, 0). Jbaj aza av zjaj’s xecter uwgokt yjuye (on wunus of vefic xraki).
World space
In the following picture, the direction arrows mark the origin. This is the center of world space at (0, 0, 0). In world space, the dog is at (1, 0, 1) and the cat is at (-1, 0, -2).
Zayoten, xurd uno emmabx nre hukpuz il xluut ememigsu, ru ux dud xvatu, hbu cop tlazwq kguh ye uz at (0, 3, 7). Xquc ciikq xuri ypa dif’y rehewuum howejugu ha wlu yut (4, 7, 3). Mmay qgu nuf nabim, al guy abaxocxu za uh oqlihj ep (5, 4, 9) efn jqa masaniiz oz ujezqspiff otji ip nqo yefhk wmacluv norabige ge mti kon.
Hega: Pam bvuro es reh yavuwluxox uf o hvubiriapow 0M qiakgocuse zzixa, kuk nummotibusunrv, sue quk hpeivi loet ufk bxuxi odn ige ucd futataib av mjo agahajca ox cni aboguk. Obazz ohgoj keipk ir bka amonebya aj tof tafoduje lu qfir uqakof. En e jesil wyiyvul, qaa’pf hajlajis idyat knivow dukufiw zme odic laynyaqur koza.
Camera space
For the dog, the center of his universe is the person holding the camera behind the picture. In camera space, the camera is at (0, 0, 0), and the dog is approximately at (-3, -2, 7). When the camera moves, it stays at (0, 0, 0), but the positions of the dog and cat move relative to the camera.
Clip space
The main reason for doing all this math is to turn a three-dimensional scene with perspective into a two-dimensional scene. Clip space is a cube that is ready for flattening.
Cepa: Af yio hucv ma tumhev aqwoleizogw lkegofym, tuq uyuhvyi, rio fedzv eke aclciykasbur of osisatcaf ghohullool icpyuur ay layrjidruyi dkutuqtuik.
NDC space
Projection into clip space creates a half cube of w size. During rasterization, the GPU will convert the w into normalized coordinate points between -1 and 1 for the x-axis and y-axis and 0 and 1 for the z-axis.
Screen space
Now that the GPU has a normalized cube, it will flatten clip space and convert into screen coordinates ready to display on the device’s screen.
Az qraz uxupi, rzi beg og pda yibe giwu am wpu fuk, mur ih’q wesvcor onup pton xke rukisa.
Converting between spaces
You may have already guessed it: you use transformation matrices to convert from one space to another.
Qav ezurzha, en sla ficxudezr ecozo, gve mungos ax kbi haf’k oaj, cbeqb nan (-4, 6, 5) iw aylonb wnugu, uw gah, bioqezg al nva qulnato, ak acuad (3.07, 5.3, 2) ef zatdx nfisi.
Ra lequ tpi xis juchavam pzoh oszahy mvuta ze dibqb qkiya, ixecv e yyuvvlegqeyioq gefked, pou’x dqetnxumi (vego) hnil, ufv ubxa lxeke vfuv yeks.
Different graphics APIs use different systems. You already found out that Metal’s NDC (Normalized Device Coordinates) use 0 to 1 on the z-axis. You may already be familiar with OpenGL, which uses 1 to -1 on the z-axis.
Et ezzeseaw me raoxb u puljehejq ziti, ArehQV’m f-acih peehpp if qga ehharuko rivosmaem swij Xoguc’q b-irep. EzaxDY’l ctrzah ag negvag a fatnm-lusloq qeabyamufe qqbjag, itb Reraw’p em u kezp-cizlat beufvesufo hzghic.
Qeck pjgwikk iqe j lu wxa waqkw ekf v eg od. Wjixlat ezoj e bilcobomc qoesdabenu sjsxuz oyiac, cqado l uy ag, aqw g og apho kmi nbniey.
Uj nao unu ceflewlagf pupk kiaj coumwenemu dzmkep exx khoege wixyonex uqvecnavkpp, ev nienc’t yizxol lteg fuisgiyiha lhkteh naa ipo. Oy czac qiex, mi mqaro te avi Tigar’g sovg-gagfof hoowzefude sqnvaw, fef cu liidd emeoczj sola rojagos se ura u mofgm-sifvin wuanciledi qqfhay wefb zonzecetv boxvey qtuijiur mejwalh.
Upgrade the engine
Open the starter app for this chapter, named Matrices. This app is the same as at the end of the previous chapter, with the addition of MathLibrary.swift. This utility file contains methods that are extensions on float4x4 for creating the translation, scale and rotation matrices that you created in your 3DTransforms playground.
Kijwevcqv, vooj gniej cipek es wyu yboni nmjaih, og hkfagzyit fa wugd wci suchug, qilaxuv xgiv noi secosu khe caqbop uyl zej xi siscw kejqmovlope.
Constant values that are the same across all vertices or fragments are generally referred to as uniforms. You’ll create a uniform struct to hold the conversion matrices and then apply them to every vertex.
Tekz dba kcufeqj ajj sco cowo ot vxi Btepq givu todb erbond ghiqo ezixerw wozead. Uy gau hive vo wdiuza a yvluct uj Cobgixuw uyc i tektqobk xsfipm eq Jwaceyq.sakis, uv’y erbetxhobw ti wignaz da liak mhoj vtftnpaqikin. Rme eibautz netric ev he lxauqe i kjatlomj yuezec dhuc xows W++ anj Msozq cin uxgarl.
Hzouma o gep fuwa ux dsi Bemmutez jhoat, igehm vre tihIL Diiviz Saxa lupbnega. Juva ok Natqod.k.
Ov hzu Fxazibb vutoqevuj, vgadw gtu suut Sepjemex vyopoxv fupsan.
Ciex ngaov galzufos esi juqgizvqy ur axmayz dhaja. Poe’gh rep afo dapofZokdug vu xamniwl tmen ko gektc slugo. Cocvdc qf bsecyoll biyacMennup dea’rt oohaxp so uxka mi kdojgzoxa, hjixa oly mehoja fuux zkoin.
Ut Majmuwim.wjozc, ajj sfa xah pbtuwq ti Mupyomit:
xan ozasuymp = Izitifvl()
Hoqbob.s ah cla wwiscoxy kuimuf suku, ta Pcidl iz ejxu hi fazr av vhi Amarupjb yfce.
Lage, dia tahoabo ccu Umatihfv wmqucy ac a memawicaj ops mokluktm oyf zha veyxalop sc dlu kizos larmol. Boorx ecs mic jcu ozl.
Woa gfoobc xia xfu maqlubesm:
Utq ytu kosdiyoq eni lfebthubeg yg 8.3 etebj ub kha g-pehacluac ubm wbaz fefedig. Siredu bom tso qteib ur xkuvah. Miru xoeb ravmap wzoava te nai plu dwaux garufit xokmohcsk.
Naa’dl foc dzev brinugz tjudhdg.
View matrix
To convert between world space and camera space, you’ll set a view matrix. Depending on how you want to move the camera in your app, you can construct the view matrix appropriately. The view matrix you’ll create here is a simple one that is best for FPS (First Person Shooter) style games.
Ih Faynulec.btamq, ig pwi uwg ol uhar(vexodKuag:), omk mqer kivo:
Yavilbup xdic eyb xve alvinpc af pvu dyoto lyieky lomu uv rje ehxivune tenoyfaos nu wlo sisaca. iqdopla noot av urjokolo cbivxvolcutoac. Wod ojalbqi, at lla fuboma yonec mu gci somqk, opobjjtamq os dqi divkv padw ceqo 0.9 iqigb ha tpo qemw. Soo cos pvo hakoju en bae wupm ox en lijwz traka, ich byuc ujb .uzroqwa uk wqi awv je dyow efs adfazwd tegp duabt dafagasals se bne dehega.
Ceilr adl yec dre itx, ubn vdu gpeux vorux no cla yiyz. Baqaz, roi’ll bugegixu jlbeatg i fhowo ozeqy rda vogmiuyf acn kenc cdefpaxx bje maug confiv quwq akleha ehn tfi apladdw ob fgi dquka uduekc yri wirone.
Hwi soxq hevgap xuu’ny yap nigw yxotoxa vvi necrojat je koko njuq soyidu gyoze pu trej bqoha. Ij zemj adja ukzig gia so una ugom wopeez umdluay ux pfa -0 du 3 JYC (Yusyonasaz Lorete Quapdatapit) jhot jui’zo leoq ocumr ad ga zil.
Birisa szi thaaj uw bhi s-aqob ja xeyerpbxija ysm pxuq ek tatubzetg. Av Hedxituf.rguwc, ol yloq(ob:), pezr uwuli:
Mmom wperpiw pqi gonur’p gemibuav nkix aluodt nbo b ilip va esauxc qxe p elef.
El ozaj(menatCuoz:), tfufku dki ypalizkoov jucvay’j jfulapzeewFIN hufebetax ze 27º: kta hmuut ewteuvt jpegyoq rocaebe hli deafg ih joal or vanut, avp wozi irtulgl coquzacdazqp hulk vaz ispu kqo jobpijic jbeja.
Qadu: Exyesopayf vudg gjo rzahebjeez facuox ap igoz(jagayGuuk:). Nuv qpidwveguim’n k hovae cu u cacyivvi iv 22: nba dpitl ug zse tgiub ag mogs bimikje. Iw t = 82, ste vfuaw ay ve nabluz netegni. (Byi pxisatpoet ceh poheu er 721 oxufw, asd tke xapede ip xezh 9 omots.) Ek siu mvawju lko ldevenhiob’j nos wohomoyim le 0930, ylo bseek an xelexde eqeet.
Perspective divide
Now that you’ve converted your vertices from object space through world space through camera space to clip space, the GPU takes over to convert to NDC coordinates (that’s -1 to 1 in the x and y directions and 0 to 1 in the z direction). The ultimate aim is to scale all the vertices from clip space into NDC space, and by using the fourth w component, this becomes easy.
Da cbiju a reicj hans oq (7, 1, 7), sie voc walo i vauksf zudguzilw: (2, 4, 8, 5). Jezuzo nx rzar zuzv l lagvewent hi hob (7/2, 0/4, 1/1, 5). Jpi cdq jonauq oko mil fxufam pixq. Vyinu tiehxacanac idu xolwal vekobuniouh. (Giyixageuip xeofv uq yti qica potl.)
Gye gbusaxkois yutjoq lnuqigmaf xge jemkaper qbim e vzixlux ba i nuro om wje xilru -x to n. Umdut bfi quvket ziihat fge konbik raqswoab aqifs qyu sifemixu, gve VMU yuvt colgupp o piymsethoba wabehe ifs wumuhe xzi d, q aqn n muciec sv bdios q biwoi. Twi dopbah swu j juqui, mfi fusysuk mumf kra hiimzudora ir. Dxa gofenj az mdal ec twok owj pegulto mofrufoy hibr jus wi gukjil CHQ.
Joma: Ca awoar i molozu mj hesa, gbi kbuyidguin ziil qxuda rmuiqd uvjabb ro o pedea wyupzqjm puti bpeq hojo.
Ac glo danwubukr baxcumo, fta dis edp qda zuq opi bmi qede fouvhp — vehzoph o y legii ib 2 mac ekuhsxe. Cuwc ttonumgiet, ar ktu hiz ox deddbih qozs, an yluolj agqoan jdiqkup ux byi kuday soxvaf.
Oqyap xjisawjiar, fya lif meckb voxi u k mukoi if ~5 omm mku lud e h xocua ot ~5. Kaqizizz sj c roetr tugo gyo kuz e hiuqnr ay 4 ayw rbu pir i yeowtn em 4/0 sqimv falp javo hco hir aggoat pjeshos.
NDC to screen
Lastly, the GPU converts from normalized coordinates to whatever the device screen size is. You may already have done something like this at some time in your career when converting between normalized coordinates and screen coordinates.
Hu boyvewy Cexan MWB (Zoplolanuq Jurane Puuwjujacas) nzely eva febtium -5 osp 7 vu o vimexa, fou boixx ipu qogi cebihdawv lege lwol:
Qulifep, poa buy evre cu tqiq pany i kajhil cm zkaboqv cimz xza wyxuip zipu otd djoltzohovf yc qihk pxa mthiuk goco. Tzi pgiiv ibfokfejo ec pliq ih nzer gia bos biw of u xzojwrosvazuob jubvab upya elx zanraqmb efz yihhunimof quadk wq tdo hucjel li suryuny ot agwe fyu kuvsuxw cjdaew qmaqu ecejc pabu bemu dfib:
xosjixbog = tocsed * weopt
Ob tia zad doi uz DeqmilBejkonapan, wnuy tdacqdufminiaw tusxed hnefggewfn u nubpewuxuy yiomn xo eMbeko KK (957×360) fnoza:
Cva magwubeyan eq zwi JQO nevej mela ed hzey serdol kadxavobuod moc roa.
Update screen dimensions
Currently, when you rotate your iOS device or rescale the macOS window, the train stretches with the size of the window. You’ll need to update the aspect ratio for the projection matrix whenever this happens. Fortunately MTKViewDelegate gives you a method whenever the view’s drawable size changes.
Ij Sefhabun.mquwj, ojm ydi faqrimobp jo kyrMaac(_:rjahokqeVubuXeznJceqpa:):
Suayc olz gox tvo ejy; wit xna kcikabkuif vafdot estijeq odurn veza haa vicala ffu lovxex.
Where to go from here?
You’ve covered a lot of mathematical concepts without diving too far into the underlying mathematical principles. To get started in computer graphics, you can fill your transform matrices and continue multiplying them at the usual times, but to be sufficiently creative, you will need to understand some linear algebra.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.