gl-matrix.js 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020
  1. /**
  2. * @fileoverview gl-matrix - High performance matrix and vector operations
  3. * @author Brandon Jones
  4. * @author Colin MacKenzie IV
  5. * @version 2.3.1
  6. */
  7. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE. */
  23. (function webpackUniversalModuleDefinition(root, factory) {
  24. if(typeof exports === 'object' && typeof module === 'object')
  25. module.exports = factory();
  26. else if(typeof define === 'function' && define.amd)
  27. define(factory);
  28. else {
  29. var a = factory();
  30. for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
  31. }
  32. })(this, function() {
  33. return /******/ (function(modules) { // webpackBootstrap
  34. /******/ // The module cache
  35. /******/ var installedModules = {};
  36. /******/ // The require function
  37. /******/ function __webpack_require__(moduleId) {
  38. /******/ // Check if module is in cache
  39. /******/ if(installedModules[moduleId])
  40. /******/ return installedModules[moduleId].exports;
  41. /******/ // Create a new module (and put it into the cache)
  42. /******/ var module = installedModules[moduleId] = {
  43. /******/ exports: {},
  44. /******/ id: moduleId,
  45. /******/ loaded: false
  46. /******/ };
  47. /******/ // Execute the module function
  48. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  49. /******/ // Flag the module as loaded
  50. /******/ module.loaded = true;
  51. /******/ // Return the exports of the module
  52. /******/ return module.exports;
  53. /******/ }
  54. /******/ // expose the modules object (__webpack_modules__)
  55. /******/ __webpack_require__.m = modules;
  56. /******/ // expose the module cache
  57. /******/ __webpack_require__.c = installedModules;
  58. /******/ // __webpack_public_path__
  59. /******/ __webpack_require__.p = "";
  60. /******/ // Load entry module and return exports
  61. /******/ return __webpack_require__(0);
  62. /******/ })
  63. /************************************************************************/
  64. /******/ ([
  65. /* 0 */
  66. /***/ function(module, exports, __webpack_require__) {
  67. /**
  68. * @fileoverview gl-matrix - High performance matrix and vector operations
  69. * @author Brandon Jones
  70. * @author Colin MacKenzie IV
  71. * @version 2.3.1
  72. */
  73. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  74. Permission is hereby granted, free of charge, to any person obtaining a copy
  75. of this software and associated documentation files (the "Software"), to deal
  76. in the Software without restriction, including without limitation the rights
  77. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  78. copies of the Software, and to permit persons to whom the Software is
  79. furnished to do so, subject to the following conditions:
  80. The above copyright notice and this permission notice shall be included in
  81. all copies or substantial portions of the Software.
  82. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  83. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  84. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  85. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  86. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  87. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  88. THE SOFTWARE. */
  89. // END HEADER
  90. exports.glMatrix = __webpack_require__(1);
  91. exports.mat2 = __webpack_require__(2);
  92. exports.mat2d = __webpack_require__(3);
  93. exports.mat3 = __webpack_require__(4);
  94. exports.mat4 = __webpack_require__(5);
  95. exports.quat = __webpack_require__(6);
  96. exports.vec2 = __webpack_require__(9);
  97. exports.vec3 = __webpack_require__(7);
  98. exports.vec4 = __webpack_require__(8);
  99. /***/ },
  100. /* 1 */
  101. /***/ function(module, exports) {
  102. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  103. Permission is hereby granted, free of charge, to any person obtaining a copy
  104. of this software and associated documentation files (the "Software"), to deal
  105. in the Software without restriction, including without limitation the rights
  106. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  107. copies of the Software, and to permit persons to whom the Software is
  108. furnished to do so, subject to the following conditions:
  109. The above copyright notice and this permission notice shall be included in
  110. all copies or substantial portions of the Software.
  111. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  112. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  113. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  114. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  115. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  116. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  117. THE SOFTWARE. */
  118. /**
  119. * @class Common utilities
  120. * @name glMatrix
  121. */
  122. var glMatrix = {};
  123. // Constants
  124. glMatrix.EPSILON = 0.000001;
  125. glMatrix.ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
  126. glMatrix.RANDOM = Math.random;
  127. /**
  128. * Sets the type of array used when creating new vectors and matrices
  129. *
  130. * @param {Type} type Array type, such as Float32Array or Array
  131. */
  132. glMatrix.setMatrixArrayType = function(type) {
  133. glMatrix.ARRAY_TYPE = type;
  134. }
  135. var degree = Math.PI / 180;
  136. /**
  137. * Convert Degree To Radian
  138. *
  139. * @param {Number} Angle in Degrees
  140. */
  141. glMatrix.toRadian = function(a){
  142. return a * degree;
  143. }
  144. module.exports = glMatrix;
  145. /***/ },
  146. /* 2 */
  147. /***/ function(module, exports, __webpack_require__) {
  148. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  149. Permission is hereby granted, free of charge, to any person obtaining a copy
  150. of this software and associated documentation files (the "Software"), to deal
  151. in the Software without restriction, including without limitation the rights
  152. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  153. copies of the Software, and to permit persons to whom the Software is
  154. furnished to do so, subject to the following conditions:
  155. The above copyright notice and this permission notice shall be included in
  156. all copies or substantial portions of the Software.
  157. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  158. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  159. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  160. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  161. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  162. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  163. THE SOFTWARE. */
  164. var glMatrix = __webpack_require__(1);
  165. /**
  166. * @class 2x2 Matrix
  167. * @name mat2
  168. */
  169. var mat2 = {};
  170. /**
  171. * Creates a new identity mat2
  172. *
  173. * @returns {mat2} a new 2x2 matrix
  174. */
  175. mat2.create = function() {
  176. var out = new glMatrix.ARRAY_TYPE(4);
  177. out[0] = 1;
  178. out[1] = 0;
  179. out[2] = 0;
  180. out[3] = 1;
  181. return out;
  182. };
  183. /**
  184. * Creates a new mat2 initialized with values from an existing matrix
  185. *
  186. * @param {mat2} a matrix to clone
  187. * @returns {mat2} a new 2x2 matrix
  188. */
  189. mat2.clone = function(a) {
  190. var out = new glMatrix.ARRAY_TYPE(4);
  191. out[0] = a[0];
  192. out[1] = a[1];
  193. out[2] = a[2];
  194. out[3] = a[3];
  195. return out;
  196. };
  197. /**
  198. * Copy the values from one mat2 to another
  199. *
  200. * @param {mat2} out the receiving matrix
  201. * @param {mat2} a the source matrix
  202. * @returns {mat2} out
  203. */
  204. mat2.copy = function(out, a) {
  205. out[0] = a[0];
  206. out[1] = a[1];
  207. out[2] = a[2];
  208. out[3] = a[3];
  209. return out;
  210. };
  211. /**
  212. * Set a mat2 to the identity matrix
  213. *
  214. * @param {mat2} out the receiving matrix
  215. * @returns {mat2} out
  216. */
  217. mat2.identity = function(out) {
  218. out[0] = 1;
  219. out[1] = 0;
  220. out[2] = 0;
  221. out[3] = 1;
  222. return out;
  223. };
  224. /**
  225. * Transpose the values of a mat2
  226. *
  227. * @param {mat2} out the receiving matrix
  228. * @param {mat2} a the source matrix
  229. * @returns {mat2} out
  230. */
  231. mat2.transpose = function(out, a) {
  232. // If we are transposing ourselves we can skip a few steps but have to cache some values
  233. if (out === a) {
  234. var a1 = a[1];
  235. out[1] = a[2];
  236. out[2] = a1;
  237. } else {
  238. out[0] = a[0];
  239. out[1] = a[2];
  240. out[2] = a[1];
  241. out[3] = a[3];
  242. }
  243. return out;
  244. };
  245. /**
  246. * Inverts a mat2
  247. *
  248. * @param {mat2} out the receiving matrix
  249. * @param {mat2} a the source matrix
  250. * @returns {mat2} out
  251. */
  252. mat2.invert = function(out, a) {
  253. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  254. // Calculate the determinant
  255. det = a0 * a3 - a2 * a1;
  256. if (!det) {
  257. return null;
  258. }
  259. det = 1.0 / det;
  260. out[0] = a3 * det;
  261. out[1] = -a1 * det;
  262. out[2] = -a2 * det;
  263. out[3] = a0 * det;
  264. return out;
  265. };
  266. /**
  267. * Calculates the adjugate of a mat2
  268. *
  269. * @param {mat2} out the receiving matrix
  270. * @param {mat2} a the source matrix
  271. * @returns {mat2} out
  272. */
  273. mat2.adjoint = function(out, a) {
  274. // Caching this value is nessecary if out == a
  275. var a0 = a[0];
  276. out[0] = a[3];
  277. out[1] = -a[1];
  278. out[2] = -a[2];
  279. out[3] = a0;
  280. return out;
  281. };
  282. /**
  283. * Calculates the determinant of a mat2
  284. *
  285. * @param {mat2} a the source matrix
  286. * @returns {Number} determinant of a
  287. */
  288. mat2.determinant = function (a) {
  289. return a[0] * a[3] - a[2] * a[1];
  290. };
  291. /**
  292. * Multiplies two mat2's
  293. *
  294. * @param {mat2} out the receiving matrix
  295. * @param {mat2} a the first operand
  296. * @param {mat2} b the second operand
  297. * @returns {mat2} out
  298. */
  299. mat2.multiply = function (out, a, b) {
  300. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
  301. var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
  302. out[0] = a0 * b0 + a2 * b1;
  303. out[1] = a1 * b0 + a3 * b1;
  304. out[2] = a0 * b2 + a2 * b3;
  305. out[3] = a1 * b2 + a3 * b3;
  306. return out;
  307. };
  308. /**
  309. * Alias for {@link mat2.multiply}
  310. * @function
  311. */
  312. mat2.mul = mat2.multiply;
  313. /**
  314. * Rotates a mat2 by the given angle
  315. *
  316. * @param {mat2} out the receiving matrix
  317. * @param {mat2} a the matrix to rotate
  318. * @param {Number} rad the angle to rotate the matrix by
  319. * @returns {mat2} out
  320. */
  321. mat2.rotate = function (out, a, rad) {
  322. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  323. s = Math.sin(rad),
  324. c = Math.cos(rad);
  325. out[0] = a0 * c + a2 * s;
  326. out[1] = a1 * c + a3 * s;
  327. out[2] = a0 * -s + a2 * c;
  328. out[3] = a1 * -s + a3 * c;
  329. return out;
  330. };
  331. /**
  332. * Scales the mat2 by the dimensions in the given vec2
  333. *
  334. * @param {mat2} out the receiving matrix
  335. * @param {mat2} a the matrix to rotate
  336. * @param {vec2} v the vec2 to scale the matrix by
  337. * @returns {mat2} out
  338. **/
  339. mat2.scale = function(out, a, v) {
  340. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  341. v0 = v[0], v1 = v[1];
  342. out[0] = a0 * v0;
  343. out[1] = a1 * v0;
  344. out[2] = a2 * v1;
  345. out[3] = a3 * v1;
  346. return out;
  347. };
  348. /**
  349. * Creates a matrix from a given angle
  350. * This is equivalent to (but much faster than):
  351. *
  352. * mat2.identity(dest);
  353. * mat2.rotate(dest, dest, rad);
  354. *
  355. * @param {mat2} out mat2 receiving operation result
  356. * @param {Number} rad the angle to rotate the matrix by
  357. * @returns {mat2} out
  358. */
  359. mat2.fromRotation = function(out, rad) {
  360. var s = Math.sin(rad),
  361. c = Math.cos(rad);
  362. out[0] = c;
  363. out[1] = s;
  364. out[2] = -s;
  365. out[3] = c;
  366. return out;
  367. }
  368. /**
  369. * Creates a matrix from a vector scaling
  370. * This is equivalent to (but much faster than):
  371. *
  372. * mat2.identity(dest);
  373. * mat2.scale(dest, dest, vec);
  374. *
  375. * @param {mat2} out mat2 receiving operation result
  376. * @param {vec2} v Scaling vector
  377. * @returns {mat2} out
  378. */
  379. mat2.fromScaling = function(out, v) {
  380. out[0] = v[0];
  381. out[1] = 0;
  382. out[2] = 0;
  383. out[3] = v[1];
  384. return out;
  385. }
  386. /**
  387. * Returns a string representation of a mat2
  388. *
  389. * @param {mat2} mat matrix to represent as a string
  390. * @returns {String} string representation of the matrix
  391. */
  392. mat2.str = function (a) {
  393. return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
  394. };
  395. /**
  396. * Returns Frobenius norm of a mat2
  397. *
  398. * @param {mat2} a the matrix to calculate Frobenius norm of
  399. * @returns {Number} Frobenius norm
  400. */
  401. mat2.frob = function (a) {
  402. return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2)))
  403. };
  404. /**
  405. * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix
  406. * @param {mat2} L the lower triangular matrix
  407. * @param {mat2} D the diagonal matrix
  408. * @param {mat2} U the upper triangular matrix
  409. * @param {mat2} a the input matrix to factorize
  410. */
  411. mat2.LDU = function (L, D, U, a) {
  412. L[2] = a[2]/a[0];
  413. U[0] = a[0];
  414. U[1] = a[1];
  415. U[3] = a[3] - L[2] * U[1];
  416. return [L, D, U];
  417. };
  418. module.exports = mat2;
  419. /***/ },
  420. /* 3 */
  421. /***/ function(module, exports, __webpack_require__) {
  422. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  423. Permission is hereby granted, free of charge, to any person obtaining a copy
  424. of this software and associated documentation files (the "Software"), to deal
  425. in the Software without restriction, including without limitation the rights
  426. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  427. copies of the Software, and to permit persons to whom the Software is
  428. furnished to do so, subject to the following conditions:
  429. The above copyright notice and this permission notice shall be included in
  430. all copies or substantial portions of the Software.
  431. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  432. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  433. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  434. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  435. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  436. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  437. THE SOFTWARE. */
  438. var glMatrix = __webpack_require__(1);
  439. /**
  440. * @class 2x3 Matrix
  441. * @name mat2d
  442. *
  443. * @description
  444. * A mat2d contains six elements defined as:
  445. * <pre>
  446. * [a, c, tx,
  447. * b, d, ty]
  448. * </pre>
  449. * This is a short form for the 3x3 matrix:
  450. * <pre>
  451. * [a, c, tx,
  452. * b, d, ty,
  453. * 0, 0, 1]
  454. * </pre>
  455. * The last row is ignored so the array is shorter and operations are faster.
  456. */
  457. var mat2d = {};
  458. /**
  459. * Creates a new identity mat2d
  460. *
  461. * @returns {mat2d} a new 2x3 matrix
  462. */
  463. mat2d.create = function() {
  464. var out = new glMatrix.ARRAY_TYPE(6);
  465. out[0] = 1;
  466. out[1] = 0;
  467. out[2] = 0;
  468. out[3] = 1;
  469. out[4] = 0;
  470. out[5] = 0;
  471. return out;
  472. };
  473. /**
  474. * Creates a new mat2d initialized with values from an existing matrix
  475. *
  476. * @param {mat2d} a matrix to clone
  477. * @returns {mat2d} a new 2x3 matrix
  478. */
  479. mat2d.clone = function(a) {
  480. var out = new glMatrix.ARRAY_TYPE(6);
  481. out[0] = a[0];
  482. out[1] = a[1];
  483. out[2] = a[2];
  484. out[3] = a[3];
  485. out[4] = a[4];
  486. out[5] = a[5];
  487. return out;
  488. };
  489. /**
  490. * Copy the values from one mat2d to another
  491. *
  492. * @param {mat2d} out the receiving matrix
  493. * @param {mat2d} a the source matrix
  494. * @returns {mat2d} out
  495. */
  496. mat2d.copy = function(out, a) {
  497. out[0] = a[0];
  498. out[1] = a[1];
  499. out[2] = a[2];
  500. out[3] = a[3];
  501. out[4] = a[4];
  502. out[5] = a[5];
  503. return out;
  504. };
  505. /**
  506. * Set a mat2d to the identity matrix
  507. *
  508. * @param {mat2d} out the receiving matrix
  509. * @returns {mat2d} out
  510. */
  511. mat2d.identity = function(out) {
  512. out[0] = 1;
  513. out[1] = 0;
  514. out[2] = 0;
  515. out[3] = 1;
  516. out[4] = 0;
  517. out[5] = 0;
  518. return out;
  519. };
  520. /**
  521. * Inverts a mat2d
  522. *
  523. * @param {mat2d} out the receiving matrix
  524. * @param {mat2d} a the source matrix
  525. * @returns {mat2d} out
  526. */
  527. mat2d.invert = function(out, a) {
  528. var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
  529. atx = a[4], aty = a[5];
  530. var det = aa * ad - ab * ac;
  531. if(!det){
  532. return null;
  533. }
  534. det = 1.0 / det;
  535. out[0] = ad * det;
  536. out[1] = -ab * det;
  537. out[2] = -ac * det;
  538. out[3] = aa * det;
  539. out[4] = (ac * aty - ad * atx) * det;
  540. out[5] = (ab * atx - aa * aty) * det;
  541. return out;
  542. };
  543. /**
  544. * Calculates the determinant of a mat2d
  545. *
  546. * @param {mat2d} a the source matrix
  547. * @returns {Number} determinant of a
  548. */
  549. mat2d.determinant = function (a) {
  550. return a[0] * a[3] - a[1] * a[2];
  551. };
  552. /**
  553. * Multiplies two mat2d's
  554. *
  555. * @param {mat2d} out the receiving matrix
  556. * @param {mat2d} a the first operand
  557. * @param {mat2d} b the second operand
  558. * @returns {mat2d} out
  559. */
  560. mat2d.multiply = function (out, a, b) {
  561. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  562. b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
  563. out[0] = a0 * b0 + a2 * b1;
  564. out[1] = a1 * b0 + a3 * b1;
  565. out[2] = a0 * b2 + a2 * b3;
  566. out[3] = a1 * b2 + a3 * b3;
  567. out[4] = a0 * b4 + a2 * b5 + a4;
  568. out[5] = a1 * b4 + a3 * b5 + a5;
  569. return out;
  570. };
  571. /**
  572. * Alias for {@link mat2d.multiply}
  573. * @function
  574. */
  575. mat2d.mul = mat2d.multiply;
  576. /**
  577. * Rotates a mat2d by the given angle
  578. *
  579. * @param {mat2d} out the receiving matrix
  580. * @param {mat2d} a the matrix to rotate
  581. * @param {Number} rad the angle to rotate the matrix by
  582. * @returns {mat2d} out
  583. */
  584. mat2d.rotate = function (out, a, rad) {
  585. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  586. s = Math.sin(rad),
  587. c = Math.cos(rad);
  588. out[0] = a0 * c + a2 * s;
  589. out[1] = a1 * c + a3 * s;
  590. out[2] = a0 * -s + a2 * c;
  591. out[3] = a1 * -s + a3 * c;
  592. out[4] = a4;
  593. out[5] = a5;
  594. return out;
  595. };
  596. /**
  597. * Scales the mat2d by the dimensions in the given vec2
  598. *
  599. * @param {mat2d} out the receiving matrix
  600. * @param {mat2d} a the matrix to translate
  601. * @param {vec2} v the vec2 to scale the matrix by
  602. * @returns {mat2d} out
  603. **/
  604. mat2d.scale = function(out, a, v) {
  605. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  606. v0 = v[0], v1 = v[1];
  607. out[0] = a0 * v0;
  608. out[1] = a1 * v0;
  609. out[2] = a2 * v1;
  610. out[3] = a3 * v1;
  611. out[4] = a4;
  612. out[5] = a5;
  613. return out;
  614. };
  615. /**
  616. * Translates the mat2d by the dimensions in the given vec2
  617. *
  618. * @param {mat2d} out the receiving matrix
  619. * @param {mat2d} a the matrix to translate
  620. * @param {vec2} v the vec2 to translate the matrix by
  621. * @returns {mat2d} out
  622. **/
  623. mat2d.translate = function(out, a, v) {
  624. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
  625. v0 = v[0], v1 = v[1];
  626. out[0] = a0;
  627. out[1] = a1;
  628. out[2] = a2;
  629. out[3] = a3;
  630. out[4] = a0 * v0 + a2 * v1 + a4;
  631. out[5] = a1 * v0 + a3 * v1 + a5;
  632. return out;
  633. };
  634. /**
  635. * Creates a matrix from a given angle
  636. * This is equivalent to (but much faster than):
  637. *
  638. * mat2d.identity(dest);
  639. * mat2d.rotate(dest, dest, rad);
  640. *
  641. * @param {mat2d} out mat2d receiving operation result
  642. * @param {Number} rad the angle to rotate the matrix by
  643. * @returns {mat2d} out
  644. */
  645. mat2d.fromRotation = function(out, rad) {
  646. var s = Math.sin(rad), c = Math.cos(rad);
  647. out[0] = c;
  648. out[1] = s;
  649. out[2] = -s;
  650. out[3] = c;
  651. out[4] = 0;
  652. out[5] = 0;
  653. return out;
  654. }
  655. /**
  656. * Creates a matrix from a vector scaling
  657. * This is equivalent to (but much faster than):
  658. *
  659. * mat2d.identity(dest);
  660. * mat2d.scale(dest, dest, vec);
  661. *
  662. * @param {mat2d} out mat2d receiving operation result
  663. * @param {vec2} v Scaling vector
  664. * @returns {mat2d} out
  665. */
  666. mat2d.fromScaling = function(out, v) {
  667. out[0] = v[0];
  668. out[1] = 0;
  669. out[2] = 0;
  670. out[3] = v[1];
  671. out[4] = 0;
  672. out[5] = 0;
  673. return out;
  674. }
  675. /**
  676. * Creates a matrix from a vector translation
  677. * This is equivalent to (but much faster than):
  678. *
  679. * mat2d.identity(dest);
  680. * mat2d.translate(dest, dest, vec);
  681. *
  682. * @param {mat2d} out mat2d receiving operation result
  683. * @param {vec2} v Translation vector
  684. * @returns {mat2d} out
  685. */
  686. mat2d.fromTranslation = function(out, v) {
  687. out[0] = 1;
  688. out[1] = 0;
  689. out[2] = 0;
  690. out[3] = 1;
  691. out[4] = v[0];
  692. out[5] = v[1];
  693. return out;
  694. }
  695. /**
  696. * Returns a string representation of a mat2d
  697. *
  698. * @param {mat2d} a matrix to represent as a string
  699. * @returns {String} string representation of the matrix
  700. */
  701. mat2d.str = function (a) {
  702. return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
  703. a[3] + ', ' + a[4] + ', ' + a[5] + ')';
  704. };
  705. /**
  706. * Returns Frobenius norm of a mat2d
  707. *
  708. * @param {mat2d} a the matrix to calculate Frobenius norm of
  709. * @returns {Number} Frobenius norm
  710. */
  711. mat2d.frob = function (a) {
  712. return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + 1))
  713. };
  714. module.exports = mat2d;
  715. /***/ },
  716. /* 4 */
  717. /***/ function(module, exports, __webpack_require__) {
  718. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  719. Permission is hereby granted, free of charge, to any person obtaining a copy
  720. of this software and associated documentation files (the "Software"), to deal
  721. in the Software without restriction, including without limitation the rights
  722. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  723. copies of the Software, and to permit persons to whom the Software is
  724. furnished to do so, subject to the following conditions:
  725. The above copyright notice and this permission notice shall be included in
  726. all copies or substantial portions of the Software.
  727. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  728. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  729. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  730. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  731. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  732. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  733. THE SOFTWARE. */
  734. var glMatrix = __webpack_require__(1);
  735. /**
  736. * @class 3x3 Matrix
  737. * @name mat3
  738. */
  739. var mat3 = {};
  740. /**
  741. * Creates a new identity mat3
  742. *
  743. * @returns {mat3} a new 3x3 matrix
  744. */
  745. mat3.create = function() {
  746. var out = new glMatrix.ARRAY_TYPE(9);
  747. out[0] = 1;
  748. out[1] = 0;
  749. out[2] = 0;
  750. out[3] = 0;
  751. out[4] = 1;
  752. out[5] = 0;
  753. out[6] = 0;
  754. out[7] = 0;
  755. out[8] = 1;
  756. return out;
  757. };
  758. /**
  759. * Copies the upper-left 3x3 values into the given mat3.
  760. *
  761. * @param {mat3} out the receiving 3x3 matrix
  762. * @param {mat4} a the source 4x4 matrix
  763. * @returns {mat3} out
  764. */
  765. mat3.fromMat4 = function(out, a) {
  766. out[0] = a[0];
  767. out[1] = a[1];
  768. out[2] = a[2];
  769. out[3] = a[4];
  770. out[4] = a[5];
  771. out[5] = a[6];
  772. out[6] = a[8];
  773. out[7] = a[9];
  774. out[8] = a[10];
  775. return out;
  776. };
  777. /**
  778. * Creates a new mat3 initialized with values from an existing matrix
  779. *
  780. * @param {mat3} a matrix to clone
  781. * @returns {mat3} a new 3x3 matrix
  782. */
  783. mat3.clone = function(a) {
  784. var out = new glMatrix.ARRAY_TYPE(9);
  785. out[0] = a[0];
  786. out[1] = a[1];
  787. out[2] = a[2];
  788. out[3] = a[3];
  789. out[4] = a[4];
  790. out[5] = a[5];
  791. out[6] = a[6];
  792. out[7] = a[7];
  793. out[8] = a[8];
  794. return out;
  795. };
  796. /**
  797. * Copy the values from one mat3 to another
  798. *
  799. * @param {mat3} out the receiving matrix
  800. * @param {mat3} a the source matrix
  801. * @returns {mat3} out
  802. */
  803. mat3.copy = function(out, a) {
  804. out[0] = a[0];
  805. out[1] = a[1];
  806. out[2] = a[2];
  807. out[3] = a[3];
  808. out[4] = a[4];
  809. out[5] = a[5];
  810. out[6] = a[6];
  811. out[7] = a[7];
  812. out[8] = a[8];
  813. return out;
  814. };
  815. /**
  816. * Set a mat3 to the identity matrix
  817. *
  818. * @param {mat3} out the receiving matrix
  819. * @returns {mat3} out
  820. */
  821. mat3.identity = function(out) {
  822. out[0] = 1;
  823. out[1] = 0;
  824. out[2] = 0;
  825. out[3] = 0;
  826. out[4] = 1;
  827. out[5] = 0;
  828. out[6] = 0;
  829. out[7] = 0;
  830. out[8] = 1;
  831. return out;
  832. };
  833. /**
  834. * Transpose the values of a mat3
  835. *
  836. * @param {mat3} out the receiving matrix
  837. * @param {mat3} a the source matrix
  838. * @returns {mat3} out
  839. */
  840. mat3.transpose = function(out, a) {
  841. // If we are transposing ourselves we can skip a few steps but have to cache some values
  842. if (out === a) {
  843. var a01 = a[1], a02 = a[2], a12 = a[5];
  844. out[1] = a[3];
  845. out[2] = a[6];
  846. out[3] = a01;
  847. out[5] = a[7];
  848. out[6] = a02;
  849. out[7] = a12;
  850. } else {
  851. out[0] = a[0];
  852. out[1] = a[3];
  853. out[2] = a[6];
  854. out[3] = a[1];
  855. out[4] = a[4];
  856. out[5] = a[7];
  857. out[6] = a[2];
  858. out[7] = a[5];
  859. out[8] = a[8];
  860. }
  861. return out;
  862. };
  863. /**
  864. * Inverts a mat3
  865. *
  866. * @param {mat3} out the receiving matrix
  867. * @param {mat3} a the source matrix
  868. * @returns {mat3} out
  869. */
  870. mat3.invert = function(out, a) {
  871. var a00 = a[0], a01 = a[1], a02 = a[2],
  872. a10 = a[3], a11 = a[4], a12 = a[5],
  873. a20 = a[6], a21 = a[7], a22 = a[8],
  874. b01 = a22 * a11 - a12 * a21,
  875. b11 = -a22 * a10 + a12 * a20,
  876. b21 = a21 * a10 - a11 * a20,
  877. // Calculate the determinant
  878. det = a00 * b01 + a01 * b11 + a02 * b21;
  879. if (!det) {
  880. return null;
  881. }
  882. det = 1.0 / det;
  883. out[0] = b01 * det;
  884. out[1] = (-a22 * a01 + a02 * a21) * det;
  885. out[2] = (a12 * a01 - a02 * a11) * det;
  886. out[3] = b11 * det;
  887. out[4] = (a22 * a00 - a02 * a20) * det;
  888. out[5] = (-a12 * a00 + a02 * a10) * det;
  889. out[6] = b21 * det;
  890. out[7] = (-a21 * a00 + a01 * a20) * det;
  891. out[8] = (a11 * a00 - a01 * a10) * det;
  892. return out;
  893. };
  894. /**
  895. * Calculates the adjugate of a mat3
  896. *
  897. * @param {mat3} out the receiving matrix
  898. * @param {mat3} a the source matrix
  899. * @returns {mat3} out
  900. */
  901. mat3.adjoint = function(out, a) {
  902. var a00 = a[0], a01 = a[1], a02 = a[2],
  903. a10 = a[3], a11 = a[4], a12 = a[5],
  904. a20 = a[6], a21 = a[7], a22 = a[8];
  905. out[0] = (a11 * a22 - a12 * a21);
  906. out[1] = (a02 * a21 - a01 * a22);
  907. out[2] = (a01 * a12 - a02 * a11);
  908. out[3] = (a12 * a20 - a10 * a22);
  909. out[4] = (a00 * a22 - a02 * a20);
  910. out[5] = (a02 * a10 - a00 * a12);
  911. out[6] = (a10 * a21 - a11 * a20);
  912. out[7] = (a01 * a20 - a00 * a21);
  913. out[8] = (a00 * a11 - a01 * a10);
  914. return out;
  915. };
  916. /**
  917. * Calculates the determinant of a mat3
  918. *
  919. * @param {mat3} a the source matrix
  920. * @returns {Number} determinant of a
  921. */
  922. mat3.determinant = function (a) {
  923. var a00 = a[0], a01 = a[1], a02 = a[2],
  924. a10 = a[3], a11 = a[4], a12 = a[5],
  925. a20 = a[6], a21 = a[7], a22 = a[8];
  926. return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
  927. };
  928. /**
  929. * Multiplies two mat3's
  930. *
  931. * @param {mat3} out the receiving matrix
  932. * @param {mat3} a the first operand
  933. * @param {mat3} b the second operand
  934. * @returns {mat3} out
  935. */
  936. mat3.multiply = function (out, a, b) {
  937. var a00 = a[0], a01 = a[1], a02 = a[2],
  938. a10 = a[3], a11 = a[4], a12 = a[5],
  939. a20 = a[6], a21 = a[7], a22 = a[8],
  940. b00 = b[0], b01 = b[1], b02 = b[2],
  941. b10 = b[3], b11 = b[4], b12 = b[5],
  942. b20 = b[6], b21 = b[7], b22 = b[8];
  943. out[0] = b00 * a00 + b01 * a10 + b02 * a20;
  944. out[1] = b00 * a01 + b01 * a11 + b02 * a21;
  945. out[2] = b00 * a02 + b01 * a12 + b02 * a22;
  946. out[3] = b10 * a00 + b11 * a10 + b12 * a20;
  947. out[4] = b10 * a01 + b11 * a11 + b12 * a21;
  948. out[5] = b10 * a02 + b11 * a12 + b12 * a22;
  949. out[6] = b20 * a00 + b21 * a10 + b22 * a20;
  950. out[7] = b20 * a01 + b21 * a11 + b22 * a21;
  951. out[8] = b20 * a02 + b21 * a12 + b22 * a22;
  952. return out;
  953. };
  954. /**
  955. * Alias for {@link mat3.multiply}
  956. * @function
  957. */
  958. mat3.mul = mat3.multiply;
  959. /**
  960. * Translate a mat3 by the given vector
  961. *
  962. * @param {mat3} out the receiving matrix
  963. * @param {mat3} a the matrix to translate
  964. * @param {vec2} v vector to translate by
  965. * @returns {mat3} out
  966. */
  967. mat3.translate = function(out, a, v) {
  968. var a00 = a[0], a01 = a[1], a02 = a[2],
  969. a10 = a[3], a11 = a[4], a12 = a[5],
  970. a20 = a[6], a21 = a[7], a22 = a[8],
  971. x = v[0], y = v[1];
  972. out[0] = a00;
  973. out[1] = a01;
  974. out[2] = a02;
  975. out[3] = a10;
  976. out[4] = a11;
  977. out[5] = a12;
  978. out[6] = x * a00 + y * a10 + a20;
  979. out[7] = x * a01 + y * a11 + a21;
  980. out[8] = x * a02 + y * a12 + a22;
  981. return out;
  982. };
  983. /**
  984. * Rotates a mat3 by the given angle
  985. *
  986. * @param {mat3} out the receiving matrix
  987. * @param {mat3} a the matrix to rotate
  988. * @param {Number} rad the angle to rotate the matrix by
  989. * @returns {mat3} out
  990. */
  991. mat3.rotate = function (out, a, rad) {
  992. var a00 = a[0], a01 = a[1], a02 = a[2],
  993. a10 = a[3], a11 = a[4], a12 = a[5],
  994. a20 = a[6], a21 = a[7], a22 = a[8],
  995. s = Math.sin(rad),
  996. c = Math.cos(rad);
  997. out[0] = c * a00 + s * a10;
  998. out[1] = c * a01 + s * a11;
  999. out[2] = c * a02 + s * a12;
  1000. out[3] = c * a10 - s * a00;
  1001. out[4] = c * a11 - s * a01;
  1002. out[5] = c * a12 - s * a02;
  1003. out[6] = a20;
  1004. out[7] = a21;
  1005. out[8] = a22;
  1006. return out;
  1007. };
  1008. /**
  1009. * Scales the mat3 by the dimensions in the given vec2
  1010. *
  1011. * @param {mat3} out the receiving matrix
  1012. * @param {mat3} a the matrix to rotate
  1013. * @param {vec2} v the vec2 to scale the matrix by
  1014. * @returns {mat3} out
  1015. **/
  1016. mat3.scale = function(out, a, v) {
  1017. var x = v[0], y = v[1];
  1018. out[0] = x * a[0];
  1019. out[1] = x * a[1];
  1020. out[2] = x * a[2];
  1021. out[3] = y * a[3];
  1022. out[4] = y * a[4];
  1023. out[5] = y * a[5];
  1024. out[6] = a[6];
  1025. out[7] = a[7];
  1026. out[8] = a[8];
  1027. return out;
  1028. };
  1029. /**
  1030. * Creates a matrix from a vector translation
  1031. * This is equivalent to (but much faster than):
  1032. *
  1033. * mat3.identity(dest);
  1034. * mat3.translate(dest, dest, vec);
  1035. *
  1036. * @param {mat3} out mat3 receiving operation result
  1037. * @param {vec2} v Translation vector
  1038. * @returns {mat3} out
  1039. */
  1040. mat3.fromTranslation = function(out, v) {
  1041. out[0] = 1;
  1042. out[1] = 0;
  1043. out[2] = 0;
  1044. out[3] = 0;
  1045. out[4] = 1;
  1046. out[5] = 0;
  1047. out[6] = v[0];
  1048. out[7] = v[1];
  1049. out[8] = 1;
  1050. return out;
  1051. }
  1052. /**
  1053. * Creates a matrix from a given angle
  1054. * This is equivalent to (but much faster than):
  1055. *
  1056. * mat3.identity(dest);
  1057. * mat3.rotate(dest, dest, rad);
  1058. *
  1059. * @param {mat3} out mat3 receiving operation result
  1060. * @param {Number} rad the angle to rotate the matrix by
  1061. * @returns {mat3} out
  1062. */
  1063. mat3.fromRotation = function(out, rad) {
  1064. var s = Math.sin(rad), c = Math.cos(rad);
  1065. out[0] = c;
  1066. out[1] = s;
  1067. out[2] = 0;
  1068. out[3] = -s;
  1069. out[4] = c;
  1070. out[5] = 0;
  1071. out[6] = 0;
  1072. out[7] = 0;
  1073. out[8] = 1;
  1074. return out;
  1075. }
  1076. /**
  1077. * Creates a matrix from a vector scaling
  1078. * This is equivalent to (but much faster than):
  1079. *
  1080. * mat3.identity(dest);
  1081. * mat3.scale(dest, dest, vec);
  1082. *
  1083. * @param {mat3} out mat3 receiving operation result
  1084. * @param {vec2} v Scaling vector
  1085. * @returns {mat3} out
  1086. */
  1087. mat3.fromScaling = function(out, v) {
  1088. out[0] = v[0];
  1089. out[1] = 0;
  1090. out[2] = 0;
  1091. out[3] = 0;
  1092. out[4] = v[1];
  1093. out[5] = 0;
  1094. out[6] = 0;
  1095. out[7] = 0;
  1096. out[8] = 1;
  1097. return out;
  1098. }
  1099. /**
  1100. * Copies the values from a mat2d into a mat3
  1101. *
  1102. * @param {mat3} out the receiving matrix
  1103. * @param {mat2d} a the matrix to copy
  1104. * @returns {mat3} out
  1105. **/
  1106. mat3.fromMat2d = function(out, a) {
  1107. out[0] = a[0];
  1108. out[1] = a[1];
  1109. out[2] = 0;
  1110. out[3] = a[2];
  1111. out[4] = a[3];
  1112. out[5] = 0;
  1113. out[6] = a[4];
  1114. out[7] = a[5];
  1115. out[8] = 1;
  1116. return out;
  1117. };
  1118. /**
  1119. * Calculates a 3x3 matrix from the given quaternion
  1120. *
  1121. * @param {mat3} out mat3 receiving operation result
  1122. * @param {quat} q Quaternion to create matrix from
  1123. *
  1124. * @returns {mat3} out
  1125. */
  1126. mat3.fromQuat = function (out, q) {
  1127. var x = q[0], y = q[1], z = q[2], w = q[3],
  1128. x2 = x + x,
  1129. y2 = y + y,
  1130. z2 = z + z,
  1131. xx = x * x2,
  1132. yx = y * x2,
  1133. yy = y * y2,
  1134. zx = z * x2,
  1135. zy = z * y2,
  1136. zz = z * z2,
  1137. wx = w * x2,
  1138. wy = w * y2,
  1139. wz = w * z2;
  1140. out[0] = 1 - yy - zz;
  1141. out[3] = yx - wz;
  1142. out[6] = zx + wy;
  1143. out[1] = yx + wz;
  1144. out[4] = 1 - xx - zz;
  1145. out[7] = zy - wx;
  1146. out[2] = zx - wy;
  1147. out[5] = zy + wx;
  1148. out[8] = 1 - xx - yy;
  1149. return out;
  1150. };
  1151. /**
  1152. * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
  1153. *
  1154. * @param {mat3} out mat3 receiving operation result
  1155. * @param {mat4} a Mat4 to derive the normal matrix from
  1156. *
  1157. * @returns {mat3} out
  1158. */
  1159. mat3.normalFromMat4 = function (out, a) {
  1160. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  1161. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  1162. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  1163. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  1164. b00 = a00 * a11 - a01 * a10,
  1165. b01 = a00 * a12 - a02 * a10,
  1166. b02 = a00 * a13 - a03 * a10,
  1167. b03 = a01 * a12 - a02 * a11,
  1168. b04 = a01 * a13 - a03 * a11,
  1169. b05 = a02 * a13 - a03 * a12,
  1170. b06 = a20 * a31 - a21 * a30,
  1171. b07 = a20 * a32 - a22 * a30,
  1172. b08 = a20 * a33 - a23 * a30,
  1173. b09 = a21 * a32 - a22 * a31,
  1174. b10 = a21 * a33 - a23 * a31,
  1175. b11 = a22 * a33 - a23 * a32,
  1176. // Calculate the determinant
  1177. det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1178. if (!det) {
  1179. return null;
  1180. }
  1181. det = 1.0 / det;
  1182. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  1183. out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  1184. out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  1185. out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  1186. out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  1187. out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  1188. out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  1189. out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  1190. out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  1191. return out;
  1192. };
  1193. /**
  1194. * Returns a string representation of a mat3
  1195. *
  1196. * @param {mat3} mat matrix to represent as a string
  1197. * @returns {String} string representation of the matrix
  1198. */
  1199. mat3.str = function (a) {
  1200. return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
  1201. a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
  1202. a[6] + ', ' + a[7] + ', ' + a[8] + ')';
  1203. };
  1204. /**
  1205. * Returns Frobenius norm of a mat3
  1206. *
  1207. * @param {mat3} a the matrix to calculate Frobenius norm of
  1208. * @returns {Number} Frobenius norm
  1209. */
  1210. mat3.frob = function (a) {
  1211. return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2)))
  1212. };
  1213. module.exports = mat3;
  1214. /***/ },
  1215. /* 5 */
  1216. /***/ function(module, exports, __webpack_require__) {
  1217. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  1218. Permission is hereby granted, free of charge, to any person obtaining a copy
  1219. of this software and associated documentation files (the "Software"), to deal
  1220. in the Software without restriction, including without limitation the rights
  1221. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1222. copies of the Software, and to permit persons to whom the Software is
  1223. furnished to do so, subject to the following conditions:
  1224. The above copyright notice and this permission notice shall be included in
  1225. all copies or substantial portions of the Software.
  1226. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1227. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1228. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1229. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1230. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1231. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1232. THE SOFTWARE. */
  1233. var glMatrix = __webpack_require__(1);
  1234. /**
  1235. * @class 4x4 Matrix
  1236. * @name mat4
  1237. */
  1238. var mat4 = {};
  1239. /**
  1240. * Creates a new identity mat4
  1241. *
  1242. * @returns {mat4} a new 4x4 matrix
  1243. */
  1244. mat4.create = function() {
  1245. var out = new glMatrix.ARRAY_TYPE(16);
  1246. out[0] = 1;
  1247. out[1] = 0;
  1248. out[2] = 0;
  1249. out[3] = 0;
  1250. out[4] = 0;
  1251. out[5] = 1;
  1252. out[6] = 0;
  1253. out[7] = 0;
  1254. out[8] = 0;
  1255. out[9] = 0;
  1256. out[10] = 1;
  1257. out[11] = 0;
  1258. out[12] = 0;
  1259. out[13] = 0;
  1260. out[14] = 0;
  1261. out[15] = 1;
  1262. return out;
  1263. };
  1264. /**
  1265. * Creates a new mat4 initialized with values from an existing matrix
  1266. *
  1267. * @param {mat4} a matrix to clone
  1268. * @returns {mat4} a new 4x4 matrix
  1269. */
  1270. mat4.clone = function(a) {
  1271. var out = new glMatrix.ARRAY_TYPE(16);
  1272. out[0] = a[0];
  1273. out[1] = a[1];
  1274. out[2] = a[2];
  1275. out[3] = a[3];
  1276. out[4] = a[4];
  1277. out[5] = a[5];
  1278. out[6] = a[6];
  1279. out[7] = a[7];
  1280. out[8] = a[8];
  1281. out[9] = a[9];
  1282. out[10] = a[10];
  1283. out[11] = a[11];
  1284. out[12] = a[12];
  1285. out[13] = a[13];
  1286. out[14] = a[14];
  1287. out[15] = a[15];
  1288. return out;
  1289. };
  1290. /**
  1291. * Copy the values from one mat4 to another
  1292. *
  1293. * @param {mat4} out the receiving matrix
  1294. * @param {mat4} a the source matrix
  1295. * @returns {mat4} out
  1296. */
  1297. mat4.copy = function(out, a) {
  1298. out[0] = a[0];
  1299. out[1] = a[1];
  1300. out[2] = a[2];
  1301. out[3] = a[3];
  1302. out[4] = a[4];
  1303. out[5] = a[5];
  1304. out[6] = a[6];
  1305. out[7] = a[7];
  1306. out[8] = a[8];
  1307. out[9] = a[9];
  1308. out[10] = a[10];
  1309. out[11] = a[11];
  1310. out[12] = a[12];
  1311. out[13] = a[13];
  1312. out[14] = a[14];
  1313. out[15] = a[15];
  1314. return out;
  1315. };
  1316. /**
  1317. * Set a mat4 to the identity matrix
  1318. *
  1319. * @param {mat4} out the receiving matrix
  1320. * @returns {mat4} out
  1321. */
  1322. mat4.identity = function(out) {
  1323. out[0] = 1;
  1324. out[1] = 0;
  1325. out[2] = 0;
  1326. out[3] = 0;
  1327. out[4] = 0;
  1328. out[5] = 1;
  1329. out[6] = 0;
  1330. out[7] = 0;
  1331. out[8] = 0;
  1332. out[9] = 0;
  1333. out[10] = 1;
  1334. out[11] = 0;
  1335. out[12] = 0;
  1336. out[13] = 0;
  1337. out[14] = 0;
  1338. out[15] = 1;
  1339. return out;
  1340. };
  1341. /**
  1342. * Transpose the values of a mat4
  1343. *
  1344. * @param {mat4} out the receiving matrix
  1345. * @param {mat4} a the source matrix
  1346. * @returns {mat4} out
  1347. */
  1348. mat4.transpose = function(out, a) {
  1349. // If we are transposing ourselves we can skip a few steps but have to cache some values
  1350. if (out === a) {
  1351. var a01 = a[1], a02 = a[2], a03 = a[3],
  1352. a12 = a[6], a13 = a[7],
  1353. a23 = a[11];
  1354. out[1] = a[4];
  1355. out[2] = a[8];
  1356. out[3] = a[12];
  1357. out[4] = a01;
  1358. out[6] = a[9];
  1359. out[7] = a[13];
  1360. out[8] = a02;
  1361. out[9] = a12;
  1362. out[11] = a[14];
  1363. out[12] = a03;
  1364. out[13] = a13;
  1365. out[14] = a23;
  1366. } else {
  1367. out[0] = a[0];
  1368. out[1] = a[4];
  1369. out[2] = a[8];
  1370. out[3] = a[12];
  1371. out[4] = a[1];
  1372. out[5] = a[5];
  1373. out[6] = a[9];
  1374. out[7] = a[13];
  1375. out[8] = a[2];
  1376. out[9] = a[6];
  1377. out[10] = a[10];
  1378. out[11] = a[14];
  1379. out[12] = a[3];
  1380. out[13] = a[7];
  1381. out[14] = a[11];
  1382. out[15] = a[15];
  1383. }
  1384. return out;
  1385. };
  1386. /**
  1387. * Inverts a mat4
  1388. *
  1389. * @param {mat4} out the receiving matrix
  1390. * @param {mat4} a the source matrix
  1391. * @returns {mat4} out
  1392. */
  1393. mat4.invert = function(out, a) {
  1394. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  1395. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  1396. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  1397. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  1398. b00 = a00 * a11 - a01 * a10,
  1399. b01 = a00 * a12 - a02 * a10,
  1400. b02 = a00 * a13 - a03 * a10,
  1401. b03 = a01 * a12 - a02 * a11,
  1402. b04 = a01 * a13 - a03 * a11,
  1403. b05 = a02 * a13 - a03 * a12,
  1404. b06 = a20 * a31 - a21 * a30,
  1405. b07 = a20 * a32 - a22 * a30,
  1406. b08 = a20 * a33 - a23 * a30,
  1407. b09 = a21 * a32 - a22 * a31,
  1408. b10 = a21 * a33 - a23 * a31,
  1409. b11 = a22 * a33 - a23 * a32,
  1410. // Calculate the determinant
  1411. det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1412. if (!det) {
  1413. return null;
  1414. }
  1415. det = 1.0 / det;
  1416. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  1417. out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  1418. out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  1419. out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  1420. out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  1421. out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  1422. out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  1423. out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  1424. out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  1425. out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  1426. out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  1427. out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  1428. out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  1429. out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  1430. out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  1431. out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  1432. return out;
  1433. };
  1434. /**
  1435. * Calculates the adjugate of a mat4
  1436. *
  1437. * @param {mat4} out the receiving matrix
  1438. * @param {mat4} a the source matrix
  1439. * @returns {mat4} out
  1440. */
  1441. mat4.adjoint = function(out, a) {
  1442. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  1443. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  1444. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  1445. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
  1446. out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
  1447. out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
  1448. out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
  1449. out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
  1450. out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
  1451. out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
  1452. out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
  1453. out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
  1454. out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
  1455. out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
  1456. out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
  1457. out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
  1458. out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
  1459. out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
  1460. out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
  1461. out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
  1462. return out;
  1463. };
  1464. /**
  1465. * Calculates the determinant of a mat4
  1466. *
  1467. * @param {mat4} a the source matrix
  1468. * @returns {Number} determinant of a
  1469. */
  1470. mat4.determinant = function (a) {
  1471. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  1472. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  1473. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  1474. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
  1475. b00 = a00 * a11 - a01 * a10,
  1476. b01 = a00 * a12 - a02 * a10,
  1477. b02 = a00 * a13 - a03 * a10,
  1478. b03 = a01 * a12 - a02 * a11,
  1479. b04 = a01 * a13 - a03 * a11,
  1480. b05 = a02 * a13 - a03 * a12,
  1481. b06 = a20 * a31 - a21 * a30,
  1482. b07 = a20 * a32 - a22 * a30,
  1483. b08 = a20 * a33 - a23 * a30,
  1484. b09 = a21 * a32 - a22 * a31,
  1485. b10 = a21 * a33 - a23 * a31,
  1486. b11 = a22 * a33 - a23 * a32;
  1487. // Calculate the determinant
  1488. return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1489. };
  1490. /**
  1491. * Multiplies two mat4's
  1492. *
  1493. * @param {mat4} out the receiving matrix
  1494. * @param {mat4} a the first operand
  1495. * @param {mat4} b the second operand
  1496. * @returns {mat4} out
  1497. */
  1498. mat4.multiply = function (out, a, b) {
  1499. var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
  1500. a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
  1501. a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
  1502. a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
  1503. // Cache only the current line of the second matrix
  1504. var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
  1505. out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
  1506. out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
  1507. out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
  1508. out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
  1509. b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
  1510. out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
  1511. out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
  1512. out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
  1513. out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
  1514. b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
  1515. out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
  1516. out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
  1517. out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
  1518. out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
  1519. b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
  1520. out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
  1521. out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
  1522. out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
  1523. out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
  1524. return out;
  1525. };
  1526. /**
  1527. * Alias for {@link mat4.multiply}
  1528. * @function
  1529. */
  1530. mat4.mul = mat4.multiply;
  1531. /**
  1532. * Translate a mat4 by the given vector
  1533. *
  1534. * @param {mat4} out the receiving matrix
  1535. * @param {mat4} a the matrix to translate
  1536. * @param {vec3} v vector to translate by
  1537. * @returns {mat4} out
  1538. */
  1539. mat4.translate = function (out, a, v) {
  1540. var x = v[0], y = v[1], z = v[2],
  1541. a00, a01, a02, a03,
  1542. a10, a11, a12, a13,
  1543. a20, a21, a22, a23;
  1544. if (a === out) {
  1545. out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
  1546. out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
  1547. out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
  1548. out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
  1549. } else {
  1550. a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
  1551. a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
  1552. a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
  1553. out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
  1554. out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
  1555. out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;
  1556. out[12] = a00 * x + a10 * y + a20 * z + a[12];
  1557. out[13] = a01 * x + a11 * y + a21 * z + a[13];
  1558. out[14] = a02 * x + a12 * y + a22 * z + a[14];
  1559. out[15] = a03 * x + a13 * y + a23 * z + a[15];
  1560. }
  1561. return out;
  1562. };
  1563. /**
  1564. * Scales the mat4 by the dimensions in the given vec3
  1565. *
  1566. * @param {mat4} out the receiving matrix
  1567. * @param {mat4} a the matrix to scale
  1568. * @param {vec3} v the vec3 to scale the matrix by
  1569. * @returns {mat4} out
  1570. **/
  1571. mat4.scale = function(out, a, v) {
  1572. var x = v[0], y = v[1], z = v[2];
  1573. out[0] = a[0] * x;
  1574. out[1] = a[1] * x;
  1575. out[2] = a[2] * x;
  1576. out[3] = a[3] * x;
  1577. out[4] = a[4] * y;
  1578. out[5] = a[5] * y;
  1579. out[6] = a[6] * y;
  1580. out[7] = a[7] * y;
  1581. out[8] = a[8] * z;
  1582. out[9] = a[9] * z;
  1583. out[10] = a[10] * z;
  1584. out[11] = a[11] * z;
  1585. out[12] = a[12];
  1586. out[13] = a[13];
  1587. out[14] = a[14];
  1588. out[15] = a[15];
  1589. return out;
  1590. };
  1591. /**
  1592. * Rotates a mat4 by the given angle around the given axis
  1593. *
  1594. * @param {mat4} out the receiving matrix
  1595. * @param {mat4} a the matrix to rotate
  1596. * @param {Number} rad the angle to rotate the matrix by
  1597. * @param {vec3} axis the axis to rotate around
  1598. * @returns {mat4} out
  1599. */
  1600. mat4.rotate = function (out, a, rad, axis) {
  1601. var x = axis[0], y = axis[1], z = axis[2],
  1602. len = Math.sqrt(x * x + y * y + z * z),
  1603. s, c, t,
  1604. a00, a01, a02, a03,
  1605. a10, a11, a12, a13,
  1606. a20, a21, a22, a23,
  1607. b00, b01, b02,
  1608. b10, b11, b12,
  1609. b20, b21, b22;
  1610. if (Math.abs(len) < glMatrix.EPSILON) { return null; }
  1611. len = 1 / len;
  1612. x *= len;
  1613. y *= len;
  1614. z *= len;
  1615. s = Math.sin(rad);
  1616. c = Math.cos(rad);
  1617. t = 1 - c;
  1618. a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
  1619. a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
  1620. a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
  1621. // Construct the elements of the rotation matrix
  1622. b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;
  1623. b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;
  1624. b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;
  1625. // Perform rotation-specific matrix multiplication
  1626. out[0] = a00 * b00 + a10 * b01 + a20 * b02;
  1627. out[1] = a01 * b00 + a11 * b01 + a21 * b02;
  1628. out[2] = a02 * b00 + a12 * b01 + a22 * b02;
  1629. out[3] = a03 * b00 + a13 * b01 + a23 * b02;
  1630. out[4] = a00 * b10 + a10 * b11 + a20 * b12;
  1631. out[5] = a01 * b10 + a11 * b11 + a21 * b12;
  1632. out[6] = a02 * b10 + a12 * b11 + a22 * b12;
  1633. out[7] = a03 * b10 + a13 * b11 + a23 * b12;
  1634. out[8] = a00 * b20 + a10 * b21 + a20 * b22;
  1635. out[9] = a01 * b20 + a11 * b21 + a21 * b22;
  1636. out[10] = a02 * b20 + a12 * b21 + a22 * b22;
  1637. out[11] = a03 * b20 + a13 * b21 + a23 * b22;
  1638. if (a !== out) { // If the source and destination differ, copy the unchanged last row
  1639. out[12] = a[12];
  1640. out[13] = a[13];
  1641. out[14] = a[14];
  1642. out[15] = a[15];
  1643. }
  1644. return out;
  1645. };
  1646. /**
  1647. * Rotates a matrix by the given angle around the X axis
  1648. *
  1649. * @param {mat4} out the receiving matrix
  1650. * @param {mat4} a the matrix to rotate
  1651. * @param {Number} rad the angle to rotate the matrix by
  1652. * @returns {mat4} out
  1653. */
  1654. mat4.rotateX = function (out, a, rad) {
  1655. var s = Math.sin(rad),
  1656. c = Math.cos(rad),
  1657. a10 = a[4],
  1658. a11 = a[5],
  1659. a12 = a[6],
  1660. a13 = a[7],
  1661. a20 = a[8],
  1662. a21 = a[9],
  1663. a22 = a[10],
  1664. a23 = a[11];
  1665. if (a !== out) { // If the source and destination differ, copy the unchanged rows
  1666. out[0] = a[0];
  1667. out[1] = a[1];
  1668. out[2] = a[2];
  1669. out[3] = a[3];
  1670. out[12] = a[12];
  1671. out[13] = a[13];
  1672. out[14] = a[14];
  1673. out[15] = a[15];
  1674. }
  1675. // Perform axis-specific matrix multiplication
  1676. out[4] = a10 * c + a20 * s;
  1677. out[5] = a11 * c + a21 * s;
  1678. out[6] = a12 * c + a22 * s;
  1679. out[7] = a13 * c + a23 * s;
  1680. out[8] = a20 * c - a10 * s;
  1681. out[9] = a21 * c - a11 * s;
  1682. out[10] = a22 * c - a12 * s;
  1683. out[11] = a23 * c - a13 * s;
  1684. return out;
  1685. };
  1686. /**
  1687. * Rotates a matrix by the given angle around the Y axis
  1688. *
  1689. * @param {mat4} out the receiving matrix
  1690. * @param {mat4} a the matrix to rotate
  1691. * @param {Number} rad the angle to rotate the matrix by
  1692. * @returns {mat4} out
  1693. */
  1694. mat4.rotateY = function (out, a, rad) {
  1695. var s = Math.sin(rad),
  1696. c = Math.cos(rad),
  1697. a00 = a[0],
  1698. a01 = a[1],
  1699. a02 = a[2],
  1700. a03 = a[3],
  1701. a20 = a[8],
  1702. a21 = a[9],
  1703. a22 = a[10],
  1704. a23 = a[11];
  1705. if (a !== out) { // If the source and destination differ, copy the unchanged rows
  1706. out[4] = a[4];
  1707. out[5] = a[5];
  1708. out[6] = a[6];
  1709. out[7] = a[7];
  1710. out[12] = a[12];
  1711. out[13] = a[13];
  1712. out[14] = a[14];
  1713. out[15] = a[15];
  1714. }
  1715. // Perform axis-specific matrix multiplication
  1716. out[0] = a00 * c - a20 * s;
  1717. out[1] = a01 * c - a21 * s;
  1718. out[2] = a02 * c - a22 * s;
  1719. out[3] = a03 * c - a23 * s;
  1720. out[8] = a00 * s + a20 * c;
  1721. out[9] = a01 * s + a21 * c;
  1722. out[10] = a02 * s + a22 * c;
  1723. out[11] = a03 * s + a23 * c;
  1724. return out;
  1725. };
  1726. /**
  1727. * Rotates a matrix by the given angle around the Z axis
  1728. *
  1729. * @param {mat4} out the receiving matrix
  1730. * @param {mat4} a the matrix to rotate
  1731. * @param {Number} rad the angle to rotate the matrix by
  1732. * @returns {mat4} out
  1733. */
  1734. mat4.rotateZ = function (out, a, rad) {
  1735. var s = Math.sin(rad),
  1736. c = Math.cos(rad),
  1737. a00 = a[0],
  1738. a01 = a[1],
  1739. a02 = a[2],
  1740. a03 = a[3],
  1741. a10 = a[4],
  1742. a11 = a[5],
  1743. a12 = a[6],
  1744. a13 = a[7];
  1745. if (a !== out) { // If the source and destination differ, copy the unchanged last row
  1746. out[8] = a[8];
  1747. out[9] = a[9];
  1748. out[10] = a[10];
  1749. out[11] = a[11];
  1750. out[12] = a[12];
  1751. out[13] = a[13];
  1752. out[14] = a[14];
  1753. out[15] = a[15];
  1754. }
  1755. // Perform axis-specific matrix multiplication
  1756. out[0] = a00 * c + a10 * s;
  1757. out[1] = a01 * c + a11 * s;
  1758. out[2] = a02 * c + a12 * s;
  1759. out[3] = a03 * c + a13 * s;
  1760. out[4] = a10 * c - a00 * s;
  1761. out[5] = a11 * c - a01 * s;
  1762. out[6] = a12 * c - a02 * s;
  1763. out[7] = a13 * c - a03 * s;
  1764. return out;
  1765. };
  1766. /**
  1767. * Creates a matrix from a vector translation
  1768. * This is equivalent to (but much faster than):
  1769. *
  1770. * mat4.identity(dest);
  1771. * mat4.translate(dest, dest, vec);
  1772. *
  1773. * @param {mat4} out mat4 receiving operation result
  1774. * @param {vec3} v Translation vector
  1775. * @returns {mat4} out
  1776. */
  1777. mat4.fromTranslation = function(out, v) {
  1778. out[0] = 1;
  1779. out[1] = 0;
  1780. out[2] = 0;
  1781. out[3] = 0;
  1782. out[4] = 0;
  1783. out[5] = 1;
  1784. out[6] = 0;
  1785. out[7] = 0;
  1786. out[8] = 0;
  1787. out[9] = 0;
  1788. out[10] = 1;
  1789. out[11] = 0;
  1790. out[12] = v[0];
  1791. out[13] = v[1];
  1792. out[14] = v[2];
  1793. out[15] = 1;
  1794. return out;
  1795. }
  1796. /**
  1797. * Creates a matrix from a vector scaling
  1798. * This is equivalent to (but much faster than):
  1799. *
  1800. * mat4.identity(dest);
  1801. * mat4.scale(dest, dest, vec);
  1802. *
  1803. * @param {mat4} out mat4 receiving operation result
  1804. * @param {vec3} v Scaling vector
  1805. * @returns {mat4} out
  1806. */
  1807. mat4.fromScaling = function(out, v) {
  1808. out[0] = v[0];
  1809. out[1] = 0;
  1810. out[2] = 0;
  1811. out[3] = 0;
  1812. out[4] = 0;
  1813. out[5] = v[1];
  1814. out[6] = 0;
  1815. out[7] = 0;
  1816. out[8] = 0;
  1817. out[9] = 0;
  1818. out[10] = v[2];
  1819. out[11] = 0;
  1820. out[12] = 0;
  1821. out[13] = 0;
  1822. out[14] = 0;
  1823. out[15] = 1;
  1824. return out;
  1825. }
  1826. /**
  1827. * Creates a matrix from a given angle around a given axis
  1828. * This is equivalent to (but much faster than):
  1829. *
  1830. * mat4.identity(dest);
  1831. * mat4.rotate(dest, dest, rad, axis);
  1832. *
  1833. * @param {mat4} out mat4 receiving operation result
  1834. * @param {Number} rad the angle to rotate the matrix by
  1835. * @param {vec3} axis the axis to rotate around
  1836. * @returns {mat4} out
  1837. */
  1838. mat4.fromRotation = function(out, rad, axis) {
  1839. var x = axis[0], y = axis[1], z = axis[2],
  1840. len = Math.sqrt(x * x + y * y + z * z),
  1841. s, c, t;
  1842. if (Math.abs(len) < glMatrix.EPSILON) { return null; }
  1843. len = 1 / len;
  1844. x *= len;
  1845. y *= len;
  1846. z *= len;
  1847. s = Math.sin(rad);
  1848. c = Math.cos(rad);
  1849. t = 1 - c;
  1850. // Perform rotation-specific matrix multiplication
  1851. out[0] = x * x * t + c;
  1852. out[1] = y * x * t + z * s;
  1853. out[2] = z * x * t - y * s;
  1854. out[3] = 0;
  1855. out[4] = x * y * t - z * s;
  1856. out[5] = y * y * t + c;
  1857. out[6] = z * y * t + x * s;
  1858. out[7] = 0;
  1859. out[8] = x * z * t + y * s;
  1860. out[9] = y * z * t - x * s;
  1861. out[10] = z * z * t + c;
  1862. out[11] = 0;
  1863. out[12] = 0;
  1864. out[13] = 0;
  1865. out[14] = 0;
  1866. out[15] = 1;
  1867. return out;
  1868. }
  1869. /**
  1870. * Creates a matrix from the given angle around the X axis
  1871. * This is equivalent to (but much faster than):
  1872. *
  1873. * mat4.identity(dest);
  1874. * mat4.rotateX(dest, dest, rad);
  1875. *
  1876. * @param {mat4} out mat4 receiving operation result
  1877. * @param {Number} rad the angle to rotate the matrix by
  1878. * @returns {mat4} out
  1879. */
  1880. mat4.fromXRotation = function(out, rad) {
  1881. var s = Math.sin(rad),
  1882. c = Math.cos(rad);
  1883. // Perform axis-specific matrix multiplication
  1884. out[0] = 1;
  1885. out[1] = 0;
  1886. out[2] = 0;
  1887. out[3] = 0;
  1888. out[4] = 0;
  1889. out[5] = c;
  1890. out[6] = s;
  1891. out[7] = 0;
  1892. out[8] = 0;
  1893. out[9] = -s;
  1894. out[10] = c;
  1895. out[11] = 0;
  1896. out[12] = 0;
  1897. out[13] = 0;
  1898. out[14] = 0;
  1899. out[15] = 1;
  1900. return out;
  1901. }
  1902. /**
  1903. * Creates a matrix from the given angle around the Y axis
  1904. * This is equivalent to (but much faster than):
  1905. *
  1906. * mat4.identity(dest);
  1907. * mat4.rotateY(dest, dest, rad);
  1908. *
  1909. * @param {mat4} out mat4 receiving operation result
  1910. * @param {Number} rad the angle to rotate the matrix by
  1911. * @returns {mat4} out
  1912. */
  1913. mat4.fromYRotation = function(out, rad) {
  1914. var s = Math.sin(rad),
  1915. c = Math.cos(rad);
  1916. // Perform axis-specific matrix multiplication
  1917. out[0] = c;
  1918. out[1] = 0;
  1919. out[2] = -s;
  1920. out[3] = 0;
  1921. out[4] = 0;
  1922. out[5] = 1;
  1923. out[6] = 0;
  1924. out[7] = 0;
  1925. out[8] = s;
  1926. out[9] = 0;
  1927. out[10] = c;
  1928. out[11] = 0;
  1929. out[12] = 0;
  1930. out[13] = 0;
  1931. out[14] = 0;
  1932. out[15] = 1;
  1933. return out;
  1934. }
  1935. /**
  1936. * Creates a matrix from the given angle around the Z axis
  1937. * This is equivalent to (but much faster than):
  1938. *
  1939. * mat4.identity(dest);
  1940. * mat4.rotateZ(dest, dest, rad);
  1941. *
  1942. * @param {mat4} out mat4 receiving operation result
  1943. * @param {Number} rad the angle to rotate the matrix by
  1944. * @returns {mat4} out
  1945. */
  1946. mat4.fromZRotation = function(out, rad) {
  1947. var s = Math.sin(rad),
  1948. c = Math.cos(rad);
  1949. // Perform axis-specific matrix multiplication
  1950. out[0] = c;
  1951. out[1] = s;
  1952. out[2] = 0;
  1953. out[3] = 0;
  1954. out[4] = -s;
  1955. out[5] = c;
  1956. out[6] = 0;
  1957. out[7] = 0;
  1958. out[8] = 0;
  1959. out[9] = 0;
  1960. out[10] = 1;
  1961. out[11] = 0;
  1962. out[12] = 0;
  1963. out[13] = 0;
  1964. out[14] = 0;
  1965. out[15] = 1;
  1966. return out;
  1967. }
  1968. /**
  1969. * Creates a matrix from a quaternion rotation and vector translation
  1970. * This is equivalent to (but much faster than):
  1971. *
  1972. * mat4.identity(dest);
  1973. * mat4.translate(dest, vec);
  1974. * var quatMat = mat4.create();
  1975. * quat4.toMat4(quat, quatMat);
  1976. * mat4.multiply(dest, quatMat);
  1977. *
  1978. * @param {mat4} out mat4 receiving operation result
  1979. * @param {quat4} q Rotation quaternion
  1980. * @param {vec3} v Translation vector
  1981. * @returns {mat4} out
  1982. */
  1983. mat4.fromRotationTranslation = function (out, q, v) {
  1984. // Quaternion math
  1985. var x = q[0], y = q[1], z = q[2], w = q[3],
  1986. x2 = x + x,
  1987. y2 = y + y,
  1988. z2 = z + z,
  1989. xx = x * x2,
  1990. xy = x * y2,
  1991. xz = x * z2,
  1992. yy = y * y2,
  1993. yz = y * z2,
  1994. zz = z * z2,
  1995. wx = w * x2,
  1996. wy = w * y2,
  1997. wz = w * z2;
  1998. out[0] = 1 - (yy + zz);
  1999. out[1] = xy + wz;
  2000. out[2] = xz - wy;
  2001. out[3] = 0;
  2002. out[4] = xy - wz;
  2003. out[5] = 1 - (xx + zz);
  2004. out[6] = yz + wx;
  2005. out[7] = 0;
  2006. out[8] = xz + wy;
  2007. out[9] = yz - wx;
  2008. out[10] = 1 - (xx + yy);
  2009. out[11] = 0;
  2010. out[12] = v[0];
  2011. out[13] = v[1];
  2012. out[14] = v[2];
  2013. out[15] = 1;
  2014. return out;
  2015. };
  2016. /**
  2017. * Creates a matrix from a quaternion rotation, vector translation and vector scale
  2018. * This is equivalent to (but much faster than):
  2019. *
  2020. * mat4.identity(dest);
  2021. * mat4.translate(dest, vec);
  2022. * var quatMat = mat4.create();
  2023. * quat4.toMat4(quat, quatMat);
  2024. * mat4.multiply(dest, quatMat);
  2025. * mat4.scale(dest, scale)
  2026. *
  2027. * @param {mat4} out mat4 receiving operation result
  2028. * @param {quat4} q Rotation quaternion
  2029. * @param {vec3} v Translation vector
  2030. * @param {vec3} s Scaling vector
  2031. * @returns {mat4} out
  2032. */
  2033. mat4.fromRotationTranslationScale = function (out, q, v, s) {
  2034. // Quaternion math
  2035. var x = q[0], y = q[1], z = q[2], w = q[3],
  2036. x2 = x + x,
  2037. y2 = y + y,
  2038. z2 = z + z,
  2039. xx = x * x2,
  2040. xy = x * y2,
  2041. xz = x * z2,
  2042. yy = y * y2,
  2043. yz = y * z2,
  2044. zz = z * z2,
  2045. wx = w * x2,
  2046. wy = w * y2,
  2047. wz = w * z2,
  2048. sx = s[0],
  2049. sy = s[1],
  2050. sz = s[2];
  2051. out[0] = (1 - (yy + zz)) * sx;
  2052. out[1] = (xy + wz) * sx;
  2053. out[2] = (xz - wy) * sx;
  2054. out[3] = 0;
  2055. out[4] = (xy - wz) * sy;
  2056. out[5] = (1 - (xx + zz)) * sy;
  2057. out[6] = (yz + wx) * sy;
  2058. out[7] = 0;
  2059. out[8] = (xz + wy) * sz;
  2060. out[9] = (yz - wx) * sz;
  2061. out[10] = (1 - (xx + yy)) * sz;
  2062. out[11] = 0;
  2063. out[12] = v[0];
  2064. out[13] = v[1];
  2065. out[14] = v[2];
  2066. out[15] = 1;
  2067. return out;
  2068. };
  2069. /**
  2070. * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
  2071. * This is equivalent to (but much faster than):
  2072. *
  2073. * mat4.identity(dest);
  2074. * mat4.translate(dest, vec);
  2075. * mat4.translate(dest, origin);
  2076. * var quatMat = mat4.create();
  2077. * quat4.toMat4(quat, quatMat);
  2078. * mat4.multiply(dest, quatMat);
  2079. * mat4.scale(dest, scale)
  2080. * mat4.translate(dest, negativeOrigin);
  2081. *
  2082. * @param {mat4} out mat4 receiving operation result
  2083. * @param {quat4} q Rotation quaternion
  2084. * @param {vec3} v Translation vector
  2085. * @param {vec3} s Scaling vector
  2086. * @param {vec3} o The origin vector around which to scale and rotate
  2087. * @returns {mat4} out
  2088. */
  2089. mat4.fromRotationTranslationScaleOrigin = function (out, q, v, s, o) {
  2090. // Quaternion math
  2091. var x = q[0], y = q[1], z = q[2], w = q[3],
  2092. x2 = x + x,
  2093. y2 = y + y,
  2094. z2 = z + z,
  2095. xx = x * x2,
  2096. xy = x * y2,
  2097. xz = x * z2,
  2098. yy = y * y2,
  2099. yz = y * z2,
  2100. zz = z * z2,
  2101. wx = w * x2,
  2102. wy = w * y2,
  2103. wz = w * z2,
  2104. sx = s[0],
  2105. sy = s[1],
  2106. sz = s[2],
  2107. ox = o[0],
  2108. oy = o[1],
  2109. oz = o[2];
  2110. out[0] = (1 - (yy + zz)) * sx;
  2111. out[1] = (xy + wz) * sx;
  2112. out[2] = (xz - wy) * sx;
  2113. out[3] = 0;
  2114. out[4] = (xy - wz) * sy;
  2115. out[5] = (1 - (xx + zz)) * sy;
  2116. out[6] = (yz + wx) * sy;
  2117. out[7] = 0;
  2118. out[8] = (xz + wy) * sz;
  2119. out[9] = (yz - wx) * sz;
  2120. out[10] = (1 - (xx + yy)) * sz;
  2121. out[11] = 0;
  2122. out[12] = v[0] + ox - (out[0] * ox + out[4] * oy + out[8] * oz);
  2123. out[13] = v[1] + oy - (out[1] * ox + out[5] * oy + out[9] * oz);
  2124. out[14] = v[2] + oz - (out[2] * ox + out[6] * oy + out[10] * oz);
  2125. out[15] = 1;
  2126. return out;
  2127. };
  2128. mat4.fromQuat = function (out, q) {
  2129. var x = q[0], y = q[1], z = q[2], w = q[3],
  2130. x2 = x + x,
  2131. y2 = y + y,
  2132. z2 = z + z,
  2133. xx = x * x2,
  2134. yx = y * x2,
  2135. yy = y * y2,
  2136. zx = z * x2,
  2137. zy = z * y2,
  2138. zz = z * z2,
  2139. wx = w * x2,
  2140. wy = w * y2,
  2141. wz = w * z2;
  2142. out[0] = 1 - yy - zz;
  2143. out[1] = yx + wz;
  2144. out[2] = zx - wy;
  2145. out[3] = 0;
  2146. out[4] = yx - wz;
  2147. out[5] = 1 - xx - zz;
  2148. out[6] = zy + wx;
  2149. out[7] = 0;
  2150. out[8] = zx + wy;
  2151. out[9] = zy - wx;
  2152. out[10] = 1 - xx - yy;
  2153. out[11] = 0;
  2154. out[12] = 0;
  2155. out[13] = 0;
  2156. out[14] = 0;
  2157. out[15] = 1;
  2158. return out;
  2159. };
  2160. /**
  2161. * Generates a frustum matrix with the given bounds
  2162. *
  2163. * @param {mat4} out mat4 frustum matrix will be written into
  2164. * @param {Number} left Left bound of the frustum
  2165. * @param {Number} right Right bound of the frustum
  2166. * @param {Number} bottom Bottom bound of the frustum
  2167. * @param {Number} top Top bound of the frustum
  2168. * @param {Number} near Near bound of the frustum
  2169. * @param {Number} far Far bound of the frustum
  2170. * @returns {mat4} out
  2171. */
  2172. mat4.frustum = function (out, left, right, bottom, top, near, far) {
  2173. var rl = 1 / (right - left),
  2174. tb = 1 / (top - bottom),
  2175. nf = 1 / (near - far);
  2176. out[0] = (near * 2) * rl;
  2177. out[1] = 0;
  2178. out[2] = 0;
  2179. out[3] = 0;
  2180. out[4] = 0;
  2181. out[5] = (near * 2) * tb;
  2182. out[6] = 0;
  2183. out[7] = 0;
  2184. out[8] = (right + left) * rl;
  2185. out[9] = (top + bottom) * tb;
  2186. out[10] = (far + near) * nf;
  2187. out[11] = -1;
  2188. out[12] = 0;
  2189. out[13] = 0;
  2190. out[14] = (far * near * 2) * nf;
  2191. out[15] = 0;
  2192. return out;
  2193. };
  2194. /**
  2195. * Generates a perspective projection matrix with the given bounds
  2196. *
  2197. * @param {mat4} out mat4 frustum matrix will be written into
  2198. * @param {number} fovy Vertical field of view in radians
  2199. * @param {number} aspect Aspect ratio. typically viewport width/height
  2200. * @param {number} near Near bound of the frustum
  2201. * @param {number} far Far bound of the frustum
  2202. * @returns {mat4} out
  2203. */
  2204. mat4.perspective = function (out, fovy, aspect, near, far) {
  2205. var f = 1.0 / Math.tan(fovy / 2),
  2206. nf = 1 / (near - far);
  2207. out[0] = f / aspect;
  2208. out[1] = 0;
  2209. out[2] = 0;
  2210. out[3] = 0;
  2211. out[4] = 0;
  2212. out[5] = f;
  2213. out[6] = 0;
  2214. out[7] = 0;
  2215. out[8] = 0;
  2216. out[9] = 0;
  2217. out[10] = (far + near) * nf;
  2218. out[11] = -1;
  2219. out[12] = 0;
  2220. out[13] = 0;
  2221. out[14] = (2 * far * near) * nf;
  2222. out[15] = 0;
  2223. return out;
  2224. };
  2225. /**
  2226. * Generates a perspective projection matrix with the given field of view.
  2227. * This is primarily useful for generating projection matrices to be used
  2228. * with the still experiemental WebVR API.
  2229. *
  2230. * @param {mat4} out mat4 frustum matrix will be written into
  2231. * @param {number} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
  2232. * @param {number} near Near bound of the frustum
  2233. * @param {number} far Far bound of the frustum
  2234. * @returns {mat4} out
  2235. */
  2236. mat4.perspectiveFromFieldOfView = function (out, fov, near, far) {
  2237. var upTan = Math.tan(fov.upDegrees * Math.PI/180.0),
  2238. downTan = Math.tan(fov.downDegrees * Math.PI/180.0),
  2239. leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0),
  2240. rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0),
  2241. xScale = 2.0 / (leftTan + rightTan),
  2242. yScale = 2.0 / (upTan + downTan);
  2243. out[0] = xScale;
  2244. out[1] = 0.0;
  2245. out[2] = 0.0;
  2246. out[3] = 0.0;
  2247. out[4] = 0.0;
  2248. out[5] = yScale;
  2249. out[6] = 0.0;
  2250. out[7] = 0.0;
  2251. out[8] = -((leftTan - rightTan) * xScale * 0.5);
  2252. out[9] = ((upTan - downTan) * yScale * 0.5);
  2253. out[10] = far / (near - far);
  2254. out[11] = -1.0;
  2255. out[12] = 0.0;
  2256. out[13] = 0.0;
  2257. out[14] = (far * near) / (near - far);
  2258. out[15] = 0.0;
  2259. return out;
  2260. }
  2261. /**
  2262. * Generates a orthogonal projection matrix with the given bounds
  2263. *
  2264. * @param {mat4} out mat4 frustum matrix will be written into
  2265. * @param {number} left Left bound of the frustum
  2266. * @param {number} right Right bound of the frustum
  2267. * @param {number} bottom Bottom bound of the frustum
  2268. * @param {number} top Top bound of the frustum
  2269. * @param {number} near Near bound of the frustum
  2270. * @param {number} far Far bound of the frustum
  2271. * @returns {mat4} out
  2272. */
  2273. mat4.ortho = function (out, left, right, bottom, top, near, far) {
  2274. var lr = 1 / (left - right),
  2275. bt = 1 / (bottom - top),
  2276. nf = 1 / (near - far);
  2277. out[0] = -2 * lr;
  2278. out[1] = 0;
  2279. out[2] = 0;
  2280. out[3] = 0;
  2281. out[4] = 0;
  2282. out[5] = -2 * bt;
  2283. out[6] = 0;
  2284. out[7] = 0;
  2285. out[8] = 0;
  2286. out[9] = 0;
  2287. out[10] = 2 * nf;
  2288. out[11] = 0;
  2289. out[12] = (left + right) * lr;
  2290. out[13] = (top + bottom) * bt;
  2291. out[14] = (far + near) * nf;
  2292. out[15] = 1;
  2293. return out;
  2294. };
  2295. /**
  2296. * Generates a look-at matrix with the given eye position, focal point, and up axis
  2297. *
  2298. * @param {mat4} out mat4 frustum matrix will be written into
  2299. * @param {vec3} eye Position of the viewer
  2300. * @param {vec3} center Point the viewer is looking at
  2301. * @param {vec3} up vec3 pointing up
  2302. * @returns {mat4} out
  2303. */
  2304. mat4.lookAt = function (out, eye, center, up) {
  2305. var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
  2306. eyex = eye[0],
  2307. eyey = eye[1],
  2308. eyez = eye[2],
  2309. upx = up[0],
  2310. upy = up[1],
  2311. upz = up[2],
  2312. centerx = center[0],
  2313. centery = center[1],
  2314. centerz = center[2];
  2315. if (Math.abs(eyex - centerx) < glMatrix.EPSILON &&
  2316. Math.abs(eyey - centery) < glMatrix.EPSILON &&
  2317. Math.abs(eyez - centerz) < glMatrix.EPSILON) {
  2318. return mat4.identity(out);
  2319. }
  2320. z0 = eyex - centerx;
  2321. z1 = eyey - centery;
  2322. z2 = eyez - centerz;
  2323. len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
  2324. z0 *= len;
  2325. z1 *= len;
  2326. z2 *= len;
  2327. x0 = upy * z2 - upz * z1;
  2328. x1 = upz * z0 - upx * z2;
  2329. x2 = upx * z1 - upy * z0;
  2330. len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
  2331. if (!len) {
  2332. x0 = 0;
  2333. x1 = 0;
  2334. x2 = 0;
  2335. } else {
  2336. len = 1 / len;
  2337. x0 *= len;
  2338. x1 *= len;
  2339. x2 *= len;
  2340. }
  2341. y0 = z1 * x2 - z2 * x1;
  2342. y1 = z2 * x0 - z0 * x2;
  2343. y2 = z0 * x1 - z1 * x0;
  2344. len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
  2345. if (!len) {
  2346. y0 = 0;
  2347. y1 = 0;
  2348. y2 = 0;
  2349. } else {
  2350. len = 1 / len;
  2351. y0 *= len;
  2352. y1 *= len;
  2353. y2 *= len;
  2354. }
  2355. out[0] = x0;
  2356. out[1] = y0;
  2357. out[2] = z0;
  2358. out[3] = 0;
  2359. out[4] = x1;
  2360. out[5] = y1;
  2361. out[6] = z1;
  2362. out[7] = 0;
  2363. out[8] = x2;
  2364. out[9] = y2;
  2365. out[10] = z2;
  2366. out[11] = 0;
  2367. out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
  2368. out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
  2369. out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
  2370. out[15] = 1;
  2371. return out;
  2372. };
  2373. /**
  2374. * Returns a string representation of a mat4
  2375. *
  2376. * @param {mat4} mat matrix to represent as a string
  2377. * @returns {String} string representation of the matrix
  2378. */
  2379. mat4.str = function (a) {
  2380. return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +
  2381. a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +
  2382. a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
  2383. a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';
  2384. };
  2385. /**
  2386. * Returns Frobenius norm of a mat4
  2387. *
  2388. * @param {mat4} a the matrix to calculate Frobenius norm of
  2389. * @returns {Number} Frobenius norm
  2390. */
  2391. mat4.frob = function (a) {
  2392. return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) ))
  2393. };
  2394. module.exports = mat4;
  2395. /***/ },
  2396. /* 6 */
  2397. /***/ function(module, exports, __webpack_require__) {
  2398. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  2399. Permission is hereby granted, free of charge, to any person obtaining a copy
  2400. of this software and associated documentation files (the "Software"), to deal
  2401. in the Software without restriction, including without limitation the rights
  2402. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2403. copies of the Software, and to permit persons to whom the Software is
  2404. furnished to do so, subject to the following conditions:
  2405. The above copyright notice and this permission notice shall be included in
  2406. all copies or substantial portions of the Software.
  2407. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2408. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2409. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2410. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2411. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2412. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2413. THE SOFTWARE. */
  2414. var glMatrix = __webpack_require__(1);
  2415. var mat3 = __webpack_require__(4);
  2416. var vec3 = __webpack_require__(7);
  2417. var vec4 = __webpack_require__(8);
  2418. /**
  2419. * @class Quaternion
  2420. * @name quat
  2421. */
  2422. var quat = {};
  2423. /**
  2424. * Creates a new identity quat
  2425. *
  2426. * @returns {quat} a new quaternion
  2427. */
  2428. quat.create = function() {
  2429. var out = new glMatrix.ARRAY_TYPE(4);
  2430. out[0] = 0;
  2431. out[1] = 0;
  2432. out[2] = 0;
  2433. out[3] = 1;
  2434. return out;
  2435. };
  2436. /**
  2437. * Sets a quaternion to represent the shortest rotation from one
  2438. * vector to another.
  2439. *
  2440. * Both vectors are assumed to be unit length.
  2441. *
  2442. * @param {quat} out the receiving quaternion.
  2443. * @param {vec3} a the initial vector
  2444. * @param {vec3} b the destination vector
  2445. * @returns {quat} out
  2446. */
  2447. quat.rotationTo = (function() {
  2448. var tmpvec3 = vec3.create();
  2449. var xUnitVec3 = vec3.fromValues(1,0,0);
  2450. var yUnitVec3 = vec3.fromValues(0,1,0);
  2451. return function(out, a, b) {
  2452. var dot = vec3.dot(a, b);
  2453. if (dot < -0.999999) {
  2454. vec3.cross(tmpvec3, xUnitVec3, a);
  2455. if (vec3.length(tmpvec3) < 0.000001)
  2456. vec3.cross(tmpvec3, yUnitVec3, a);
  2457. vec3.normalize(tmpvec3, tmpvec3);
  2458. quat.setAxisAngle(out, tmpvec3, Math.PI);
  2459. return out;
  2460. } else if (dot > 0.999999) {
  2461. out[0] = 0;
  2462. out[1] = 0;
  2463. out[2] = 0;
  2464. out[3] = 1;
  2465. return out;
  2466. } else {
  2467. vec3.cross(tmpvec3, a, b);
  2468. out[0] = tmpvec3[0];
  2469. out[1] = tmpvec3[1];
  2470. out[2] = tmpvec3[2];
  2471. out[3] = 1 + dot;
  2472. return quat.normalize(out, out);
  2473. }
  2474. };
  2475. })();
  2476. /**
  2477. * Sets the specified quaternion with values corresponding to the given
  2478. * axes. Each axis is a vec3 and is expected to be unit length and
  2479. * perpendicular to all other specified axes.
  2480. *
  2481. * @param {vec3} view the vector representing the viewing direction
  2482. * @param {vec3} right the vector representing the local "right" direction
  2483. * @param {vec3} up the vector representing the local "up" direction
  2484. * @returns {quat} out
  2485. */
  2486. quat.setAxes = (function() {
  2487. var matr = mat3.create();
  2488. return function(out, view, right, up) {
  2489. matr[0] = right[0];
  2490. matr[3] = right[1];
  2491. matr[6] = right[2];
  2492. matr[1] = up[0];
  2493. matr[4] = up[1];
  2494. matr[7] = up[2];
  2495. matr[2] = -view[0];
  2496. matr[5] = -view[1];
  2497. matr[8] = -view[2];
  2498. return quat.normalize(out, quat.fromMat3(out, matr));
  2499. };
  2500. })();
  2501. /**
  2502. * Creates a new quat initialized with values from an existing quaternion
  2503. *
  2504. * @param {quat} a quaternion to clone
  2505. * @returns {quat} a new quaternion
  2506. * @function
  2507. */
  2508. quat.clone = vec4.clone;
  2509. /**
  2510. * Creates a new quat initialized with the given values
  2511. *
  2512. * @param {Number} x X component
  2513. * @param {Number} y Y component
  2514. * @param {Number} z Z component
  2515. * @param {Number} w W component
  2516. * @returns {quat} a new quaternion
  2517. * @function
  2518. */
  2519. quat.fromValues = vec4.fromValues;
  2520. /**
  2521. * Copy the values from one quat to another
  2522. *
  2523. * @param {quat} out the receiving quaternion
  2524. * @param {quat} a the source quaternion
  2525. * @returns {quat} out
  2526. * @function
  2527. */
  2528. quat.copy = vec4.copy;
  2529. /**
  2530. * Set the components of a quat to the given values
  2531. *
  2532. * @param {quat} out the receiving quaternion
  2533. * @param {Number} x X component
  2534. * @param {Number} y Y component
  2535. * @param {Number} z Z component
  2536. * @param {Number} w W component
  2537. * @returns {quat} out
  2538. * @function
  2539. */
  2540. quat.set = vec4.set;
  2541. /**
  2542. * Set a quat to the identity quaternion
  2543. *
  2544. * @param {quat} out the receiving quaternion
  2545. * @returns {quat} out
  2546. */
  2547. quat.identity = function(out) {
  2548. out[0] = 0;
  2549. out[1] = 0;
  2550. out[2] = 0;
  2551. out[3] = 1;
  2552. return out;
  2553. };
  2554. /**
  2555. * Sets a quat from the given angle and rotation axis,
  2556. * then returns it.
  2557. *
  2558. * @param {quat} out the receiving quaternion
  2559. * @param {vec3} axis the axis around which to rotate
  2560. * @param {Number} rad the angle in radians
  2561. * @returns {quat} out
  2562. **/
  2563. quat.setAxisAngle = function(out, axis, rad) {
  2564. rad = rad * 0.5;
  2565. var s = Math.sin(rad);
  2566. out[0] = s * axis[0];
  2567. out[1] = s * axis[1];
  2568. out[2] = s * axis[2];
  2569. out[3] = Math.cos(rad);
  2570. return out;
  2571. };
  2572. /**
  2573. * Adds two quat's
  2574. *
  2575. * @param {quat} out the receiving quaternion
  2576. * @param {quat} a the first operand
  2577. * @param {quat} b the second operand
  2578. * @returns {quat} out
  2579. * @function
  2580. */
  2581. quat.add = vec4.add;
  2582. /**
  2583. * Multiplies two quat's
  2584. *
  2585. * @param {quat} out the receiving quaternion
  2586. * @param {quat} a the first operand
  2587. * @param {quat} b the second operand
  2588. * @returns {quat} out
  2589. */
  2590. quat.multiply = function(out, a, b) {
  2591. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2592. bx = b[0], by = b[1], bz = b[2], bw = b[3];
  2593. out[0] = ax * bw + aw * bx + ay * bz - az * by;
  2594. out[1] = ay * bw + aw * by + az * bx - ax * bz;
  2595. out[2] = az * bw + aw * bz + ax * by - ay * bx;
  2596. out[3] = aw * bw - ax * bx - ay * by - az * bz;
  2597. return out;
  2598. };
  2599. /**
  2600. * Alias for {@link quat.multiply}
  2601. * @function
  2602. */
  2603. quat.mul = quat.multiply;
  2604. /**
  2605. * Scales a quat by a scalar number
  2606. *
  2607. * @param {quat} out the receiving vector
  2608. * @param {quat} a the vector to scale
  2609. * @param {Number} b amount to scale the vector by
  2610. * @returns {quat} out
  2611. * @function
  2612. */
  2613. quat.scale = vec4.scale;
  2614. /**
  2615. * Rotates a quaternion by the given angle about the X axis
  2616. *
  2617. * @param {quat} out quat receiving operation result
  2618. * @param {quat} a quat to rotate
  2619. * @param {number} rad angle (in radians) to rotate
  2620. * @returns {quat} out
  2621. */
  2622. quat.rotateX = function (out, a, rad) {
  2623. rad *= 0.5;
  2624. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2625. bx = Math.sin(rad), bw = Math.cos(rad);
  2626. out[0] = ax * bw + aw * bx;
  2627. out[1] = ay * bw + az * bx;
  2628. out[2] = az * bw - ay * bx;
  2629. out[3] = aw * bw - ax * bx;
  2630. return out;
  2631. };
  2632. /**
  2633. * Rotates a quaternion by the given angle about the Y axis
  2634. *
  2635. * @param {quat} out quat receiving operation result
  2636. * @param {quat} a quat to rotate
  2637. * @param {number} rad angle (in radians) to rotate
  2638. * @returns {quat} out
  2639. */
  2640. quat.rotateY = function (out, a, rad) {
  2641. rad *= 0.5;
  2642. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2643. by = Math.sin(rad), bw = Math.cos(rad);
  2644. out[0] = ax * bw - az * by;
  2645. out[1] = ay * bw + aw * by;
  2646. out[2] = az * bw + ax * by;
  2647. out[3] = aw * bw - ay * by;
  2648. return out;
  2649. };
  2650. /**
  2651. * Rotates a quaternion by the given angle about the Z axis
  2652. *
  2653. * @param {quat} out quat receiving operation result
  2654. * @param {quat} a quat to rotate
  2655. * @param {number} rad angle (in radians) to rotate
  2656. * @returns {quat} out
  2657. */
  2658. quat.rotateZ = function (out, a, rad) {
  2659. rad *= 0.5;
  2660. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2661. bz = Math.sin(rad), bw = Math.cos(rad);
  2662. out[0] = ax * bw + ay * bz;
  2663. out[1] = ay * bw - ax * bz;
  2664. out[2] = az * bw + aw * bz;
  2665. out[3] = aw * bw - az * bz;
  2666. return out;
  2667. };
  2668. /**
  2669. * Calculates the W component of a quat from the X, Y, and Z components.
  2670. * Assumes that quaternion is 1 unit in length.
  2671. * Any existing W component will be ignored.
  2672. *
  2673. * @param {quat} out the receiving quaternion
  2674. * @param {quat} a quat to calculate W component of
  2675. * @returns {quat} out
  2676. */
  2677. quat.calculateW = function (out, a) {
  2678. var x = a[0], y = a[1], z = a[2];
  2679. out[0] = x;
  2680. out[1] = y;
  2681. out[2] = z;
  2682. out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
  2683. return out;
  2684. };
  2685. /**
  2686. * Calculates the dot product of two quat's
  2687. *
  2688. * @param {quat} a the first operand
  2689. * @param {quat} b the second operand
  2690. * @returns {Number} dot product of a and b
  2691. * @function
  2692. */
  2693. quat.dot = vec4.dot;
  2694. /**
  2695. * Performs a linear interpolation between two quat's
  2696. *
  2697. * @param {quat} out the receiving quaternion
  2698. * @param {quat} a the first operand
  2699. * @param {quat} b the second operand
  2700. * @param {Number} t interpolation amount between the two inputs
  2701. * @returns {quat} out
  2702. * @function
  2703. */
  2704. quat.lerp = vec4.lerp;
  2705. /**
  2706. * Performs a spherical linear interpolation between two quat
  2707. *
  2708. * @param {quat} out the receiving quaternion
  2709. * @param {quat} a the first operand
  2710. * @param {quat} b the second operand
  2711. * @param {Number} t interpolation amount between the two inputs
  2712. * @returns {quat} out
  2713. */
  2714. quat.slerp = function (out, a, b, t) {
  2715. // benchmarks:
  2716. // http://jsperf.com/quaternion-slerp-implementations
  2717. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2718. bx = b[0], by = b[1], bz = b[2], bw = b[3];
  2719. var omega, cosom, sinom, scale0, scale1;
  2720. // calc cosine
  2721. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2722. // adjust signs (if necessary)
  2723. if ( cosom < 0.0 ) {
  2724. cosom = -cosom;
  2725. bx = - bx;
  2726. by = - by;
  2727. bz = - bz;
  2728. bw = - bw;
  2729. }
  2730. // calculate coefficients
  2731. if ( (1.0 - cosom) > 0.000001 ) {
  2732. // standard case (slerp)
  2733. omega = Math.acos(cosom);
  2734. sinom = Math.sin(omega);
  2735. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2736. scale1 = Math.sin(t * omega) / sinom;
  2737. } else {
  2738. // "from" and "to" quaternions are very close
  2739. // ... so we can do a linear interpolation
  2740. scale0 = 1.0 - t;
  2741. scale1 = t;
  2742. }
  2743. // calculate final values
  2744. out[0] = scale0 * ax + scale1 * bx;
  2745. out[1] = scale0 * ay + scale1 * by;
  2746. out[2] = scale0 * az + scale1 * bz;
  2747. out[3] = scale0 * aw + scale1 * bw;
  2748. return out;
  2749. };
  2750. /**
  2751. * Performs a spherical linear interpolation with two control points
  2752. *
  2753. * @param {quat} out the receiving quaternion
  2754. * @param {quat} a the first operand
  2755. * @param {quat} b the second operand
  2756. * @param {quat} c the third operand
  2757. * @param {quat} d the fourth operand
  2758. * @param {Number} t interpolation amount
  2759. * @returns {quat} out
  2760. */
  2761. quat.sqlerp = (function () {
  2762. var temp1 = quat.create();
  2763. var temp2 = quat.create();
  2764. return function (out, a, b, c, d, t) {
  2765. quat.slerp(temp1, a, d, t);
  2766. quat.slerp(temp2, b, c, t);
  2767. quat.slerp(out, temp1, temp2, 2 * t * (1 - t));
  2768. return out;
  2769. };
  2770. }());
  2771. /**
  2772. * Calculates the inverse of a quat
  2773. *
  2774. * @param {quat} out the receiving quaternion
  2775. * @param {quat} a quat to calculate inverse of
  2776. * @returns {quat} out
  2777. */
  2778. quat.invert = function(out, a) {
  2779. var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
  2780. dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,
  2781. invDot = dot ? 1.0/dot : 0;
  2782. // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  2783. out[0] = -a0*invDot;
  2784. out[1] = -a1*invDot;
  2785. out[2] = -a2*invDot;
  2786. out[3] = a3*invDot;
  2787. return out;
  2788. };
  2789. /**
  2790. * Calculates the conjugate of a quat
  2791. * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
  2792. *
  2793. * @param {quat} out the receiving quaternion
  2794. * @param {quat} a quat to calculate conjugate of
  2795. * @returns {quat} out
  2796. */
  2797. quat.conjugate = function (out, a) {
  2798. out[0] = -a[0];
  2799. out[1] = -a[1];
  2800. out[2] = -a[2];
  2801. out[3] = a[3];
  2802. return out;
  2803. };
  2804. /**
  2805. * Calculates the length of a quat
  2806. *
  2807. * @param {quat} a vector to calculate length of
  2808. * @returns {Number} length of a
  2809. * @function
  2810. */
  2811. quat.length = vec4.length;
  2812. /**
  2813. * Alias for {@link quat.length}
  2814. * @function
  2815. */
  2816. quat.len = quat.length;
  2817. /**
  2818. * Calculates the squared length of a quat
  2819. *
  2820. * @param {quat} a vector to calculate squared length of
  2821. * @returns {Number} squared length of a
  2822. * @function
  2823. */
  2824. quat.squaredLength = vec4.squaredLength;
  2825. /**
  2826. * Alias for {@link quat.squaredLength}
  2827. * @function
  2828. */
  2829. quat.sqrLen = quat.squaredLength;
  2830. /**
  2831. * Normalize a quat
  2832. *
  2833. * @param {quat} out the receiving quaternion
  2834. * @param {quat} a quaternion to normalize
  2835. * @returns {quat} out
  2836. * @function
  2837. */
  2838. quat.normalize = vec4.normalize;
  2839. /**
  2840. * Creates a quaternion from the given 3x3 rotation matrix.
  2841. *
  2842. * NOTE: The resultant quaternion is not normalized, so you should be sure
  2843. * to renormalize the quaternion yourself where necessary.
  2844. *
  2845. * @param {quat} out the receiving quaternion
  2846. * @param {mat3} m rotation matrix
  2847. * @returns {quat} out
  2848. * @function
  2849. */
  2850. quat.fromMat3 = function(out, m) {
  2851. // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  2852. // article "Quaternion Calculus and Fast Animation".
  2853. var fTrace = m[0] + m[4] + m[8];
  2854. var fRoot;
  2855. if ( fTrace > 0.0 ) {
  2856. // |w| > 1/2, may as well choose w > 1/2
  2857. fRoot = Math.sqrt(fTrace + 1.0); // 2w
  2858. out[3] = 0.5 * fRoot;
  2859. fRoot = 0.5/fRoot; // 1/(4w)
  2860. out[0] = (m[5]-m[7])*fRoot;
  2861. out[1] = (m[6]-m[2])*fRoot;
  2862. out[2] = (m[1]-m[3])*fRoot;
  2863. } else {
  2864. // |w| <= 1/2
  2865. var i = 0;
  2866. if ( m[4] > m[0] )
  2867. i = 1;
  2868. if ( m[8] > m[i*3+i] )
  2869. i = 2;
  2870. var j = (i+1)%3;
  2871. var k = (i+2)%3;
  2872. fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0);
  2873. out[i] = 0.5 * fRoot;
  2874. fRoot = 0.5 / fRoot;
  2875. out[3] = (m[j*3+k] - m[k*3+j]) * fRoot;
  2876. out[j] = (m[j*3+i] + m[i*3+j]) * fRoot;
  2877. out[k] = (m[k*3+i] + m[i*3+k]) * fRoot;
  2878. }
  2879. return out;
  2880. };
  2881. /**
  2882. * Returns a string representation of a quatenion
  2883. *
  2884. * @param {quat} vec vector to represent as a string
  2885. * @returns {String} string representation of the vector
  2886. */
  2887. quat.str = function (a) {
  2888. return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
  2889. };
  2890. module.exports = quat;
  2891. /***/ },
  2892. /* 7 */
  2893. /***/ function(module, exports, __webpack_require__) {
  2894. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  2895. Permission is hereby granted, free of charge, to any person obtaining a copy
  2896. of this software and associated documentation files (the "Software"), to deal
  2897. in the Software without restriction, including without limitation the rights
  2898. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2899. copies of the Software, and to permit persons to whom the Software is
  2900. furnished to do so, subject to the following conditions:
  2901. The above copyright notice and this permission notice shall be included in
  2902. all copies or substantial portions of the Software.
  2903. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2904. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2905. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2906. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2907. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2908. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2909. THE SOFTWARE. */
  2910. var glMatrix = __webpack_require__(1);
  2911. /**
  2912. * @class 3 Dimensional Vector
  2913. * @name vec3
  2914. */
  2915. var vec3 = {};
  2916. /**
  2917. * Creates a new, empty vec3
  2918. *
  2919. * @returns {vec3} a new 3D vector
  2920. */
  2921. vec3.create = function() {
  2922. var out = new glMatrix.ARRAY_TYPE(3);
  2923. out[0] = 0;
  2924. out[1] = 0;
  2925. out[2] = 0;
  2926. return out;
  2927. };
  2928. /**
  2929. * Creates a new vec3 initialized with values from an existing vector
  2930. *
  2931. * @param {vec3} a vector to clone
  2932. * @returns {vec3} a new 3D vector
  2933. */
  2934. vec3.clone = function(a) {
  2935. var out = new glMatrix.ARRAY_TYPE(3);
  2936. out[0] = a[0];
  2937. out[1] = a[1];
  2938. out[2] = a[2];
  2939. return out;
  2940. };
  2941. /**
  2942. * Creates a new vec3 initialized with the given values
  2943. *
  2944. * @param {Number} x X component
  2945. * @param {Number} y Y component
  2946. * @param {Number} z Z component
  2947. * @returns {vec3} a new 3D vector
  2948. */
  2949. vec3.fromValues = function(x, y, z) {
  2950. var out = new glMatrix.ARRAY_TYPE(3);
  2951. out[0] = x;
  2952. out[1] = y;
  2953. out[2] = z;
  2954. return out;
  2955. };
  2956. /**
  2957. * Copy the values from one vec3 to another
  2958. *
  2959. * @param {vec3} out the receiving vector
  2960. * @param {vec3} a the source vector
  2961. * @returns {vec3} out
  2962. */
  2963. vec3.copy = function(out, a) {
  2964. out[0] = a[0];
  2965. out[1] = a[1];
  2966. out[2] = a[2];
  2967. return out;
  2968. };
  2969. /**
  2970. * Set the components of a vec3 to the given values
  2971. *
  2972. * @param {vec3} out the receiving vector
  2973. * @param {Number} x X component
  2974. * @param {Number} y Y component
  2975. * @param {Number} z Z component
  2976. * @returns {vec3} out
  2977. */
  2978. vec3.set = function(out, x, y, z) {
  2979. out[0] = x;
  2980. out[1] = y;
  2981. out[2] = z;
  2982. return out;
  2983. };
  2984. /**
  2985. * Adds two vec3's
  2986. *
  2987. * @param {vec3} out the receiving vector
  2988. * @param {vec3} a the first operand
  2989. * @param {vec3} b the second operand
  2990. * @returns {vec3} out
  2991. */
  2992. vec3.add = function(out, a, b) {
  2993. out[0] = a[0] + b[0];
  2994. out[1] = a[1] + b[1];
  2995. out[2] = a[2] + b[2];
  2996. return out;
  2997. };
  2998. /**
  2999. * Subtracts vector b from vector a
  3000. *
  3001. * @param {vec3} out the receiving vector
  3002. * @param {vec3} a the first operand
  3003. * @param {vec3} b the second operand
  3004. * @returns {vec3} out
  3005. */
  3006. vec3.subtract = function(out, a, b) {
  3007. out[0] = a[0] - b[0];
  3008. out[1] = a[1] - b[1];
  3009. out[2] = a[2] - b[2];
  3010. return out;
  3011. };
  3012. /**
  3013. * Alias for {@link vec3.subtract}
  3014. * @function
  3015. */
  3016. vec3.sub = vec3.subtract;
  3017. /**
  3018. * Multiplies two vec3's
  3019. *
  3020. * @param {vec3} out the receiving vector
  3021. * @param {vec3} a the first operand
  3022. * @param {vec3} b the second operand
  3023. * @returns {vec3} out
  3024. */
  3025. vec3.multiply = function(out, a, b) {
  3026. out[0] = a[0] * b[0];
  3027. out[1] = a[1] * b[1];
  3028. out[2] = a[2] * b[2];
  3029. return out;
  3030. };
  3031. /**
  3032. * Alias for {@link vec3.multiply}
  3033. * @function
  3034. */
  3035. vec3.mul = vec3.multiply;
  3036. /**
  3037. * Divides two vec3's
  3038. *
  3039. * @param {vec3} out the receiving vector
  3040. * @param {vec3} a the first operand
  3041. * @param {vec3} b the second operand
  3042. * @returns {vec3} out
  3043. */
  3044. vec3.divide = function(out, a, b) {
  3045. out[0] = a[0] / b[0];
  3046. out[1] = a[1] / b[1];
  3047. out[2] = a[2] / b[2];
  3048. return out;
  3049. };
  3050. /**
  3051. * Alias for {@link vec3.divide}
  3052. * @function
  3053. */
  3054. vec3.div = vec3.divide;
  3055. /**
  3056. * Returns the minimum of two vec3's
  3057. *
  3058. * @param {vec3} out the receiving vector
  3059. * @param {vec3} a the first operand
  3060. * @param {vec3} b the second operand
  3061. * @returns {vec3} out
  3062. */
  3063. vec3.min = function(out, a, b) {
  3064. out[0] = Math.min(a[0], b[0]);
  3065. out[1] = Math.min(a[1], b[1]);
  3066. out[2] = Math.min(a[2], b[2]);
  3067. return out;
  3068. };
  3069. /**
  3070. * Returns the maximum of two vec3's
  3071. *
  3072. * @param {vec3} out the receiving vector
  3073. * @param {vec3} a the first operand
  3074. * @param {vec3} b the second operand
  3075. * @returns {vec3} out
  3076. */
  3077. vec3.max = function(out, a, b) {
  3078. out[0] = Math.max(a[0], b[0]);
  3079. out[1] = Math.max(a[1], b[1]);
  3080. out[2] = Math.max(a[2], b[2]);
  3081. return out;
  3082. };
  3083. /**
  3084. * Scales a vec3 by a scalar number
  3085. *
  3086. * @param {vec3} out the receiving vector
  3087. * @param {vec3} a the vector to scale
  3088. * @param {Number} b amount to scale the vector by
  3089. * @returns {vec3} out
  3090. */
  3091. vec3.scale = function(out, a, b) {
  3092. out[0] = a[0] * b;
  3093. out[1] = a[1] * b;
  3094. out[2] = a[2] * b;
  3095. return out;
  3096. };
  3097. /**
  3098. * Adds two vec3's after scaling the second operand by a scalar value
  3099. *
  3100. * @param {vec3} out the receiving vector
  3101. * @param {vec3} a the first operand
  3102. * @param {vec3} b the second operand
  3103. * @param {Number} scale the amount to scale b by before adding
  3104. * @returns {vec3} out
  3105. */
  3106. vec3.scaleAndAdd = function(out, a, b, scale) {
  3107. out[0] = a[0] + (b[0] * scale);
  3108. out[1] = a[1] + (b[1] * scale);
  3109. out[2] = a[2] + (b[2] * scale);
  3110. return out;
  3111. };
  3112. /**
  3113. * Calculates the euclidian distance between two vec3's
  3114. *
  3115. * @param {vec3} a the first operand
  3116. * @param {vec3} b the second operand
  3117. * @returns {Number} distance between a and b
  3118. */
  3119. vec3.distance = function(a, b) {
  3120. var x = b[0] - a[0],
  3121. y = b[1] - a[1],
  3122. z = b[2] - a[2];
  3123. return Math.sqrt(x*x + y*y + z*z);
  3124. };
  3125. /**
  3126. * Alias for {@link vec3.distance}
  3127. * @function
  3128. */
  3129. vec3.dist = vec3.distance;
  3130. /**
  3131. * Calculates the squared euclidian distance between two vec3's
  3132. *
  3133. * @param {vec3} a the first operand
  3134. * @param {vec3} b the second operand
  3135. * @returns {Number} squared distance between a and b
  3136. */
  3137. vec3.squaredDistance = function(a, b) {
  3138. var x = b[0] - a[0],
  3139. y = b[1] - a[1],
  3140. z = b[2] - a[2];
  3141. return x*x + y*y + z*z;
  3142. };
  3143. /**
  3144. * Alias for {@link vec3.squaredDistance}
  3145. * @function
  3146. */
  3147. vec3.sqrDist = vec3.squaredDistance;
  3148. /**
  3149. * Calculates the length of a vec3
  3150. *
  3151. * @param {vec3} a vector to calculate length of
  3152. * @returns {Number} length of a
  3153. */
  3154. vec3.length = function (a) {
  3155. var x = a[0],
  3156. y = a[1],
  3157. z = a[2];
  3158. return Math.sqrt(x*x + y*y + z*z);
  3159. };
  3160. /**
  3161. * Alias for {@link vec3.length}
  3162. * @function
  3163. */
  3164. vec3.len = vec3.length;
  3165. /**
  3166. * Calculates the squared length of a vec3
  3167. *
  3168. * @param {vec3} a vector to calculate squared length of
  3169. * @returns {Number} squared length of a
  3170. */
  3171. vec3.squaredLength = function (a) {
  3172. var x = a[0],
  3173. y = a[1],
  3174. z = a[2];
  3175. return x*x + y*y + z*z;
  3176. };
  3177. /**
  3178. * Alias for {@link vec3.squaredLength}
  3179. * @function
  3180. */
  3181. vec3.sqrLen = vec3.squaredLength;
  3182. /**
  3183. * Negates the components of a vec3
  3184. *
  3185. * @param {vec3} out the receiving vector
  3186. * @param {vec3} a vector to negate
  3187. * @returns {vec3} out
  3188. */
  3189. vec3.negate = function(out, a) {
  3190. out[0] = -a[0];
  3191. out[1] = -a[1];
  3192. out[2] = -a[2];
  3193. return out;
  3194. };
  3195. /**
  3196. * Returns the inverse of the components of a vec3
  3197. *
  3198. * @param {vec3} out the receiving vector
  3199. * @param {vec3} a vector to invert
  3200. * @returns {vec3} out
  3201. */
  3202. vec3.inverse = function(out, a) {
  3203. out[0] = 1.0 / a[0];
  3204. out[1] = 1.0 / a[1];
  3205. out[2] = 1.0 / a[2];
  3206. return out;
  3207. };
  3208. /**
  3209. * Normalize a vec3
  3210. *
  3211. * @param {vec3} out the receiving vector
  3212. * @param {vec3} a vector to normalize
  3213. * @returns {vec3} out
  3214. */
  3215. vec3.normalize = function(out, a) {
  3216. var x = a[0],
  3217. y = a[1],
  3218. z = a[2];
  3219. var len = x*x + y*y + z*z;
  3220. if (len > 0) {
  3221. //TODO: evaluate use of glm_invsqrt here?
  3222. len = 1 / Math.sqrt(len);
  3223. out[0] = a[0] * len;
  3224. out[1] = a[1] * len;
  3225. out[2] = a[2] * len;
  3226. }
  3227. return out;
  3228. };
  3229. /**
  3230. * Calculates the dot product of two vec3's
  3231. *
  3232. * @param {vec3} a the first operand
  3233. * @param {vec3} b the second operand
  3234. * @returns {Number} dot product of a and b
  3235. */
  3236. vec3.dot = function (a, b) {
  3237. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  3238. };
  3239. /**
  3240. * Computes the cross product of two vec3's
  3241. *
  3242. * @param {vec3} out the receiving vector
  3243. * @param {vec3} a the first operand
  3244. * @param {vec3} b the second operand
  3245. * @returns {vec3} out
  3246. */
  3247. vec3.cross = function(out, a, b) {
  3248. var ax = a[0], ay = a[1], az = a[2],
  3249. bx = b[0], by = b[1], bz = b[2];
  3250. out[0] = ay * bz - az * by;
  3251. out[1] = az * bx - ax * bz;
  3252. out[2] = ax * by - ay * bx;
  3253. return out;
  3254. };
  3255. /**
  3256. * Performs a linear interpolation between two vec3's
  3257. *
  3258. * @param {vec3} out the receiving vector
  3259. * @param {vec3} a the first operand
  3260. * @param {vec3} b the second operand
  3261. * @param {Number} t interpolation amount between the two inputs
  3262. * @returns {vec3} out
  3263. */
  3264. vec3.lerp = function (out, a, b, t) {
  3265. var ax = a[0],
  3266. ay = a[1],
  3267. az = a[2];
  3268. out[0] = ax + t * (b[0] - ax);
  3269. out[1] = ay + t * (b[1] - ay);
  3270. out[2] = az + t * (b[2] - az);
  3271. return out;
  3272. };
  3273. /**
  3274. * Performs a hermite interpolation with two control points
  3275. *
  3276. * @param {vec3} out the receiving vector
  3277. * @param {vec3} a the first operand
  3278. * @param {vec3} b the second operand
  3279. * @param {vec3} c the third operand
  3280. * @param {vec3} d the fourth operand
  3281. * @param {Number} t interpolation amount between the two inputs
  3282. * @returns {vec3} out
  3283. */
  3284. vec3.hermite = function (out, a, b, c, d, t) {
  3285. var factorTimes2 = t * t,
  3286. factor1 = factorTimes2 * (2 * t - 3) + 1,
  3287. factor2 = factorTimes2 * (t - 2) + t,
  3288. factor3 = factorTimes2 * (t - 1),
  3289. factor4 = factorTimes2 * (3 - 2 * t);
  3290. out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
  3291. out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
  3292. out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
  3293. return out;
  3294. };
  3295. /**
  3296. * Performs a bezier interpolation with two control points
  3297. *
  3298. * @param {vec3} out the receiving vector
  3299. * @param {vec3} a the first operand
  3300. * @param {vec3} b the second operand
  3301. * @param {vec3} c the third operand
  3302. * @param {vec3} d the fourth operand
  3303. * @param {Number} t interpolation amount between the two inputs
  3304. * @returns {vec3} out
  3305. */
  3306. vec3.bezier = function (out, a, b, c, d, t) {
  3307. var inverseFactor = 1 - t,
  3308. inverseFactorTimesTwo = inverseFactor * inverseFactor,
  3309. factorTimes2 = t * t,
  3310. factor1 = inverseFactorTimesTwo * inverseFactor,
  3311. factor2 = 3 * t * inverseFactorTimesTwo,
  3312. factor3 = 3 * factorTimes2 * inverseFactor,
  3313. factor4 = factorTimes2 * t;
  3314. out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
  3315. out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
  3316. out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
  3317. return out;
  3318. };
  3319. /**
  3320. * Generates a random vector with the given scale
  3321. *
  3322. * @param {vec3} out the receiving vector
  3323. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  3324. * @returns {vec3} out
  3325. */
  3326. vec3.random = function (out, scale) {
  3327. scale = scale || 1.0;
  3328. var r = glMatrix.RANDOM() * 2.0 * Math.PI;
  3329. var z = (glMatrix.RANDOM() * 2.0) - 1.0;
  3330. var zScale = Math.sqrt(1.0-z*z) * scale;
  3331. out[0] = Math.cos(r) * zScale;
  3332. out[1] = Math.sin(r) * zScale;
  3333. out[2] = z * scale;
  3334. return out;
  3335. };
  3336. /**
  3337. * Transforms the vec3 with a mat4.
  3338. * 4th vector component is implicitly '1'
  3339. *
  3340. * @param {vec3} out the receiving vector
  3341. * @param {vec3} a the vector to transform
  3342. * @param {mat4} m matrix to transform with
  3343. * @returns {vec3} out
  3344. */
  3345. vec3.transformMat4 = function(out, a, m) {
  3346. var x = a[0], y = a[1], z = a[2],
  3347. w = m[3] * x + m[7] * y + m[11] * z + m[15];
  3348. w = w || 1.0;
  3349. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  3350. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  3351. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  3352. return out;
  3353. };
  3354. /**
  3355. * Transforms the vec3 with a mat3.
  3356. *
  3357. * @param {vec3} out the receiving vector
  3358. * @param {vec3} a the vector to transform
  3359. * @param {mat4} m the 3x3 matrix to transform with
  3360. * @returns {vec3} out
  3361. */
  3362. vec3.transformMat3 = function(out, a, m) {
  3363. var x = a[0], y = a[1], z = a[2];
  3364. out[0] = x * m[0] + y * m[3] + z * m[6];
  3365. out[1] = x * m[1] + y * m[4] + z * m[7];
  3366. out[2] = x * m[2] + y * m[5] + z * m[8];
  3367. return out;
  3368. };
  3369. /**
  3370. * Transforms the vec3 with a quat
  3371. *
  3372. * @param {vec3} out the receiving vector
  3373. * @param {vec3} a the vector to transform
  3374. * @param {quat} q quaternion to transform with
  3375. * @returns {vec3} out
  3376. */
  3377. vec3.transformQuat = function(out, a, q) {
  3378. // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
  3379. var x = a[0], y = a[1], z = a[2],
  3380. qx = q[0], qy = q[1], qz = q[2], qw = q[3],
  3381. // calculate quat * vec
  3382. ix = qw * x + qy * z - qz * y,
  3383. iy = qw * y + qz * x - qx * z,
  3384. iz = qw * z + qx * y - qy * x,
  3385. iw = -qx * x - qy * y - qz * z;
  3386. // calculate result * inverse quat
  3387. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3388. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3389. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3390. return out;
  3391. };
  3392. /**
  3393. * Rotate a 3D vector around the x-axis
  3394. * @param {vec3} out The receiving vec3
  3395. * @param {vec3} a The vec3 point to rotate
  3396. * @param {vec3} b The origin of the rotation
  3397. * @param {Number} c The angle of rotation
  3398. * @returns {vec3} out
  3399. */
  3400. vec3.rotateX = function(out, a, b, c){
  3401. var p = [], r=[];
  3402. //Translate point to the origin
  3403. p[0] = a[0] - b[0];
  3404. p[1] = a[1] - b[1];
  3405. p[2] = a[2] - b[2];
  3406. //perform rotation
  3407. r[0] = p[0];
  3408. r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c);
  3409. r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c);
  3410. //translate to correct position
  3411. out[0] = r[0] + b[0];
  3412. out[1] = r[1] + b[1];
  3413. out[2] = r[2] + b[2];
  3414. return out;
  3415. };
  3416. /**
  3417. * Rotate a 3D vector around the y-axis
  3418. * @param {vec3} out The receiving vec3
  3419. * @param {vec3} a The vec3 point to rotate
  3420. * @param {vec3} b The origin of the rotation
  3421. * @param {Number} c The angle of rotation
  3422. * @returns {vec3} out
  3423. */
  3424. vec3.rotateY = function(out, a, b, c){
  3425. var p = [], r=[];
  3426. //Translate point to the origin
  3427. p[0] = a[0] - b[0];
  3428. p[1] = a[1] - b[1];
  3429. p[2] = a[2] - b[2];
  3430. //perform rotation
  3431. r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c);
  3432. r[1] = p[1];
  3433. r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c);
  3434. //translate to correct position
  3435. out[0] = r[0] + b[0];
  3436. out[1] = r[1] + b[1];
  3437. out[2] = r[2] + b[2];
  3438. return out;
  3439. };
  3440. /**
  3441. * Rotate a 3D vector around the z-axis
  3442. * @param {vec3} out The receiving vec3
  3443. * @param {vec3} a The vec3 point to rotate
  3444. * @param {vec3} b The origin of the rotation
  3445. * @param {Number} c The angle of rotation
  3446. * @returns {vec3} out
  3447. */
  3448. vec3.rotateZ = function(out, a, b, c){
  3449. var p = [], r=[];
  3450. //Translate point to the origin
  3451. p[0] = a[0] - b[0];
  3452. p[1] = a[1] - b[1];
  3453. p[2] = a[2] - b[2];
  3454. //perform rotation
  3455. r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c);
  3456. r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c);
  3457. r[2] = p[2];
  3458. //translate to correct position
  3459. out[0] = r[0] + b[0];
  3460. out[1] = r[1] + b[1];
  3461. out[2] = r[2] + b[2];
  3462. return out;
  3463. };
  3464. /**
  3465. * Perform some operation over an array of vec3s.
  3466. *
  3467. * @param {Array} a the array of vectors to iterate over
  3468. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  3469. * @param {Number} offset Number of elements to skip at the beginning of the array
  3470. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  3471. * @param {Function} fn Function to call for each vector in the array
  3472. * @param {Object} [arg] additional argument to pass to fn
  3473. * @returns {Array} a
  3474. * @function
  3475. */
  3476. vec3.forEach = (function() {
  3477. var vec = vec3.create();
  3478. return function(a, stride, offset, count, fn, arg) {
  3479. var i, l;
  3480. if(!stride) {
  3481. stride = 3;
  3482. }
  3483. if(!offset) {
  3484. offset = 0;
  3485. }
  3486. if(count) {
  3487. l = Math.min((count * stride) + offset, a.length);
  3488. } else {
  3489. l = a.length;
  3490. }
  3491. for(i = offset; i < l; i += stride) {
  3492. vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];
  3493. fn(vec, vec, arg);
  3494. a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];
  3495. }
  3496. return a;
  3497. };
  3498. })();
  3499. /**
  3500. * Get the angle between two 3D vectors
  3501. * @param {vec3} a The first operand
  3502. * @param {vec3} b The second operand
  3503. * @returns {Number} The angle in radians
  3504. */
  3505. vec3.angle = function(a, b) {
  3506. var tempA = vec3.fromValues(a[0], a[1], a[2]);
  3507. var tempB = vec3.fromValues(b[0], b[1], b[2]);
  3508. vec3.normalize(tempA, tempA);
  3509. vec3.normalize(tempB, tempB);
  3510. var cosine = vec3.dot(tempA, tempB);
  3511. if(cosine > 1.0){
  3512. return 0;
  3513. } else {
  3514. return Math.acos(cosine);
  3515. }
  3516. };
  3517. /**
  3518. * Returns a string representation of a vector
  3519. *
  3520. * @param {vec3} vec vector to represent as a string
  3521. * @returns {String} string representation of the vector
  3522. */
  3523. vec3.str = function (a) {
  3524. return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';
  3525. };
  3526. module.exports = vec3;
  3527. /***/ },
  3528. /* 8 */
  3529. /***/ function(module, exports, __webpack_require__) {
  3530. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  3531. Permission is hereby granted, free of charge, to any person obtaining a copy
  3532. of this software and associated documentation files (the "Software"), to deal
  3533. in the Software without restriction, including without limitation the rights
  3534. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3535. copies of the Software, and to permit persons to whom the Software is
  3536. furnished to do so, subject to the following conditions:
  3537. The above copyright notice and this permission notice shall be included in
  3538. all copies or substantial portions of the Software.
  3539. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3540. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3541. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3542. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3543. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3544. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3545. THE SOFTWARE. */
  3546. var glMatrix = __webpack_require__(1);
  3547. /**
  3548. * @class 4 Dimensional Vector
  3549. * @name vec4
  3550. */
  3551. var vec4 = {};
  3552. /**
  3553. * Creates a new, empty vec4
  3554. *
  3555. * @returns {vec4} a new 4D vector
  3556. */
  3557. vec4.create = function() {
  3558. var out = new glMatrix.ARRAY_TYPE(4);
  3559. out[0] = 0;
  3560. out[1] = 0;
  3561. out[2] = 0;
  3562. out[3] = 0;
  3563. return out;
  3564. };
  3565. /**
  3566. * Creates a new vec4 initialized with values from an existing vector
  3567. *
  3568. * @param {vec4} a vector to clone
  3569. * @returns {vec4} a new 4D vector
  3570. */
  3571. vec4.clone = function(a) {
  3572. var out = new glMatrix.ARRAY_TYPE(4);
  3573. out[0] = a[0];
  3574. out[1] = a[1];
  3575. out[2] = a[2];
  3576. out[3] = a[3];
  3577. return out;
  3578. };
  3579. /**
  3580. * Creates a new vec4 initialized with the given values
  3581. *
  3582. * @param {Number} x X component
  3583. * @param {Number} y Y component
  3584. * @param {Number} z Z component
  3585. * @param {Number} w W component
  3586. * @returns {vec4} a new 4D vector
  3587. */
  3588. vec4.fromValues = function(x, y, z, w) {
  3589. var out = new glMatrix.ARRAY_TYPE(4);
  3590. out[0] = x;
  3591. out[1] = y;
  3592. out[2] = z;
  3593. out[3] = w;
  3594. return out;
  3595. };
  3596. /**
  3597. * Copy the values from one vec4 to another
  3598. *
  3599. * @param {vec4} out the receiving vector
  3600. * @param {vec4} a the source vector
  3601. * @returns {vec4} out
  3602. */
  3603. vec4.copy = function(out, a) {
  3604. out[0] = a[0];
  3605. out[1] = a[1];
  3606. out[2] = a[2];
  3607. out[3] = a[3];
  3608. return out;
  3609. };
  3610. /**
  3611. * Set the components of a vec4 to the given values
  3612. *
  3613. * @param {vec4} out the receiving vector
  3614. * @param {Number} x X component
  3615. * @param {Number} y Y component
  3616. * @param {Number} z Z component
  3617. * @param {Number} w W component
  3618. * @returns {vec4} out
  3619. */
  3620. vec4.set = function(out, x, y, z, w) {
  3621. out[0] = x;
  3622. out[1] = y;
  3623. out[2] = z;
  3624. out[3] = w;
  3625. return out;
  3626. };
  3627. /**
  3628. * Adds two vec4's
  3629. *
  3630. * @param {vec4} out the receiving vector
  3631. * @param {vec4} a the first operand
  3632. * @param {vec4} b the second operand
  3633. * @returns {vec4} out
  3634. */
  3635. vec4.add = function(out, a, b) {
  3636. out[0] = a[0] + b[0];
  3637. out[1] = a[1] + b[1];
  3638. out[2] = a[2] + b[2];
  3639. out[3] = a[3] + b[3];
  3640. return out;
  3641. };
  3642. /**
  3643. * Subtracts vector b from vector a
  3644. *
  3645. * @param {vec4} out the receiving vector
  3646. * @param {vec4} a the first operand
  3647. * @param {vec4} b the second operand
  3648. * @returns {vec4} out
  3649. */
  3650. vec4.subtract = function(out, a, b) {
  3651. out[0] = a[0] - b[0];
  3652. out[1] = a[1] - b[1];
  3653. out[2] = a[2] - b[2];
  3654. out[3] = a[3] - b[3];
  3655. return out;
  3656. };
  3657. /**
  3658. * Alias for {@link vec4.subtract}
  3659. * @function
  3660. */
  3661. vec4.sub = vec4.subtract;
  3662. /**
  3663. * Multiplies two vec4's
  3664. *
  3665. * @param {vec4} out the receiving vector
  3666. * @param {vec4} a the first operand
  3667. * @param {vec4} b the second operand
  3668. * @returns {vec4} out
  3669. */
  3670. vec4.multiply = function(out, a, b) {
  3671. out[0] = a[0] * b[0];
  3672. out[1] = a[1] * b[1];
  3673. out[2] = a[2] * b[2];
  3674. out[3] = a[3] * b[3];
  3675. return out;
  3676. };
  3677. /**
  3678. * Alias for {@link vec4.multiply}
  3679. * @function
  3680. */
  3681. vec4.mul = vec4.multiply;
  3682. /**
  3683. * Divides two vec4's
  3684. *
  3685. * @param {vec4} out the receiving vector
  3686. * @param {vec4} a the first operand
  3687. * @param {vec4} b the second operand
  3688. * @returns {vec4} out
  3689. */
  3690. vec4.divide = function(out, a, b) {
  3691. out[0] = a[0] / b[0];
  3692. out[1] = a[1] / b[1];
  3693. out[2] = a[2] / b[2];
  3694. out[3] = a[3] / b[3];
  3695. return out;
  3696. };
  3697. /**
  3698. * Alias for {@link vec4.divide}
  3699. * @function
  3700. */
  3701. vec4.div = vec4.divide;
  3702. /**
  3703. * Returns the minimum of two vec4's
  3704. *
  3705. * @param {vec4} out the receiving vector
  3706. * @param {vec4} a the first operand
  3707. * @param {vec4} b the second operand
  3708. * @returns {vec4} out
  3709. */
  3710. vec4.min = function(out, a, b) {
  3711. out[0] = Math.min(a[0], b[0]);
  3712. out[1] = Math.min(a[1], b[1]);
  3713. out[2] = Math.min(a[2], b[2]);
  3714. out[3] = Math.min(a[3], b[3]);
  3715. return out;
  3716. };
  3717. /**
  3718. * Returns the maximum of two vec4's
  3719. *
  3720. * @param {vec4} out the receiving vector
  3721. * @param {vec4} a the first operand
  3722. * @param {vec4} b the second operand
  3723. * @returns {vec4} out
  3724. */
  3725. vec4.max = function(out, a, b) {
  3726. out[0] = Math.max(a[0], b[0]);
  3727. out[1] = Math.max(a[1], b[1]);
  3728. out[2] = Math.max(a[2], b[2]);
  3729. out[3] = Math.max(a[3], b[3]);
  3730. return out;
  3731. };
  3732. /**
  3733. * Scales a vec4 by a scalar number
  3734. *
  3735. * @param {vec4} out the receiving vector
  3736. * @param {vec4} a the vector to scale
  3737. * @param {Number} b amount to scale the vector by
  3738. * @returns {vec4} out
  3739. */
  3740. vec4.scale = function(out, a, b) {
  3741. out[0] = a[0] * b;
  3742. out[1] = a[1] * b;
  3743. out[2] = a[2] * b;
  3744. out[3] = a[3] * b;
  3745. return out;
  3746. };
  3747. /**
  3748. * Adds two vec4's after scaling the second operand by a scalar value
  3749. *
  3750. * @param {vec4} out the receiving vector
  3751. * @param {vec4} a the first operand
  3752. * @param {vec4} b the second operand
  3753. * @param {Number} scale the amount to scale b by before adding
  3754. * @returns {vec4} out
  3755. */
  3756. vec4.scaleAndAdd = function(out, a, b, scale) {
  3757. out[0] = a[0] + (b[0] * scale);
  3758. out[1] = a[1] + (b[1] * scale);
  3759. out[2] = a[2] + (b[2] * scale);
  3760. out[3] = a[3] + (b[3] * scale);
  3761. return out;
  3762. };
  3763. /**
  3764. * Calculates the euclidian distance between two vec4's
  3765. *
  3766. * @param {vec4} a the first operand
  3767. * @param {vec4} b the second operand
  3768. * @returns {Number} distance between a and b
  3769. */
  3770. vec4.distance = function(a, b) {
  3771. var x = b[0] - a[0],
  3772. y = b[1] - a[1],
  3773. z = b[2] - a[2],
  3774. w = b[3] - a[3];
  3775. return Math.sqrt(x*x + y*y + z*z + w*w);
  3776. };
  3777. /**
  3778. * Alias for {@link vec4.distance}
  3779. * @function
  3780. */
  3781. vec4.dist = vec4.distance;
  3782. /**
  3783. * Calculates the squared euclidian distance between two vec4's
  3784. *
  3785. * @param {vec4} a the first operand
  3786. * @param {vec4} b the second operand
  3787. * @returns {Number} squared distance between a and b
  3788. */
  3789. vec4.squaredDistance = function(a, b) {
  3790. var x = b[0] - a[0],
  3791. y = b[1] - a[1],
  3792. z = b[2] - a[2],
  3793. w = b[3] - a[3];
  3794. return x*x + y*y + z*z + w*w;
  3795. };
  3796. /**
  3797. * Alias for {@link vec4.squaredDistance}
  3798. * @function
  3799. */
  3800. vec4.sqrDist = vec4.squaredDistance;
  3801. /**
  3802. * Calculates the length of a vec4
  3803. *
  3804. * @param {vec4} a vector to calculate length of
  3805. * @returns {Number} length of a
  3806. */
  3807. vec4.length = function (a) {
  3808. var x = a[0],
  3809. y = a[1],
  3810. z = a[2],
  3811. w = a[3];
  3812. return Math.sqrt(x*x + y*y + z*z + w*w);
  3813. };
  3814. /**
  3815. * Alias for {@link vec4.length}
  3816. * @function
  3817. */
  3818. vec4.len = vec4.length;
  3819. /**
  3820. * Calculates the squared length of a vec4
  3821. *
  3822. * @param {vec4} a vector to calculate squared length of
  3823. * @returns {Number} squared length of a
  3824. */
  3825. vec4.squaredLength = function (a) {
  3826. var x = a[0],
  3827. y = a[1],
  3828. z = a[2],
  3829. w = a[3];
  3830. return x*x + y*y + z*z + w*w;
  3831. };
  3832. /**
  3833. * Alias for {@link vec4.squaredLength}
  3834. * @function
  3835. */
  3836. vec4.sqrLen = vec4.squaredLength;
  3837. /**
  3838. * Negates the components of a vec4
  3839. *
  3840. * @param {vec4} out the receiving vector
  3841. * @param {vec4} a vector to negate
  3842. * @returns {vec4} out
  3843. */
  3844. vec4.negate = function(out, a) {
  3845. out[0] = -a[0];
  3846. out[1] = -a[1];
  3847. out[2] = -a[2];
  3848. out[3] = -a[3];
  3849. return out;
  3850. };
  3851. /**
  3852. * Returns the inverse of the components of a vec4
  3853. *
  3854. * @param {vec4} out the receiving vector
  3855. * @param {vec4} a vector to invert
  3856. * @returns {vec4} out
  3857. */
  3858. vec4.inverse = function(out, a) {
  3859. out[0] = 1.0 / a[0];
  3860. out[1] = 1.0 / a[1];
  3861. out[2] = 1.0 / a[2];
  3862. out[3] = 1.0 / a[3];
  3863. return out;
  3864. };
  3865. /**
  3866. * Normalize a vec4
  3867. *
  3868. * @param {vec4} out the receiving vector
  3869. * @param {vec4} a vector to normalize
  3870. * @returns {vec4} out
  3871. */
  3872. vec4.normalize = function(out, a) {
  3873. var x = a[0],
  3874. y = a[1],
  3875. z = a[2],
  3876. w = a[3];
  3877. var len = x*x + y*y + z*z + w*w;
  3878. if (len > 0) {
  3879. len = 1 / Math.sqrt(len);
  3880. out[0] = x * len;
  3881. out[1] = y * len;
  3882. out[2] = z * len;
  3883. out[3] = w * len;
  3884. }
  3885. return out;
  3886. };
  3887. /**
  3888. * Calculates the dot product of two vec4's
  3889. *
  3890. * @param {vec4} a the first operand
  3891. * @param {vec4} b the second operand
  3892. * @returns {Number} dot product of a and b
  3893. */
  3894. vec4.dot = function (a, b) {
  3895. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  3896. };
  3897. /**
  3898. * Performs a linear interpolation between two vec4's
  3899. *
  3900. * @param {vec4} out the receiving vector
  3901. * @param {vec4} a the first operand
  3902. * @param {vec4} b the second operand
  3903. * @param {Number} t interpolation amount between the two inputs
  3904. * @returns {vec4} out
  3905. */
  3906. vec4.lerp = function (out, a, b, t) {
  3907. var ax = a[0],
  3908. ay = a[1],
  3909. az = a[2],
  3910. aw = a[3];
  3911. out[0] = ax + t * (b[0] - ax);
  3912. out[1] = ay + t * (b[1] - ay);
  3913. out[2] = az + t * (b[2] - az);
  3914. out[3] = aw + t * (b[3] - aw);
  3915. return out;
  3916. };
  3917. /**
  3918. * Generates a random vector with the given scale
  3919. *
  3920. * @param {vec4} out the receiving vector
  3921. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  3922. * @returns {vec4} out
  3923. */
  3924. vec4.random = function (out, scale) {
  3925. scale = scale || 1.0;
  3926. //TODO: This is a pretty awful way of doing this. Find something better.
  3927. out[0] = glMatrix.RANDOM();
  3928. out[1] = glMatrix.RANDOM();
  3929. out[2] = glMatrix.RANDOM();
  3930. out[3] = glMatrix.RANDOM();
  3931. vec4.normalize(out, out);
  3932. vec4.scale(out, out, scale);
  3933. return out;
  3934. };
  3935. /**
  3936. * Transforms the vec4 with a mat4.
  3937. *
  3938. * @param {vec4} out the receiving vector
  3939. * @param {vec4} a the vector to transform
  3940. * @param {mat4} m matrix to transform with
  3941. * @returns {vec4} out
  3942. */
  3943. vec4.transformMat4 = function(out, a, m) {
  3944. var x = a[0], y = a[1], z = a[2], w = a[3];
  3945. out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
  3946. out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
  3947. out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
  3948. out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
  3949. return out;
  3950. };
  3951. /**
  3952. * Transforms the vec4 with a quat
  3953. *
  3954. * @param {vec4} out the receiving vector
  3955. * @param {vec4} a the vector to transform
  3956. * @param {quat} q quaternion to transform with
  3957. * @returns {vec4} out
  3958. */
  3959. vec4.transformQuat = function(out, a, q) {
  3960. var x = a[0], y = a[1], z = a[2],
  3961. qx = q[0], qy = q[1], qz = q[2], qw = q[3],
  3962. // calculate quat * vec
  3963. ix = qw * x + qy * z - qz * y,
  3964. iy = qw * y + qz * x - qx * z,
  3965. iz = qw * z + qx * y - qy * x,
  3966. iw = -qx * x - qy * y - qz * z;
  3967. // calculate result * inverse quat
  3968. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3969. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3970. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3971. out[3] = a[3];
  3972. return out;
  3973. };
  3974. /**
  3975. * Perform some operation over an array of vec4s.
  3976. *
  3977. * @param {Array} a the array of vectors to iterate over
  3978. * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
  3979. * @param {Number} offset Number of elements to skip at the beginning of the array
  3980. * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
  3981. * @param {Function} fn Function to call for each vector in the array
  3982. * @param {Object} [arg] additional argument to pass to fn
  3983. * @returns {Array} a
  3984. * @function
  3985. */
  3986. vec4.forEach = (function() {
  3987. var vec = vec4.create();
  3988. return function(a, stride, offset, count, fn, arg) {
  3989. var i, l;
  3990. if(!stride) {
  3991. stride = 4;
  3992. }
  3993. if(!offset) {
  3994. offset = 0;
  3995. }
  3996. if(count) {
  3997. l = Math.min((count * stride) + offset, a.length);
  3998. } else {
  3999. l = a.length;
  4000. }
  4001. for(i = offset; i < l; i += stride) {
  4002. vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3];
  4003. fn(vec, vec, arg);
  4004. a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3];
  4005. }
  4006. return a;
  4007. };
  4008. })();
  4009. /**
  4010. * Returns a string representation of a vector
  4011. *
  4012. * @param {vec4} vec vector to represent as a string
  4013. * @returns {String} string representation of the vector
  4014. */
  4015. vec4.str = function (a) {
  4016. return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
  4017. };
  4018. module.exports = vec4;
  4019. /***/ },
  4020. /* 9 */
  4021. /***/ function(module, exports, __webpack_require__) {
  4022. /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  4023. Permission is hereby granted, free of charge, to any person obtaining a copy
  4024. of this software and associated documentation files (the "Software"), to deal
  4025. in the Software without restriction, including without limitation the rights
  4026. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4027. copies of the Software, and to permit persons to whom the Software is
  4028. furnished to do so, subject to the following conditions:
  4029. The above copyright notice and this permission notice shall be included in
  4030. all copies or substantial portions of the Software.
  4031. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4032. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4033. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4034. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4035. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4036. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4037. THE SOFTWARE. */
  4038. var glMatrix = __webpack_require__(1);
  4039. /**
  4040. * @class 2 Dimensional Vector
  4041. * @name vec2
  4042. */
  4043. var vec2 = {};
  4044. /**
  4045. * Creates a new, empty vec2
  4046. *
  4047. * @returns {vec2} a new 2D vector
  4048. */
  4049. vec2.create = function() {
  4050. var out = new glMatrix.ARRAY_TYPE(2);
  4051. out[0] = 0;
  4052. out[1] = 0;
  4053. return out;
  4054. };
  4055. /**
  4056. * Creates a new vec2 initialized with values from an existing vector
  4057. *
  4058. * @param {vec2} a vector to clone
  4059. * @returns {vec2} a new 2D vector
  4060. */
  4061. vec2.clone = function(a) {
  4062. var out = new glMatrix.ARRAY_TYPE(2);
  4063. out[0] = a[0];
  4064. out[1] = a[1];
  4065. return out;
  4066. };
  4067. /**
  4068. * Creates a new vec2 initialized with the given values
  4069. *
  4070. * @param {Number} x X component
  4071. * @param {Number} y Y component
  4072. * @returns {vec2} a new 2D vector
  4073. */
  4074. vec2.fromValues = function(x, y) {
  4075. var out = new glMatrix.ARRAY_TYPE(2);
  4076. out[0] = x;
  4077. out[1] = y;
  4078. return out;
  4079. };
  4080. /**
  4081. * Copy the values from one vec2 to another
  4082. *
  4083. * @param {vec2} out the receiving vector
  4084. * @param {vec2} a the source vector
  4085. * @returns {vec2} out
  4086. */
  4087. vec2.copy = function(out, a) {
  4088. out[0] = a[0];
  4089. out[1] = a[1];
  4090. return out;
  4091. };
  4092. /**
  4093. * Set the components of a vec2 to the given values
  4094. *
  4095. * @param {vec2} out the receiving vector
  4096. * @param {Number} x X component
  4097. * @param {Number} y Y component
  4098. * @returns {vec2} out
  4099. */
  4100. vec2.set = function(out, x, y) {
  4101. out[0] = x;
  4102. out[1] = y;
  4103. return out;
  4104. };
  4105. /**
  4106. * Adds two vec2's
  4107. *
  4108. * @param {vec2} out the receiving vector
  4109. * @param {vec2} a the first operand
  4110. * @param {vec2} b the second operand
  4111. * @returns {vec2} out
  4112. */
  4113. vec2.add = function(out, a, b) {
  4114. out[0] = a[0] + b[0];
  4115. out[1] = a[1] + b[1];
  4116. return out;
  4117. };
  4118. /**
  4119. * Subtracts vector b from vector a
  4120. *
  4121. * @param {vec2} out the receiving vector
  4122. * @param {vec2} a the first operand
  4123. * @param {vec2} b the second operand
  4124. * @returns {vec2} out
  4125. */
  4126. vec2.subtract = function(out, a, b) {
  4127. out[0] = a[0] - b[0];
  4128. out[1] = a[1] - b[1];
  4129. return out;
  4130. };
  4131. /**
  4132. * Alias for {@link vec2.subtract}
  4133. * @function
  4134. */
  4135. vec2.sub = vec2.subtract;
  4136. /**
  4137. * Multiplies two vec2's
  4138. *
  4139. * @param {vec2} out the receiving vector
  4140. * @param {vec2} a the first operand
  4141. * @param {vec2} b the second operand
  4142. * @returns {vec2} out
  4143. */
  4144. vec2.multiply = function(out, a, b) {
  4145. out[0] = a[0] * b[0];
  4146. out[1] = a[1] * b[1];
  4147. return out;
  4148. };
  4149. /**
  4150. * Alias for {@link vec2.multiply}
  4151. * @function
  4152. */
  4153. vec2.mul = vec2.multiply;
  4154. /**
  4155. * Divides two vec2's
  4156. *
  4157. * @param {vec2} out the receiving vector
  4158. * @param {vec2} a the first operand
  4159. * @param {vec2} b the second operand
  4160. * @returns {vec2} out
  4161. */
  4162. vec2.divide = function(out, a, b) {
  4163. out[0] = a[0] / b[0];
  4164. out[1] = a[1] / b[1];
  4165. return out;
  4166. };
  4167. /**
  4168. * Alias for {@link vec2.divide}
  4169. * @function
  4170. */
  4171. vec2.div = vec2.divide;
  4172. /**
  4173. * Returns the minimum of two vec2's
  4174. *
  4175. * @param {vec2} out the receiving vector
  4176. * @param {vec2} a the first operand
  4177. * @param {vec2} b the second operand
  4178. * @returns {vec2} out
  4179. */
  4180. vec2.min = function(out, a, b) {
  4181. out[0] = Math.min(a[0], b[0]);
  4182. out[1] = Math.min(a[1], b[1]);
  4183. return out;
  4184. };
  4185. /**
  4186. * Returns the maximum of two vec2's
  4187. *
  4188. * @param {vec2} out the receiving vector
  4189. * @param {vec2} a the first operand
  4190. * @param {vec2} b the second operand
  4191. * @returns {vec2} out
  4192. */
  4193. vec2.max = function(out, a, b) {
  4194. out[0] = Math.max(a[0], b[0]);
  4195. out[1] = Math.max(a[1], b[1]);
  4196. return out;
  4197. };
  4198. /**
  4199. * Scales a vec2 by a scalar number
  4200. *
  4201. * @param {vec2} out the receiving vector
  4202. * @param {vec2} a the vector to scale
  4203. * @param {Number} b amount to scale the vector by
  4204. * @returns {vec2} out
  4205. */
  4206. vec2.scale = function(out, a, b) {
  4207. out[0] = a[0] * b;
  4208. out[1] = a[1] * b;
  4209. return out;
  4210. };
  4211. /**
  4212. * Adds two vec2's after scaling the second operand by a scalar value
  4213. *
  4214. * @param {vec2} out the receiving vector
  4215. * @param {vec2} a the first operand
  4216. * @param {vec2} b the second operand
  4217. * @param {Number} scale the amount to scale b by before adding
  4218. * @returns {vec2} out
  4219. */
  4220. vec2.scaleAndAdd = function(out, a, b, scale) {
  4221. out[0] = a[0] + (b[0] * scale);
  4222. out[1] = a[1] + (b[1] * scale);
  4223. return out;
  4224. };
  4225. /**
  4226. * Calculates the euclidian distance between two vec2's
  4227. *
  4228. * @param {vec2} a the first operand
  4229. * @param {vec2} b the second operand
  4230. * @returns {Number} distance between a and b
  4231. */
  4232. vec2.distance = function(a, b) {
  4233. var x = b[0] - a[0],
  4234. y = b[1] - a[1];
  4235. return Math.sqrt(x*x + y*y);
  4236. };
  4237. /**
  4238. * Alias for {@link vec2.distance}
  4239. * @function
  4240. */
  4241. vec2.dist = vec2.distance;
  4242. /**
  4243. * Calculates the squared euclidian distance between two vec2's
  4244. *
  4245. * @param {vec2} a the first operand
  4246. * @param {vec2} b the second operand
  4247. * @returns {Number} squared distance between a and b
  4248. */
  4249. vec2.squaredDistance = function(a, b) {
  4250. var x = b[0] - a[0],
  4251. y = b[1] - a[1];
  4252. return x*x + y*y;
  4253. };
  4254. /**
  4255. * Alias for {@link vec2.squaredDistance}
  4256. * @function
  4257. */
  4258. vec2.sqrDist = vec2.squaredDistance;
  4259. /**
  4260. * Calculates the length of a vec2
  4261. *
  4262. * @param {vec2} a vector to calculate length of
  4263. * @returns {Number} length of a
  4264. */
  4265. vec2.length = function (a) {
  4266. var x = a[0],
  4267. y = a[1];
  4268. return Math.sqrt(x*x + y*y);
  4269. };
  4270. /**
  4271. * Alias for {@link vec2.length}
  4272. * @function
  4273. */
  4274. vec2.len = vec2.length;
  4275. /**
  4276. * Calculates the squared length of a vec2
  4277. *
  4278. * @param {vec2} a vector to calculate squared length of
  4279. * @returns {Number} squared length of a
  4280. */
  4281. vec2.squaredLength = function (a) {
  4282. var x = a[0],
  4283. y = a[1];
  4284. return x*x + y*y;
  4285. };
  4286. /**
  4287. * Alias for {@link vec2.squaredLength}
  4288. * @function
  4289. */
  4290. vec2.sqrLen = vec2.squaredLength;
  4291. /**
  4292. * Negates the components of a vec2
  4293. *
  4294. * @param {vec2} out the receiving vector
  4295. * @param {vec2} a vector to negate
  4296. * @returns {vec2} out
  4297. */
  4298. vec2.negate = function(out, a) {
  4299. out[0] = -a[0];
  4300. out[1] = -a[1];
  4301. return out;
  4302. };
  4303. /**
  4304. * Returns the inverse of the components of a vec2
  4305. *
  4306. * @param {vec2} out the receiving vector
  4307. * @param {vec2} a vector to invert
  4308. * @returns {vec2} out
  4309. */
  4310. vec2.inverse = function(out, a) {
  4311. out[0] = 1.0 / a[0];
  4312. out[1] = 1.0 / a[1];
  4313. return out;
  4314. };
  4315. /**
  4316. * Normalize a vec2
  4317. *
  4318. * @param {vec2} out the receiving vector
  4319. * @param {vec2} a vector to normalize
  4320. * @returns {vec2} out
  4321. */
  4322. vec2.normalize = function(out, a) {
  4323. var x = a[0],
  4324. y = a[1];
  4325. var len = x*x + y*y;
  4326. if (len > 0) {
  4327. //TODO: evaluate use of glm_invsqrt here?
  4328. len = 1 / Math.sqrt(len);
  4329. out[0] = a[0] * len;
  4330. out[1] = a[1] * len;
  4331. }
  4332. return out;
  4333. };
  4334. /**
  4335. * Calculates the dot product of two vec2's
  4336. *
  4337. * @param {vec2} a the first operand
  4338. * @param {vec2} b the second operand
  4339. * @returns {Number} dot product of a and b
  4340. */
  4341. vec2.dot = function (a, b) {
  4342. return a[0] * b[0] + a[1] * b[1];
  4343. };
  4344. /**
  4345. * Computes the cross product of two vec2's
  4346. * Note that the cross product must by definition produce a 3D vector
  4347. *
  4348. * @param {vec3} out the receiving vector
  4349. * @param {vec2} a the first operand
  4350. * @param {vec2} b the second operand
  4351. * @returns {vec3} out
  4352. */
  4353. vec2.cross = function(out, a, b) {
  4354. var z = a[0] * b[1] - a[1] * b[0];
  4355. out[0] = out[1] = 0;
  4356. out[2] = z;
  4357. return out;
  4358. };
  4359. /**
  4360. * Performs a linear interpolation between two vec2's
  4361. *
  4362. * @param {vec2} out the receiving vector
  4363. * @param {vec2} a the first operand
  4364. * @param {vec2} b the second operand
  4365. * @param {Number} t interpolation amount between the two inputs
  4366. * @returns {vec2} out
  4367. */
  4368. vec2.lerp = function (out, a, b, t) {
  4369. var ax = a[0],
  4370. ay = a[1];
  4371. out[0] = ax + t * (b[0] - ax);
  4372. out[1] = ay + t * (b[1] - ay);
  4373. return out;
  4374. };
  4375. /**
  4376. * Generates a random vector with the given scale
  4377. *
  4378. * @param {vec2} out the receiving vector
  4379. * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
  4380. * @returns {vec2} out
  4381. */
  4382. vec2.random = function (out, scale) {
  4383. scale = scale || 1.0;
  4384. var r = glMatrix.RANDOM() * 2.0 * Math.PI;
  4385. out[0] = Math.cos(r) * scale;
  4386. out[1] = Math.sin(r) * scale;
  4387. return out;
  4388. };
  4389. /**
  4390. * Transforms the vec2 with a mat2
  4391. *
  4392. * @param {vec2} out the receiving vector
  4393. * @param {vec2} a the vector to transform
  4394. * @param {mat2} m matrix to transform with
  4395. * @returns {vec2} out
  4396. */
  4397. vec2.transformMat2 = function(out, a, m) {
  4398. var x = a[0],
  4399. y = a[1];
  4400. out[0] = m[0] * x + m[2] * y;
  4401. out[1] = m[1] * x + m[3] * y;
  4402. return out;
  4403. };
  4404. /**
  4405. * Transforms the vec2 with a mat2d
  4406. *
  4407. * @param {vec2} out the receiving vector
  4408. * @param {vec2} a the vector to transform
  4409. * @param {mat2d} m matrix to transform with
  4410. * @returns {vec2} out
  4411. */
  4412. vec2.transformMat2d = function(out, a, m) {
  4413. var x = a[0],
  4414. y = a[1];
  4415. out[0] = m[0] * x + m[2] * y + m[4];
  4416. out[1] = m[1] * x + m[3] * y + m[5];
  4417. return out;
  4418. };
  4419. /**
  4420. * Transforms the vec2 with a mat3
  4421. * 3rd vector component is implicitly '1'
  4422. *
  4423. * @param {vec2} out the receiving vector
  4424. * @param {vec2} a the vector to transform
  4425. * @param {mat3} m matrix to transform with
  4426. * @returns {vec2} out
  4427. */
  4428. vec2.transformMat3 = function(out, a, m) {
  4429. var x = a[0],
  4430. y = a[1];
  4431. out[0] = m[0] * x + m[3] * y + m[6];
  4432. out[1] = m[1] * x + m[4] * y + m[7];
  4433. return out;
  4434. };
  4435. /**
  4436. * Transforms the vec2 with a mat4
  4437. * 3rd vector component is implicitly '0'
  4438. * 4th vector component is implicitly '1'
  4439. *
  4440. * @param {vec2} out the receiving vector
  4441. * @param {vec2} a the vector to transform
  4442. * @param {mat4} m matrix to transform with
  4443. * @returns {vec2} out
  4444. */
  4445. vec2.transformMat4 = function(out, a, m) {
  4446. var x = a[0],
  4447. y = a[1];
  4448. out[0] = m[0] * x + m[4] * y + m[12];
  4449. out[1] = m[1] * x + m[5] * y + m[13];
  4450. return out;
  4451. };
  4452. /**
  4453. * Perform some operation over an array of vec2s.
  4454. *
  4455. * @param {Array} a the array of vectors to iterate over
  4456. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  4457. * @param {Number} offset Number of elements to skip at the beginning of the array
  4458. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  4459. * @param {Function} fn Function to call for each vector in the array
  4460. * @param {Object} [arg] additional argument to pass to fn
  4461. * @returns {Array} a
  4462. * @function
  4463. */
  4464. vec2.forEach = (function() {
  4465. var vec = vec2.create();
  4466. return function(a, stride, offset, count, fn, arg) {
  4467. var i, l;
  4468. if(!stride) {
  4469. stride = 2;
  4470. }
  4471. if(!offset) {
  4472. offset = 0;
  4473. }
  4474. if(count) {
  4475. l = Math.min((count * stride) + offset, a.length);
  4476. } else {
  4477. l = a.length;
  4478. }
  4479. for(i = offset; i < l; i += stride) {
  4480. vec[0] = a[i]; vec[1] = a[i+1];
  4481. fn(vec, vec, arg);
  4482. a[i] = vec[0]; a[i+1] = vec[1];
  4483. }
  4484. return a;
  4485. };
  4486. })();
  4487. /**
  4488. * Returns a string representation of a vector
  4489. *
  4490. * @param {vec2} vec vector to represent as a string
  4491. * @returns {String} string representation of the vector
  4492. */
  4493. vec2.str = function (a) {
  4494. return 'vec2(' + a[0] + ', ' + a[1] + ')';
  4495. };
  4496. module.exports = vec2;
  4497. /***/ }
  4498. /******/ ])
  4499. });
  4500. ;