Table Of ContentFoundations
of
GatnEen giDneev eloptnent
1
VüLUME
MATHEMATICS
byE riLce ngyel
TeratShoofnt wLaLrCe
LincCoallni,f ornia
FoundaotfiGoanEmsne g iDneev elopment
Volu1m:Me a thematics
ISBN9-7183-: 0-9858117-4-7
Copyr©i2 g0h1bt6yE , r Liecn gyel
Alrli grhetsse Nrovp eaodrft.th piusb altiimcoanby e r eprosdtuocireanedn d,
informraettirosinye svttaerlma ,n somrui ttitleiidnaz, nfoey rd m e,l ectorro nic
mechainnicclapulhd,oi tnogc socpaynidnniiggn,ig t,oi rz irnegc,o rding, without
thper ipoerr miosfts hcieoo pny orwingehrt.
Fiprsrti nting
PublibsyTh eerda tShoofnt LwLaCr e
www.terathon.com
Serwieebss fiotuen:d ationsofgameenginedev.com
Abotuhtce o vTehrce:o viemrai gases cefrnoema g areunet iThte3l 1e ds t,
develboytp haeeud t uhsoirtn hTgeo mbsEtnognien e.
Preface ix
Chap1t eVre ctaonrMdsa trices 1
1.V1e ctFourn damentals 1
1.B2a sViecc tOopre rations 3
1.2M.a1g niatnuSddc ea Mlualrt iplication 5
1.2A.d2d iatniSdou nb traction 8
1.M3a trFiuxn damentals 11
1.B4a sMiact rOipexr ations 16
1.4A.d1d itSiuobcntt,ri aaonnSd,c aMlualrt iplication 16
1.4M.a2t rMiuxl tiplication 16
1.V5e ctMourl tiplication
20
l5.. 1D oPtr uocdt
20
1.5C.r2o Psrso duct 24
1.5S.c3a TlrairPp rloed uct 30
1.V6e ctPorro jection 31
1.M7a trIinxv ersion 36
l7.. 1I denMtaittryi ces 36
1.7D.e2t erminants 37
17.. 3E lemeMnattariiyc es 42
17.. I4n veCraslec ulation 45
l7.. 5I vne rosfSe msa ll Matrices
46
ExercfoirCs heasp1 t er 51
V
Cont ents v i
Chap2t eTrr ansforms 55
2.C1o oirndaStpea ces 55
2.1T.r1a nsforMmaattriiocne s 56
2.1O.r2t hoTgroannaslfo rms 57
2.1T.r3a nsCfoormmp ons itio 58
2.R2o tations 59
2.2R.o1t aAtbiooaunC t o oirndaAtxei s 59
2.2R.o2t aAtbiooaunntA rbitArxairys 62
2.R3e flections 65
2.S4c ales 69
2.S5k ews 71
2.H6o mogenCeoooiurnsda tes 74
27. Q uaternions 82
27.. 1Q uateFrnuinaodmne ntals 82
2.7R.o2t atWiiotQnhus a ternions 87
ExercfoirCs heasp 2t er 95
Chap3t eGre ometry 97
3.T1r iaMnegslhee s 97
3.N2o rmVaelc tors 99
3.2C.a1l culatiVnegcNtoorrmsa l 99
3.2.2 TrNaonrsmfoVarelmc itnogr s 102
3.L3i naensRd a ys 107
3. .31 P aramLeitnreisc 107
3.3.2 DBiesttwaaeP neocniae n ntadL ine 108
3.3.3 DistTawnocL ei neBse tween 110
3.P4l anes 112
3.4I.m1p lPilcainte s 113
3.4D.i2s tBaentcweae P eonia nntadP lane 115
3.4R.e3fl ecTthiroonauP glha ne 117
3.4I.n4t ersoefaLc itnaienoa dnP lane 119
3.4I.n5t ersoefTc htrPieloean n es 120
3.4I.n6t ersoefTc wtoPi loann es 122
3.4T.r7a nsfoPrlmainnegs 124
Contents vi i
3.P5l ücCkoeorr dinates 125
3.5I.m1p lLiicniets 126
3.5H.o2m ogenFeoorumsu las 128
3. .53 T ransfLoirnmeisn g 132
ExercfioCsrhe asp3 t er 134
Chap4t eArd vanAclegde bra 137
4.G1r assAmlagnenb ra 138
4.1W.e1d gPer oduct 138
4.1B.i2v ectors 139
4.1T.r3i vectors 142
4.1A.l4g ebSrtariucc ture 143
4.1C.o5m plements 149
4.1A.n6t ivectors 153
4.1A.n7t iwPerdogdeu ct 155
4.P2r ojeGcetoimveet ry 159
4.2L.i1n es 159
4.2P.l2a nes 160
4.2J.o3ai nnMd e et 162
4.2L.i4nC er ossing 163
4.2P.l5a Dnies tance 165
4.2S.u6m maarnlydm plementation 166
4.M3a tIrnivxe rses 170
4.G4e omeAtlrgiecb ra 173
4.4G.e1o mePtrroidcu ct 174
4.4V.e2c tDoirv ision 176
4.4R.o3t ors 178
4.C5o nclusion 181
ExercfioCsrhe asp 4t er 182
Index 185
Preface
Thibso opkr ovaid deetsa iinlterdo dtuotc htmeia otnh emuastebidycm so dero
gameen gipnreo graTmhmfieer rtssht.r cehea pctoevrteshrt e o poiflc isn aelar
geb(rvae catnomdra st ritcreasn)s,afo nrgdme so,m eitnacr oyn venmtainonnearl
commtoomn a noyt hteerx tboonto hksesu bjTehciitsds. o nteop rovaif daem il
iarwiitttyhh u es uaaplp rosaotc hhia tte' asst yom ake contnose icmtiiloanrs
exposoiftt ihsoean mtseo pics ielnts hleeiw theerAraleto tunhrgwee a .yw ,ew ill
make severtaofl o raetsthteahdmdeipo stwcs u osfasm iaonni femsotrelely e gant
and morem actohrermmeaoctdtie cla lt hiantt hfoeau prpctehhaa rpTsth elera .s t
quarotfte hbreo oekn deatvopo rrosva id deee puenrd erstoafmn adnoiyftn hge
concdeipstcsu esasrebldyii enrt rodGurcaisnsagml agnenab nrgdae omeatlric
gebKrnao.w leodftg heeb srea ncohfme ast hemaaltsioc sua slt loco ownsv ey
intuaintpdir oonv diedteai intl hfiser stth rcehea pttheaarrtsde i ffitcofu ilntd
anywheelrsee .
Oneo ft hgeo aolfts h bioso ikts o g ivper acetnigcianlea edrviiTnchgeii .ss
accomplthirsohuegdh s hmocarontdly ei stingst harpopuetgahhrbeoio unotgk
showhionwtg h mea themwaet'ivces diiissm cpulsesmeiednn strieeddae l -world
gameen giTnoea sv.ofi ildl pianggwe istc ho dlei sttihnaagrtise l lustrreatively
dundsaonrntde,a tsat rucotrfuu nrcetsir oenfesr einnvc aerdi poluashc aevsie n
tentiboenelanelo ftlu yTt h.i hsa ppoennlwsyh etnh feo ramn bde haovfit ohre
missciondigeso bviFoouersx .a mpClhea,p1 ti enrc lcuoddelesi sttihndagets
fiand ea tsat ruacntodup reer ations tcoaot rhrreesep-odnidvmieencngts oiro,n al
buitdt o essnh'ostwi micloadforera fo ur-dimevnesciteoovnreta,nhl o uigth' s
usebdyo thceordl ei stliantigentsr h b eo obke,c aiuwtso eu bledl argiedleyn ti
caTlh.ce o mplliebtorefa c ryo dieas v aiolnat bhwleee b sciittbeee dl ow.
ix
Preface X
Wea ssutrnheta htre e ahdaeasrs loi udn derstoafb nadstiirncig g onao rnetry,
workkinnogw loefdt ghCee+ +l anguaangsdeo ,rnfa ern iliwairtiht ys tandard
floatinngu-rnpboeAir bnsito.t fc alcauplpueisan Cr hsa p3tb,eu rtfu lgalr aosfp
thiisso lateidsn oeutss saegtneott ihraeel os ftt hbeo oOkt.h erawliolsft e h,e
rnatherntahtwaietcc osv iesbr u iflrtot rnhg er ouunpAd.d vanrceeaddp eorss
sessait nhgo rough okfln ionwelaerd grneaa ylw giestbhosr kairn pu cohft he
firtswtco h apHtoewresv.we err e,c ornrntehanaldtri e adtearakls eo oaktC hap
te3rb efoprreo ceteotdh ifeni gnc ahla pbteecra use4 a Cshsauparnft eaesmr i liar
itwyi tthhn eo taatnicdoo nn cedpettudaaiilsl csu isnCs headp3 t.e r
Irnporetqaunatta inokdne rsye sualptpse airnti hntege axrtbe o xweidt ah
bluoeu tlTihniiesis. n tebnodttehohd i ghtlhirnego hsvtta luianbfolrem aantdio n
torn akieet a stiofie nrwd h euns itnhbgeo oaksa r eference.
Eacchh apctoenrc lwuidtaesh se o tfe xercainsrndea sno,yft hoesxee rcises
asfko ars hoprrtoo ofsf o rnkei nTdh.ee x ercairdseee ssi tgonp erdo vaidddei
tioendaulc avtailoaunneawd,lh irnlaen oyft hehrna veea ssyo lutoitohanersre,s
al ittleT ote rnistcuhkrgaieete t rt.i ng 'sdtte upcrkai nvrdyeeo aeodsfaens r rn all
buitn terrneastthienrngra etvieclatalht aein osnw,te oar lsol ft heex ercairsee s
provoindt ehwdee bsciittbeee dl ow.
Thibso oikst hfei rvosltu irnnae s ertihecasot v eawr isd rea nogfte o pics
relattoge adrne en gidneev eloTphrnoeeffi nctiw.ae lb sfiottrheF e o undaotfi ons
GamEngei neD evelospemrecinaebtnse f ouanttd h foel lowaidndgr ess:
foundiaotnsofgarn.eceonrng inedev
Thiwse bsciotnet ianifonrsm aatbioaoulontlf t hbeo oiknts h see riinecsl,u ding
announceerrnrecanottdlasei,, s tainnadgn ss,wt eoer xse rcises.
Perface xi
Acknowledgements
Thfei vrosltu wmaems a dpeo ssbiyabs luec cecsrsofuwld fucnadmipnagai ngdn ,
thaeu tohwoerasd eobtfg rattiott huhedu en dorfecd osn triwbhusotu oprpso rted
thFeo undaotfGi aomnEesn giDneev elospemrebineetfs eo vreeasn i nwgolred
wawsr itten. Sgpote oct ihfoaell l otwphieanongpik lnpse a rtifocrsu hloawri ng
extsruap pboymr atk icnogn tritbhueatxtic oetnehcsdeo osfatc opoyft hbeo ok.
AlexaAnbdrreeu TreGvroere n NorbNeorptp er
LuiAsl varado NicoGluaisl lemoNti kolPaatossi ouras
KelvAirnc elay MattGiuansn arssGoeno rPgeetsr yk
DanAireclh ard AarGount ierrezI aPnr est
RobBeerctk ebans TimoHtehlyd na MikRea msey
AndrBeewl l AndrHeesm andezD arrReann alli
AndrBeearsg meierH auHkiel debranSdtteR eans mussen
MarcBoo uterse JamHeusn tsman GuamReordio lphe
LanBcuem s MartHiunr ton YuKruin dSec hlesner
DanCiaerle y FranJi;aocicsa rd BiSleli tzinger
BertCraarnrde MartJiojons ten MichaeSlh aDh.
IgnaCcaisotA agnuoa doT onJcuik ic BriSahna rp
S0rCehnr istenseTni mKane SeaSnl avik
DanCioelll in SoufKihainaet Daniel Smith
ViceCnuteel lar HyukKim SouSfoiu aiaia
CourDtaomiise n Yo ungKsiimk TiaSgoou sa
PauDle meulenaerCeh ristopher AKairnSogpnse lhery
FranDi;eoviisc KierLoann ning JusStqiuni rek
Jean-FDruabnec oiKsw onL-eiel TiSmt ewart
AshrafEassa Jean-BLaeppteissmtReeu nTahro rstensen
WolfgEanngge l William Leu JodeelV ahl
FreEdnrgikk vist ShaocLhiunn LarVsi klund
BranFdoogne rty YushLuiou KenV oskuil
Jean-FFrF aonri;toiinsY unlongMa ShaWwanl ker-Salas
Nicholas FranBcrioMsoi kl es IaWnh yte
MarcFursi tzsch JavMioeyrPa é rez GrahWaimh lidal
TayGleorrp heideM ichMayel le s
Nicholas GildDeaMaey ung
1
1
Chapter
VectaonrdsM atrices
Vectaonrmdsa traircbeea ssm iact hembautiilcbdalilon icgntk hsfe i eolfld i near
algeTbhresayh. o uwpi nt hdee veloopfgm aemenent g ipnreasc teivcearlylwyh ere
anadr ues etdod escarw iibdaeer roafcy o nceptsfr ormsa inmgppiloneigt n ot s
projeccotoirvdteir naantsef oTrhmieam tpioornotsfaa. cn qcueia sr tirniognn tgu i
tifoornv ecmtaotrh emaantmdia csst etrhfuienn dga mental tchaaalrtce u lations
involvedb eo cvaenrnsbotetac taeaudg s reen autm boefgr a meen gine tapies
inescadpeapbeolnntyd h esskei Wliltsth.h iinsm inwde,b egaittn h eea rliest
possiblpeo isantntbad ur itfrliodnmt g h ger ouunpwd i tath h orionutgrho duction
thaasts uomnealsnye xisptrionfigc iinte rnicgyo noontm hepeta orrfytt rheea der.
1.V1e ctFourn damentals
Traditbiaosnniauclm leyrq,iu caanlta irtiisieingsn e go mepthryysa,in cmdsa ,n y
othfieerla dpsp ltiove idr stiumaull faaltli oinnsbt rooc aatdtw eog coarlsilceeasd
laarnsvd e ctAos resa.i/ asaq ru anstuicathsdy i stmaanscosert,, i mtehc aatbn e
fulldye scruisbiaens dgi nngulmee rviaclrauelep resietsnsit zoierin, tgm s a gni
tudAev .e citasoq ru antthicatatyr ernioeusig nhfo rmattor ieopnra ed siernetction
ins pace int oama adgdniitatisduo ednse bc,er bdiyt hfeo lloewxianmgp les.
• Thdei fferbeentcwete wepono icnotnst ianifonrsm aatbiobouonttt hhd ei s
tanbceet wtehepeno iwnhtisic,tsh h mea gniotftu hdveee ctaontrdh, de i rec
titohnya otwu o unledet dog ot goe frto mo npeo itnott ho et haelroa ns gt raight
line.
• Thvee loocfaip tyr ojeaactp tairlteii cnusiltgsaair nv tbe ybn o ithts sp e(etdh e
magniatnutddh ede)i reicnwt hiioicnith cs u rrternatvleyl ling.
Description:The first volume of Foundations of Game Engine Development discusses the mathematics needed by engineers who work on games or other types of virtual simulations. The book begins with conventional treatments of topics such as linear algebra, transforms, and geometry. Then, it introduces Grassmann alg