box2d.js_c 325 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942
  1. var performance = performance || {};
  2. performance.now = function() {
  3. return performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || Date.now
  4. }();
  5. function Benchmark(a, c, b, d, e, f, g, h, l) {
  6. this.name = a;
  7. this.doWarmup = c;
  8. this.doDeterministic = b;
  9. this.deterministicIterations = d;
  10. this.run = e;
  11. this.Setup = f ? f : function() {};
  12. this.TearDown = g ? g : function() {};
  13. this.rmsResult = h ? h : null;
  14. this.minIterations = l ? l : 32
  15. }
  16. function BenchmarkResult(a, c, b) {
  17. this.benchmark = a;
  18. this.time = c;
  19. this.latency = b
  20. }
  21. BenchmarkResult.prototype.valueOf = function() {
  22. return this.time
  23. };
  24. function BenchmarkSuite(a, c, b) {
  25. this.name = a;
  26. this.reference = c;
  27. this.benchmarks = b;
  28. BenchmarkSuite.suites.push(this)
  29. }
  30. BenchmarkSuite.suites = [];
  31. BenchmarkSuite.version = "9";
  32. BenchmarkSuite.config = {
  33. doWarmup: void 0,
  34. doDeterministic: void 0
  35. };
  36. alert = function(a) {
  37. throw "Alert called with argument: " + a;
  38. };
  39. BenchmarkSuite.ResetRNG = function() {
  40. Math.random = function() {
  41. var a = 49734321;
  42. return function() {
  43. a = a + 2127912214 + (a << 12) & 4294967295;
  44. a = (a ^ 3345072700 ^ a >>> 19) & 4294967295;
  45. a = a + 374761393 + (a << 5) & 4294967295;
  46. a = (a + 3550635116 ^ a << 9) & 4294967295;
  47. a = a + 4251993797 + (a << 3) & 4294967295;
  48. a = (a ^ 3042594569 ^ a >>> 16) & 4294967295;
  49. return (a & 268435455) / 268435456
  50. }
  51. }()
  52. };
  53. BenchmarkSuite.RunSuites = function(a, c) {
  54. function b() {
  55. for (; d || g < f;) {
  56. if (d) d = d();
  57. else {
  58. var h = e[g++];
  59. a.NotifyStart && a.NotifyStart(h.name); - 1 < c.indexOf(h.name) ? h.NotifySkipped(a) : d = h.RunStep(a)
  60. }
  61. if (d && "undefined" != typeof window && window.setTimeout) {
  62. window.setTimeout(b, 25);
  63. return
  64. }
  65. }
  66. a.NotifyScore && (h = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores), h = BenchmarkSuite.FormatScore(100 * h), a.NotifyScore(h))
  67. }
  68. c = "undefined" === typeof c ? [] : c;
  69. var d = null,
  70. e = BenchmarkSuite.suites,
  71. f = e.length;
  72. BenchmarkSuite.scores = [];
  73. var g =
  74. 0;
  75. b()
  76. };
  77. BenchmarkSuite.CountBenchmarks = function() {
  78. for (var a = 0, c = BenchmarkSuite.suites, b = 0; b < c.length; b++) a += c[b].benchmarks.length;
  79. return a
  80. };
  81. BenchmarkSuite.GeometricMean = function(a) {
  82. for (var c = 0, b = 0; b < a.length; b++) c += Math.log(a[b]);
  83. return Math.pow(Math.E, c / a.length)
  84. };
  85. BenchmarkSuite.GeometricMeanTime = function(a) {
  86. for (var c = 0, b = 0; b < a.length; b++) c += Math.log(a[b].time);
  87. return Math.pow(Math.E, c / a.length)
  88. };
  89. BenchmarkSuite.GeometricMeanLatency = function(a) {
  90. for (var c = 0, b = !1, d = 0; d < a.length; d++) 0 != a[d].latency && (c += Math.log(a[d].latency), b = !0);
  91. return b ? Math.pow(Math.E, c / a.length) : 0
  92. };
  93. BenchmarkSuite.FormatScore = function(a) {
  94. return 100 < a ? a.toFixed(0) : a.toPrecision(3)
  95. };
  96. BenchmarkSuite.prototype.NotifyStep = function(a) {
  97. this.results.push(a);
  98. this.runner.NotifyStep && this.runner.NotifyStep(a.benchmark.name)
  99. };
  100. BenchmarkSuite.prototype.NotifyResult = function() {
  101. var a = BenchmarkSuite.GeometricMeanTime(this.results),
  102. a = this.reference[0] / a;
  103. BenchmarkSuite.scores.push(a);
  104. this.runner.NotifyResult && (a = BenchmarkSuite.FormatScore(100 * a), this.runner.NotifyResult(this.name, a));
  105. 2 == this.reference.length && (a = BenchmarkSuite.GeometricMeanLatency(this.results), 0 != a && (a = this.reference[1] / a, BenchmarkSuite.scores.push(a), this.runner.NotifyResult && (a = BenchmarkSuite.FormatScore(100 * a), this.runner.NotifyResult(this.name + "Latency",
  106. a))))
  107. };
  108. BenchmarkSuite.prototype.NotifySkipped = function(a) {
  109. BenchmarkSuite.scores.push(1);
  110. a.NotifyResult && a.NotifyResult(this.name, "Skipped")
  111. };
  112. BenchmarkSuite.prototype.NotifyError = function(a) {
  113. this.runner.NotifyError && this.runner.NotifyError(this.name, a);
  114. this.runner.NotifyStep && this.runner.NotifyStep(this.name)
  115. };
  116. BenchmarkSuite.prototype.RunSingleBenchmark = function(a, c) {
  117. function b(b) {
  118. for (var c = 0, d = new Date, f = 0; e ? f < a.deterministicIterations : 1E3 > c; f++) a.run(), c = new Date - d;
  119. null != b && (b.runs += f, b.elapsed += c)
  120. }
  121. var d = BenchmarkSuite.config,
  122. e = void 0 !== d.doDeterministic ? d.doDeterministic : a.doDeterministic;
  123. (void 0 !== d.doWarmup ? d.doWarmup : a.doWarmup) || null != c || (c = {
  124. runs: 0,
  125. elapsed: 0
  126. });
  127. if (null == c) return b(null), {
  128. runs: 0,
  129. elapsed: 0
  130. };
  131. b(c);
  132. if (c.runs < a.minIterations) return c;
  133. var d = 1E3 * c.elapsed / c.runs,
  134. f = null != a.rmsResult ? a.rmsResult() :
  135. 0;
  136. this.NotifyStep(new BenchmarkResult(a, d, f));
  137. return null
  138. };
  139. BenchmarkSuite.prototype.RunStep = function(a) {
  140. function c() {
  141. if (f < e) {
  142. try {
  143. g.benchmarks[f].Setup()
  144. } catch (a) {
  145. return g.NotifyError(a), null
  146. }
  147. return b
  148. }
  149. g.NotifyResult();
  150. return null
  151. }
  152. function b() {
  153. try {
  154. h = g.RunSingleBenchmark(g.benchmarks[f], h)
  155. } catch (a) {
  156. return g.NotifyError(a), null
  157. }
  158. return null == h ? d : b()
  159. }
  160. function d() {
  161. try {
  162. g.benchmarks[f++].TearDown()
  163. } catch (a) {
  164. return g.NotifyError(a), null
  165. }
  166. return c
  167. }
  168. BenchmarkSuite.ResetRNG();
  169. this.results = [];
  170. this.runner = a;
  171. var e = this.benchmarks.length,
  172. f = 0,
  173. g = this,
  174. h;
  175. return c()
  176. };
  177. var Box2D = {};
  178. (function(a, c) {
  179. function b() {}!(Object.defineProperty instanceof Function) && Object.prototype.__defineGetter__ instanceof Function && Object.prototype.__defineSetter__ instanceof Function && (Object.defineProperty = function(a, b, c) {
  180. c.get instanceof Function && a.__defineGetter__(b, c.get);
  181. c.set instanceof Function && a.__defineSetter__(b, c.set)
  182. });
  183. a.inherit = function(a, c) {
  184. b.prototype = c.prototype;
  185. a.prototype = new b;
  186. a.prototype.constructor = a
  187. };
  188. a.generateCallback = function(a, b) {
  189. return function() {
  190. b.apply(a, arguments)
  191. }
  192. };
  193. a.NVector = function(a) {
  194. a === c && (a = 0);
  195. for (var b = Array(a || 0), f = 0; f < a; ++f) b[f] = 0;
  196. return b
  197. };
  198. a.is = function(a, b) {
  199. return null === a ? !1 : b instanceof Function && a instanceof b || a.constructor.__implements != c && a.constructor.__implements[b] ? !0 : !1
  200. };
  201. a.parseUInt = function(a) {
  202. return Math.abs(parseInt(a))
  203. }
  204. })(Box2D);
  205. var Vector = Array,
  206. Vector_a2j_Number = Box2D.NVector;
  207. "undefined" === typeof Box2D && (Box2D = {});
  208. "undefined" === typeof Box2D.Collision && (Box2D.Collision = {});
  209. "undefined" === typeof Box2D.Collision.Shapes && (Box2D.Collision.Shapes = {});
  210. "undefined" === typeof Box2D.Common && (Box2D.Common = {});
  211. "undefined" === typeof Box2D.Common.Math && (Box2D.Common.Math = {});
  212. "undefined" === typeof Box2D.Dynamics && (Box2D.Dynamics = {});
  213. "undefined" === typeof Box2D.Dynamics.Contacts && (Box2D.Dynamics.Contacts = {});
  214. "undefined" === typeof Box2D.Dynamics.Controllers && (Box2D.Dynamics.Controllers = {});
  215. "undefined" === typeof Box2D.Dynamics.Joints && (Box2D.Dynamics.Joints = {});
  216. (function() {
  217. function a() {
  218. a.b2AABB.apply(this, arguments)
  219. }
  220. function c() {
  221. c.b2Bound.apply(this, arguments)
  222. }
  223. function b() {
  224. b.b2BoundValues.apply(this, arguments);
  225. this.constructor === b && this.b2BoundValues.apply(this, arguments)
  226. }
  227. function d() {
  228. d.b2Collision.apply(this, arguments)
  229. }
  230. function e() {
  231. e.b2ContactID.apply(this, arguments);
  232. this.constructor === e && this.b2ContactID.apply(this, arguments)
  233. }
  234. function f() {
  235. f.b2ContactPoint.apply(this, arguments)
  236. }
  237. function g() {
  238. g.b2Distance.apply(this, arguments)
  239. }
  240. function h() {
  241. h.b2DistanceInput.apply(this,
  242. arguments)
  243. }
  244. function l() {
  245. l.b2DistanceOutput.apply(this, arguments)
  246. }
  247. function m() {
  248. m.b2DistanceProxy.apply(this, arguments)
  249. }
  250. function q() {
  251. q.b2DynamicTree.apply(this, arguments);
  252. this.constructor === q && this.b2DynamicTree.apply(this, arguments)
  253. }
  254. function p() {
  255. p.b2DynamicTreeBroadPhase.apply(this, arguments)
  256. }
  257. function y() {
  258. y.b2DynamicTreeNode.apply(this, arguments)
  259. }
  260. function A() {
  261. A.b2DynamicTreePair.apply(this, arguments)
  262. }
  263. function B() {
  264. B.b2Manifold.apply(this, arguments);
  265. this.constructor === B && this.b2Manifold.apply(this, arguments)
  266. }
  267. function K() {
  268. K.b2ManifoldPoint.apply(this, arguments);
  269. this.constructor === K && this.b2ManifoldPoint.apply(this, arguments)
  270. }
  271. function H() {
  272. H.b2Point.apply(this, arguments)
  273. }
  274. function E() {
  275. E.b2RayCastInput.apply(this, arguments);
  276. this.constructor === E && this.b2RayCastInput.apply(this, arguments)
  277. }
  278. function M() {
  279. M.b2RayCastOutput.apply(this, arguments)
  280. }
  281. function Xb() {
  282. Xb.b2Segment.apply(this, arguments)
  283. }
  284. function Zb() {
  285. Zb.b2SeparationFunction.apply(this, arguments)
  286. }
  287. function aa() {
  288. aa.b2Simplex.apply(this, arguments);
  289. this.constructor ===
  290. aa && this.b2Simplex.apply(this, arguments)
  291. }
  292. function Yb() {
  293. Yb.b2SimplexCache.apply(this, arguments)
  294. }
  295. function $b() {
  296. $b.b2SimplexVertex.apply(this, arguments)
  297. }
  298. function ac() {
  299. ac.b2TimeOfImpact.apply(this, arguments)
  300. }
  301. function bc() {
  302. bc.b2TOIInput.apply(this, arguments)
  303. }
  304. function ec() {
  305. ec.b2WorldManifold.apply(this, arguments);
  306. this.constructor === ec && this.b2WorldManifold.apply(this, arguments)
  307. }
  308. function jc() {
  309. jc.ClipVertex.apply(this, arguments)
  310. }
  311. function cc() {
  312. cc.Features.apply(this, arguments)
  313. }
  314. function dc() {
  315. dc.b2CircleShape.apply(this,
  316. arguments);
  317. this.constructor === dc && this.b2CircleShape.apply(this, arguments)
  318. }
  319. function gc() {
  320. gc.b2EdgeChainDef.apply(this, arguments);
  321. this.constructor === gc && this.b2EdgeChainDef.apply(this, arguments)
  322. }
  323. function hc() {
  324. hc.b2EdgeShape.apply(this, arguments);
  325. this.constructor === hc && this.b2EdgeShape.apply(this, arguments)
  326. }
  327. function fc() {
  328. fc.b2MassData.apply(this, arguments)
  329. }
  330. function kc() {
  331. kc.b2PolygonShape.apply(this, arguments);
  332. this.constructor === kc && this.b2PolygonShape.apply(this, arguments)
  333. }
  334. function lc() {
  335. lc.b2Shape.apply(this,
  336. arguments);
  337. this.constructor === lc && this.b2Shape.apply(this, arguments)
  338. }
  339. function mc() {
  340. mc.b2Color.apply(this, arguments);
  341. this.constructor === mc && this.b2Color.apply(this, arguments)
  342. }
  343. function nc() {
  344. nc.b2Settings.apply(this, arguments)
  345. }
  346. function oc() {
  347. oc.b2Mat22.apply(this, arguments);
  348. this.constructor === oc && this.b2Mat22.apply(this, arguments)
  349. }
  350. function qc() {
  351. qc.b2Mat33.apply(this, arguments);
  352. this.constructor === qc && this.b2Mat33.apply(this, arguments)
  353. }
  354. function pc() {
  355. pc.b2Math.apply(this, arguments)
  356. }
  357. function rc() {
  358. rc.b2Sweep.apply(this,
  359. arguments)
  360. }
  361. function uc() {
  362. uc.b2Transform.apply(this, arguments);
  363. this.constructor === uc && this.b2Transform.apply(this, arguments)
  364. }
  365. function wc() {
  366. wc.b2Vec2.apply(this, arguments);
  367. this.constructor === wc && this.b2Vec2.apply(this, arguments)
  368. }
  369. function sc() {
  370. sc.b2Vec3.apply(this, arguments);
  371. this.constructor === sc && this.b2Vec3.apply(this, arguments)
  372. }
  373. function xc() {
  374. xc.b2Body.apply(this, arguments);
  375. this.constructor === xc && this.b2Body.apply(this, arguments)
  376. }
  377. function tc() {
  378. tc.b2BodyDef.apply(this, arguments);
  379. this.constructor ===
  380. tc && this.b2BodyDef.apply(this, arguments)
  381. }
  382. function yc() {
  383. yc.b2ContactFilter.apply(this, arguments)
  384. }
  385. function Ac() {
  386. Ac.b2ContactImpulse.apply(this, arguments)
  387. }
  388. function zc() {
  389. zc.b2ContactListener.apply(this, arguments)
  390. }
  391. function Cc() {
  392. Cc.b2ContactManager.apply(this, arguments);
  393. this.constructor === Cc && this.b2ContactManager.apply(this, arguments)
  394. }
  395. function Bc() {
  396. Bc.b2DebugDraw.apply(this, arguments);
  397. this.constructor === Bc && this.b2DebugDraw.apply(this, arguments)
  398. }
  399. function ud() {
  400. ud.b2DestructionListener.apply(this, arguments)
  401. }
  402. function Dc() {
  403. Dc.b2FilterData.apply(this, arguments)
  404. }
  405. function Cd() {
  406. Cd.b2Fixture.apply(this, arguments);
  407. this.constructor === Cd && this.b2Fixture.apply(this, arguments)
  408. }
  409. function Dd() {
  410. Dd.b2FixtureDef.apply(this, arguments);
  411. this.constructor === Dd && this.b2FixtureDef.apply(this, arguments)
  412. }
  413. function Ed() {
  414. Ed.b2Island.apply(this, arguments);
  415. this.constructor === Ed && this.b2Island.apply(this, arguments)
  416. }
  417. function Xd() {
  418. Xd.b2TimeStep.apply(this, arguments)
  419. }
  420. function Fd() {
  421. Fd.b2World.apply(this, arguments);
  422. this.constructor === Fd &&
  423. this.b2World.apply(this, arguments)
  424. }
  425. function Yd() {
  426. Yd.b2CircleContact.apply(this, arguments)
  427. }
  428. function Gd() {
  429. Gd.b2Contact.apply(this, arguments);
  430. this.constructor === Gd && this.b2Contact.apply(this, arguments)
  431. }
  432. function Hd() {
  433. Hd.b2ContactConstraint.apply(this, arguments);
  434. this.constructor === Hd && this.b2ContactConstraint.apply(this, arguments)
  435. }
  436. function Zd() {
  437. Zd.b2ContactConstraintPoint.apply(this, arguments)
  438. }
  439. function $d() {
  440. $d.b2ContactEdge.apply(this, arguments)
  441. }
  442. function Id() {
  443. Id.b2ContactFactory.apply(this, arguments);
  444. this.constructor === Id && this.b2ContactFactory.apply(this, arguments)
  445. }
  446. function ae() {
  447. ae.b2ContactRegister.apply(this, arguments)
  448. }
  449. function be() {
  450. be.b2ContactResult.apply(this, arguments)
  451. }
  452. function vd() {
  453. vd.b2ContactSolver.apply(this, arguments);
  454. this.constructor === vd && this.b2ContactSolver.apply(this, arguments)
  455. }
  456. function ce() {
  457. ce.b2EdgeAndCircleContact.apply(this, arguments)
  458. }
  459. function Jd() {
  460. Jd.b2NullContact.apply(this, arguments);
  461. this.constructor === Jd && this.b2NullContact.apply(this, arguments)
  462. }
  463. function de() {
  464. de.b2PolyAndCircleContact.apply(this,
  465. arguments)
  466. }
  467. function ee() {
  468. ee.b2PolyAndEdgeContact.apply(this, arguments)
  469. }
  470. function fe() {
  471. fe.b2PolygonContact.apply(this, arguments)
  472. }
  473. function Kd() {
  474. Kd.b2PositionSolverManifold.apply(this, arguments);
  475. this.constructor === Kd && this.b2PositionSolverManifold.apply(this, arguments)
  476. }
  477. function ge() {
  478. ge.b2BuoyancyController.apply(this, arguments)
  479. }
  480. function he() {
  481. he.b2ConstantAccelController.apply(this, arguments)
  482. }
  483. function ie() {
  484. ie.b2ConstantForceController.apply(this, arguments)
  485. }
  486. function je() {
  487. je.b2Controller.apply(this, arguments)
  488. }
  489. function ke() {
  490. ke.b2ControllerEdge.apply(this, arguments)
  491. }
  492. function le() {
  493. le.b2GravityController.apply(this, arguments)
  494. }
  495. function Ld() {
  496. Ld.b2TensorDampingController.apply(this, arguments)
  497. }
  498. function ld() {
  499. ld.b2DistanceJoint.apply(this, arguments);
  500. this.constructor === ld && this.b2DistanceJoint.apply(this, arguments)
  501. }
  502. function md() {
  503. md.b2DistanceJointDef.apply(this, arguments);
  504. this.constructor === md && this.b2DistanceJointDef.apply(this, arguments)
  505. }
  506. function wd() {
  507. wd.b2FrictionJoint.apply(this, arguments);
  508. this.constructor ===
  509. wd && this.b2FrictionJoint.apply(this, arguments)
  510. }
  511. function jd() {
  512. jd.b2FrictionJointDef.apply(this, arguments);
  513. this.constructor === jd && this.b2FrictionJointDef.apply(this, arguments)
  514. }
  515. function xd() {
  516. xd.b2GearJoint.apply(this, arguments);
  517. this.constructor === xd && this.b2GearJoint.apply(this, arguments)
  518. }
  519. function yd() {
  520. yd.b2GearJointDef.apply(this, arguments);
  521. this.constructor === yd && this.b2GearJointDef.apply(this, arguments)
  522. }
  523. function me() {
  524. me.b2Jacobian.apply(this, arguments)
  525. }
  526. function Md() {
  527. Md.b2Joint.apply(this, arguments);
  528. this.constructor === Md && this.b2Joint.apply(this, arguments)
  529. }
  530. function Nd() {
  531. Nd.b2JointDef.apply(this, arguments);
  532. this.constructor === Nd && this.b2JointDef.apply(this, arguments)
  533. }
  534. function Od() {
  535. Od.b2JointEdge.apply(this, arguments)
  536. }
  537. function Pd() {
  538. Pd.b2LineJoint.apply(this, arguments);
  539. this.constructor === Pd && this.b2LineJoint.apply(this, arguments)
  540. }
  541. function zd() {
  542. zd.b2LineJointDef.apply(this, arguments);
  543. this.constructor === zd && this.b2LineJointDef.apply(this, arguments)
  544. }
  545. function Qd() {
  546. Qd.b2MouseJoint.apply(this, arguments);
  547. this.constructor === Qd && this.b2MouseJoint.apply(this, arguments)
  548. }
  549. function Ad() {
  550. Ad.b2MouseJointDef.apply(this, arguments);
  551. this.constructor === Ad && this.b2MouseJointDef.apply(this, arguments)
  552. }
  553. function Rd() {
  554. Rd.b2PrismaticJoint.apply(this, arguments);
  555. this.constructor === Rd && this.b2PrismaticJoint.apply(this, arguments)
  556. }
  557. function kd() {
  558. kd.b2PrismaticJointDef.apply(this, arguments);
  559. this.constructor === kd && this.b2PrismaticJointDef.apply(this, arguments)
  560. }
  561. function nd() {
  562. nd.b2PulleyJoint.apply(this, arguments);
  563. this.constructor ===
  564. nd && this.b2PulleyJoint.apply(this, arguments)
  565. }
  566. function ed() {
  567. ed.b2PulleyJointDef.apply(this, arguments);
  568. this.constructor === ed && this.b2PulleyJointDef.apply(this, arguments)
  569. }
  570. function Gc() {
  571. Gc.b2RevoluteJoint.apply(this, arguments);
  572. this.constructor === Gc && this.b2RevoluteJoint.apply(this, arguments)
  573. }
  574. function od() {
  575. od.b2RevoluteJointDef.apply(this, arguments);
  576. this.constructor === od && this.b2RevoluteJointDef.apply(this, arguments)
  577. }
  578. function Ic() {
  579. Ic.b2WeldJoint.apply(this, arguments);
  580. this.constructor === Ic && this.b2WeldJoint.apply(this,
  581. arguments)
  582. }
  583. function ad() {
  584. ad.b2WeldJointDef.apply(this, arguments);
  585. this.constructor === ad && this.b2WeldJointDef.apply(this, arguments)
  586. }
  587. Box2D.Collision.IBroadPhase = "Box2D.Collision.IBroadPhase";
  588. Box2D.Collision.b2AABB = a;
  589. Box2D.Collision.b2Bound = c;
  590. Box2D.Collision.b2BoundValues = b;
  591. Box2D.Collision.b2Collision = d;
  592. Box2D.Collision.b2ContactID = e;
  593. Box2D.Collision.b2ContactPoint = f;
  594. Box2D.Collision.b2Distance = g;
  595. Box2D.Collision.b2DistanceInput = h;
  596. Box2D.Collision.b2DistanceOutput = l;
  597. Box2D.Collision.b2DistanceProxy = m;
  598. Box2D.Collision.b2DynamicTree =
  599. q;
  600. Box2D.Collision.b2DynamicTreeBroadPhase = p;
  601. Box2D.Collision.b2DynamicTreeNode = y;
  602. Box2D.Collision.b2DynamicTreePair = A;
  603. Box2D.Collision.b2Manifold = B;
  604. Box2D.Collision.b2ManifoldPoint = K;
  605. Box2D.Collision.b2Point = H;
  606. Box2D.Collision.b2RayCastInput = E;
  607. Box2D.Collision.b2RayCastOutput = M;
  608. Box2D.Collision.b2Segment = Xb;
  609. Box2D.Collision.b2SeparationFunction = Zb;
  610. Box2D.Collision.b2Simplex = aa;
  611. Box2D.Collision.b2SimplexCache = Yb;
  612. Box2D.Collision.b2SimplexVertex = $b;
  613. Box2D.Collision.b2TimeOfImpact = ac;
  614. Box2D.Collision.b2TOIInput = bc;
  615. Box2D.Collision.b2WorldManifold = ec;
  616. Box2D.Collision.ClipVertex = jc;
  617. Box2D.Collision.Features = cc;
  618. Box2D.Collision.Shapes.b2CircleShape = dc;
  619. Box2D.Collision.Shapes.b2EdgeChainDef = gc;
  620. Box2D.Collision.Shapes.b2EdgeShape = hc;
  621. Box2D.Collision.Shapes.b2MassData = fc;
  622. Box2D.Collision.Shapes.b2PolygonShape = kc;
  623. Box2D.Collision.Shapes.b2Shape = lc;
  624. Box2D.Common.b2internal = "Box2D.Common.b2internal";
  625. Box2D.Common.b2Color = mc;
  626. Box2D.Common.b2Settings = nc;
  627. Box2D.Common.Math.b2Mat22 = oc;
  628. Box2D.Common.Math.b2Mat33 = qc;
  629. Box2D.Common.Math.b2Math =
  630. pc;
  631. Box2D.Common.Math.b2Sweep = rc;
  632. Box2D.Common.Math.b2Transform = uc;
  633. Box2D.Common.Math.b2Vec2 = wc;
  634. Box2D.Common.Math.b2Vec3 = sc;
  635. Box2D.Dynamics.b2Body = xc;
  636. Box2D.Dynamics.b2BodyDef = tc;
  637. Box2D.Dynamics.b2ContactFilter = yc;
  638. Box2D.Dynamics.b2ContactImpulse = Ac;
  639. Box2D.Dynamics.b2ContactListener = zc;
  640. Box2D.Dynamics.b2ContactManager = Cc;
  641. Box2D.Dynamics.b2DebugDraw = Bc;
  642. Box2D.Dynamics.b2DestructionListener = ud;
  643. Box2D.Dynamics.b2FilterData = Dc;
  644. Box2D.Dynamics.b2Fixture = Cd;
  645. Box2D.Dynamics.b2FixtureDef = Dd;
  646. Box2D.Dynamics.b2Island = Ed;
  647. Box2D.Dynamics.b2TimeStep = Xd;
  648. Box2D.Dynamics.b2World = Fd;
  649. Box2D.Dynamics.Contacts.b2CircleContact = Yd;
  650. Box2D.Dynamics.Contacts.b2Contact = Gd;
  651. Box2D.Dynamics.Contacts.b2ContactConstraint = Hd;
  652. Box2D.Dynamics.Contacts.b2ContactConstraintPoint = Zd;
  653. Box2D.Dynamics.Contacts.b2ContactEdge = $d;
  654. Box2D.Dynamics.Contacts.b2ContactFactory = Id;
  655. Box2D.Dynamics.Contacts.b2ContactRegister = ae;
  656. Box2D.Dynamics.Contacts.b2ContactResult = be;
  657. Box2D.Dynamics.Contacts.b2ContactSolver = vd;
  658. Box2D.Dynamics.Contacts.b2EdgeAndCircleContact = ce;
  659. Box2D.Dynamics.Contacts.b2NullContact =
  660. Jd;
  661. Box2D.Dynamics.Contacts.b2PolyAndCircleContact = de;
  662. Box2D.Dynamics.Contacts.b2PolyAndEdgeContact = ee;
  663. Box2D.Dynamics.Contacts.b2PolygonContact = fe;
  664. Box2D.Dynamics.Contacts.b2PositionSolverManifold = Kd;
  665. Box2D.Dynamics.Controllers.b2BuoyancyController = ge;
  666. Box2D.Dynamics.Controllers.b2ConstantAccelController = he;
  667. Box2D.Dynamics.Controllers.b2ConstantForceController = ie;
  668. Box2D.Dynamics.Controllers.b2Controller = je;
  669. Box2D.Dynamics.Controllers.b2ControllerEdge = ke;
  670. Box2D.Dynamics.Controllers.b2GravityController = le;
  671. Box2D.Dynamics.Controllers.b2TensorDampingController =
  672. Ld;
  673. Box2D.Dynamics.Joints.b2DistanceJoint = ld;
  674. Box2D.Dynamics.Joints.b2DistanceJointDef = md;
  675. Box2D.Dynamics.Joints.b2FrictionJoint = wd;
  676. Box2D.Dynamics.Joints.b2FrictionJointDef = jd;
  677. Box2D.Dynamics.Joints.b2GearJoint = xd;
  678. Box2D.Dynamics.Joints.b2GearJointDef = yd;
  679. Box2D.Dynamics.Joints.b2Jacobian = me;
  680. Box2D.Dynamics.Joints.b2Joint = Md;
  681. Box2D.Dynamics.Joints.b2JointDef = Nd;
  682. Box2D.Dynamics.Joints.b2JointEdge = Od;
  683. Box2D.Dynamics.Joints.b2LineJoint = Pd;
  684. Box2D.Dynamics.Joints.b2LineJointDef = zd;
  685. Box2D.Dynamics.Joints.b2MouseJoint =
  686. Qd;
  687. Box2D.Dynamics.Joints.b2MouseJointDef = Ad;
  688. Box2D.Dynamics.Joints.b2PrismaticJoint = Rd;
  689. Box2D.Dynamics.Joints.b2PrismaticJointDef = kd;
  690. Box2D.Dynamics.Joints.b2PulleyJoint = nd;
  691. Box2D.Dynamics.Joints.b2PulleyJointDef = ed;
  692. Box2D.Dynamics.Joints.b2RevoluteJoint = Gc;
  693. Box2D.Dynamics.Joints.b2RevoluteJointDef = od;
  694. Box2D.Dynamics.Joints.b2WeldJoint = Ic;
  695. Box2D.Dynamics.Joints.b2WeldJointDef = ad
  696. })();
  697. Box2D.postDefs = [];
  698. (function() {
  699. var a = Box2D.Collision.Shapes.b2CircleShape,
  700. c = Box2D.Collision.Shapes.b2PolygonShape,
  701. b = Box2D.Collision.Shapes.b2Shape,
  702. d = Box2D.Common.b2Settings,
  703. e = Box2D.Common.Math.b2Math,
  704. f = Box2D.Common.Math.b2Sweep,
  705. g = Box2D.Common.Math.b2Transform,
  706. h = Box2D.Common.Math.b2Vec2,
  707. l = Box2D.Collision.b2AABB,
  708. m = Box2D.Collision.b2Bound,
  709. q = Box2D.Collision.b2BoundValues,
  710. p = Box2D.Collision.b2Collision,
  711. y = Box2D.Collision.b2ContactID,
  712. A = Box2D.Collision.b2ContactPoint,
  713. B = Box2D.Collision.b2Distance,
  714. K = Box2D.Collision.b2DistanceInput,
  715. H = Box2D.Collision.b2DistanceOutput,
  716. E = Box2D.Collision.b2DistanceProxy,
  717. M = Box2D.Collision.b2DynamicTree,
  718. Xb = Box2D.Collision.b2DynamicTreeBroadPhase,
  719. Zb = Box2D.Collision.b2DynamicTreeNode,
  720. aa = Box2D.Collision.b2DynamicTreePair,
  721. Yb = Box2D.Collision.b2Manifold,
  722. $b = Box2D.Collision.b2ManifoldPoint,
  723. ac = Box2D.Collision.b2Point,
  724. bc = Box2D.Collision.b2RayCastInput,
  725. ec = Box2D.Collision.b2RayCastOutput,
  726. jc = Box2D.Collision.b2Segment,
  727. cc = Box2D.Collision.b2SeparationFunction,
  728. dc = Box2D.Collision.b2Simplex,
  729. gc = Box2D.Collision.b2SimplexCache,
  730. hc = Box2D.Collision.b2SimplexVertex,
  731. fc = Box2D.Collision.b2TimeOfImpact,
  732. kc = Box2D.Collision.b2TOIInput,
  733. lc = Box2D.Collision.b2WorldManifold,
  734. mc = Box2D.Collision.ClipVertex,
  735. nc = Box2D.Collision.Features,
  736. oc = Box2D.Collision.IBroadPhase;
  737. l.b2AABB = function() {
  738. this.lowerBound = new h;
  739. this.upperBound = new h
  740. };
  741. l.prototype.IsValid = function() {
  742. var a = this.upperBound.y - this.lowerBound.y;
  743. return 0 <= this.upperBound.x - this.lowerBound.x && 0 <= a && this.lowerBound.IsValid() && this.upperBound.IsValid()
  744. };
  745. l.prototype.GetCenter = function() {
  746. return new h((this.lowerBound.x +
  747. this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2)
  748. };
  749. l.prototype.GetExtents = function() {
  750. return new h((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2)
  751. };
  752. l.prototype.Contains = function(a) {
  753. return this.lowerBound.x <= a.lowerBound.x && this.lowerBound.y <= a.lowerBound.y && a.upperBound.x <= this.upperBound.x && a.upperBound.y <= this.upperBound.y
  754. };
  755. l.prototype.RayCast = function(a, b) {
  756. var c = -Number.MAX_VALUE,
  757. d = Number.MAX_VALUE,
  758. e = b.p1.x,
  759. f = b.p1.y,
  760. g = b.p2.x - b.p1.x,
  761. h = b.p2.y - b.p1.y,
  762. l =
  763. Math.abs(h),
  764. m = a.normal,
  765. p;
  766. if (Math.abs(g) < Number.MIN_VALUE) {
  767. if (e < this.lowerBound.x || this.upperBound.x < e) return !1
  768. } else if (g = 1 / g, p = (this.lowerBound.x - e) * g, g *= this.upperBound.x - e, e = -1, p > g && (e = p, p = g, g = e, e = 1), p > c && (m.x = e, m.y = 0, c = p), d = Math.min(d, g), c > d) return !1;
  769. if (l < Number.MIN_VALUE) {
  770. if (f < this.lowerBound.y || this.upperBound.y < f) return !1
  771. } else if (g = 1 / h, p = (this.lowerBound.y - f) * g, g *= this.upperBound.y - f, e = -1, p > g && (e = p, p = g, g = e, e = 1), p > c && (m.y = e, m.x = 0, c = p), d = Math.min(d, g), c > d) return !1;
  772. a.fraction = c;
  773. return !0
  774. };
  775. l.prototype.TestOverlap =
  776. function(a) {
  777. var b = a.lowerBound.y - this.upperBound.y,
  778. c = this.lowerBound.y - a.upperBound.y;
  779. return 0 < a.lowerBound.x - this.upperBound.x || 0 < b || 0 < this.lowerBound.x - a.upperBound.x || 0 < c ? !1 : !0
  780. };
  781. l.Combine = function(a, b) {
  782. var c = new l;
  783. c.Combine(a, b);
  784. return c
  785. };
  786. l.prototype.Combine = function(a, b) {
  787. this.lowerBound.x = Math.min(a.lowerBound.x, b.lowerBound.x);
  788. this.lowerBound.y = Math.min(a.lowerBound.y, b.lowerBound.y);
  789. this.upperBound.x = Math.max(a.upperBound.x, b.upperBound.x);
  790. this.upperBound.y = Math.max(a.upperBound.y, b.upperBound.y)
  791. };
  792. m.b2Bound = function() {};
  793. m.prototype.IsLower = function() {
  794. return 0 == (this.value & 1)
  795. };
  796. m.prototype.IsUpper = function() {
  797. return 1 == (this.value & 1)
  798. };
  799. m.prototype.Swap = function(a) {
  800. var b = this.value,
  801. c = this.proxy,
  802. d = this.stabbingCount;
  803. this.value = a.value;
  804. this.proxy = a.proxy;
  805. this.stabbingCount = a.stabbingCount;
  806. a.value = b;
  807. a.proxy = c;
  808. a.stabbingCount = d
  809. };
  810. q.b2BoundValues = function() {};
  811. q.prototype.b2BoundValues = function() {
  812. this.lowerValues = new Vector_a2j_Number;
  813. this.lowerValues[0] = 0;
  814. this.lowerValues[1] = 0;
  815. this.upperValues = new Vector_a2j_Number;
  816. this.upperValues[0] = 0;
  817. this.upperValues[1] = 0
  818. };
  819. p.b2Collision = function() {};
  820. p.ClipSegmentToLine = function(a, b, c, d) {
  821. void 0 === d && (d = 0);
  822. var e, f = 0;
  823. e = b[0];
  824. var g = e.v;
  825. e = b[1];
  826. var h = e.v,
  827. l = c.x * g.x + c.y * g.y - d;
  828. e = c.x * h.x + c.y * h.y - d;
  829. 0 >= l && a[f++].Set(b[0]);
  830. 0 >= e && a[f++].Set(b[1]);
  831. 0 > l * e && (c = l / (l - e), e = a[f], e = e.v, e.x = g.x + c * (h.x - g.x), e.y = g.y + c * (h.y - g.y), e = a[f], e.id = (0 < l ? b[0] : b[1]).id, ++f);
  832. return f
  833. };
  834. p.EdgeSeparation = function(a, b, c, d, e) {
  835. void 0 === c && (c = 0);
  836. parseInt(a.m_vertexCount);
  837. var f = a.m_vertices;
  838. a = a.m_normals;
  839. var g = parseInt(d.m_vertexCount),
  840. h = d.m_vertices,
  841. l, m;
  842. l = b.R;
  843. m = a[c];
  844. a = l.col1.x * m.x + l.col2.x * m.y;
  845. d = l.col1.y * m.x + l.col2.y * m.y;
  846. l = e.R;
  847. var p = l.col1.x * a + l.col1.y * d;
  848. l = l.col2.x * a + l.col2.y * d;
  849. for (var q = 0, y = Number.MAX_VALUE, A = 0; A < g; ++A) m = h[A], m = m.x * p + m.y * l, m < y && (y = m, q = A);
  850. m = f[c];
  851. l = b.R;
  852. c = b.position.x + (l.col1.x * m.x + l.col2.x * m.y);
  853. b = b.position.y + (l.col1.y * m.x + l.col2.y * m.y);
  854. m = h[q];
  855. l = e.R;
  856. f = e.position.x + (l.col1.x * m.x + l.col2.x * m.y);
  857. e = e.position.y + (l.col1.y * m.x + l.col2.y * m.y);
  858. return (f - c) * a + (e - b) * d
  859. };
  860. p.FindMaxSeparation = function(a, b, c, d, e) {
  861. var f = parseInt(b.m_vertexCount),
  862. g = b.m_normals,
  863. h, l;
  864. l = e.R;
  865. h = d.m_centroid;
  866. var m = e.position.x + (l.col1.x * h.x + l.col2.x * h.y),
  867. q = e.position.y + (l.col1.y * h.x + l.col2.y * h.y);
  868. l = c.R;
  869. h = b.m_centroid;
  870. m -= c.position.x + (l.col1.x * h.x + l.col2.x * h.y);
  871. q -= c.position.y + (l.col1.y * h.x + l.col2.y * h.y);
  872. l = m * c.R.col1.x + q * c.R.col1.y;
  873. for (var q = m * c.R.col2.x + q * c.R.col2.y, m = 0, y = -Number.MAX_VALUE, A = 0; A < f; ++A) h = g[A], h = h.x * l + h.y * q, h > y && (y = h, m = A);
  874. g = p.EdgeSeparation(b, c, m, d, e);
  875. h = parseInt(0 <= m - 1 ? m - 1 : f - 1);
  876. l = p.EdgeSeparation(b, c, h, d, e);
  877. var q = parseInt(m + 1 < f ? m + 1 : 0),
  878. y = p.EdgeSeparation(b,
  879. c, q, d, e),
  880. B;
  881. if (l > g && l > y) B = -1, A = h, h = l;
  882. else if (y > g) B = 1, A = q, h = y;
  883. else return a[0] = m, g;
  884. for (;;)
  885. if (m = -1 == B ? 0 <= A - 1 ? A - 1 : f - 1 : A + 1 < f ? A + 1 : 0, g = p.EdgeSeparation(b, c, m, d, e), g > h) A = m, h = g;
  886. else break;
  887. a[0] = A;
  888. return h
  889. };
  890. p.FindIncidentEdge = function(a, b, c, d, e, f) {
  891. void 0 === d && (d = 0);
  892. parseInt(b.m_vertexCount);
  893. var g = b.m_normals,
  894. h = parseInt(e.m_vertexCount);
  895. b = e.m_vertices;
  896. e = e.m_normals;
  897. var l;
  898. l = c.R;
  899. c = g[d];
  900. var g = l.col1.x * c.x + l.col2.x * c.y,
  901. m = l.col1.y * c.x + l.col2.y * c.y;
  902. l = f.R;
  903. c = l.col1.x * g + l.col1.y * m;
  904. m = l.col2.x * g + l.col2.y * m;
  905. g = c;
  906. l = 0;
  907. for (var p =
  908. Number.MAX_VALUE, q = 0; q < h; ++q) c = e[q], c = g * c.x + m * c.y, c < p && (p = c, l = q);
  909. e = parseInt(l);
  910. g = parseInt(e + 1 < h ? e + 1 : 0);
  911. h = a[0];
  912. c = b[e];
  913. l = f.R;
  914. h.v.x = f.position.x + (l.col1.x * c.x + l.col2.x * c.y);
  915. h.v.y = f.position.y + (l.col1.y * c.x + l.col2.y * c.y);
  916. h.id.features.referenceEdge = d;
  917. h.id.features.incidentEdge = e;
  918. h.id.features.incidentVertex = 0;
  919. h = a[1];
  920. c = b[g];
  921. l = f.R;
  922. h.v.x = f.position.x + (l.col1.x * c.x + l.col2.x * c.y);
  923. h.v.y = f.position.y + (l.col1.y * c.x + l.col2.y * c.y);
  924. h.id.features.referenceEdge = d;
  925. h.id.features.incidentEdge = g;
  926. h.id.features.incidentVertex =
  927. 1
  928. };
  929. p.MakeClipPointVector = function() {
  930. var a = new Vector(2);
  931. a[0] = new mc;
  932. a[1] = new mc;
  933. return a
  934. };
  935. p.CollidePolygons = function(a, b, c, e, f) {
  936. var g;
  937. a.m_pointCount = 0;
  938. var h = b.m_radius + e.m_radius;
  939. p.s_edgeAO[0] = 0;
  940. var l = p.FindMaxSeparation(p.s_edgeAO, b, c, e, f);
  941. g = p.s_edgeAO[0];
  942. if (!(l > h)) {
  943. var m;
  944. p.s_edgeBO[0] = 0;
  945. var q = p.FindMaxSeparation(p.s_edgeBO, e, f, b, c);
  946. m = p.s_edgeBO[0];
  947. if (!(q > h)) {
  948. var y, A;
  949. q > .98 * l + .001 ? (l = e, e = b, b = f, y = m, a.m_type = Yb.e_faceB, A = 1) : (l = b, b = c, c = f, y = g, a.m_type = Yb.e_faceA, A = 0);
  950. g = p.s_incidentEdge;
  951. p.FindIncidentEdge(g,
  952. l, b, y, e, c);
  953. m = parseInt(l.m_vertexCount);
  954. f = l.m_vertices;
  955. var l = f[y],
  956. B;
  957. B = y + 1 < m ? f[parseInt(y + 1)] : f[0];
  958. y = p.s_localTangent;
  959. y.Set(B.x - l.x, B.y - l.y);
  960. y.Normalize();
  961. f = p.s_localNormal;
  962. f.x = y.y;
  963. f.y = -y.x;
  964. e = p.s_planePoint;
  965. e.Set(.5 * (l.x + B.x), .5 * (l.y + B.y));
  966. q = p.s_tangent;
  967. m = b.R;
  968. q.x = m.col1.x * y.x + m.col2.x * y.y;
  969. q.y = m.col1.y * y.x + m.col2.y * y.y;
  970. var H = p.s_tangent2;
  971. H.x = -q.x;
  972. H.y = -q.y;
  973. y = p.s_normal;
  974. y.x = q.y;
  975. y.y = -q.x;
  976. var E = p.s_v11,
  977. M = p.s_v12;
  978. E.x = b.position.x + (m.col1.x * l.x + m.col2.x * l.y);
  979. E.y = b.position.y + (m.col1.y * l.x + m.col2.y * l.y);
  980. M.x =
  981. b.position.x + (m.col1.x * B.x + m.col2.x * B.y);
  982. M.y = b.position.y + (m.col1.y * B.x + m.col2.y * B.y);
  983. b = y.x * E.x + y.y * E.y;
  984. m = q.x * M.x + q.y * M.y + h;
  985. B = p.s_clipPoints1;
  986. l = p.s_clipPoints2;
  987. M = p.ClipSegmentToLine(B, g, H, -q.x * E.x - q.y * E.y + h);
  988. if (!(2 > M || (M = p.ClipSegmentToLine(l, B, q, m), 2 > M))) {
  989. a.m_localPlaneNormal.SetV(f);
  990. a.m_localPoint.SetV(e);
  991. for (e = f = 0; e < d.b2_maxManifoldPoints; ++e) g = l[e], y.x * g.v.x + y.y * g.v.y - b <= h && (q = a.m_points[f], m = c.R, H = g.v.x - c.position.x, E = g.v.y - c.position.y, q.m_localPoint.x = H * m.col1.x + E * m.col1.y, q.m_localPoint.y =
  992. H * m.col2.x + E * m.col2.y, q.m_id.Set(g.id), q.m_id.features.flip = A, ++f);
  993. a.m_pointCount = f
  994. }
  995. }
  996. }
  997. };
  998. p.CollideCircles = function(a, b, c, d, e) {
  999. a.m_pointCount = 0;
  1000. var f, g;
  1001. f = c.R;
  1002. g = b.m_p;
  1003. var h = c.position.x + (f.col1.x * g.x + f.col2.x * g.y);
  1004. c = c.position.y + (f.col1.y * g.x + f.col2.y * g.y);
  1005. f = e.R;
  1006. g = d.m_p;
  1007. h = e.position.x + (f.col1.x * g.x + f.col2.x * g.y) - h;
  1008. e = e.position.y + (f.col1.y * g.x + f.col2.y * g.y) - c;
  1009. f = b.m_radius + d.m_radius;
  1010. h * h + e * e > f * f || (a.m_type = Yb.e_circles, a.m_localPoint.SetV(b.m_p), a.m_localPlaneNormal.SetZero(), a.m_pointCount = 1, a.m_points[0].m_localPoint.SetV(d.m_p),
  1011. a.m_points[0].m_id.key = 0)
  1012. };
  1013. p.CollidePolygonAndCircle = function(a, b, c, d, e) {
  1014. var f;
  1015. a.m_pointCount = 0;
  1016. var g, h, l;
  1017. l = e.R;
  1018. h = d.m_p;
  1019. var m = e.position.y + (l.col1.y * h.x + l.col2.y * h.y);
  1020. f = e.position.x + (l.col1.x * h.x + l.col2.x * h.y) - c.position.x;
  1021. g = m - c.position.y;
  1022. l = c.R;
  1023. c = f * l.col1.x + g * l.col1.y;
  1024. l = f * l.col2.x + g * l.col2.y;
  1025. var p = 0,
  1026. m = -Number.MAX_VALUE;
  1027. e = b.m_radius + d.m_radius;
  1028. var q = parseInt(b.m_vertexCount),
  1029. y = b.m_vertices;
  1030. b = b.m_normals;
  1031. for (var A = 0; A < q; ++A) {
  1032. h = y[A];
  1033. f = c - h.x;
  1034. g = l - h.y;
  1035. h = b[A];
  1036. f = h.x * f + h.y * g;
  1037. if (f > e) return;
  1038. f > m && (m = f, p = A)
  1039. }
  1040. f =
  1041. parseInt(p);
  1042. g = parseInt(f + 1 < q ? f + 1 : 0);
  1043. h = y[f];
  1044. y = y[g];
  1045. if (m < Number.MIN_VALUE) a.m_pointCount = 1, a.m_type = Yb.e_faceA, a.m_localPlaneNormal.SetV(b[p]), a.m_localPoint.x = .5 * (h.x + y.x), a.m_localPoint.y = .5 * (h.y + y.y);
  1046. else if (m = (c - y.x) * (h.x - y.x) + (l - y.y) * (h.y - y.y), 0 >= (c - h.x) * (y.x - h.x) + (l - h.y) * (y.y - h.y)) {
  1047. if ((c - h.x) * (c - h.x) + (l - h.y) * (l - h.y) > e * e) return;
  1048. a.m_pointCount = 1;
  1049. a.m_type = Yb.e_faceA;
  1050. a.m_localPlaneNormal.x = c - h.x;
  1051. a.m_localPlaneNormal.y = l - h.y;
  1052. a.m_localPlaneNormal.Normalize();
  1053. a.m_localPoint.SetV(h)
  1054. } else if (0 >= m) {
  1055. if ((c -
  1056. y.x) * (c - y.x) + (l - y.y) * (l - y.y) > e * e) return;
  1057. a.m_pointCount = 1;
  1058. a.m_type = Yb.e_faceA;
  1059. a.m_localPlaneNormal.x = c - y.x;
  1060. a.m_localPlaneNormal.y = l - y.y;
  1061. a.m_localPlaneNormal.Normalize();
  1062. a.m_localPoint.SetV(y)
  1063. } else {
  1064. p = .5 * (h.x + y.x);
  1065. h = .5 * (h.y + y.y);
  1066. m = (c - p) * b[f].x + (l - h) * b[f].y;
  1067. if (m > e) return;
  1068. a.m_pointCount = 1;
  1069. a.m_type = Yb.e_faceA;
  1070. a.m_localPlaneNormal.x = b[f].x;
  1071. a.m_localPlaneNormal.y = b[f].y;
  1072. a.m_localPlaneNormal.Normalize();
  1073. a.m_localPoint.Set(p, h)
  1074. }
  1075. a.m_points[0].m_localPoint.SetV(d.m_p);
  1076. a.m_points[0].m_id.key = 0
  1077. };
  1078. p.TestOverlap =
  1079. function(a, b) {
  1080. var c = b.lowerBound,
  1081. d = a.upperBound,
  1082. e = c.x - d.x,
  1083. f = c.y - d.y,
  1084. c = a.lowerBound,
  1085. d = b.upperBound,
  1086. g = c.y - d.y;
  1087. return 0 < e || 0 < f || 0 < c.x - d.x || 0 < g ? !1 : !0
  1088. };
  1089. Box2D.postDefs.push(function() {
  1090. Box2D.Collision.b2Collision.s_incidentEdge = p.MakeClipPointVector();
  1091. Box2D.Collision.b2Collision.s_clipPoints1 = p.MakeClipPointVector();
  1092. Box2D.Collision.b2Collision.s_clipPoints2 = p.MakeClipPointVector();
  1093. Box2D.Collision.b2Collision.s_edgeAO = new Vector_a2j_Number(1);
  1094. Box2D.Collision.b2Collision.s_edgeBO = new Vector_a2j_Number(1);
  1095. Box2D.Collision.b2Collision.s_localTangent = new h;
  1096. Box2D.Collision.b2Collision.s_localNormal = new h;
  1097. Box2D.Collision.b2Collision.s_planePoint = new h;
  1098. Box2D.Collision.b2Collision.s_normal = new h;
  1099. Box2D.Collision.b2Collision.s_tangent = new h;
  1100. Box2D.Collision.b2Collision.s_tangent2 = new h;
  1101. Box2D.Collision.b2Collision.s_v11 = new h;
  1102. Box2D.Collision.b2Collision.s_v12 = new h;
  1103. Box2D.Collision.b2Collision.b2CollidePolyTempVec = new h;
  1104. Box2D.Collision.b2Collision.b2_nullFeature = 255
  1105. });
  1106. y.b2ContactID = function() {
  1107. this.features = new nc
  1108. };
  1109. y.prototype.b2ContactID = function() {
  1110. this.features._m_id = this
  1111. };
  1112. y.prototype.Set = function(a) {
  1113. this.key = a._key
  1114. };
  1115. y.prototype.Copy = function() {
  1116. var a = new y;
  1117. a.key = this.key;
  1118. return a
  1119. };
  1120. Object.defineProperty(y.prototype, "key", {
  1121. enumerable: !1,
  1122. configurable: !0,
  1123. get: function() {
  1124. return this._key
  1125. }
  1126. });
  1127. Object.defineProperty(y.prototype, "key", {
  1128. enumerable: !1,
  1129. configurable: !0,
  1130. set: function(a) {
  1131. void 0 === a && (a = 0);
  1132. this._key = a;
  1133. this.features._referenceEdge = this._key & 255;
  1134. this.features._incidentEdge = (this._key & 65280) >> 8 & 255;
  1135. this.features._incidentVertex =
  1136. (this._key & 16711680) >> 16 & 255;
  1137. this.features._flip = (this._key & 4278190080) >> 24 & 255
  1138. }
  1139. });
  1140. A.b2ContactPoint = function() {
  1141. this.position = new h;
  1142. this.velocity = new h;
  1143. this.normal = new h;
  1144. this.id = new y
  1145. };
  1146. B.b2Distance = function() {};
  1147. B.Distance = function(a, b, c) {
  1148. ++B.b2_gjkCalls;
  1149. var f = c.proxyA,
  1150. g = c.proxyB,
  1151. l = c.transformA,
  1152. m = c.transformB,
  1153. p = B.s_simplex;
  1154. p.ReadCache(b, f, l, g, m);
  1155. var q = p.m_vertices,
  1156. y = B.s_saveA,
  1157. A = B.s_saveB,
  1158. H;
  1159. p.GetClosestPoint().LengthSquared();
  1160. for (var E, M, K = 0; 20 > K;) {
  1161. H = p.m_count;
  1162. for (E = 0; E < H; E++) y[E] = q[E].indexA, A[E] = q[E].indexB;
  1163. switch (p.m_count) {
  1164. case 1:
  1165. break;
  1166. case 2:
  1167. p.Solve2();
  1168. break;
  1169. case 3:
  1170. p.Solve3();
  1171. break;
  1172. default:
  1173. d.b2Assert(!1)
  1174. }
  1175. if (3 == p.m_count) break;
  1176. M = p.GetClosestPoint();
  1177. M.LengthSquared();
  1178. E = p.GetSearchDirection();
  1179. if (E.LengthSquared() < Number.MIN_VALUE * Number.MIN_VALUE) break;
  1180. M = q[p.m_count];
  1181. M.indexA = f.GetSupport(e.MulTMV(l.R, E.GetNegative()));
  1182. M.wA = e.MulX(l, f.GetVertex(M.indexA));
  1183. M.indexB = g.GetSupport(e.MulTMV(m.R, E));
  1184. M.wB = e.MulX(m, g.GetVertex(M.indexB));
  1185. M.w = e.SubtractVV(M.wB, M.wA);
  1186. ++K;
  1187. ++B.b2_gjkIters;
  1188. var aa = !1;
  1189. for (E = 0; E < H; E++)
  1190. if (M.indexA ==
  1191. y[E] && M.indexB == A[E]) {
  1192. aa = !0;
  1193. break
  1194. }
  1195. if (aa) break;
  1196. ++p.m_count
  1197. }
  1198. B.b2_gjkMaxIters = e.Max(B.b2_gjkMaxIters, K);
  1199. p.GetWitnessPoints(a.pointA, a.pointB);
  1200. a.distance = e.SubtractVV(a.pointA, a.pointB).Length();
  1201. a.iterations = K;
  1202. p.WriteCache(b);
  1203. c.useRadii && (b = f.m_radius, g = g.m_radius, a.distance > b + g && a.distance > Number.MIN_VALUE ? (a.distance -= b + g, c = e.SubtractVV(a.pointB, a.pointA), c.Normalize(), a.pointA.x += b * c.x, a.pointA.y += b * c.y, a.pointB.x -= g * c.x, a.pointB.y -= g * c.y) : (M = new h, M.x = .5 * (a.pointA.x + a.pointB.x), M.y = .5 * (a.pointA.y +
  1204. a.pointB.y), a.pointA.x = a.pointB.x = M.x, a.pointA.y = a.pointB.y = M.y, a.distance = 0))
  1205. };
  1206. Box2D.postDefs.push(function() {
  1207. Box2D.Collision.b2Distance.s_simplex = new dc;
  1208. Box2D.Collision.b2Distance.s_saveA = new Vector_a2j_Number(3);
  1209. Box2D.Collision.b2Distance.s_saveB = new Vector_a2j_Number(3)
  1210. });
  1211. K.b2DistanceInput = function() {};
  1212. H.b2DistanceOutput = function() {
  1213. this.pointA = new h;
  1214. this.pointB = new h
  1215. };
  1216. E.b2DistanceProxy = function() {};
  1217. E.prototype.Set = function(e) {
  1218. switch (e.GetType()) {
  1219. case b.e_circleShape:
  1220. e = e instanceof a ? e : null;
  1221. this.m_vertices =
  1222. new Vector(1, !0);
  1223. this.m_vertices[0] = e.m_p;
  1224. this.m_count = 1;
  1225. this.m_radius = e.m_radius;
  1226. break;
  1227. case b.e_polygonShape:
  1228. e = e instanceof c ? e : null;
  1229. this.m_vertices = e.m_vertices;
  1230. this.m_count = e.m_vertexCount;
  1231. this.m_radius = e.m_radius;
  1232. break;
  1233. default:
  1234. d.b2Assert(!1)
  1235. }
  1236. };
  1237. E.prototype.GetSupport = function(a) {
  1238. for (var b = 0, c = this.m_vertices[0].x * a.x + this.m_vertices[0].y * a.y, d = 1; d < this.m_count; ++d) {
  1239. var e = this.m_vertices[d].x * a.x + this.m_vertices[d].y * a.y;
  1240. e > c && (b = d, c = e)
  1241. }
  1242. return b
  1243. };
  1244. E.prototype.GetSupportVertex = function(a) {
  1245. for (var b =
  1246. 0, c = this.m_vertices[0].x * a.x + this.m_vertices[0].y * a.y, d = 1; d < this.m_count; ++d) {
  1247. var e = this.m_vertices[d].x * a.x + this.m_vertices[d].y * a.y;
  1248. e > c && (b = d, c = e)
  1249. }
  1250. return this.m_vertices[b]
  1251. };
  1252. E.prototype.GetVertexCount = function() {
  1253. return this.m_count
  1254. };
  1255. E.prototype.GetVertex = function(a) {
  1256. void 0 === a && (a = 0);
  1257. d.b2Assert(0 <= a && a < this.m_count);
  1258. return this.m_vertices[a]
  1259. };
  1260. M.b2DynamicTree = function() {};
  1261. M.prototype.b2DynamicTree = function() {
  1262. this.m_freeList = this.m_root = null;
  1263. this.m_insertionCount = this.m_path = 0
  1264. };
  1265. M.prototype.CreateProxy =
  1266. function(a, b) {
  1267. var c = this.AllocateNode(),
  1268. e = d.b2_aabbExtension,
  1269. f = d.b2_aabbExtension;
  1270. c.aabb.lowerBound.x = a.lowerBound.x - e;
  1271. c.aabb.lowerBound.y = a.lowerBound.y - f;
  1272. c.aabb.upperBound.x = a.upperBound.x + e;
  1273. c.aabb.upperBound.y = a.upperBound.y + f;
  1274. c.userData = b;
  1275. this.InsertLeaf(c);
  1276. return c
  1277. };
  1278. M.prototype.DestroyProxy = function(a) {
  1279. this.RemoveLeaf(a);
  1280. this.FreeNode(a)
  1281. };
  1282. M.prototype.MoveProxy = function(a, b, c) {
  1283. d.b2Assert(a.IsLeaf());
  1284. if (a.aabb.Contains(b)) return !1;
  1285. this.RemoveLeaf(a);
  1286. var e = d.b2_aabbExtension + d.b2_aabbMultiplier *
  1287. (0 < c.x ? c.x : -c.x);
  1288. c = d.b2_aabbExtension + d.b2_aabbMultiplier * (0 < c.y ? c.y : -c.y);
  1289. a.aabb.lowerBound.x = b.lowerBound.x - e;
  1290. a.aabb.lowerBound.y = b.lowerBound.y - c;
  1291. a.aabb.upperBound.x = b.upperBound.x + e;
  1292. a.aabb.upperBound.y = b.upperBound.y + c;
  1293. this.InsertLeaf(a);
  1294. return !0
  1295. };
  1296. M.prototype.Rebalance = function(a) {
  1297. void 0 === a && (a = 0);
  1298. if (null != this.m_root)
  1299. for (var b = 0; b < a; b++) {
  1300. for (var c = this.m_root, d = 0; 0 == c.IsLeaf();) c = this.m_path >> d & 1 ? c.child2 : c.child1, d = d + 1 & 31;
  1301. ++this.m_path;
  1302. this.RemoveLeaf(c);
  1303. this.InsertLeaf(c)
  1304. }
  1305. };
  1306. M.prototype.GetFatAABB =
  1307. function(a) {
  1308. return a.aabb
  1309. };
  1310. M.prototype.GetUserData = function(a) {
  1311. return a.userData
  1312. };
  1313. M.prototype.Query = function(a, b) {
  1314. if (null != this.m_root) {
  1315. var c = new Vector,
  1316. d = 0;
  1317. for (c[d++] = this.m_root; 0 < d;) {
  1318. var e = c[--d];
  1319. if (e.aabb.TestOverlap(b))
  1320. if (e.IsLeaf()) {
  1321. if (!a(e)) break
  1322. } else c[d++] = e.child1, c[d++] = e.child2
  1323. }
  1324. }
  1325. };
  1326. M.prototype.RayCast = function(a, b) {
  1327. if (null != this.m_root) {
  1328. var c = b.p1,
  1329. d = b.p2,
  1330. f = e.SubtractVV(c, d);
  1331. f.Normalize();
  1332. var f = e.CrossFV(1, f),
  1333. g = e.AbsV(f),
  1334. h = b.maxFraction,
  1335. m = new l,
  1336. p, q;
  1337. p = c.x + h * (d.x - c.x);
  1338. q = c.y + h * (d.y - c.y);
  1339. m.lowerBound.x =
  1340. Math.min(c.x, p);
  1341. m.lowerBound.y = Math.min(c.y, q);
  1342. m.upperBound.x = Math.max(c.x, p);
  1343. m.upperBound.y = Math.max(c.y, q);
  1344. var y = new Vector,
  1345. A = 0;
  1346. for (y[A++] = this.m_root; 0 < A;)
  1347. if (h = y[--A], 0 != h.aabb.TestOverlap(m) && (p = h.aabb.GetCenter(), q = h.aabb.GetExtents(), !(0 < Math.abs(f.x * (c.x - p.x) + f.y * (c.y - p.y)) - g.x * q.x - g.y * q.y)))
  1348. if (h.IsLeaf()) {
  1349. p = new bc;
  1350. p.p1 = b.p1;
  1351. p.p2 = b.p2;
  1352. p.maxFraction = b.maxFraction;
  1353. h = a(p, h);
  1354. if (0 == h) break;
  1355. 0 < h && (p = c.x + h * (d.x - c.x), q = c.y + h * (d.y - c.y), m.lowerBound.x = Math.min(c.x, p), m.lowerBound.y = Math.min(c.y, q), m.upperBound.x =
  1356. Math.max(c.x, p), m.upperBound.y = Math.max(c.y, q))
  1357. } else y[A++] = h.child1, y[A++] = h.child2
  1358. }
  1359. };
  1360. M.prototype.AllocateNode = function() {
  1361. if (this.m_freeList) {
  1362. var a = this.m_freeList;
  1363. this.m_freeList = a.parent;
  1364. a.parent = null;
  1365. a.child1 = null;
  1366. a.child2 = null;
  1367. return a
  1368. }
  1369. return new Zb
  1370. };
  1371. M.prototype.FreeNode = function(a) {
  1372. a.parent = this.m_freeList;
  1373. this.m_freeList = a
  1374. };
  1375. M.prototype.InsertLeaf = function(a) {
  1376. ++this.m_insertionCount;
  1377. if (null == this.m_root) this.m_root = a, this.m_root.parent = null;
  1378. else {
  1379. var b = a.aabb.GetCenter(),
  1380. c = this.m_root;
  1381. if (0 ==
  1382. c.IsLeaf()) {
  1383. do var d = c.child1,
  1384. c = c.child2,
  1385. c = Math.abs((d.aabb.lowerBound.x + d.aabb.upperBound.x) / 2 - b.x) + Math.abs((d.aabb.lowerBound.y + d.aabb.upperBound.y) / 2 - b.y) < Math.abs((c.aabb.lowerBound.x + c.aabb.upperBound.x) / 2 - b.x) + Math.abs((c.aabb.lowerBound.y + c.aabb.upperBound.y) / 2 - b.y) ? d : c; while (0 == c.IsLeaf())
  1386. }
  1387. b = c.parent;
  1388. d = this.AllocateNode();
  1389. d.parent = b;
  1390. d.userData = null;
  1391. d.aabb.Combine(a.aabb, c.aabb);
  1392. if (b) {
  1393. c.parent.child1 == c ? b.child1 = d : b.child2 = d;
  1394. d.child1 = c;
  1395. d.child2 = a;
  1396. c.parent = d;
  1397. a.parent = d;
  1398. do {
  1399. if (b.aabb.Contains(d.aabb)) break;
  1400. b.aabb.Combine(b.child1.aabb, b.child2.aabb);
  1401. d = b;
  1402. b = b.parent
  1403. } while (b)
  1404. } else d.child1 = c, d.child2 = a, c.parent = d, this.m_root = a.parent = d
  1405. }
  1406. };
  1407. M.prototype.RemoveLeaf = function(a) {
  1408. if (a == this.m_root) this.m_root = null;
  1409. else {
  1410. var b = a.parent,
  1411. c = b.parent;
  1412. a = b.child1 == a ? b.child2 : b.child1;
  1413. if (c)
  1414. for (c.child1 == b ? c.child1 = a : c.child2 = a, a.parent = c, this.FreeNode(b); c;) {
  1415. b = c.aabb;
  1416. c.aabb = l.Combine(c.child1.aabb, c.child2.aabb);
  1417. if (b.Contains(c.aabb)) break;
  1418. c = c.parent
  1419. } else this.m_root = a, a.parent = null, this.FreeNode(b)
  1420. }
  1421. };
  1422. Xb.b2DynamicTreeBroadPhase =
  1423. function() {
  1424. this.m_tree = new M;
  1425. this.m_moveBuffer = new Vector;
  1426. this.m_pairBuffer = new Vector;
  1427. this.m_pairCount = 0
  1428. };
  1429. Xb.prototype.CreateProxy = function(a, b) {
  1430. var c = this.m_tree.CreateProxy(a, b);
  1431. ++this.m_proxyCount;
  1432. this.BufferMove(c);
  1433. return c
  1434. };
  1435. Xb.prototype.DestroyProxy = function(a) {
  1436. this.UnBufferMove(a);
  1437. --this.m_proxyCount;
  1438. this.m_tree.DestroyProxy(a)
  1439. };
  1440. Xb.prototype.MoveProxy = function(a, b, c) {
  1441. this.m_tree.MoveProxy(a, b, c) && this.BufferMove(a)
  1442. };
  1443. Xb.prototype.TestOverlap = function(a, b) {
  1444. var c = this.m_tree.GetFatAABB(a),
  1445. d = this.m_tree.GetFatAABB(b);
  1446. return c.TestOverlap(d)
  1447. };
  1448. Xb.prototype.GetUserData = function(a) {
  1449. return this.m_tree.GetUserData(a)
  1450. };
  1451. Xb.prototype.GetFatAABB = function(a) {
  1452. return this.m_tree.GetFatAABB(a)
  1453. };
  1454. Xb.prototype.GetProxyCount = function() {
  1455. return this.m_proxyCount
  1456. };
  1457. Xb.prototype.UpdatePairs = function(a) {
  1458. for (var b = this, c = b.m_pairCount = 0, d, c = 0; c < b.m_moveBuffer.length; ++c) {
  1459. d = b.m_moveBuffer[c];
  1460. var e = b.m_tree.GetFatAABB(d);
  1461. b.m_tree.Query(function(a) {
  1462. if (a == d) return !0;
  1463. b.m_pairCount == b.m_pairBuffer.length && (b.m_pairBuffer[b.m_pairCount] = new aa);
  1464. var c = b.m_pairBuffer[b.m_pairCount];
  1465. c.proxyA = a < d ? a : d;
  1466. c.proxyB = a >= d ? a : d;
  1467. ++b.m_pairCount;
  1468. return !0
  1469. }, e)
  1470. }
  1471. for (c = b.m_moveBuffer.length = 0; c < b.m_pairCount;) {
  1472. var e = b.m_pairBuffer[c],
  1473. f = b.m_tree.GetUserData(e.proxyA),
  1474. g = b.m_tree.GetUserData(e.proxyB);
  1475. a(f, g);
  1476. for (++c; c < b.m_pairCount;) {
  1477. f = b.m_pairBuffer[c];
  1478. if (f.proxyA != e.proxyA || f.proxyB != e.proxyB) break;
  1479. ++c
  1480. }
  1481. }
  1482. };
  1483. Xb.prototype.Query = function(a, b) {
  1484. this.m_tree.Query(a, b)
  1485. };
  1486. Xb.prototype.RayCast = function(a, b) {
  1487. this.m_tree.RayCast(a, b)
  1488. };
  1489. Xb.prototype.Validate = function() {};
  1490. Xb.prototype.Rebalance =
  1491. function(a) {
  1492. void 0 === a && (a = 0);
  1493. this.m_tree.Rebalance(a)
  1494. };
  1495. Xb.prototype.BufferMove = function(a) {
  1496. this.m_moveBuffer[this.m_moveBuffer.length] = a
  1497. };
  1498. Xb.prototype.UnBufferMove = function(a) {
  1499. this.m_moveBuffer.splice(parseInt(this.m_moveBuffer.indexOf(a)), 1)
  1500. };
  1501. Xb.prototype.ComparePairs = function() {
  1502. return 0
  1503. };
  1504. Xb.__implements = {};
  1505. Xb.__implements[oc] = !0;
  1506. Zb.b2DynamicTreeNode = function() {
  1507. this.aabb = new l
  1508. };
  1509. Zb.prototype.IsLeaf = function() {
  1510. return null == this.child1
  1511. };
  1512. aa.b2DynamicTreePair = function() {};
  1513. Yb.b2Manifold = function() {
  1514. this.m_pointCount =
  1515. 0
  1516. };
  1517. Yb.prototype.b2Manifold = function() {
  1518. this.m_points = new Vector(d.b2_maxManifoldPoints);
  1519. for (var a = 0; a < d.b2_maxManifoldPoints; a++) this.m_points[a] = new $b;
  1520. this.m_localPlaneNormal = new h;
  1521. this.m_localPoint = new h
  1522. };
  1523. Yb.prototype.Reset = function() {
  1524. for (var a = 0; a < d.b2_maxManifoldPoints; a++)(this.m_points[a] instanceof $b ? this.m_points[a] : null).Reset();
  1525. this.m_localPlaneNormal.SetZero();
  1526. this.m_localPoint.SetZero();
  1527. this.m_pointCount = this.m_type = 0
  1528. };
  1529. Yb.prototype.Set = function(a) {
  1530. this.m_pointCount = a.m_pointCount;
  1531. for (var b =
  1532. 0; b < d.b2_maxManifoldPoints; b++)(this.m_points[b] instanceof $b ? this.m_points[b] : null).Set(a.m_points[b]);
  1533. this.m_localPlaneNormal.SetV(a.m_localPlaneNormal);
  1534. this.m_localPoint.SetV(a.m_localPoint);
  1535. this.m_type = a.m_type
  1536. };
  1537. Yb.prototype.Copy = function() {
  1538. var a = new Yb;
  1539. a.Set(this);
  1540. return a
  1541. };
  1542. Box2D.postDefs.push(function() {
  1543. Box2D.Collision.b2Manifold.e_circles = 1;
  1544. Box2D.Collision.b2Manifold.e_faceA = 2;
  1545. Box2D.Collision.b2Manifold.e_faceB = 4
  1546. });
  1547. $b.b2ManifoldPoint = function() {
  1548. this.m_localPoint = new h;
  1549. this.m_id = new y
  1550. };
  1551. $b.prototype.b2ManifoldPoint =
  1552. function() {
  1553. this.Reset()
  1554. };
  1555. $b.prototype.Reset = function() {
  1556. this.m_localPoint.SetZero();
  1557. this.m_tangentImpulse = this.m_normalImpulse = 0;
  1558. this.m_id.key = 0
  1559. };
  1560. $b.prototype.Set = function(a) {
  1561. this.m_localPoint.SetV(a.m_localPoint);
  1562. this.m_normalImpulse = a.m_normalImpulse;
  1563. this.m_tangentImpulse = a.m_tangentImpulse;
  1564. this.m_id.Set(a.m_id)
  1565. };
  1566. ac.b2Point = function() {
  1567. this.p = new h
  1568. };
  1569. ac.prototype.Support = function() {
  1570. return this.p
  1571. };
  1572. ac.prototype.GetFirstVertex = function() {
  1573. return this.p
  1574. };
  1575. bc.b2RayCastInput = function() {
  1576. this.p1 = new h;
  1577. this.p2 =
  1578. new h
  1579. };
  1580. bc.prototype.b2RayCastInput = function(a, b, c) {
  1581. void 0 === a && (a = null);
  1582. void 0 === b && (b = null);
  1583. void 0 === c && (c = 1);
  1584. a && this.p1.SetV(a);
  1585. b && this.p2.SetV(b);
  1586. this.maxFraction = c
  1587. };
  1588. ec.b2RayCastOutput = function() {
  1589. this.normal = new h
  1590. };
  1591. jc.b2Segment = function() {
  1592. this.p1 = new h;
  1593. this.p2 = new h
  1594. };
  1595. jc.prototype.TestSegment = function(a, b, c, d) {
  1596. void 0 === d && (d = 0);
  1597. var e = c.p1,
  1598. f = c.p2.x - e.x,
  1599. g = c.p2.y - e.y;
  1600. c = this.p2.y - this.p1.y;
  1601. var h = -(this.p2.x - this.p1.x),
  1602. l = 100 * Number.MIN_VALUE,
  1603. m = -(f * c + g * h);
  1604. if (m > l) {
  1605. var p = e.x - this.p1.x,
  1606. q = e.y - this.p1.y,
  1607. e =
  1608. p * c + q * h;
  1609. if (0 <= e && e <= d * m && (d = -f * q + g * p, -l * m <= d && d <= m * (1 + l))) return d = Math.sqrt(c * c + h * h), a[0] = e / m, b.Set(c / d, h / d), !0
  1610. }
  1611. return !1
  1612. };
  1613. jc.prototype.Extend = function(a) {
  1614. this.ExtendForward(a);
  1615. this.ExtendBackward(a)
  1616. };
  1617. jc.prototype.ExtendForward = function(a) {
  1618. var b = this.p2.x - this.p1.x,
  1619. c = this.p2.y - this.p1.y;
  1620. a = Math.min(0 < b ? (a.upperBound.x - this.p1.x) / b : 0 > b ? (a.lowerBound.x - this.p1.x) / b : Number.POSITIVE_INFINITY, 0 < c ? (a.upperBound.y - this.p1.y) / c : 0 > c ? (a.lowerBound.y - this.p1.y) / c : Number.POSITIVE_INFINITY);
  1621. this.p2.x = this.p1.x +
  1622. b * a;
  1623. this.p2.y = this.p1.y + c * a
  1624. };
  1625. jc.prototype.ExtendBackward = function(a) {
  1626. var b = -this.p2.x + this.p1.x,
  1627. c = -this.p2.y + this.p1.y;
  1628. a = Math.min(0 < b ? (a.upperBound.x - this.p2.x) / b : 0 > b ? (a.lowerBound.x - this.p2.x) / b : Number.POSITIVE_INFINITY, 0 < c ? (a.upperBound.y - this.p2.y) / c : 0 > c ? (a.lowerBound.y - this.p2.y) / c : Number.POSITIVE_INFINITY);
  1629. this.p1.x = this.p2.x + b * a;
  1630. this.p1.y = this.p2.y + c * a
  1631. };
  1632. cc.b2SeparationFunction = function() {
  1633. this.m_localPoint = new h;
  1634. this.m_axis = new h
  1635. };
  1636. cc.prototype.Initialize = function(a, b, c, f, g) {
  1637. this.m_proxyA = b;
  1638. this.m_proxyB =
  1639. f;
  1640. var l = parseInt(a.count);
  1641. d.b2Assert(0 < l && 3 > l);
  1642. var m, p, q, y, A, B;
  1643. 1 == l ? (this.m_type = cc.e_points, m = this.m_proxyA.GetVertex(a.indexA[0]), p = this.m_proxyB.GetVertex(a.indexB[0]), l = m, a = c.R, b = c.position.x + (a.col1.x * l.x + a.col2.x * l.y), f = c.position.y + (a.col1.y * l.x + a.col2.y * l.y), l = p, a = g.R, q = g.position.x + (a.col1.x * l.x + a.col2.x * l.y), y = g.position.y + (a.col1.y * l.x + a.col2.y * l.y), this.m_axis.x = q - b, this.m_axis.y = y - f, this.m_axis.Normalize()) : (a.indexB[0] == a.indexB[1] ? (this.m_type = cc.e_faceA, b = this.m_proxyA.GetVertex(a.indexA[0]),
  1644. f = this.m_proxyA.GetVertex(a.indexA[1]), p = this.m_proxyB.GetVertex(a.indexB[0]), this.m_localPoint.x = .5 * (b.x + f.x), this.m_localPoint.y = .5 * (b.y + f.y), this.m_axis = e.CrossVF(e.SubtractVV(f, b), 1), this.m_axis.Normalize(), l = this.m_axis, a = c.R, A = a.col1.x * l.x + a.col2.x * l.y, B = a.col1.y * l.x + a.col2.y * l.y, l = this.m_localPoint, a = c.R, b = c.position.x + (a.col1.x * l.x + a.col2.x * l.y), f = c.position.y + (a.col1.y * l.x + a.col2.y * l.y), l = p, a = g.R, q = g.position.x + (a.col1.x * l.x + a.col2.x * l.y), y = g.position.y + (a.col1.y * l.x + a.col2.y * l.y), A = (q - b) *
  1645. A + (y - f) * B) : a.indexA[0] == a.indexA[0] ? (this.m_type = cc.e_faceB, q = this.m_proxyB.GetVertex(a.indexB[0]), y = this.m_proxyB.GetVertex(a.indexB[1]), m = this.m_proxyA.GetVertex(a.indexA[0]), this.m_localPoint.x = .5 * (q.x + y.x), this.m_localPoint.y = .5 * (q.y + y.y), this.m_axis = e.CrossVF(e.SubtractVV(y, q), 1), this.m_axis.Normalize(), l = this.m_axis, a = g.R, A = a.col1.x * l.x + a.col2.x * l.y, B = a.col1.y * l.x + a.col2.y * l.y, l = this.m_localPoint, a = g.R, q = g.position.x + (a.col1.x * l.x + a.col2.x * l.y), y = g.position.y + (a.col1.y * l.x + a.col2.y * l.y), l = m,
  1646. a = c.R, b = c.position.x + (a.col1.x * l.x + a.col2.x * l.y), f = c.position.y + (a.col1.y * l.x + a.col2.y * l.y), A = (b - q) * A + (f - y) * B) : (b = this.m_proxyA.GetVertex(a.indexA[0]), f = this.m_proxyA.GetVertex(a.indexA[1]), q = this.m_proxyB.GetVertex(a.indexB[0]), y = this.m_proxyB.GetVertex(a.indexB[1]), e.MulX(c, m), m = e.MulMV(c.R, e.SubtractVV(f, b)), e.MulX(g, p), A = e.MulMV(g.R, e.SubtractVV(y, q)), g = m.x * m.x + m.y * m.y, p = A.x * A.x + A.y * A.y, a = e.SubtractVV(A, m), c = m.x * a.x + m.y * a.y, a = A.x * a.x + A.y * a.y, m = m.x * A.x + m.y * A.y, B = g * p - m * m, A = 0, 0 != B && (A = e.Clamp((m *
  1647. a - c * p) / B, 0, 1)), 0 > (m * A + a) / p && (A = e.Clamp((m - c) / g, 0, 1)), m = new h, m.x = b.x + A * (f.x - b.x), m.y = b.y + A * (f.y - b.y), p = new h, p.x = q.x + A * (y.x - q.x), p.y = q.y + A * (y.y - q.y), 0 == A || 1 == A ? (this.m_type = cc.e_faceB, this.m_axis = e.CrossVF(e.SubtractVV(y, q), 1), this.m_axis.Normalize(), this.m_localPoint = p) : (this.m_type = cc.e_faceA, this.m_axis = e.CrossVF(e.SubtractVV(f, b), 1), this.m_localPoint = m)), 0 > A && this.m_axis.NegativeSelf())
  1648. };
  1649. cc.prototype.Evaluate = function(a, b) {
  1650. var c, f, g;
  1651. switch (this.m_type) {
  1652. case cc.e_points:
  1653. return c = e.MulTMV(a.R, this.m_axis),
  1654. f = e.MulTMV(b.R, this.m_axis.GetNegative()), c = this.m_proxyA.GetSupportVertex(c), f = this.m_proxyB.GetSupportVertex(f), c = e.MulX(a, c), f = e.MulX(b, f), (f.x - c.x) * this.m_axis.x + (f.y - c.y) * this.m_axis.y;
  1655. case cc.e_faceA:
  1656. return g = e.MulMV(a.R, this.m_axis), c = e.MulX(a, this.m_localPoint), f = e.MulTMV(b.R, g.GetNegative()), f = this.m_proxyB.GetSupportVertex(f), f = e.MulX(b, f), (f.x - c.x) * g.x + (f.y - c.y) * g.y;
  1657. case cc.e_faceB:
  1658. return g = e.MulMV(b.R, this.m_axis), f = e.MulX(b, this.m_localPoint), c = e.MulTMV(a.R, g.GetNegative()), c = this.m_proxyA.GetSupportVertex(c),
  1659. c = e.MulX(a, c), (c.x - f.x) * g.x + (c.y - f.y) * g.y;
  1660. default:
  1661. return d.b2Assert(!1), 0
  1662. }
  1663. };
  1664. Box2D.postDefs.push(function() {
  1665. Box2D.Collision.b2SeparationFunction.e_points = 1;
  1666. Box2D.Collision.b2SeparationFunction.e_faceA = 2;
  1667. Box2D.Collision.b2SeparationFunction.e_faceB = 4
  1668. });
  1669. dc.b2Simplex = function() {
  1670. this.m_v1 = new hc;
  1671. this.m_v2 = new hc;
  1672. this.m_v3 = new hc;
  1673. this.m_vertices = new Vector(3)
  1674. };
  1675. dc.prototype.b2Simplex = function() {
  1676. this.m_vertices[0] = this.m_v1;
  1677. this.m_vertices[1] = this.m_v2;
  1678. this.m_vertices[2] = this.m_v3
  1679. };
  1680. dc.prototype.ReadCache =
  1681. function(a, b, c, f, g) {
  1682. d.b2Assert(0 <= a.count && 3 >= a.count);
  1683. var h, l;
  1684. this.m_count = a.count;
  1685. for (var m = this.m_vertices, p = 0; p < this.m_count; p++) {
  1686. var q = m[p];
  1687. q.indexA = a.indexA[p];
  1688. q.indexB = a.indexB[p];
  1689. h = b.GetVertex(q.indexA);
  1690. l = f.GetVertex(q.indexB);
  1691. q.wA = e.MulX(c, h);
  1692. q.wB = e.MulX(g, l);
  1693. q.w = e.SubtractVV(q.wB, q.wA);
  1694. q.a = 0
  1695. }
  1696. 1 < this.m_count && (a = a.metric, h = this.GetMetric(), h < .5 * a || 2 * a < h || h < Number.MIN_VALUE) && (this.m_count = 0);
  1697. 0 == this.m_count && (q = m[0], q.indexA = 0, q.indexB = 0, h = b.GetVertex(0), l = f.GetVertex(0), q.wA = e.MulX(c, h),
  1698. q.wB = e.MulX(g, l), q.w = e.SubtractVV(q.wB, q.wA), this.m_count = 1)
  1699. };
  1700. dc.prototype.WriteCache = function(a) {
  1701. a.metric = this.GetMetric();
  1702. a.count = Box2D.parseUInt(this.m_count);
  1703. for (var b = this.m_vertices, c = 0; c < this.m_count; c++) a.indexA[c] = Box2D.parseUInt(b[c].indexA), a.indexB[c] = Box2D.parseUInt(b[c].indexB)
  1704. };
  1705. dc.prototype.GetSearchDirection = function() {
  1706. switch (this.m_count) {
  1707. case 1:
  1708. return this.m_v1.w.GetNegative();
  1709. case 2:
  1710. var a = e.SubtractVV(this.m_v2.w, this.m_v1.w);
  1711. return 0 < e.CrossVV(a, this.m_v1.w.GetNegative()) ? e.CrossFV(1,
  1712. a) : e.CrossVF(a, 1);
  1713. default:
  1714. return d.b2Assert(!1), new h
  1715. }
  1716. };
  1717. dc.prototype.GetClosestPoint = function() {
  1718. switch (this.m_count) {
  1719. case 0:
  1720. return d.b2Assert(!1), new h;
  1721. case 1:
  1722. return this.m_v1.w;
  1723. case 2:
  1724. return new h(this.m_v1.a * this.m_v1.w.x + this.m_v2.a * this.m_v2.w.x, this.m_v1.a * this.m_v1.w.y + this.m_v2.a * this.m_v2.w.y);
  1725. default:
  1726. return d.b2Assert(!1), new h
  1727. }
  1728. };
  1729. dc.prototype.GetWitnessPoints = function(a, b) {
  1730. switch (this.m_count) {
  1731. case 0:
  1732. d.b2Assert(!1);
  1733. break;
  1734. case 1:
  1735. a.SetV(this.m_v1.wA);
  1736. b.SetV(this.m_v1.wB);
  1737. break;
  1738. case 2:
  1739. a.x = this.m_v1.a *
  1740. this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x;
  1741. a.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y;
  1742. b.x = this.m_v1.a * this.m_v1.wB.x + this.m_v2.a * this.m_v2.wB.x;
  1743. b.y = this.m_v1.a * this.m_v1.wB.y + this.m_v2.a * this.m_v2.wB.y;
  1744. break;
  1745. case 3:
  1746. b.x = a.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x + this.m_v3.a * this.m_v3.wA.x;
  1747. b.y = a.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y + this.m_v3.a * this.m_v3.wA.y;
  1748. break;
  1749. default:
  1750. d.b2Assert(!1)
  1751. }
  1752. };
  1753. dc.prototype.GetMetric = function() {
  1754. switch (this.m_count) {
  1755. case 0:
  1756. return d.b2Assert(!1),
  1757. 0;
  1758. case 1:
  1759. return 0;
  1760. case 2:
  1761. return e.SubtractVV(this.m_v1.w, this.m_v2.w).Length();
  1762. case 3:
  1763. return e.CrossVV(e.SubtractVV(this.m_v2.w, this.m_v1.w), e.SubtractVV(this.m_v3.w, this.m_v1.w));
  1764. default:
  1765. return d.b2Assert(!1), 0
  1766. }
  1767. };
  1768. dc.prototype.Solve2 = function() {
  1769. var a = this.m_v1.w,
  1770. b = this.m_v2.w,
  1771. c = e.SubtractVV(b, a),
  1772. a = -(a.x * c.x + a.y * c.y);
  1773. 0 >= a ? this.m_count = this.m_v1.a = 1 : (b = b.x * c.x + b.y * c.y, 0 >= b ? (this.m_count = this.m_v2.a = 1, this.m_v1.Set(this.m_v2)) : (c = 1 / (b + a), this.m_v1.a = b * c, this.m_v2.a = a * c, this.m_count = 2))
  1774. };
  1775. dc.prototype.Solve3 =
  1776. function() {
  1777. var a = this.m_v1.w,
  1778. b = this.m_v2.w,
  1779. c = this.m_v3.w,
  1780. d = e.SubtractVV(b, a),
  1781. f = e.Dot(a, d),
  1782. g = e.Dot(b, d),
  1783. f = -f,
  1784. h = e.SubtractVV(c, a),
  1785. l = e.Dot(a, h),
  1786. m = e.Dot(c, h),
  1787. l = -l,
  1788. p = e.SubtractVV(c, b),
  1789. q = e.Dot(b, p),
  1790. p = e.Dot(c, p),
  1791. q = -q,
  1792. h = e.CrossVV(d, h),
  1793. d = h * e.CrossVV(b, c),
  1794. c = h * e.CrossVV(c, a),
  1795. a = h * e.CrossVV(a, b);
  1796. 0 >= f && 0 >= l ? this.m_count = this.m_v1.a = 1 : 0 < g && 0 < f && 0 >= a ? (m = 1 / (g + f), this.m_v1.a = g * m, this.m_v2.a = f * m, this.m_count = 2) : 0 < m && 0 < l && 0 >= c ? (g = 1 / (m + l), this.m_v1.a = m * g, this.m_v3.a = l * g, this.m_count = 2, this.m_v2.Set(this.m_v3)) : 0 >= g &&
  1797. 0 >= q ? (this.m_count = this.m_v2.a = 1, this.m_v1.Set(this.m_v2)) : 0 >= m && 0 >= p ? (this.m_count = this.m_v3.a = 1, this.m_v1.Set(this.m_v3)) : 0 < p && 0 < q && 0 >= d ? (g = 1 / (p + q), this.m_v2.a = p * g, this.m_v3.a = q * g, this.m_count = 2, this.m_v1.Set(this.m_v3)) : (g = 1 / (d + c + a), this.m_v1.a = d * g, this.m_v2.a = c * g, this.m_v3.a = a * g, this.m_count = 3)
  1798. };
  1799. gc.b2SimplexCache = function() {
  1800. this.indexA = new Vector_a2j_Number(3);
  1801. this.indexB = new Vector_a2j_Number(3)
  1802. };
  1803. hc.b2SimplexVertex = function() {};
  1804. hc.prototype.Set = function(a) {
  1805. this.wA.SetV(a.wA);
  1806. this.wB.SetV(a.wB);
  1807. this.w.SetV(a.w);
  1808. this.a = a.a;
  1809. this.indexA = a.indexA;
  1810. this.indexB = a.indexB
  1811. };
  1812. fc.b2TimeOfImpact = function() {};
  1813. fc.TimeOfImpact = function(a) {
  1814. ++fc.b2_toiCalls;
  1815. var b = a.proxyA,
  1816. c = a.proxyB,
  1817. f = a.sweepA,
  1818. g = a.sweepB;
  1819. d.b2Assert(f.t0 == g.t0);
  1820. d.b2Assert(1 - f.t0 > Number.MIN_VALUE);
  1821. var h = b.m_radius + c.m_radius;
  1822. a = a.tolerance;
  1823. var l = 0,
  1824. m = 0,
  1825. p = 0;
  1826. fc.s_cache.count = 0;
  1827. for (fc.s_distanceInput.useRadii = !1;;) {
  1828. f.GetTransform(fc.s_xfA, l);
  1829. g.GetTransform(fc.s_xfB, l);
  1830. fc.s_distanceInput.proxyA = b;
  1831. fc.s_distanceInput.proxyB = c;
  1832. fc.s_distanceInput.transformA =
  1833. fc.s_xfA;
  1834. fc.s_distanceInput.transformB = fc.s_xfB;
  1835. B.Distance(fc.s_distanceOutput, fc.s_cache, fc.s_distanceInput);
  1836. if (0 >= fc.s_distanceOutput.distance) {
  1837. l = 1;
  1838. break
  1839. }
  1840. fc.s_fcn.Initialize(fc.s_cache, b, fc.s_xfA, c, fc.s_xfB);
  1841. var q = fc.s_fcn.Evaluate(fc.s_xfA, fc.s_xfB);
  1842. if (0 >= q) {
  1843. l = 1;
  1844. break
  1845. }
  1846. 0 == m && (p = q > h ? e.Max(h - a, .75 * h) : e.Max(q - a, .02 * h));
  1847. if (q - p < .5 * a) {
  1848. if (0 == m) {
  1849. l = 1;
  1850. break
  1851. }
  1852. break
  1853. }
  1854. var y = l,
  1855. A = l,
  1856. H = 1;
  1857. f.GetTransform(fc.s_xfA, H);
  1858. g.GetTransform(fc.s_xfB, H);
  1859. var E = fc.s_fcn.Evaluate(fc.s_xfA, fc.s_xfB);
  1860. if (E >= p) {
  1861. l = 1;
  1862. break
  1863. }
  1864. for (var M = 0;;) {
  1865. var K;
  1866. K = M & 1 ? A + (p - q) * (H - A) / (E - q) : .5 * (A + H);
  1867. f.GetTransform(fc.s_xfA, K);
  1868. g.GetTransform(fc.s_xfB, K);
  1869. var aa = fc.s_fcn.Evaluate(fc.s_xfA, fc.s_xfB);
  1870. if (e.Abs(aa - p) < .025 * a) {
  1871. y = K;
  1872. break
  1873. }
  1874. aa > p ? (A = K, q = aa) : (H = K, E = aa);
  1875. ++M;
  1876. ++fc.b2_toiRootIters;
  1877. if (50 == M) break
  1878. }
  1879. fc.b2_toiMaxRootIters = e.Max(fc.b2_toiMaxRootIters, M);
  1880. if (y < (1 + 100 * Number.MIN_VALUE) * l) break;
  1881. l = y;
  1882. m++;
  1883. ++fc.b2_toiIters;
  1884. if (1E3 == m) break
  1885. }
  1886. fc.b2_toiMaxIters = e.Max(fc.b2_toiMaxIters, m);
  1887. return l
  1888. };
  1889. Box2D.postDefs.push(function() {
  1890. Box2D.Collision.b2TimeOfImpact.b2_toiCalls = 0;
  1891. Box2D.Collision.b2TimeOfImpact.b2_toiIters =
  1892. 0;
  1893. Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters = 0;
  1894. Box2D.Collision.b2TimeOfImpact.b2_toiRootIters = 0;
  1895. Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters = 0;
  1896. Box2D.Collision.b2TimeOfImpact.s_cache = new gc;
  1897. Box2D.Collision.b2TimeOfImpact.s_distanceInput = new K;
  1898. Box2D.Collision.b2TimeOfImpact.s_xfA = new g;
  1899. Box2D.Collision.b2TimeOfImpact.s_xfB = new g;
  1900. Box2D.Collision.b2TimeOfImpact.s_fcn = new cc;
  1901. Box2D.Collision.b2TimeOfImpact.s_distanceOutput = new H
  1902. });
  1903. kc.b2TOIInput = function() {
  1904. this.proxyA = new E;
  1905. this.proxyB = new E;
  1906. this.sweepA =
  1907. new f;
  1908. this.sweepB = new f
  1909. };
  1910. lc.b2WorldManifold = function() {
  1911. this.m_normal = new h
  1912. };
  1913. lc.prototype.b2WorldManifold = function() {
  1914. this.m_points = new Vector(d.b2_maxManifoldPoints);
  1915. for (var a = 0; a < d.b2_maxManifoldPoints; a++) this.m_points[a] = new h
  1916. };
  1917. lc.prototype.Initialize = function(a, b, c, d, e) {
  1918. void 0 === c && (c = 0);
  1919. void 0 === e && (e = 0);
  1920. if (0 != a.m_pointCount) {
  1921. var f, g, h, l, m, p, q, y;
  1922. switch (a.m_type) {
  1923. case Yb.e_circles:
  1924. h = b.R;
  1925. g = a.m_localPoint;
  1926. f = b.position.x + h.col1.x * g.x + h.col2.x * g.y;
  1927. b = b.position.y + h.col1.y * g.x + h.col2.y * g.y;
  1928. h = d.R;
  1929. g = a.m_points[0].m_localPoint;
  1930. a = d.position.x + h.col1.x * g.x + h.col2.x * g.y;
  1931. d = d.position.y + h.col1.y * g.x + h.col2.y * g.y;
  1932. g = a - f;
  1933. h = d - b;
  1934. l = g * g + h * h;
  1935. l > Number.MIN_VALUE * Number.MIN_VALUE ? (l = Math.sqrt(l), this.m_normal.x = g / l, this.m_normal.y = h / l) : (this.m_normal.x = 1, this.m_normal.y = 0);
  1936. g = b + c * this.m_normal.y;
  1937. d -= e * this.m_normal.y;
  1938. this.m_points[0].x = .5 * (f + c * this.m_normal.x + (a - e * this.m_normal.x));
  1939. this.m_points[0].y = .5 * (g + d);
  1940. break;
  1941. case Yb.e_faceA:
  1942. h = b.R;
  1943. g = a.m_localPlaneNormal;
  1944. l = h.col1.x * g.x + h.col2.x * g.y;
  1945. m = h.col1.y * g.x + h.col2.y * g.y;
  1946. h = b.R;
  1947. g = a.m_localPoint;
  1948. p = b.position.x + h.col1.x * g.x + h.col2.x * g.y;
  1949. q = b.position.y + h.col1.y * g.x + h.col2.y * g.y;
  1950. this.m_normal.x = l;
  1951. this.m_normal.y = m;
  1952. for (f = 0; f < a.m_pointCount; f++) h = d.R, g = a.m_points[f].m_localPoint, y = d.position.x + h.col1.x * g.x + h.col2.x * g.y, g = d.position.y + h.col1.y * g.x + h.col2.y * g.y, this.m_points[f].x = y + .5 * (c - (y - p) * l - (g - q) * m - e) * l, this.m_points[f].y = g + .5 * (c - (y - p) * l - (g - q) * m - e) * m;
  1953. break;
  1954. case Yb.e_faceB:
  1955. for (h = d.R, g = a.m_localPlaneNormal, l = h.col1.x * g.x + h.col2.x * g.y, m = h.col1.y * g.x + h.col2.y * g.y, h = d.R, g = a.m_localPoint, p = d.position.x +
  1956. h.col1.x * g.x + h.col2.x * g.y, q = d.position.y + h.col1.y * g.x + h.col2.y * g.y, this.m_normal.x = -l, this.m_normal.y = -m, f = 0; f < a.m_pointCount; f++) h = b.R, g = a.m_points[f].m_localPoint, y = b.position.x + h.col1.x * g.x + h.col2.x * g.y, g = b.position.y + h.col1.y * g.x + h.col2.y * g.y, this.m_points[f].x = y + .5 * (e - (y - p) * l - (g - q) * m - c) * l, this.m_points[f].y = g + .5 * (e - (y - p) * l - (g - q) * m - c) * m
  1957. }
  1958. }
  1959. };
  1960. mc.ClipVertex = function() {
  1961. this.v = new h;
  1962. this.id = new y
  1963. };
  1964. mc.prototype.Set = function(a) {
  1965. this.v.SetV(a.v);
  1966. this.id.Set(a.id)
  1967. };
  1968. nc.Features = function() {};
  1969. Object.defineProperty(nc.prototype,
  1970. "referenceEdge", {
  1971. enumerable: !1,
  1972. configurable: !0,
  1973. get: function() {
  1974. return this._referenceEdge
  1975. }
  1976. });
  1977. Object.defineProperty(nc.prototype, "referenceEdge", {
  1978. enumerable: !1,
  1979. configurable: !0,
  1980. set: function(a) {
  1981. void 0 === a && (a = 0);
  1982. this._referenceEdge = a;
  1983. this._m_id._key = this._m_id._key & 4294967040 | this._referenceEdge & 255
  1984. }
  1985. });
  1986. Object.defineProperty(nc.prototype, "incidentEdge", {
  1987. enumerable: !1,
  1988. configurable: !0,
  1989. get: function() {
  1990. return this._incidentEdge
  1991. }
  1992. });
  1993. Object.defineProperty(nc.prototype, "incidentEdge", {
  1994. enumerable: !1,
  1995. configurable: !0,
  1996. set: function(a) {
  1997. void 0 === a && (a = 0);
  1998. this._incidentEdge = a;
  1999. this._m_id._key = this._m_id._key & 4294902015 | this._incidentEdge << 8 & 65280
  2000. }
  2001. });
  2002. Object.defineProperty(nc.prototype, "incidentVertex", {
  2003. enumerable: !1,
  2004. configurable: !0,
  2005. get: function() {
  2006. return this._incidentVertex
  2007. }
  2008. });
  2009. Object.defineProperty(nc.prototype, "incidentVertex", {
  2010. enumerable: !1,
  2011. configurable: !0,
  2012. set: function(a) {
  2013. void 0 === a && (a = 0);
  2014. this._incidentVertex = a;
  2015. this._m_id._key = this._m_id._key & 4278255615 | this._incidentVertex << 16 & 16711680
  2016. }
  2017. });
  2018. Object.defineProperty(nc.prototype,
  2019. "flip", {
  2020. enumerable: !1,
  2021. configurable: !0,
  2022. get: function() {
  2023. return this._flip
  2024. }
  2025. });
  2026. Object.defineProperty(nc.prototype, "flip", {
  2027. enumerable: !1,
  2028. configurable: !0,
  2029. set: function(a) {
  2030. void 0 === a && (a = 0);
  2031. this._flip = a;
  2032. this._m_id._key = this._m_id._key & 16777215 | this._flip << 24 & 4278190080
  2033. }
  2034. })
  2035. })();
  2036. (function() {
  2037. var a = Box2D.Common.b2Settings,
  2038. c = Box2D.Collision.Shapes.b2CircleShape,
  2039. b = Box2D.Collision.Shapes.b2EdgeChainDef,
  2040. d = Box2D.Collision.Shapes.b2EdgeShape,
  2041. e = Box2D.Collision.Shapes.b2MassData,
  2042. f = Box2D.Collision.Shapes.b2PolygonShape,
  2043. g = Box2D.Collision.Shapes.b2Shape,
  2044. h = Box2D.Common.Math.b2Mat22,
  2045. l = Box2D.Common.Math.b2Math,
  2046. m = Box2D.Common.Math.b2Transform,
  2047. q = Box2D.Common.Math.b2Vec2,
  2048. p = Box2D.Collision.b2Distance,
  2049. y = Box2D.Collision.b2DistanceInput,
  2050. A = Box2D.Collision.b2DistanceOutput,
  2051. B = Box2D.Collision.b2DistanceProxy,
  2052. K = Box2D.Collision.b2SimplexCache;
  2053. Box2D.inherit(c, Box2D.Collision.Shapes.b2Shape);
  2054. c.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
  2055. c.b2CircleShape = function() {
  2056. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
  2057. this.m_p = new q
  2058. };
  2059. c.prototype.Copy = function() {
  2060. var a = new c;
  2061. a.Set(this);
  2062. return a
  2063. };
  2064. c.prototype.Set = function(a) {
  2065. this.__super.Set.call(this, a);
  2066. Box2D.is(a, c) && this.m_p.SetV((a instanceof c ? a : null).m_p)
  2067. };
  2068. c.prototype.TestPoint = function(a, b) {
  2069. var c = a.R,
  2070. d = a.position.x + (c.col1.x * this.m_p.x +
  2071. c.col2.x * this.m_p.y),
  2072. c = a.position.y + (c.col1.y * this.m_p.x + c.col2.y * this.m_p.y),
  2073. d = b.x - d,
  2074. c = b.y - c;
  2075. return d * d + c * c <= this.m_radius * this.m_radius
  2076. };
  2077. c.prototype.RayCast = function(a, b, c) {
  2078. var d = c.R,
  2079. e = b.p1.x - (c.position.x + (d.col1.x * this.m_p.x + d.col2.x * this.m_p.y));
  2080. c = b.p1.y - (c.position.y + (d.col1.y * this.m_p.x + d.col2.y * this.m_p.y));
  2081. var d = b.p2.x - b.p1.x,
  2082. f = b.p2.y - b.p1.y,
  2083. g = e * d + c * f,
  2084. h = d * d + f * f,
  2085. l = g * g - h * (e * e + c * c - this.m_radius * this.m_radius);
  2086. if (0 > l || h < Number.MIN_VALUE) return !1;
  2087. g = -(g + Math.sqrt(l));
  2088. return 0 <= g && g <= b.maxFraction *
  2089. h ? (g /= h, a.fraction = g, a.normal.x = e + g * d, a.normal.y = c + g * f, a.normal.Normalize(), !0) : !1
  2090. };
  2091. c.prototype.ComputeAABB = function(a, b) {
  2092. var c = b.R,
  2093. d = b.position.x + (c.col1.x * this.m_p.x + c.col2.x * this.m_p.y),
  2094. c = b.position.y + (c.col1.y * this.m_p.x + c.col2.y * this.m_p.y);
  2095. a.lowerBound.Set(d - this.m_radius, c - this.m_radius);
  2096. a.upperBound.Set(d + this.m_radius, c + this.m_radius)
  2097. };
  2098. c.prototype.ComputeMass = function(b, c) {
  2099. void 0 === c && (c = 0);
  2100. b.mass = c * a.b2_pi * this.m_radius * this.m_radius;
  2101. b.center.SetV(this.m_p);
  2102. b.I = b.mass * (.5 * this.m_radius *
  2103. this.m_radius + (this.m_p.x * this.m_p.x + this.m_p.y * this.m_p.y))
  2104. };
  2105. c.prototype.ComputeSubmergedArea = function(a, b, c, d) {
  2106. void 0 === b && (b = 0);
  2107. c = l.MulX(c, this.m_p);
  2108. var e = -(l.Dot(a, c) - b);
  2109. if (e < -this.m_radius + Number.MIN_VALUE) return 0;
  2110. if (e > this.m_radius) return d.SetV(c), Math.PI * this.m_radius * this.m_radius;
  2111. b = this.m_radius * this.m_radius;
  2112. var f = e * e,
  2113. e = b * (Math.asin(e / this.m_radius) + Math.PI / 2) + e * Math.sqrt(b - f);
  2114. b = -2 / 3 * Math.pow(b - f, 1.5) / e;
  2115. d.x = c.x + a.x * b;
  2116. d.y = c.y + a.y * b;
  2117. return e
  2118. };
  2119. c.prototype.GetLocalPosition = function() {
  2120. return this.m_p
  2121. };
  2122. c.prototype.SetLocalPosition = function(a) {
  2123. this.m_p.SetV(a)
  2124. };
  2125. c.prototype.GetRadius = function() {
  2126. return this.m_radius
  2127. };
  2128. c.prototype.SetRadius = function(a) {
  2129. void 0 === a && (a = 0);
  2130. this.m_radius = a
  2131. };
  2132. c.prototype.b2CircleShape = function(a) {
  2133. void 0 === a && (a = 0);
  2134. this.__super.b2Shape.call(this);
  2135. this.m_type = g.e_circleShape;
  2136. this.m_radius = a
  2137. };
  2138. b.b2EdgeChainDef = function() {};
  2139. b.prototype.b2EdgeChainDef = function() {
  2140. this.vertexCount = 0;
  2141. this.isALoop = !0;
  2142. this.vertices = []
  2143. };
  2144. Box2D.inherit(d, Box2D.Collision.Shapes.b2Shape);
  2145. d.prototype.__super =
  2146. Box2D.Collision.Shapes.b2Shape.prototype;
  2147. d.b2EdgeShape = function() {
  2148. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
  2149. this.s_supportVec = new q;
  2150. this.m_v1 = new q;
  2151. this.m_v2 = new q;
  2152. this.m_coreV1 = new q;
  2153. this.m_coreV2 = new q;
  2154. this.m_normal = new q;
  2155. this.m_direction = new q;
  2156. this.m_cornerDir1 = new q;
  2157. this.m_cornerDir2 = new q
  2158. };
  2159. d.prototype.TestPoint = function() {
  2160. return !1
  2161. };
  2162. d.prototype.RayCast = function(a, b, c) {
  2163. var d, e = b.p2.x - b.p1.x,
  2164. f = b.p2.y - b.p1.y;
  2165. d = c.R;
  2166. var g = c.position.x + (d.col1.x * this.m_v1.x + d.col2.x * this.m_v1.y),
  2167. h = c.position.y + (d.col1.y * this.m_v1.x + d.col2.y * this.m_v1.y),
  2168. l = c.position.y + (d.col1.y * this.m_v2.x + d.col2.y * this.m_v2.y) - h;
  2169. c = -(c.position.x + (d.col1.x * this.m_v2.x + d.col2.x * this.m_v2.y) - g);
  2170. d = 100 * Number.MIN_VALUE;
  2171. var m = -(e * l + f * c);
  2172. if (m > d) {
  2173. var g = b.p1.x - g,
  2174. p = b.p1.y - h,
  2175. h = g * l + p * c;
  2176. if (0 <= h && h <= b.maxFraction * m && (b = -e * p + f * g, -d * m <= b && b <= m * (1 + d))) return a.fraction = h / m, b = Math.sqrt(l * l + c * c), a.normal.x = l / b, a.normal.y = c / b, !0
  2177. }
  2178. return !1
  2179. };
  2180. d.prototype.ComputeAABB = function(a, b) {
  2181. var c = b.R,
  2182. d = b.position.x + (c.col1.x * this.m_v1.x +
  2183. c.col2.x * this.m_v1.y),
  2184. e = b.position.y + (c.col1.y * this.m_v1.x + c.col2.y * this.m_v1.y),
  2185. f = b.position.x + (c.col1.x * this.m_v2.x + c.col2.x * this.m_v2.y),
  2186. c = b.position.y + (c.col1.y * this.m_v2.x + c.col2.y * this.m_v2.y);
  2187. d < f ? (a.lowerBound.x = d, a.upperBound.x = f) : (a.lowerBound.x = f, a.upperBound.x = d);
  2188. e < c ? (a.lowerBound.y = e, a.upperBound.y = c) : (a.lowerBound.y = c, a.upperBound.y = e)
  2189. };
  2190. d.prototype.ComputeMass = function(a) {
  2191. a.mass = 0;
  2192. a.center.SetV(this.m_v1);
  2193. a.I = 0
  2194. };
  2195. d.prototype.ComputeSubmergedArea = function(a, b, c, d) {
  2196. void 0 === b && (b = 0);
  2197. var e =
  2198. new q(a.x * b, a.y * b),
  2199. f = l.MulX(c, this.m_v1);
  2200. c = l.MulX(c, this.m_v2);
  2201. var g = l.Dot(a, f) - b;
  2202. a = l.Dot(a, c) - b;
  2203. if (0 < g) {
  2204. if (0 < a) return 0;
  2205. f.x = -a / (g - a) * f.x + g / (g - a) * c.x;
  2206. f.y = -a / (g - a) * f.y + g / (g - a) * c.y
  2207. } else 0 < a && (c.x = -a / (g - a) * f.x + g / (g - a) * c.x, c.y = -a / (g - a) * f.y + g / (g - a) * c.y);
  2208. d.x = (e.x + f.x + c.x) / 3;
  2209. d.y = (e.y + f.y + c.y) / 3;
  2210. return .5 * ((f.x - e.x) * (c.y - e.y) - (f.y - e.y) * (c.x - e.x))
  2211. };
  2212. d.prototype.GetLength = function() {
  2213. return this.m_length
  2214. };
  2215. d.prototype.GetVertex1 = function() {
  2216. return this.m_v1
  2217. };
  2218. d.prototype.GetVertex2 = function() {
  2219. return this.m_v2
  2220. };
  2221. d.prototype.GetCoreVertex1 =
  2222. function() {
  2223. return this.m_coreV1
  2224. };
  2225. d.prototype.GetCoreVertex2 = function() {
  2226. return this.m_coreV2
  2227. };
  2228. d.prototype.GetNormalVector = function() {
  2229. return this.m_normal
  2230. };
  2231. d.prototype.GetDirectionVector = function() {
  2232. return this.m_direction
  2233. };
  2234. d.prototype.GetCorner1Vector = function() {
  2235. return this.m_cornerDir1
  2236. };
  2237. d.prototype.GetCorner2Vector = function() {
  2238. return this.m_cornerDir2
  2239. };
  2240. d.prototype.Corner1IsConvex = function() {
  2241. return this.m_cornerConvex1
  2242. };
  2243. d.prototype.Corner2IsConvex = function() {
  2244. return this.m_cornerConvex2
  2245. };
  2246. d.prototype.GetFirstVertex =
  2247. function(a) {
  2248. var b = a.R;
  2249. return new q(a.position.x + (b.col1.x * this.m_coreV1.x + b.col2.x * this.m_coreV1.y), a.position.y + (b.col1.y * this.m_coreV1.x + b.col2.y * this.m_coreV1.y))
  2250. };
  2251. d.prototype.GetNextEdge = function() {
  2252. return this.m_nextEdge
  2253. };
  2254. d.prototype.GetPrevEdge = function() {
  2255. return this.m_prevEdge
  2256. };
  2257. d.prototype.Support = function(a, b, c) {
  2258. void 0 === b && (b = 0);
  2259. void 0 === c && (c = 0);
  2260. var d = a.R,
  2261. e = a.position.x + (d.col1.x * this.m_coreV1.x + d.col2.x * this.m_coreV1.y),
  2262. f = a.position.y + (d.col1.y * this.m_coreV1.x + d.col2.y * this.m_coreV1.y),
  2263. g = a.position.x + (d.col1.x * this.m_coreV2.x + d.col2.x * this.m_coreV2.y);
  2264. a = a.position.y + (d.col1.y * this.m_coreV2.x + d.col2.y * this.m_coreV2.y);
  2265. e * b + f * c > g * b + a * c ? (this.s_supportVec.x = e, this.s_supportVec.y = f) : (this.s_supportVec.x = g, this.s_supportVec.y = a);
  2266. return this.s_supportVec
  2267. };
  2268. d.prototype.b2EdgeShape = function(b, c) {
  2269. this.__super.b2Shape.call(this);
  2270. this.m_type = g.e_edgeShape;
  2271. this.m_nextEdge = this.m_prevEdge = null;
  2272. this.m_v1 = b;
  2273. this.m_v2 = c;
  2274. this.m_direction.Set(this.m_v2.x - this.m_v1.x, this.m_v2.y - this.m_v1.y);
  2275. this.m_length =
  2276. this.m_direction.Normalize();
  2277. this.m_normal.Set(this.m_direction.y, -this.m_direction.x);
  2278. this.m_coreV1.Set(-a.b2_toiSlop * (this.m_normal.x - this.m_direction.x) + this.m_v1.x, -a.b2_toiSlop * (this.m_normal.y - this.m_direction.y) + this.m_v1.y);
  2279. this.m_coreV2.Set(-a.b2_toiSlop * (this.m_normal.x + this.m_direction.x) + this.m_v2.x, -a.b2_toiSlop * (this.m_normal.y + this.m_direction.y) + this.m_v2.y);
  2280. this.m_cornerDir1 = this.m_normal;
  2281. this.m_cornerDir2.Set(-this.m_normal.x, -this.m_normal.y)
  2282. };
  2283. d.prototype.SetPrevEdge = function(a,
  2284. b, c, d) {
  2285. this.m_prevEdge = a;
  2286. this.m_coreV1 = b;
  2287. this.m_cornerDir1 = c;
  2288. this.m_cornerConvex1 = d
  2289. };
  2290. d.prototype.SetNextEdge = function(a, b, c, d) {
  2291. this.m_nextEdge = a;
  2292. this.m_coreV2 = b;
  2293. this.m_cornerDir2 = c;
  2294. this.m_cornerConvex2 = d
  2295. };
  2296. e.b2MassData = function() {
  2297. this.mass = 0;
  2298. this.center = new q(0, 0);
  2299. this.I = 0
  2300. };
  2301. Box2D.inherit(f, Box2D.Collision.Shapes.b2Shape);
  2302. f.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
  2303. f.b2PolygonShape = function() {
  2304. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments)
  2305. };
  2306. f.prototype.Copy = function() {
  2307. var a =
  2308. new f;
  2309. a.Set(this);
  2310. return a
  2311. };
  2312. f.prototype.Set = function(a) {
  2313. this.__super.Set.call(this, a);
  2314. if (Box2D.is(a, f)) {
  2315. a = a instanceof f ? a : null;
  2316. this.m_centroid.SetV(a.m_centroid);
  2317. this.m_vertexCount = a.m_vertexCount;
  2318. this.Reserve(this.m_vertexCount);
  2319. for (var b = 0; b < this.m_vertexCount; b++) this.m_vertices[b].SetV(a.m_vertices[b]), this.m_normals[b].SetV(a.m_normals[b])
  2320. }
  2321. };
  2322. f.prototype.SetAsArray = function(a, b) {
  2323. void 0 === b && (b = 0);
  2324. var c = new Vector,
  2325. d, e;
  2326. for (d = 0; d < a.length; ++d) e = a[d], c.push(e);
  2327. this.SetAsVector(c, b)
  2328. };
  2329. f.AsArray = function(a,
  2330. b) {
  2331. void 0 === b && (b = 0);
  2332. var c = new f;
  2333. c.SetAsArray(a, b);
  2334. return c
  2335. };
  2336. f.prototype.SetAsVector = function(b, c) {
  2337. void 0 === c && (c = 0);
  2338. 0 == c && (c = b.length);
  2339. a.b2Assert(2 <= c);
  2340. this.m_vertexCount = c;
  2341. this.Reserve(c);
  2342. var d;
  2343. for (d = 0; d < this.m_vertexCount; d++) this.m_vertices[d].SetV(b[d]);
  2344. for (d = 0; d < this.m_vertexCount; ++d) {
  2345. var e = parseInt(d),
  2346. g = parseInt(d + 1 < this.m_vertexCount ? d + 1 : 0),
  2347. e = l.SubtractVV(this.m_vertices[g], this.m_vertices[e]);
  2348. a.b2Assert(e.LengthSquared() > Number.MIN_VALUE);
  2349. this.m_normals[d].SetV(l.CrossVF(e, 1));
  2350. this.m_normals[d].Normalize()
  2351. }
  2352. this.m_centroid =
  2353. f.ComputeCentroid(this.m_vertices, this.m_vertexCount)
  2354. };
  2355. f.AsVector = function(a, b) {
  2356. void 0 === b && (b = 0);
  2357. var c = new f;
  2358. c.SetAsVector(a, b);
  2359. return c
  2360. };
  2361. f.prototype.SetAsBox = function(a, b) {
  2362. void 0 === a && (a = 0);
  2363. void 0 === b && (b = 0);
  2364. this.m_vertexCount = 4;
  2365. this.Reserve(4);
  2366. this.m_vertices[0].Set(-a, -b);
  2367. this.m_vertices[1].Set(a, -b);
  2368. this.m_vertices[2].Set(a, b);
  2369. this.m_vertices[3].Set(-a, b);
  2370. this.m_normals[0].Set(0, -1);
  2371. this.m_normals[1].Set(1, 0);
  2372. this.m_normals[2].Set(0, 1);
  2373. this.m_normals[3].Set(-1, 0);
  2374. this.m_centroid.SetZero()
  2375. };
  2376. f.AsBox =
  2377. function(a, b) {
  2378. void 0 === a && (a = 0);
  2379. void 0 === b && (b = 0);
  2380. var c = new f;
  2381. c.SetAsBox(a, b);
  2382. return c
  2383. };
  2384. f.prototype.SetAsOrientedBox = function(a, b, c, d) {
  2385. void 0 === a && (a = 0);
  2386. void 0 === b && (b = 0);
  2387. void 0 === c && (c = null);
  2388. void 0 === d && (d = 0);
  2389. this.m_vertexCount = 4;
  2390. this.Reserve(4);
  2391. this.m_vertices[0].Set(-a, -b);
  2392. this.m_vertices[1].Set(a, -b);
  2393. this.m_vertices[2].Set(a, b);
  2394. this.m_vertices[3].Set(-a, b);
  2395. this.m_normals[0].Set(0, -1);
  2396. this.m_normals[1].Set(1, 0);
  2397. this.m_normals[2].Set(0, 1);
  2398. this.m_normals[3].Set(-1, 0);
  2399. this.m_centroid = c;
  2400. a = new m;
  2401. a.position =
  2402. c;
  2403. a.R.Set(d);
  2404. for (c = 0; c < this.m_vertexCount; ++c) this.m_vertices[c] = l.MulX(a, this.m_vertices[c]), this.m_normals[c] = l.MulMV(a.R, this.m_normals[c])
  2405. };
  2406. f.AsOrientedBox = function(a, b, c, d) {
  2407. void 0 === a && (a = 0);
  2408. void 0 === b && (b = 0);
  2409. void 0 === c && (c = null);
  2410. void 0 === d && (d = 0);
  2411. var e = new f;
  2412. e.SetAsOrientedBox(a, b, c, d);
  2413. return e
  2414. };
  2415. f.prototype.SetAsEdge = function(a, b) {
  2416. this.m_vertexCount = 2;
  2417. this.Reserve(2);
  2418. this.m_vertices[0].SetV(a);
  2419. this.m_vertices[1].SetV(b);
  2420. this.m_centroid.x = .5 * (a.x + b.x);
  2421. this.m_centroid.y = .5 * (a.y + b.y);
  2422. this.m_normals[0] =
  2423. l.CrossVF(l.SubtractVV(b, a), 1);
  2424. this.m_normals[0].Normalize();
  2425. this.m_normals[1].x = -this.m_normals[0].x;
  2426. this.m_normals[1].y = -this.m_normals[0].y
  2427. };
  2428. f.AsEdge = function(a, b) {
  2429. var c = new f;
  2430. c.SetAsEdge(a, b);
  2431. return c
  2432. };
  2433. f.prototype.TestPoint = function(a, b) {
  2434. var c;
  2435. c = a.R;
  2436. for (var d = b.x - a.position.x, e = b.y - a.position.y, f = d * c.col1.x + e * c.col1.y, g = d * c.col2.x + e * c.col2.y, h = 0; h < this.m_vertexCount; ++h)
  2437. if (c = this.m_vertices[h], d = f - c.x, e = g - c.y, c = this.m_normals[h], 0 < c.x * d + c.y * e) return !1;
  2438. return !0
  2439. };
  2440. f.prototype.RayCast = function(a,
  2441. b, c) {
  2442. var d = 0,
  2443. e = b.maxFraction,
  2444. f, g, h, l;
  2445. f = b.p1.x - c.position.x;
  2446. g = b.p1.y - c.position.y;
  2447. h = c.R;
  2448. var m = f * h.col1.x + g * h.col1.y,
  2449. p = f * h.col2.x + g * h.col2.y;
  2450. f = b.p2.x - c.position.x;
  2451. g = b.p2.y - c.position.y;
  2452. h = c.R;
  2453. b = f * h.col1.x + g * h.col1.y - m;
  2454. h = f * h.col2.x + g * h.col2.y - p;
  2455. for (var q = -1, y = 0; y < this.m_vertexCount; ++y) {
  2456. l = this.m_vertices[y];
  2457. f = l.x - m;
  2458. g = l.y - p;
  2459. l = this.m_normals[y];
  2460. f = l.x * f + l.y * g;
  2461. g = l.x * b + l.y * h;
  2462. if (0 == g) {
  2463. if (0 > f) return !1
  2464. } else 0 > g && f < d * g ? (d = f / g, q = y) : 0 < g && f < e * g && (e = f / g);
  2465. if (e < d - Number.MIN_VALUE) return !1
  2466. }
  2467. return 0 <= q ? (a.fraction = d,
  2468. h = c.R, l = this.m_normals[q], a.normal.x = h.col1.x * l.x + h.col2.x * l.y, a.normal.y = h.col1.y * l.x + h.col2.y * l.y, !0) : !1
  2469. };
  2470. f.prototype.ComputeAABB = function(a, b) {
  2471. for (var c = b.R, d = this.m_vertices[0], e = b.position.x + (c.col1.x * d.x + c.col2.x * d.y), f = b.position.y + (c.col1.y * d.x + c.col2.y * d.y), g = e, h = f, l = 1; l < this.m_vertexCount; ++l) var d = this.m_vertices[l],
  2472. m = b.position.x + (c.col1.x * d.x + c.col2.x * d.y),
  2473. d = b.position.y + (c.col1.y * d.x + c.col2.y * d.y),
  2474. e = e < m ? e : m,
  2475. f = f < d ? f : d,
  2476. g = g > m ? g : m,
  2477. h = h > d ? h : d;
  2478. a.lowerBound.x = e - this.m_radius;
  2479. a.lowerBound.y =
  2480. f - this.m_radius;
  2481. a.upperBound.x = g + this.m_radius;
  2482. a.upperBound.y = h + this.m_radius
  2483. };
  2484. f.prototype.ComputeMass = function(a, b) {
  2485. void 0 === b && (b = 0);
  2486. if (2 == this.m_vertexCount) a.center.x = .5 * (this.m_vertices[0].x + this.m_vertices[1].x), a.center.y = .5 * (this.m_vertices[0].y + this.m_vertices[1].y), a.mass = 0, a.I = 0;
  2487. else {
  2488. for (var c = 0, d = 0, e = 0, f = 0, g = 1 / 3, h = 0; h < this.m_vertexCount; ++h) var l = this.m_vertices[h],
  2489. m = h + 1 < this.m_vertexCount ? this.m_vertices[parseInt(h + 1)] : this.m_vertices[0],
  2490. p = l.x - 0,
  2491. q = l.y - 0,
  2492. y = m.x - 0,
  2493. A = m.y - 0,
  2494. B = p * A - q * y,
  2495. K = .5 *
  2496. B,
  2497. e = e + K,
  2498. c = c + K * g * (0 + l.x + m.x),
  2499. d = d + K * g * (0 + l.y + m.y),
  2500. l = p,
  2501. f = f + B * (g * (.25 * (l * l + y * l + y * y) + (0 * l + 0 * y)) + 0 + (g * (.25 * (q * q + A * q + A * A) + (0 * q + 0 * A)) + 0));
  2502. a.mass = b * e;
  2503. a.center.Set(1 / e * c, 1 / e * d);
  2504. a.I = b * f
  2505. }
  2506. };
  2507. f.prototype.ComputeSubmergedArea = function(a, b, c, d) {
  2508. void 0 === b && (b = 0);
  2509. var f = l.MulTMV(c.R, a),
  2510. g = b - l.Dot(a, c.position),
  2511. h = new Vector_a2j_Number,
  2512. m = 0,
  2513. p = -1;
  2514. b = -1;
  2515. var y = !1;
  2516. for (a = a = 0; a < this.m_vertexCount; ++a) {
  2517. h[a] = l.Dot(f, this.m_vertices[a]) - g;
  2518. var A = h[a] < -Number.MIN_VALUE;
  2519. 0 < a && (A ? y || (p = a - 1, m++) : y && (b = a - 1, m++));
  2520. y = A
  2521. }
  2522. switch (m) {
  2523. case 0:
  2524. return y ?
  2525. (a = new e, this.ComputeMass(a, 1), d.SetV(l.MulX(c, a.center)), a.mass) : 0;
  2526. case 1:
  2527. -1 == p ? p = this.m_vertexCount - 1 : b = this.m_vertexCount - 1
  2528. }
  2529. a = parseInt((p + 1) % this.m_vertexCount);
  2530. f = parseInt((b + 1) % this.m_vertexCount);
  2531. g = (0 - h[p]) / (h[a] - h[p]);
  2532. h = (0 - h[b]) / (h[f] - h[b]);
  2533. p = new q(this.m_vertices[p].x * (1 - g) + this.m_vertices[a].x * g, this.m_vertices[p].y * (1 - g) + this.m_vertices[a].y * g);
  2534. b = new q(this.m_vertices[b].x * (1 - h) + this.m_vertices[f].x * h, this.m_vertices[b].y * (1 - h) + this.m_vertices[f].y * h);
  2535. h = 0;
  2536. g = new q;
  2537. for (m = this.m_vertices[a]; a !=
  2538. f;) a = (a + 1) % this.m_vertexCount, y = a == f ? b : this.m_vertices[a], A = .5 * ((m.x - p.x) * (y.y - p.y) - (m.y - p.y) * (y.x - p.x)), h += A, g.x += A * (p.x + m.x + y.x) / 3, g.y += A * (p.y + m.y + y.y) / 3, m = y;
  2539. g.Multiply(1 / h);
  2540. d.SetV(l.MulX(c, g));
  2541. return h
  2542. };
  2543. f.prototype.GetVertexCount = function() {
  2544. return this.m_vertexCount
  2545. };
  2546. f.prototype.GetVertices = function() {
  2547. return this.m_vertices
  2548. };
  2549. f.prototype.GetNormals = function() {
  2550. return this.m_normals
  2551. };
  2552. f.prototype.GetSupport = function(a) {
  2553. for (var b = 0, c = this.m_vertices[0].x * a.x + this.m_vertices[0].y * a.y, d = 1; d < this.m_vertexCount; ++d) {
  2554. var e =
  2555. this.m_vertices[d].x * a.x + this.m_vertices[d].y * a.y;
  2556. e > c && (b = d, c = e)
  2557. }
  2558. return b
  2559. };
  2560. f.prototype.GetSupportVertex = function(a) {
  2561. for (var b = 0, c = this.m_vertices[0].x * a.x + this.m_vertices[0].y * a.y, d = 1; d < this.m_vertexCount; ++d) {
  2562. var e = this.m_vertices[d].x * a.x + this.m_vertices[d].y * a.y;
  2563. e > c && (b = d, c = e)
  2564. }
  2565. return this.m_vertices[b]
  2566. };
  2567. f.prototype.Validate = function() {
  2568. return !1
  2569. };
  2570. f.prototype.b2PolygonShape = function() {
  2571. this.__super.b2Shape.call(this);
  2572. this.m_type = g.e_polygonShape;
  2573. this.m_centroid = new q;
  2574. this.m_vertices = new Vector;
  2575. this.m_normals =
  2576. new Vector
  2577. };
  2578. f.prototype.Reserve = function(a) {
  2579. void 0 === a && (a = 0);
  2580. for (var b = parseInt(this.m_vertices.length); b < a; b++) this.m_vertices[b] = new q, this.m_normals[b] = new q
  2581. };
  2582. f.ComputeCentroid = function(a, b) {
  2583. void 0 === b && (b = 0);
  2584. for (var c = new q, d = 0, e = 1 / 3, f = 0; f < b; ++f) {
  2585. var g = a[f],
  2586. h = f + 1 < b ? a[parseInt(f + 1)] : a[0],
  2587. l = .5 * ((g.x - 0) * (h.y - 0) - (g.y - 0) * (h.x - 0)),
  2588. d = d + l;
  2589. c.x += l * e * (0 + g.x + h.x);
  2590. c.y += l * e * (0 + g.y + h.y)
  2591. }
  2592. c.x *= 1 / d;
  2593. c.y *= 1 / d;
  2594. return c
  2595. };
  2596. f.ComputeOBB = function(a, b, c) {
  2597. void 0 === c && (c = 0);
  2598. var d, e = new Vector(c + 1);
  2599. for (d = 0; d < c; ++d) e[d] = b[d];
  2600. e[c] = e[0];
  2601. b = Number.MAX_VALUE;
  2602. for (d = 1; d <= c; ++d) {
  2603. for (var f = e[parseInt(d - 1)], g = e[d].x - f.x, h = e[d].y - f.y, l = Math.sqrt(g * g + h * h), g = g / l, h = h / l, m = -h, p = g, q = l = Number.MAX_VALUE, y = -Number.MAX_VALUE, A = -Number.MAX_VALUE, B = 0; B < c; ++B) {
  2604. var K = e[B].x - f.x,
  2605. fc = e[B].y - f.y,
  2606. kc = g * K + h * fc,
  2607. K = m * K + p * fc;
  2608. kc < l && (l = kc);
  2609. K < q && (q = K);
  2610. kc > y && (y = kc);
  2611. K > A && (A = K)
  2612. }
  2613. B = (y - l) * (A - q);
  2614. B < .95 * b && (b = B, a.R.col1.x = g, a.R.col1.y = h, a.R.col2.x = m, a.R.col2.y = p, g = .5 * (l + y), h = .5 * (q + A), m = a.R, a.center.x = f.x + (m.col1.x * g + m.col2.x * h), a.center.y = f.y + (m.col1.y * g + m.col2.y *
  2615. h), a.extents.x = .5 * (y - l), a.extents.y = .5 * (A - q))
  2616. }
  2617. };
  2618. Box2D.postDefs.push(function() {
  2619. Box2D.Collision.Shapes.b2PolygonShape.s_mat = new h
  2620. });
  2621. g.b2Shape = function() {};
  2622. g.prototype.Copy = function() {
  2623. return null
  2624. };
  2625. g.prototype.Set = function(a) {
  2626. this.m_radius = a.m_radius
  2627. };
  2628. g.prototype.GetType = function() {
  2629. return this.m_type
  2630. };
  2631. g.prototype.TestPoint = function() {
  2632. return !1
  2633. };
  2634. g.prototype.RayCast = function() {
  2635. return !1
  2636. };
  2637. g.prototype.ComputeAABB = function() {};
  2638. g.prototype.ComputeMass = function() {};
  2639. g.prototype.ComputeSubmergedArea = function() {
  2640. return 0
  2641. };
  2642. g.TestOverlap = function(a, b, c, d) {
  2643. var e = new y;
  2644. e.proxyA = new B;
  2645. e.proxyA.Set(a);
  2646. e.proxyB = new B;
  2647. e.proxyB.Set(c);
  2648. e.transformA = b;
  2649. e.transformB = d;
  2650. e.useRadii = !0;
  2651. a = new K;
  2652. a.count = 0;
  2653. b = new A;
  2654. p.Distance(b, a, e);
  2655. return b.distance < 10 * Number.MIN_VALUE
  2656. };
  2657. g.prototype.b2Shape = function() {
  2658. this.m_type = g.e_unknownShape;
  2659. this.m_radius = a.b2_linearSlop
  2660. };
  2661. Box2D.postDefs.push(function() {
  2662. Box2D.Collision.Shapes.b2Shape.e_unknownShape = -1;
  2663. Box2D.Collision.Shapes.b2Shape.e_circleShape = 0;
  2664. Box2D.Collision.Shapes.b2Shape.e_polygonShape = 1;
  2665. Box2D.Collision.Shapes.b2Shape.e_edgeShape =
  2666. 2;
  2667. Box2D.Collision.Shapes.b2Shape.e_shapeTypeCount = 3;
  2668. Box2D.Collision.Shapes.b2Shape.e_hitCollide = 1;
  2669. Box2D.Collision.Shapes.b2Shape.e_missCollide = 0;
  2670. Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide = -1
  2671. })
  2672. })();
  2673. (function() {
  2674. var a = Box2D.Common.b2Color,
  2675. c = Box2D.Common.b2Settings,
  2676. b = Box2D.Common.Math.b2Math;
  2677. a.b2Color = function() {
  2678. this._b = this._g = this._r = 0
  2679. };
  2680. a.prototype.b2Color = function(a, c, f) {
  2681. void 0 === a && (a = 0);
  2682. void 0 === c && (c = 0);
  2683. void 0 === f && (f = 0);
  2684. this._r = Box2D.parseUInt(255 * b.Clamp(a, 0, 1));
  2685. this._g = Box2D.parseUInt(255 * b.Clamp(c, 0, 1));
  2686. this._b = Box2D.parseUInt(255 * b.Clamp(f, 0, 1))
  2687. };
  2688. a.prototype.Set = function(a, c, f) {
  2689. void 0 === a && (a = 0);
  2690. void 0 === c && (c = 0);
  2691. void 0 === f && (f = 0);
  2692. this._r = Box2D.parseUInt(255 * b.Clamp(a, 0, 1));
  2693. this._g =
  2694. Box2D.parseUInt(255 * b.Clamp(c, 0, 1));
  2695. this._b = Box2D.parseUInt(255 * b.Clamp(f, 0, 1))
  2696. };
  2697. Object.defineProperty(a.prototype, "r", {
  2698. enumerable: !1,
  2699. configurable: !0,
  2700. set: function(a) {
  2701. void 0 === a && (a = 0);
  2702. this._r = Box2D.parseUInt(255 * b.Clamp(a, 0, 1))
  2703. }
  2704. });
  2705. Object.defineProperty(a.prototype, "g", {
  2706. enumerable: !1,
  2707. configurable: !0,
  2708. set: function(a) {
  2709. void 0 === a && (a = 0);
  2710. this._g = Box2D.parseUInt(255 * b.Clamp(a, 0, 1))
  2711. }
  2712. });
  2713. Object.defineProperty(a.prototype, "b", {
  2714. enumerable: !1,
  2715. configurable: !0,
  2716. set: function(a) {
  2717. void 0 === a && (a = 0);
  2718. this._b = Box2D.parseUInt(255 *
  2719. b.Clamp(a, 0, 1))
  2720. }
  2721. });
  2722. Object.defineProperty(a.prototype, "color", {
  2723. enumerable: !1,
  2724. configurable: !0,
  2725. get: function() {
  2726. return this._r << 16 | this._g << 8 | this._b
  2727. }
  2728. });
  2729. c.b2Settings = function() {};
  2730. c.b2MixFriction = function(a, b) {
  2731. void 0 === a && (a = 0);
  2732. void 0 === b && (b = 0);
  2733. return Math.sqrt(a * b)
  2734. };
  2735. c.b2MixRestitution = function(a, b) {
  2736. void 0 === a && (a = 0);
  2737. void 0 === b && (b = 0);
  2738. return a > b ? a : b
  2739. };
  2740. c.b2Assert = function(a) {
  2741. if (!a) throw "Assertion Failed";
  2742. };
  2743. Box2D.postDefs.push(function() {
  2744. Box2D.Common.b2Settings.VERSION = "2.1alpha";
  2745. Box2D.Common.b2Settings.USHRT_MAX =
  2746. 65535;
  2747. Box2D.Common.b2Settings.b2_pi = Math.PI;
  2748. Box2D.Common.b2Settings.b2_maxManifoldPoints = 2;
  2749. Box2D.Common.b2Settings.b2_aabbExtension = .1;
  2750. Box2D.Common.b2Settings.b2_aabbMultiplier = 2;
  2751. Box2D.Common.b2Settings.b2_polygonRadius = 2 * c.b2_linearSlop;
  2752. Box2D.Common.b2Settings.b2_linearSlop = .005;
  2753. Box2D.Common.b2Settings.b2_angularSlop = 2 / 180 * c.b2_pi;
  2754. Box2D.Common.b2Settings.b2_toiSlop = 8 * c.b2_linearSlop;
  2755. Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland = 32;
  2756. Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland = 32;
  2757. Box2D.Common.b2Settings.b2_velocityThreshold =
  2758. 1;
  2759. Box2D.Common.b2Settings.b2_maxLinearCorrection = .2;
  2760. Box2D.Common.b2Settings.b2_maxAngularCorrection = 8 / 180 * c.b2_pi;
  2761. Box2D.Common.b2Settings.b2_maxTranslation = 2;
  2762. Box2D.Common.b2Settings.b2_maxTranslationSquared = c.b2_maxTranslation * c.b2_maxTranslation;
  2763. Box2D.Common.b2Settings.b2_maxRotation = .5 * c.b2_pi;
  2764. Box2D.Common.b2Settings.b2_maxRotationSquared = c.b2_maxRotation * c.b2_maxRotation;
  2765. Box2D.Common.b2Settings.b2_contactBaumgarte = .2;
  2766. Box2D.Common.b2Settings.b2_timeToSleep = .5;
  2767. Box2D.Common.b2Settings.b2_linearSleepTolerance =
  2768. .01;
  2769. Box2D.Common.b2Settings.b2_angularSleepTolerance = 2 / 180 * c.b2_pi
  2770. })
  2771. })();
  2772. (function() {
  2773. var a = Box2D.Common.Math.b2Mat22,
  2774. c = Box2D.Common.Math.b2Mat33,
  2775. b = Box2D.Common.Math.b2Math,
  2776. d = Box2D.Common.Math.b2Sweep,
  2777. e = Box2D.Common.Math.b2Transform,
  2778. f = Box2D.Common.Math.b2Vec2,
  2779. g = Box2D.Common.Math.b2Vec3;
  2780. a.b2Mat22 = function() {
  2781. this.col1 = new f;
  2782. this.col2 = new f
  2783. };
  2784. a.prototype.b2Mat22 = function() {
  2785. this.SetIdentity()
  2786. };
  2787. a.FromAngle = function(b) {
  2788. void 0 === b && (b = 0);
  2789. var c = new a;
  2790. c.Set(b);
  2791. return c
  2792. };
  2793. a.FromVV = function(b, c) {
  2794. var d = new a;
  2795. d.SetVV(b, c);
  2796. return d
  2797. };
  2798. a.prototype.Set = function(a) {
  2799. void 0 === a && (a = 0);
  2800. var b =
  2801. Math.cos(a);
  2802. a = Math.sin(a);
  2803. this.col1.x = b;
  2804. this.col2.x = -a;
  2805. this.col1.y = a;
  2806. this.col2.y = b
  2807. };
  2808. a.prototype.SetVV = function(a, b) {
  2809. this.col1.SetV(a);
  2810. this.col2.SetV(b)
  2811. };
  2812. a.prototype.Copy = function() {
  2813. var b = new a;
  2814. b.SetM(this);
  2815. return b
  2816. };
  2817. a.prototype.SetM = function(a) {
  2818. this.col1.SetV(a.col1);
  2819. this.col2.SetV(a.col2)
  2820. };
  2821. a.prototype.AddM = function(a) {
  2822. this.col1.x += a.col1.x;
  2823. this.col1.y += a.col1.y;
  2824. this.col2.x += a.col2.x;
  2825. this.col2.y += a.col2.y
  2826. };
  2827. a.prototype.SetIdentity = function() {
  2828. this.col1.x = 1;
  2829. this.col2.x = 0;
  2830. this.col1.y = 0;
  2831. this.col2.y = 1
  2832. };
  2833. a.prototype.SetZero = function() {
  2834. this.col1.x = 0;
  2835. this.col2.x = 0;
  2836. this.col1.y = 0;
  2837. this.col2.y = 0
  2838. };
  2839. a.prototype.GetAngle = function() {
  2840. return Math.atan2(this.col1.y, this.col1.x)
  2841. };
  2842. a.prototype.GetInverse = function(a) {
  2843. var b = this.col1.x,
  2844. c = this.col2.x,
  2845. d = this.col1.y,
  2846. e = this.col2.y,
  2847. f = b * e - c * d;
  2848. 0 != f && (f = 1 / f);
  2849. a.col1.x = f * e;
  2850. a.col2.x = -f * c;
  2851. a.col1.y = -f * d;
  2852. a.col2.y = f * b;
  2853. return a
  2854. };
  2855. a.prototype.Solve = function(a, b, c) {
  2856. void 0 === b && (b = 0);
  2857. void 0 === c && (c = 0);
  2858. var d = this.col1.x,
  2859. e = this.col2.x,
  2860. f = this.col1.y,
  2861. g = this.col2.y,
  2862. B = d * g - e * f;
  2863. 0 != B && (B = 1 / B);
  2864. a.x = B * (g * b - e * c);
  2865. a.y = B * (d * c - f * b);
  2866. return a
  2867. };
  2868. a.prototype.Abs = function() {
  2869. this.col1.Abs();
  2870. this.col2.Abs()
  2871. };
  2872. c.b2Mat33 = function() {
  2873. this.col1 = new g;
  2874. this.col2 = new g;
  2875. this.col3 = new g
  2876. };
  2877. c.prototype.b2Mat33 = function(a, b, c) {
  2878. void 0 === a && (a = null);
  2879. void 0 === b && (b = null);
  2880. void 0 === c && (c = null);
  2881. a || b || c ? (this.col1.SetV(a), this.col2.SetV(b), this.col3.SetV(c)) : (this.col1.SetZero(), this.col2.SetZero(), this.col3.SetZero())
  2882. };
  2883. c.prototype.SetVVV = function(a, b, c) {
  2884. this.col1.SetV(a);
  2885. this.col2.SetV(b);
  2886. this.col3.SetV(c)
  2887. };
  2888. c.prototype.Copy =
  2889. function() {
  2890. return new c(this.col1, this.col2, this.col3)
  2891. };
  2892. c.prototype.SetM = function(a) {
  2893. this.col1.SetV(a.col1);
  2894. this.col2.SetV(a.col2);
  2895. this.col3.SetV(a.col3)
  2896. };
  2897. c.prototype.AddM = function(a) {
  2898. this.col1.x += a.col1.x;
  2899. this.col1.y += a.col1.y;
  2900. this.col1.z += a.col1.z;
  2901. this.col2.x += a.col2.x;
  2902. this.col2.y += a.col2.y;
  2903. this.col2.z += a.col2.z;
  2904. this.col3.x += a.col3.x;
  2905. this.col3.y += a.col3.y;
  2906. this.col3.z += a.col3.z
  2907. };
  2908. c.prototype.SetIdentity = function() {
  2909. this.col1.x = 1;
  2910. this.col2.x = 0;
  2911. this.col3.x = 0;
  2912. this.col1.y = 0;
  2913. this.col2.y = 1;
  2914. this.col3.y = 0;
  2915. this.col1.z = 0;
  2916. this.col2.z = 0;
  2917. this.col3.z = 1
  2918. };
  2919. c.prototype.SetZero = function() {
  2920. this.col1.x = 0;
  2921. this.col2.x = 0;
  2922. this.col3.x = 0;
  2923. this.col1.y = 0;
  2924. this.col2.y = 0;
  2925. this.col3.y = 0;
  2926. this.col1.z = 0;
  2927. this.col2.z = 0;
  2928. this.col3.z = 0
  2929. };
  2930. c.prototype.Solve22 = function(a, b, c) {
  2931. void 0 === b && (b = 0);
  2932. void 0 === c && (c = 0);
  2933. var d = this.col1.x,
  2934. e = this.col2.x,
  2935. f = this.col1.y,
  2936. g = this.col2.y,
  2937. B = d * g - e * f;
  2938. 0 != B && (B = 1 / B);
  2939. a.x = B * (g * b - e * c);
  2940. a.y = B * (d * c - f * b);
  2941. return a
  2942. };
  2943. c.prototype.Solve33 = function(a, b, c, d) {
  2944. void 0 === b && (b = 0);
  2945. void 0 === c && (c = 0);
  2946. void 0 === d && (d = 0);
  2947. var e = this.col1.x,
  2948. f = this.col1.y,
  2949. g = this.col1.z,
  2950. B = this.col2.x,
  2951. K = this.col2.y,
  2952. H = this.col2.z,
  2953. E = this.col3.x,
  2954. M = this.col3.y,
  2955. Xb = this.col3.z,
  2956. Zb = e * (K * Xb - H * M) + f * (H * E - B * Xb) + g * (B * M - K * E);
  2957. 0 != Zb && (Zb = 1 / Zb);
  2958. a.x = Zb * (b * (K * Xb - H * M) + c * (H * E - B * Xb) + d * (B * M - K * E));
  2959. a.y = Zb * (e * (c * Xb - d * M) + f * (d * E - b * Xb) + g * (b * M - c * E));
  2960. a.z = Zb * (e * (K * d - H * c) + f * (H * b - B * d) + g * (B * c - K * b));
  2961. return a
  2962. };
  2963. b.b2Math = function() {};
  2964. b.IsValid = function(a) {
  2965. void 0 === a && (a = 0);
  2966. return isFinite(a)
  2967. };
  2968. b.Dot = function(a, b) {
  2969. return a.x * b.x + a.y * b.y
  2970. };
  2971. b.CrossVV = function(a, b) {
  2972. return a.x * b.y - a.y * b.x
  2973. };
  2974. b.CrossVF =
  2975. function(a, b) {
  2976. void 0 === b && (b = 0);
  2977. return new f(b * a.y, -b * a.x)
  2978. };
  2979. b.CrossFV = function(a, b) {
  2980. void 0 === a && (a = 0);
  2981. return new f(-a * b.y, a * b.x)
  2982. };
  2983. b.MulMV = function(a, b) {
  2984. return new f(a.col1.x * b.x + a.col2.x * b.y, a.col1.y * b.x + a.col2.y * b.y)
  2985. };
  2986. b.MulTMV = function(a, c) {
  2987. return new f(b.Dot(c, a.col1), b.Dot(c, a.col2))
  2988. };
  2989. b.MulX = function(a, c) {
  2990. var d = b.MulMV(a.R, c);
  2991. d.x += a.position.x;
  2992. d.y += a.position.y;
  2993. return d
  2994. };
  2995. b.MulXT = function(a, c) {
  2996. var d = b.SubtractVV(c, a.position),
  2997. e = d.x * a.R.col1.x + d.y * a.R.col1.y;
  2998. d.y = d.x * a.R.col2.x + d.y * a.R.col2.y;
  2999. d.x =
  3000. e;
  3001. return d
  3002. };
  3003. b.AddVV = function(a, b) {
  3004. return new f(a.x + b.x, a.y + b.y)
  3005. };
  3006. b.SubtractVV = function(a, b) {
  3007. return new f(a.x - b.x, a.y - b.y)
  3008. };
  3009. b.Distance = function(a, b) {
  3010. var c = a.x - b.x,
  3011. d = a.y - b.y;
  3012. return Math.sqrt(c * c + d * d)
  3013. };
  3014. b.DistanceSquared = function(a, b) {
  3015. var c = a.x - b.x,
  3016. d = a.y - b.y;
  3017. return c * c + d * d
  3018. };
  3019. b.MulFV = function(a, b) {
  3020. void 0 === a && (a = 0);
  3021. return new f(a * b.x, a * b.y)
  3022. };
  3023. b.AddMM = function(c, d) {
  3024. return a.FromVV(b.AddVV(c.col1, d.col1), b.AddVV(c.col2, d.col2))
  3025. };
  3026. b.MulMM = function(c, d) {
  3027. return a.FromVV(b.MulMV(c, d.col1), b.MulMV(c, d.col2))
  3028. };
  3029. b.MulTMM =
  3030. function(c, d) {
  3031. var e = new f(b.Dot(c.col1, d.col1), b.Dot(c.col2, d.col1)),
  3032. g = new f(b.Dot(c.col1, d.col2), b.Dot(c.col2, d.col2));
  3033. return a.FromVV(e, g)
  3034. };
  3035. b.Abs = function(a) {
  3036. void 0 === a && (a = 0);
  3037. return 0 < a ? a : -a
  3038. };
  3039. b.AbsV = function(a) {
  3040. return new f(b.Abs(a.x), b.Abs(a.y))
  3041. };
  3042. b.AbsM = function(c) {
  3043. return a.FromVV(b.AbsV(c.col1), b.AbsV(c.col2))
  3044. };
  3045. b.Min = function(a, b) {
  3046. void 0 === a && (a = 0);
  3047. void 0 === b && (b = 0);
  3048. return a < b ? a : b
  3049. };
  3050. b.MinV = function(a, c) {
  3051. return new f(b.Min(a.x, c.x), b.Min(a.y, c.y))
  3052. };
  3053. b.Max = function(a, b) {
  3054. void 0 === a && (a = 0);
  3055. void 0 ===
  3056. b && (b = 0);
  3057. return a > b ? a : b
  3058. };
  3059. b.MaxV = function(a, c) {
  3060. return new f(b.Max(a.x, c.x), b.Max(a.y, c.y))
  3061. };
  3062. b.Clamp = function(a, b, c) {
  3063. void 0 === a && (a = 0);
  3064. void 0 === b && (b = 0);
  3065. void 0 === c && (c = 0);
  3066. return a < b ? b : a > c ? c : a
  3067. };
  3068. b.ClampV = function(a, c, d) {
  3069. return b.MaxV(c, b.MinV(a, d))
  3070. };
  3071. b.Swap = function(a, b) {
  3072. var c = a[0];
  3073. a[0] = b[0];
  3074. b[0] = c
  3075. };
  3076. b.Random = function() {
  3077. return 2 * Math.random() - 1
  3078. };
  3079. b.RandomRange = function(a, b) {
  3080. void 0 === a && (a = 0);
  3081. void 0 === b && (b = 0);
  3082. return (b - a) * Math.random() + a
  3083. };
  3084. b.NextPowerOfTwo = function(a) {
  3085. void 0 === a && (a = 0);
  3086. a |= a >> 1 & 2147483647;
  3087. a |= a >> 2 & 1073741823;
  3088. a |= a >> 4 & 268435455;
  3089. a |= a >> 8 & 16777215;
  3090. return (a | a >> 16 & 65535) + 1
  3091. };
  3092. b.IsPowerOfTwo = function(a) {
  3093. void 0 === a && (a = 0);
  3094. return 0 < a && 0 == (a & a - 1)
  3095. };
  3096. Box2D.postDefs.push(function() {
  3097. Box2D.Common.Math.b2Math.b2Vec2_zero = new f(0, 0);
  3098. Box2D.Common.Math.b2Math.b2Mat22_identity = a.FromVV(new f(1, 0), new f(0, 1));
  3099. Box2D.Common.Math.b2Math.b2Transform_identity = new e(b.b2Vec2_zero, b.b2Mat22_identity)
  3100. });
  3101. d.b2Sweep = function() {
  3102. this.localCenter = new f;
  3103. this.c0 = new f;
  3104. this.c = new f
  3105. };
  3106. d.prototype.Set = function(a) {
  3107. this.localCenter.SetV(a.localCenter);
  3108. this.c0.SetV(a.c0);
  3109. this.c.SetV(a.c);
  3110. this.a0 = a.a0;
  3111. this.a = a.a;
  3112. this.t0 = a.t0
  3113. };
  3114. d.prototype.Copy = function() {
  3115. var a = new d;
  3116. a.localCenter.SetV(this.localCenter);
  3117. a.c0.SetV(this.c0);
  3118. a.c.SetV(this.c);
  3119. a.a0 = this.a0;
  3120. a.a = this.a;
  3121. a.t0 = this.t0;
  3122. return a
  3123. };
  3124. d.prototype.GetTransform = function(a, b) {
  3125. void 0 === b && (b = 0);
  3126. a.position.x = (1 - b) * this.c0.x + b * this.c.x;
  3127. a.position.y = (1 - b) * this.c0.y + b * this.c.y;
  3128. a.R.Set((1 - b) * this.a0 + b * this.a);
  3129. var c = a.R;
  3130. a.position.x -= c.col1.x * this.localCenter.x + c.col2.x * this.localCenter.y;
  3131. a.position.y -= c.col1.y *
  3132. this.localCenter.x + c.col2.y * this.localCenter.y
  3133. };
  3134. d.prototype.Advance = function(a) {
  3135. void 0 === a && (a = 0);
  3136. if (this.t0 < a && 1 - this.t0 > Number.MIN_VALUE) {
  3137. var b = (a - this.t0) / (1 - this.t0);
  3138. this.c0.x = (1 - b) * this.c0.x + b * this.c.x;
  3139. this.c0.y = (1 - b) * this.c0.y + b * this.c.y;
  3140. this.a0 = (1 - b) * this.a0 + b * this.a;
  3141. this.t0 = a
  3142. }
  3143. };
  3144. e.b2Transform = function() {
  3145. this.position = new f;
  3146. this.R = new a
  3147. };
  3148. e.prototype.b2Transform = function(a, b) {
  3149. void 0 === a && (a = null);
  3150. void 0 === b && (b = null);
  3151. a && (this.position.SetV(a), this.R.SetM(b))
  3152. };
  3153. e.prototype.Initialize = function(a,
  3154. b) {
  3155. this.position.SetV(a);
  3156. this.R.SetM(b)
  3157. };
  3158. e.prototype.SetIdentity = function() {
  3159. this.position.SetZero();
  3160. this.R.SetIdentity()
  3161. };
  3162. e.prototype.Set = function(a) {
  3163. this.position.SetV(a.position);
  3164. this.R.SetM(a.R)
  3165. };
  3166. e.prototype.GetAngle = function() {
  3167. return Math.atan2(this.R.col1.y, this.R.col1.x)
  3168. };
  3169. f.b2Vec2 = function() {};
  3170. f.prototype.b2Vec2 = function(a, b) {
  3171. void 0 === a && (a = 0);
  3172. void 0 === b && (b = 0);
  3173. this.x = a;
  3174. this.y = b
  3175. };
  3176. f.prototype.SetZero = function() {
  3177. this.y = this.x = 0
  3178. };
  3179. f.prototype.Set = function(a, b) {
  3180. void 0 === a && (a = 0);
  3181. void 0 === b && (b = 0);
  3182. this.x = a;
  3183. this.y = b
  3184. };
  3185. f.prototype.SetV = function(a) {
  3186. this.x = a.x;
  3187. this.y = a.y
  3188. };
  3189. f.prototype.GetNegative = function() {
  3190. return new f(-this.x, -this.y)
  3191. };
  3192. f.prototype.NegativeSelf = function() {
  3193. this.x = -this.x;
  3194. this.y = -this.y
  3195. };
  3196. f.Make = function(a, b) {
  3197. void 0 === a && (a = 0);
  3198. void 0 === b && (b = 0);
  3199. return new f(a, b)
  3200. };
  3201. f.prototype.Copy = function() {
  3202. return new f(this.x, this.y)
  3203. };
  3204. f.prototype.Add = function(a) {
  3205. this.x += a.x;
  3206. this.y += a.y
  3207. };
  3208. f.prototype.Subtract = function(a) {
  3209. this.x -= a.x;
  3210. this.y -= a.y
  3211. };
  3212. f.prototype.Multiply = function(a) {
  3213. void 0 === a && (a = 0);
  3214. this.x *=
  3215. a;
  3216. this.y *= a
  3217. };
  3218. f.prototype.MulM = function(a) {
  3219. var b = this.x;
  3220. this.x = a.col1.x * b + a.col2.x * this.y;
  3221. this.y = a.col1.y * b + a.col2.y * this.y
  3222. };
  3223. f.prototype.MulTM = function(a) {
  3224. var c = b.Dot(this, a.col1);
  3225. this.y = b.Dot(this, a.col2);
  3226. this.x = c
  3227. };
  3228. f.prototype.CrossVF = function(a) {
  3229. void 0 === a && (a = 0);
  3230. var b = this.x;
  3231. this.x = a * this.y;
  3232. this.y = -a * b
  3233. };
  3234. f.prototype.CrossFV = function(a) {
  3235. void 0 === a && (a = 0);
  3236. var b = this.x;
  3237. this.x = -a * this.y;
  3238. this.y = a * b
  3239. };
  3240. f.prototype.MinV = function(a) {
  3241. this.x = this.x < a.x ? this.x : a.x;
  3242. this.y = this.y < a.y ? this.y : a.y
  3243. };
  3244. f.prototype.MaxV =
  3245. function(a) {
  3246. this.x = this.x > a.x ? this.x : a.x;
  3247. this.y = this.y > a.y ? this.y : a.y
  3248. };
  3249. f.prototype.Abs = function() {
  3250. 0 > this.x && (this.x = -this.x);
  3251. 0 > this.y && (this.y = -this.y)
  3252. };
  3253. f.prototype.Length = function() {
  3254. return Math.sqrt(this.x * this.x + this.y * this.y)
  3255. };
  3256. f.prototype.LengthSquared = function() {
  3257. return this.x * this.x + this.y * this.y
  3258. };
  3259. f.prototype.Normalize = function() {
  3260. var a = Math.sqrt(this.x * this.x + this.y * this.y);
  3261. if (a < Number.MIN_VALUE) return 0;
  3262. var b = 1 / a;
  3263. this.x *= b;
  3264. this.y *= b;
  3265. return a
  3266. };
  3267. f.prototype.IsValid = function() {
  3268. return b.IsValid(this.x) &&
  3269. b.IsValid(this.y)
  3270. };
  3271. g.b2Vec3 = function() {};
  3272. g.prototype.b2Vec3 = function(a, b, c) {
  3273. void 0 === a && (a = 0);
  3274. void 0 === b && (b = 0);
  3275. void 0 === c && (c = 0);
  3276. this.x = a;
  3277. this.y = b;
  3278. this.z = c
  3279. };
  3280. g.prototype.SetZero = function() {
  3281. this.x = this.y = this.z = 0
  3282. };
  3283. g.prototype.Set = function(a, b, c) {
  3284. void 0 === a && (a = 0);
  3285. void 0 === b && (b = 0);
  3286. void 0 === c && (c = 0);
  3287. this.x = a;
  3288. this.y = b;
  3289. this.z = c
  3290. };
  3291. g.prototype.SetV = function(a) {
  3292. this.x = a.x;
  3293. this.y = a.y;
  3294. this.z = a.z
  3295. };
  3296. g.prototype.GetNegative = function() {
  3297. return new g(-this.x, -this.y, -this.z)
  3298. };
  3299. g.prototype.NegativeSelf = function() {
  3300. this.x = -this.x;
  3301. this.y = -this.y;
  3302. this.z = -this.z
  3303. };
  3304. g.prototype.Copy = function() {
  3305. return new g(this.x, this.y, this.z)
  3306. };
  3307. g.prototype.Add = function(a) {
  3308. this.x += a.x;
  3309. this.y += a.y;
  3310. this.z += a.z
  3311. };
  3312. g.prototype.Subtract = function(a) {
  3313. this.x -= a.x;
  3314. this.y -= a.y;
  3315. this.z -= a.z
  3316. };
  3317. g.prototype.Multiply = function(a) {
  3318. void 0 === a && (a = 0);
  3319. this.x *= a;
  3320. this.y *= a;
  3321. this.z *= a
  3322. }
  3323. })();
  3324. (function() {
  3325. var a = Box2D.Common.Math.b2Math,
  3326. c = Box2D.Common.Math.b2Sweep,
  3327. b = Box2D.Common.Math.b2Transform,
  3328. d = Box2D.Common.Math.b2Vec2,
  3329. e = Box2D.Common.b2Color,
  3330. f = Box2D.Common.b2Settings,
  3331. g = Box2D.Collision.b2AABB,
  3332. h = Box2D.Collision.b2ContactPoint,
  3333. l = Box2D.Collision.b2DynamicTreeBroadPhase,
  3334. m = Box2D.Collision.b2RayCastInput,
  3335. q = Box2D.Collision.b2RayCastOutput,
  3336. p = Box2D.Collision.Shapes.b2CircleShape,
  3337. y = Box2D.Collision.Shapes.b2EdgeShape,
  3338. A = Box2D.Collision.Shapes.b2MassData,
  3339. B = Box2D.Collision.Shapes.b2PolygonShape,
  3340. K = Box2D.Collision.Shapes.b2Shape,
  3341. H = Box2D.Dynamics.b2Body,
  3342. E = Box2D.Dynamics.b2BodyDef,
  3343. M = Box2D.Dynamics.b2ContactFilter,
  3344. Xb = Box2D.Dynamics.b2ContactImpulse,
  3345. Zb = Box2D.Dynamics.b2ContactListener,
  3346. aa = Box2D.Dynamics.b2ContactManager,
  3347. Yb = Box2D.Dynamics.b2DebugDraw,
  3348. $b = Box2D.Dynamics.b2DestructionListener,
  3349. ac = Box2D.Dynamics.b2FilterData,
  3350. bc = Box2D.Dynamics.b2Fixture,
  3351. ec = Box2D.Dynamics.b2FixtureDef,
  3352. jc = Box2D.Dynamics.b2Island,
  3353. cc = Box2D.Dynamics.b2TimeStep,
  3354. dc = Box2D.Dynamics.b2World,
  3355. gc = Box2D.Dynamics.Contacts.b2Contact,
  3356. hc = Box2D.Dynamics.Contacts.b2ContactFactory,
  3357. fc = Box2D.Dynamics.Contacts.b2ContactSolver,
  3358. kc = Box2D.Dynamics.Joints.b2Joint,
  3359. lc = Box2D.Dynamics.Joints.b2PulleyJoint;
  3360. H.b2Body = function() {
  3361. this.m_xf = new b;
  3362. this.m_sweep = new c;
  3363. this.m_linearVelocity = new d;
  3364. this.m_force = new d
  3365. };
  3366. H.prototype.connectEdges = function(b, c, d) {
  3367. void 0 === d && (d = 0);
  3368. var e = Math.atan2(c.GetDirectionVector().y, c.GetDirectionVector().x);
  3369. d = a.MulFV(Math.tan(.5 * (e - d)), c.GetDirectionVector());
  3370. d = a.SubtractVV(d, c.GetNormalVector());
  3371. d = a.MulFV(f.b2_toiSlop, d);
  3372. d = a.AddVV(d, c.GetVertex1());
  3373. var g = a.AddVV(b.GetDirectionVector(),
  3374. c.GetDirectionVector());
  3375. g.Normalize();
  3376. var h = 0 < a.Dot(b.GetDirectionVector(), c.GetNormalVector());
  3377. b.SetNextEdge(c, d, g, h);
  3378. c.SetPrevEdge(b, d, g, h);
  3379. return e
  3380. };
  3381. H.prototype.CreateFixture = function(a) {
  3382. if (1 == this.m_world.IsLocked()) return null;
  3383. var b = new bc;
  3384. b.Create(this, this.m_xf, a);
  3385. this.m_flags & H.e_activeFlag && b.CreateProxy(this.m_world.m_contactManager.m_broadPhase, this.m_xf);
  3386. b.m_next = this.m_fixtureList;
  3387. this.m_fixtureList = b;
  3388. ++this.m_fixtureCount;
  3389. b.m_body = this;
  3390. 0 < b.m_density && this.ResetMassData();
  3391. this.m_world.m_flags |=
  3392. dc.e_newFixture;
  3393. return b
  3394. };
  3395. H.prototype.CreateFixture2 = function(a, b) {
  3396. void 0 === b && (b = 0);
  3397. var c = new ec;
  3398. c.shape = a;
  3399. c.density = b;
  3400. return this.CreateFixture(c)
  3401. };
  3402. H.prototype.DestroyFixture = function(a) {
  3403. if (1 != this.m_world.IsLocked()) {
  3404. for (var b = this.m_fixtureList, c = null; null != b;) {
  3405. if (b == a) {
  3406. c ? c.m_next = a.m_next : this.m_fixtureList = a.m_next;
  3407. break
  3408. }
  3409. c = b;
  3410. b = b.m_next
  3411. }
  3412. for (b = this.m_contactList; b;) {
  3413. var c = b.contact,
  3414. b = b.next,
  3415. d = c.GetFixtureA(),
  3416. e = c.GetFixtureB();
  3417. a != d && a != e || this.m_world.m_contactManager.Destroy(c)
  3418. }
  3419. this.m_flags & H.e_activeFlag &&
  3420. a.DestroyProxy(this.m_world.m_contactManager.m_broadPhase);
  3421. a.Destroy();
  3422. a.m_body = null;
  3423. a.m_next = null;
  3424. --this.m_fixtureCount;
  3425. this.ResetMassData()
  3426. }
  3427. };
  3428. H.prototype.SetPositionAndAngle = function(a, b) {
  3429. void 0 === b && (b = 0);
  3430. var c;
  3431. if (1 != this.m_world.IsLocked()) {
  3432. this.m_xf.R.Set(b);
  3433. this.m_xf.position.SetV(a);
  3434. c = this.m_xf.R;
  3435. var d = this.m_sweep.localCenter;
  3436. this.m_sweep.c.x = c.col1.x * d.x + c.col2.x * d.y;
  3437. this.m_sweep.c.y = c.col1.y * d.x + c.col2.y * d.y;
  3438. this.m_sweep.c.x += this.m_xf.position.x;
  3439. this.m_sweep.c.y += this.m_xf.position.y;
  3440. this.m_sweep.c0.SetV(this.m_sweep.c);
  3441. this.m_sweep.a0 = this.m_sweep.a = b;
  3442. d = this.m_world.m_contactManager.m_broadPhase;
  3443. for (c = this.m_fixtureList; c; c = c.m_next) c.Synchronize(d, this.m_xf, this.m_xf);
  3444. this.m_world.m_contactManager.FindNewContacts()
  3445. }
  3446. };
  3447. H.prototype.SetTransform = function(a) {
  3448. this.SetPositionAndAngle(a.position, a.GetAngle())
  3449. };
  3450. H.prototype.GetTransform = function() {
  3451. return this.m_xf
  3452. };
  3453. H.prototype.GetPosition = function() {
  3454. return this.m_xf.position
  3455. };
  3456. H.prototype.SetPosition = function(a) {
  3457. this.SetPositionAndAngle(a, this.GetAngle())
  3458. };
  3459. H.prototype.GetAngle =
  3460. function() {
  3461. return this.m_sweep.a
  3462. };
  3463. H.prototype.SetAngle = function(a) {
  3464. void 0 === a && (a = 0);
  3465. this.SetPositionAndAngle(this.GetPosition(), a)
  3466. };
  3467. H.prototype.GetWorldCenter = function() {
  3468. return this.m_sweep.c
  3469. };
  3470. H.prototype.GetLocalCenter = function() {
  3471. return this.m_sweep.localCenter
  3472. };
  3473. H.prototype.SetLinearVelocity = function(a) {
  3474. this.m_type != H.b2_staticBody && this.m_linearVelocity.SetV(a)
  3475. };
  3476. H.prototype.GetLinearVelocity = function() {
  3477. return this.m_linearVelocity
  3478. };
  3479. H.prototype.SetAngularVelocity = function(a) {
  3480. void 0 === a && (a = 0);
  3481. this.m_type !=
  3482. H.b2_staticBody && (this.m_angularVelocity = a)
  3483. };
  3484. H.prototype.GetAngularVelocity = function() {
  3485. return this.m_angularVelocity
  3486. };
  3487. H.prototype.GetDefinition = function() {
  3488. var a = new E;
  3489. a.type = this.GetType();
  3490. a.allowSleep = (this.m_flags & H.e_allowSleepFlag) == H.e_allowSleepFlag;
  3491. a.angle = this.GetAngle();
  3492. a.angularDamping = this.m_angularDamping;
  3493. a.angularVelocity = this.m_angularVelocity;
  3494. a.fixedRotation = (this.m_flags & H.e_fixedRotationFlag) == H.e_fixedRotationFlag;
  3495. a.bullet = (this.m_flags & H.e_bulletFlag) == H.e_bulletFlag;
  3496. a.awake = (this.m_flags &
  3497. H.e_awakeFlag) == H.e_awakeFlag;
  3498. a.linearDamping = this.m_linearDamping;
  3499. a.linearVelocity.SetV(this.GetLinearVelocity());
  3500. a.position = this.GetPosition();
  3501. a.userData = this.GetUserData();
  3502. return a
  3503. };
  3504. H.prototype.ApplyForce = function(a, b) {
  3505. this.m_type == H.b2_dynamicBody && (0 == this.IsAwake() && this.SetAwake(!0), this.m_force.x += a.x, this.m_force.y += a.y, this.m_torque += (b.x - this.m_sweep.c.x) * a.y - (b.y - this.m_sweep.c.y) * a.x)
  3506. };
  3507. H.prototype.ApplyTorque = function(a) {
  3508. void 0 === a && (a = 0);
  3509. this.m_type == H.b2_dynamicBody && (0 == this.IsAwake() &&
  3510. this.SetAwake(!0), this.m_torque += a)
  3511. };
  3512. H.prototype.ApplyImpulse = function(a, b) {
  3513. this.m_type == H.b2_dynamicBody && (0 == this.IsAwake() && this.SetAwake(!0), this.m_linearVelocity.x += this.m_invMass * a.x, this.m_linearVelocity.y += this.m_invMass * a.y, this.m_angularVelocity += this.m_invI * ((b.x - this.m_sweep.c.x) * a.y - (b.y - this.m_sweep.c.y) * a.x))
  3514. };
  3515. H.prototype.Split = function(b) {
  3516. for (var c = this.GetLinearVelocity().Copy(), d = this.GetAngularVelocity(), e = this.GetWorldCenter(), f = this.m_world.CreateBody(this.GetDefinition()), g,
  3517. h = this.m_fixtureList; h;)
  3518. if (b(h)) {
  3519. var l = h.m_next;
  3520. g ? g.m_next = l : this.m_fixtureList = l;
  3521. this.m_fixtureCount--;
  3522. h.m_next = f.m_fixtureList;
  3523. f.m_fixtureList = h;
  3524. f.m_fixtureCount++;
  3525. h.m_body = f;
  3526. h = l
  3527. } else g = h, h = h.m_next;
  3528. this.ResetMassData();
  3529. f.ResetMassData();
  3530. g = this.GetWorldCenter();
  3531. b = f.GetWorldCenter();
  3532. g = a.AddVV(c, a.CrossFV(d, a.SubtractVV(g, e)));
  3533. c = a.AddVV(c, a.CrossFV(d, a.SubtractVV(b, e)));
  3534. this.SetLinearVelocity(g);
  3535. f.SetLinearVelocity(c);
  3536. this.SetAngularVelocity(d);
  3537. f.SetAngularVelocity(d);
  3538. this.SynchronizeFixtures();
  3539. f.SynchronizeFixtures();
  3540. return f
  3541. };
  3542. H.prototype.Merge = function(a) {
  3543. var b;
  3544. for (b = a.m_fixtureList; b;) {
  3545. var c = b.m_next;
  3546. a.m_fixtureCount--;
  3547. b.m_next = this.m_fixtureList;
  3548. this.m_fixtureList = b;
  3549. this.m_fixtureCount++;
  3550. b.m_body = e;
  3551. b = c
  3552. }
  3553. d.m_fixtureCount = 0;
  3554. var d = this,
  3555. e = a;
  3556. d.GetWorldCenter();
  3557. e.GetWorldCenter();
  3558. d.GetLinearVelocity().Copy();
  3559. e.GetLinearVelocity().Copy();
  3560. d.GetAngularVelocity();
  3561. e.GetAngularVelocity();
  3562. d.ResetMassData();
  3563. this.SynchronizeFixtures()
  3564. };
  3565. H.prototype.GetMass = function() {
  3566. return this.m_mass
  3567. };
  3568. H.prototype.GetInertia = function() {
  3569. return this.m_I
  3570. };
  3571. H.prototype.GetMassData = function(a) {
  3572. a.mass = this.m_mass;
  3573. a.I = this.m_I;
  3574. a.center.SetV(this.m_sweep.localCenter)
  3575. };
  3576. H.prototype.SetMassData = function(b) {
  3577. f.b2Assert(0 == this.m_world.IsLocked());
  3578. if (1 != this.m_world.IsLocked() && this.m_type == H.b2_dynamicBody) {
  3579. this.m_invI = this.m_I = this.m_invMass = 0;
  3580. this.m_mass = b.mass;
  3581. 0 >= this.m_mass && (this.m_mass = 1);
  3582. this.m_invMass = 1 / this.m_mass;
  3583. 0 < b.I && 0 == (this.m_flags & H.e_fixedRotationFlag) && (this.m_I = b.I - this.m_mass * (b.center.x * b.center.x + b.center.y * b.center.y), this.m_invI = 1 / this.m_I);
  3584. var c = this.m_sweep.c.Copy();
  3585. this.m_sweep.localCenter.SetV(b.center);
  3586. this.m_sweep.c0.SetV(a.MulX(this.m_xf, this.m_sweep.localCenter));
  3587. this.m_sweep.c.SetV(this.m_sweep.c0);
  3588. this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - c.y);
  3589. this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - c.x)
  3590. }
  3591. };
  3592. H.prototype.ResetMassData = function() {
  3593. this.m_invI = this.m_I = this.m_invMass = this.m_mass = 0;
  3594. this.m_sweep.localCenter.SetZero();
  3595. if (this.m_type != H.b2_staticBody && this.m_type != H.b2_kinematicBody) {
  3596. for (var b =
  3597. d.Make(0, 0), c = this.m_fixtureList; c; c = c.m_next)
  3598. if (0 != c.m_density) {
  3599. var e = c.GetMassData();
  3600. this.m_mass += e.mass;
  3601. b.x += e.center.x * e.mass;
  3602. b.y += e.center.y * e.mass;
  3603. this.m_I += e.I
  3604. }
  3605. 0 < this.m_mass ? (this.m_invMass = 1 / this.m_mass, b.x *= this.m_invMass, b.y *= this.m_invMass) : this.m_invMass = this.m_mass = 1;
  3606. 0 < this.m_I && 0 == (this.m_flags & H.e_fixedRotationFlag) ? (this.m_I -= this.m_mass * (b.x * b.x + b.y * b.y), this.m_I *= this.m_inertiaScale, f.b2Assert(0 < this.m_I), this.m_invI = 1 / this.m_I) : this.m_invI = this.m_I = 0;
  3607. c = this.m_sweep.c.Copy();
  3608. this.m_sweep.localCenter.SetV(b);
  3609. this.m_sweep.c0.SetV(a.MulX(this.m_xf, this.m_sweep.localCenter));
  3610. this.m_sweep.c.SetV(this.m_sweep.c0);
  3611. this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - c.y);
  3612. this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - c.x)
  3613. }
  3614. };
  3615. H.prototype.GetWorldPoint = function(a) {
  3616. var b = this.m_xf.R;
  3617. a = new d(b.col1.x * a.x + b.col2.x * a.y, b.col1.y * a.x + b.col2.y * a.y);
  3618. a.x += this.m_xf.position.x;
  3619. a.y += this.m_xf.position.y;
  3620. return a
  3621. };
  3622. H.prototype.GetWorldVector = function(b) {
  3623. return a.MulMV(this.m_xf.R, b)
  3624. };
  3625. H.prototype.GetLocalPoint =
  3626. function(b) {
  3627. return a.MulXT(this.m_xf, b)
  3628. };
  3629. H.prototype.GetLocalVector = function(b) {
  3630. return a.MulTMV(this.m_xf.R, b)
  3631. };
  3632. H.prototype.GetLinearVelocityFromWorldPoint = function(a) {
  3633. return new d(this.m_linearVelocity.x - this.m_angularVelocity * (a.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (a.x - this.m_sweep.c.x))
  3634. };
  3635. H.prototype.GetLinearVelocityFromLocalPoint = function(a) {
  3636. var b = this.m_xf.R;
  3637. a = new d(b.col1.x * a.x + b.col2.x * a.y, b.col1.y * a.x + b.col2.y * a.y);
  3638. a.x += this.m_xf.position.x;
  3639. a.y += this.m_xf.position.y;
  3640. return new d(this.m_linearVelocity.x - this.m_angularVelocity * (a.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (a.x - this.m_sweep.c.x))
  3641. };
  3642. H.prototype.GetLinearDamping = function() {
  3643. return this.m_linearDamping
  3644. };
  3645. H.prototype.SetLinearDamping = function(a) {
  3646. void 0 === a && (a = 0);
  3647. this.m_linearDamping = a
  3648. };
  3649. H.prototype.GetAngularDamping = function() {
  3650. return this.m_angularDamping
  3651. };
  3652. H.prototype.SetAngularDamping = function(a) {
  3653. void 0 === a && (a = 0);
  3654. this.m_angularDamping = a
  3655. };
  3656. H.prototype.SetType = function(a) {
  3657. void 0 ===
  3658. a && (a = 0);
  3659. if (this.m_type != a)
  3660. for (this.m_type = a, this.ResetMassData(), this.m_type == H.b2_staticBody && (this.m_linearVelocity.SetZero(), this.m_angularVelocity = 0), this.SetAwake(!0), this.m_force.SetZero(), this.m_torque = 0, a = this.m_contactList; a; a = a.next) a.contact.FlagForFiltering()
  3661. };
  3662. H.prototype.GetType = function() {
  3663. return this.m_type
  3664. };
  3665. H.prototype.SetBullet = function(a) {
  3666. this.m_flags = a ? this.m_flags | H.e_bulletFlag : this.m_flags & ~H.e_bulletFlag
  3667. };
  3668. H.prototype.IsBullet = function() {
  3669. return (this.m_flags & H.e_bulletFlag) ==
  3670. H.e_bulletFlag
  3671. };
  3672. H.prototype.SetSleepingAllowed = function(a) {
  3673. a ? this.m_flags |= H.e_allowSleepFlag : (this.m_flags &= ~H.e_allowSleepFlag, this.SetAwake(!0))
  3674. };
  3675. H.prototype.SetAwake = function(a) {
  3676. a ? (this.m_flags |= H.e_awakeFlag, this.m_sleepTime = 0) : (this.m_flags &= ~H.e_awakeFlag, this.m_sleepTime = 0, this.m_linearVelocity.SetZero(), this.m_angularVelocity = 0, this.m_force.SetZero(), this.m_torque = 0)
  3677. };
  3678. H.prototype.IsAwake = function() {
  3679. return (this.m_flags & H.e_awakeFlag) == H.e_awakeFlag
  3680. };
  3681. H.prototype.SetFixedRotation = function(a) {
  3682. this.m_flags =
  3683. a ? this.m_flags | H.e_fixedRotationFlag : this.m_flags & ~H.e_fixedRotationFlag;
  3684. this.ResetMassData()
  3685. };
  3686. H.prototype.IsFixedRotation = function() {
  3687. return (this.m_flags & H.e_fixedRotationFlag) == H.e_fixedRotationFlag
  3688. };
  3689. H.prototype.SetActive = function(a) {
  3690. if (a != this.IsActive()) {
  3691. var b;
  3692. if (a)
  3693. for (this.m_flags |= H.e_activeFlag, a = this.m_world.m_contactManager.m_broadPhase, b = this.m_fixtureList; b; b = b.m_next) b.CreateProxy(a, this.m_xf);
  3694. else {
  3695. this.m_flags &= ~H.e_activeFlag;
  3696. a = this.m_world.m_contactManager.m_broadPhase;
  3697. for (b = this.m_fixtureList; b; b =
  3698. b.m_next) b.DestroyProxy(a);
  3699. for (a = this.m_contactList; a;) b = a, a = a.next, this.m_world.m_contactManager.Destroy(b.contact);
  3700. this.m_contactList = null
  3701. }
  3702. }
  3703. };
  3704. H.prototype.IsActive = function() {
  3705. return (this.m_flags & H.e_activeFlag) == H.e_activeFlag
  3706. };
  3707. H.prototype.IsSleepingAllowed = function() {
  3708. return (this.m_flags & H.e_allowSleepFlag) == H.e_allowSleepFlag
  3709. };
  3710. H.prototype.GetFixtureList = function() {
  3711. return this.m_fixtureList
  3712. };
  3713. H.prototype.GetJointList = function() {
  3714. return this.m_jointList
  3715. };
  3716. H.prototype.GetControllerList = function() {
  3717. return this.m_controllerList
  3718. };
  3719. H.prototype.GetContactList = function() {
  3720. return this.m_contactList
  3721. };
  3722. H.prototype.GetNext = function() {
  3723. return this.m_next
  3724. };
  3725. H.prototype.GetUserData = function() {
  3726. return this.m_userData
  3727. };
  3728. H.prototype.SetUserData = function(a) {
  3729. this.m_userData = a
  3730. };
  3731. H.prototype.GetWorld = function() {
  3732. return this.m_world
  3733. };
  3734. H.prototype.b2Body = function(a, b) {
  3735. this.m_flags = 0;
  3736. a.bullet && (this.m_flags |= H.e_bulletFlag);
  3737. a.fixedRotation && (this.m_flags |= H.e_fixedRotationFlag);
  3738. a.allowSleep && (this.m_flags |= H.e_allowSleepFlag);
  3739. a.awake && (this.m_flags |= H.e_awakeFlag);
  3740. a.active && (this.m_flags |= H.e_activeFlag);
  3741. this.m_world = b;
  3742. this.m_xf.position.SetV(a.position);
  3743. this.m_xf.R.Set(a.angle);
  3744. this.m_sweep.localCenter.SetZero();
  3745. this.m_sweep.t0 = 1;
  3746. this.m_sweep.a0 = this.m_sweep.a = a.angle;
  3747. var c = this.m_xf.R,
  3748. d = this.m_sweep.localCenter;
  3749. this.m_sweep.c.x = c.col1.x * d.x + c.col2.x * d.y;
  3750. this.m_sweep.c.y = c.col1.y * d.x + c.col2.y * d.y;
  3751. this.m_sweep.c.x += this.m_xf.position.x;
  3752. this.m_sweep.c.y += this.m_xf.position.y;
  3753. this.m_sweep.c0.SetV(this.m_sweep.c);
  3754. this.m_contactList = this.m_controllerList = this.m_jointList =
  3755. null;
  3756. this.m_controllerCount = 0;
  3757. this.m_next = this.m_prev = null;
  3758. this.m_linearVelocity.SetV(a.linearVelocity);
  3759. this.m_angularVelocity = a.angularVelocity;
  3760. this.m_linearDamping = a.linearDamping;
  3761. this.m_angularDamping = a.angularDamping;
  3762. this.m_force.Set(0, 0);
  3763. this.m_sleepTime = this.m_torque = 0;
  3764. this.m_type = a.type;
  3765. this.m_invMass = this.m_type == H.b2_dynamicBody ? this.m_mass = 1 : this.m_mass = 0;
  3766. this.m_invI = this.m_I = 0;
  3767. this.m_inertiaScale = a.inertiaScale;
  3768. this.m_userData = a.userData;
  3769. this.m_fixtureList = null;
  3770. this.m_fixtureCount = 0
  3771. };
  3772. H.prototype.SynchronizeFixtures =
  3773. function() {
  3774. var a = H.s_xf1;
  3775. a.R.Set(this.m_sweep.a0);
  3776. var b = a.R,
  3777. c = this.m_sweep.localCenter;
  3778. a.position.x = this.m_sweep.c0.x - (b.col1.x * c.x + b.col2.x * c.y);
  3779. a.position.y = this.m_sweep.c0.y - (b.col1.y * c.x + b.col2.y * c.y);
  3780. c = this.m_world.m_contactManager.m_broadPhase;
  3781. for (b = this.m_fixtureList; b; b = b.m_next) b.Synchronize(c, a, this.m_xf)
  3782. };
  3783. H.prototype.SynchronizeTransform = function() {
  3784. this.m_xf.R.Set(this.m_sweep.a);
  3785. var a = this.m_xf.R,
  3786. b = this.m_sweep.localCenter;
  3787. this.m_xf.position.x = this.m_sweep.c.x - (a.col1.x * b.x + a.col2.x * b.y);
  3788. this.m_xf.position.y = this.m_sweep.c.y - (a.col1.y * b.x + a.col2.y * b.y)
  3789. };
  3790. H.prototype.ShouldCollide = function(a) {
  3791. if (this.m_type != H.b2_dynamicBody && a.m_type != H.b2_dynamicBody) return !1;
  3792. for (var b = this.m_jointList; b; b = b.next)
  3793. if (b.other == a && 0 == b.joint.m_collideConnected) return !1;
  3794. return !0
  3795. };
  3796. H.prototype.Advance = function(a) {
  3797. void 0 === a && (a = 0);
  3798. this.m_sweep.Advance(a);
  3799. this.m_sweep.c.SetV(this.m_sweep.c0);
  3800. this.m_sweep.a = this.m_sweep.a0;
  3801. this.SynchronizeTransform()
  3802. };
  3803. Box2D.postDefs.push(function() {
  3804. Box2D.Dynamics.b2Body.s_xf1 =
  3805. new b;
  3806. Box2D.Dynamics.b2Body.e_islandFlag = 1;
  3807. Box2D.Dynamics.b2Body.e_awakeFlag = 2;
  3808. Box2D.Dynamics.b2Body.e_allowSleepFlag = 4;
  3809. Box2D.Dynamics.b2Body.e_bulletFlag = 8;
  3810. Box2D.Dynamics.b2Body.e_fixedRotationFlag = 16;
  3811. Box2D.Dynamics.b2Body.e_activeFlag = 32;
  3812. Box2D.Dynamics.b2Body.b2_staticBody = 0;
  3813. Box2D.Dynamics.b2Body.b2_kinematicBody = 1;
  3814. Box2D.Dynamics.b2Body.b2_dynamicBody = 2
  3815. });
  3816. E.b2BodyDef = function() {
  3817. this.position = new d;
  3818. this.linearVelocity = new d
  3819. };
  3820. E.prototype.b2BodyDef = function() {
  3821. this.userData = null;
  3822. this.position.Set(0,
  3823. 0);
  3824. this.angle = 0;
  3825. this.linearVelocity.Set(0, 0);
  3826. this.angularDamping = this.linearDamping = this.angularVelocity = 0;
  3827. this.awake = this.allowSleep = !0;
  3828. this.bullet = this.fixedRotation = !1;
  3829. this.type = H.b2_staticBody;
  3830. this.active = !0;
  3831. this.inertiaScale = 1
  3832. };
  3833. M.b2ContactFilter = function() {};
  3834. M.prototype.ShouldCollide = function(a, b) {
  3835. var c = a.GetFilterData(),
  3836. d = b.GetFilterData();
  3837. return c.groupIndex == d.groupIndex && 0 != c.groupIndex ? 0 < c.groupIndex : 0 != (c.maskBits & d.categoryBits) && 0 != (c.categoryBits & d.maskBits)
  3838. };
  3839. M.prototype.RayCollide =
  3840. function(a, b) {
  3841. return a ? this.ShouldCollide(a instanceof bc ? a : null, b) : !0
  3842. };
  3843. Box2D.postDefs.push(function() {
  3844. Box2D.Dynamics.b2ContactFilter.b2_defaultFilter = new M
  3845. });
  3846. Xb.b2ContactImpulse = function() {
  3847. this.normalImpulses = new Vector_a2j_Number(f.b2_maxManifoldPoints);
  3848. this.tangentImpulses = new Vector_a2j_Number(f.b2_maxManifoldPoints)
  3849. };
  3850. Zb.b2ContactListener = function() {};
  3851. Zb.prototype.BeginContact = function() {};
  3852. Zb.prototype.EndContact = function() {};
  3853. Zb.prototype.PreSolve = function() {};
  3854. Zb.prototype.PostSolve = function() {};
  3855. Box2D.postDefs.push(function() {
  3856. Box2D.Dynamics.b2ContactListener.b2_defaultListener = new Zb
  3857. });
  3858. aa.b2ContactManager = function() {};
  3859. aa.prototype.b2ContactManager = function() {
  3860. this.m_world = null;
  3861. this.m_contactCount = 0;
  3862. this.m_contactFilter = M.b2_defaultFilter;
  3863. this.m_contactListener = Zb.b2_defaultListener;
  3864. this.m_contactFactory = new hc(this.m_allocator);
  3865. this.m_broadPhase = new l
  3866. };
  3867. aa.prototype.AddPair = function(a, b) {
  3868. var c = a instanceof bc ? a : null,
  3869. d = b instanceof bc ? b : null,
  3870. e = c.GetBody(),
  3871. f = d.GetBody();
  3872. if (e != f) {
  3873. for (var g = f.GetContactList(); g;) {
  3874. if (g.other ==
  3875. e) {
  3876. var h = g.contact.GetFixtureA(),
  3877. l = g.contact.GetFixtureB();
  3878. if (h == c && l == d || h == d && l == c) return
  3879. }
  3880. g = g.next
  3881. }
  3882. 0 != f.ShouldCollide(e) && 0 != this.m_contactFilter.ShouldCollide(c, d) && (g = this.m_contactFactory.Create(c, d), c = g.GetFixtureA(), d = g.GetFixtureB(), e = c.m_body, f = d.m_body, g.m_prev = null, g.m_next = this.m_world.m_contactList, null != this.m_world.m_contactList && (this.m_world.m_contactList.m_prev = g), this.m_world.m_contactList = g, g.m_nodeA.contact = g, g.m_nodeA.other = f, g.m_nodeA.prev = null, g.m_nodeA.next = e.m_contactList,
  3883. null != e.m_contactList && (e.m_contactList.prev = g.m_nodeA), e.m_contactList = g.m_nodeA, g.m_nodeB.contact = g, g.m_nodeB.other = e, g.m_nodeB.prev = null, g.m_nodeB.next = f.m_contactList, null != f.m_contactList && (f.m_contactList.prev = g.m_nodeB), f.m_contactList = g.m_nodeB, ++this.m_world.m_contactCount)
  3884. }
  3885. };
  3886. aa.prototype.FindNewContacts = function() {
  3887. this.m_broadPhase.UpdatePairs(Box2D.generateCallback(this, this.AddPair))
  3888. };
  3889. aa.prototype.Destroy = function(a) {
  3890. var b = a.GetFixtureA(),
  3891. c = a.GetFixtureB(),
  3892. b = b.GetBody(),
  3893. c = c.GetBody();
  3894. a.IsTouching() && this.m_contactListener.EndContact(a);
  3895. a.m_prev && (a.m_prev.m_next = a.m_next);
  3896. a.m_next && (a.m_next.m_prev = a.m_prev);
  3897. a == this.m_world.m_contactList && (this.m_world.m_contactList = a.m_next);
  3898. a.m_nodeA.prev && (a.m_nodeA.prev.next = a.m_nodeA.next);
  3899. a.m_nodeA.next && (a.m_nodeA.next.prev = a.m_nodeA.prev);
  3900. a.m_nodeA == b.m_contactList && (b.m_contactList = a.m_nodeA.next);
  3901. a.m_nodeB.prev && (a.m_nodeB.prev.next = a.m_nodeB.next);
  3902. a.m_nodeB.next && (a.m_nodeB.next.prev = a.m_nodeB.prev);
  3903. a.m_nodeB == c.m_contactList && (c.m_contactList =
  3904. a.m_nodeB.next);
  3905. this.m_contactFactory.Destroy(a);
  3906. --this.m_contactCount
  3907. };
  3908. aa.prototype.Collide = function() {
  3909. for (var a = this.m_world.m_contactList; a;) {
  3910. var b = a.GetFixtureA(),
  3911. c = a.GetFixtureB(),
  3912. d = b.GetBody(),
  3913. e = c.GetBody();
  3914. if (0 == d.IsAwake() && 0 == e.IsAwake()) a = a.GetNext();
  3915. else {
  3916. if (a.m_flags & gc.e_filterFlag) {
  3917. if (0 == e.ShouldCollide(d)) {
  3918. b = a;
  3919. a = b.GetNext();
  3920. this.Destroy(b);
  3921. continue
  3922. }
  3923. if (0 == this.m_contactFilter.ShouldCollide(b, c)) {
  3924. b = a;
  3925. a = b.GetNext();
  3926. this.Destroy(b);
  3927. continue
  3928. }
  3929. a.m_flags &= ~gc.e_filterFlag
  3930. }
  3931. 0 == this.m_broadPhase.TestOverlap(b.m_proxy,
  3932. c.m_proxy) ? (b = a, a = b.GetNext(), this.Destroy(b)) : (a.Update(this.m_contactListener), a = a.GetNext())
  3933. }
  3934. }
  3935. };
  3936. Box2D.postDefs.push(function() {
  3937. Box2D.Dynamics.b2ContactManager.s_evalCP = new h
  3938. });
  3939. Yb.b2DebugDraw = function() {};
  3940. Yb.prototype.b2DebugDraw = function() {};
  3941. Yb.prototype.SetFlags = function() {};
  3942. Yb.prototype.GetFlags = function() {};
  3943. Yb.prototype.AppendFlags = function() {};
  3944. Yb.prototype.ClearFlags = function() {};
  3945. Yb.prototype.SetSprite = function() {};
  3946. Yb.prototype.GetSprite = function() {};
  3947. Yb.prototype.SetDrawScale = function() {};
  3948. Yb.prototype.GetDrawScale = function() {};
  3949. Yb.prototype.SetLineThickness = function() {};
  3950. Yb.prototype.GetLineThickness = function() {};
  3951. Yb.prototype.SetAlpha = function() {};
  3952. Yb.prototype.GetAlpha = function() {};
  3953. Yb.prototype.SetFillAlpha = function() {};
  3954. Yb.prototype.GetFillAlpha = function() {};
  3955. Yb.prototype.SetXFormScale = function() {};
  3956. Yb.prototype.GetXFormScale = function() {};
  3957. Yb.prototype.DrawPolygon = function() {};
  3958. Yb.prototype.DrawSolidPolygon = function() {};
  3959. Yb.prototype.DrawCircle = function() {};
  3960. Yb.prototype.DrawSolidCircle = function() {};
  3961. Yb.prototype.DrawSegment = function() {};
  3962. Yb.prototype.DrawTransform = function() {};
  3963. Box2D.postDefs.push(function() {
  3964. Box2D.Dynamics.b2DebugDraw.e_shapeBit = 1;
  3965. Box2D.Dynamics.b2DebugDraw.e_jointBit = 2;
  3966. Box2D.Dynamics.b2DebugDraw.e_aabbBit = 4;
  3967. Box2D.Dynamics.b2DebugDraw.e_pairBit = 8;
  3968. Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit = 16;
  3969. Box2D.Dynamics.b2DebugDraw.e_controllerBit = 32
  3970. });
  3971. $b.b2DestructionListener = function() {};
  3972. $b.prototype.SayGoodbyeJoint = function() {};
  3973. $b.prototype.SayGoodbyeFixture = function() {};
  3974. ac.b2FilterData =
  3975. function() {
  3976. this.categoryBits = 1;
  3977. this.maskBits = 65535;
  3978. this.groupIndex = 0
  3979. };
  3980. ac.prototype.Copy = function() {
  3981. var a = new ac;
  3982. a.categoryBits = this.categoryBits;
  3983. a.maskBits = this.maskBits;
  3984. a.groupIndex = this.groupIndex;
  3985. return a
  3986. };
  3987. bc.b2Fixture = function() {
  3988. this.m_filter = new ac
  3989. };
  3990. bc.prototype.GetType = function() {
  3991. return this.m_shape.GetType()
  3992. };
  3993. bc.prototype.GetShape = function() {
  3994. return this.m_shape
  3995. };
  3996. bc.prototype.SetSensor = function(a) {
  3997. if (this.m_isSensor != a && (this.m_isSensor = a, null != this.m_body))
  3998. for (a = this.m_body.GetContactList(); a;) {
  3999. var b =
  4000. a.contact,
  4001. c = b.GetFixtureA(),
  4002. d = b.GetFixtureB();
  4003. c != this && d != this || b.SetSensor(c.IsSensor() || d.IsSensor());
  4004. a = a.next
  4005. }
  4006. };
  4007. bc.prototype.IsSensor = function() {
  4008. return this.m_isSensor
  4009. };
  4010. bc.prototype.SetFilterData = function(a) {
  4011. this.m_filter = a.Copy();
  4012. if (!this.m_body)
  4013. for (a = this.m_body.GetContactList(); a;) {
  4014. var b = a.contact,
  4015. c = b.GetFixtureA(),
  4016. d = b.GetFixtureB();
  4017. c != this && d != this || b.FlagForFiltering();
  4018. a = a.next
  4019. }
  4020. };
  4021. bc.prototype.GetFilterData = function() {
  4022. return this.m_filter.Copy()
  4023. };
  4024. bc.prototype.GetBody = function() {
  4025. return this.m_body
  4026. };
  4027. bc.prototype.GetNext = function() {
  4028. return this.m_next
  4029. };
  4030. bc.prototype.GetUserData = function() {
  4031. return this.m_userData
  4032. };
  4033. bc.prototype.SetUserData = function(a) {
  4034. this.m_userData = a
  4035. };
  4036. bc.prototype.TestPoint = function(a) {
  4037. return this.m_shape.TestPoint(this.m_body.GetTransform(), a)
  4038. };
  4039. bc.prototype.RayCast = function(a, b) {
  4040. return this.m_shape.RayCast(a, b, this.m_body.GetTransform())
  4041. };
  4042. bc.prototype.GetMassData = function(a) {
  4043. void 0 === a && (a = null);
  4044. null == a && (a = new A);
  4045. this.m_shape.ComputeMass(a, this.m_density);
  4046. return a
  4047. };
  4048. bc.prototype.SetDensity =
  4049. function(a) {
  4050. void 0 === a && (a = 0);
  4051. this.m_density = a
  4052. };
  4053. bc.prototype.GetDensity = function() {
  4054. return this.m_density
  4055. };
  4056. bc.prototype.GetFriction = function() {
  4057. return this.m_friction
  4058. };
  4059. bc.prototype.SetFriction = function(a) {
  4060. void 0 === a && (a = 0);
  4061. this.m_friction = a
  4062. };
  4063. bc.prototype.GetRestitution = function() {
  4064. return this.m_restitution
  4065. };
  4066. bc.prototype.SetRestitution = function(a) {
  4067. void 0 === a && (a = 0);
  4068. this.m_restitution = a
  4069. };
  4070. bc.prototype.GetAABB = function() {
  4071. return this.m_aabb
  4072. };
  4073. bc.prototype.b2Fixture = function() {
  4074. this.m_aabb = new g;
  4075. this.m_shape =
  4076. this.m_next = this.m_body = this.m_userData = null;
  4077. this.m_restitution = this.m_friction = this.m_density = 0
  4078. };
  4079. bc.prototype.Create = function(a, b, c) {
  4080. this.m_userData = c.userData;
  4081. this.m_friction = c.friction;
  4082. this.m_restitution = c.restitution;
  4083. this.m_body = a;
  4084. this.m_next = null;
  4085. this.m_filter = c.filter.Copy();
  4086. this.m_isSensor = c.isSensor;
  4087. this.m_shape = c.shape.Copy();
  4088. this.m_density = c.density
  4089. };
  4090. bc.prototype.Destroy = function() {
  4091. this.m_shape = null
  4092. };
  4093. bc.prototype.CreateProxy = function(a, b) {
  4094. this.m_shape.ComputeAABB(this.m_aabb, b);
  4095. this.m_proxy =
  4096. a.CreateProxy(this.m_aabb, this)
  4097. };
  4098. bc.prototype.DestroyProxy = function(a) {
  4099. null != this.m_proxy && (a.DestroyProxy(this.m_proxy), this.m_proxy = null)
  4100. };
  4101. bc.prototype.Synchronize = function(b, c, d) {
  4102. if (this.m_proxy) {
  4103. var e = new g,
  4104. f = new g;
  4105. this.m_shape.ComputeAABB(e, c);
  4106. this.m_shape.ComputeAABB(f, d);
  4107. this.m_aabb.Combine(e, f);
  4108. c = a.SubtractVV(d.position, c.position);
  4109. b.MoveProxy(this.m_proxy, this.m_aabb, c)
  4110. }
  4111. };
  4112. ec.b2FixtureDef = function() {
  4113. this.filter = new ac
  4114. };
  4115. ec.prototype.b2FixtureDef = function() {
  4116. this.userData = this.shape = null;
  4117. this.friction =
  4118. .2;
  4119. this.density = this.restitution = 0;
  4120. this.filter.categoryBits = 1;
  4121. this.filter.maskBits = 65535;
  4122. this.filter.groupIndex = 0;
  4123. this.isSensor = !1
  4124. };
  4125. jc.b2Island = function() {};
  4126. jc.prototype.b2Island = function() {
  4127. this.m_bodies = new Vector;
  4128. this.m_contacts = new Vector;
  4129. this.m_joints = new Vector
  4130. };
  4131. jc.prototype.Initialize = function(a, b, c, d, e, f) {
  4132. void 0 === a && (a = 0);
  4133. void 0 === b && (b = 0);
  4134. void 0 === c && (c = 0);
  4135. this.m_bodyCapacity = a;
  4136. this.m_contactCapacity = b;
  4137. this.m_jointCapacity = c;
  4138. this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0;
  4139. this.m_allocator =
  4140. d;
  4141. this.m_listener = e;
  4142. this.m_contactSolver = f;
  4143. for (d = this.m_bodies.length; d < a; d++) this.m_bodies[d] = null;
  4144. for (d = this.m_contacts.length; d < b; d++) this.m_contacts[d] = null;
  4145. for (d = this.m_joints.length; d < c; d++) this.m_joints[d] = null
  4146. };
  4147. jc.prototype.Clear = function() {
  4148. this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0
  4149. };
  4150. jc.prototype.Solve = function(b, c, d) {
  4151. var e, g, h;
  4152. for (e = 0; e < this.m_bodyCount; ++e) g = this.m_bodies[e], g.GetType() == H.b2_dynamicBody && (g.m_linearVelocity.x += b.dt * (c.x + g.m_invMass * g.m_force.x), g.m_linearVelocity.y +=
  4153. b.dt * (c.y + g.m_invMass * g.m_force.y), g.m_angularVelocity += b.dt * g.m_invI * g.m_torque, g.m_linearVelocity.Multiply(a.Clamp(1 - b.dt * g.m_linearDamping, 0, 1)), g.m_angularVelocity *= a.Clamp(1 - b.dt * g.m_angularDamping, 0, 1));
  4154. this.m_contactSolver.Initialize(b, this.m_contacts, this.m_contactCount, this.m_allocator);
  4155. c = this.m_contactSolver;
  4156. c.InitVelocityConstraints(b);
  4157. for (e = 0; e < this.m_jointCount; ++e) h = this.m_joints[e], h.InitVelocityConstraints(b);
  4158. for (e = 0; e < b.velocityIterations; ++e) {
  4159. for (g = 0; g < this.m_jointCount; ++g) h = this.m_joints[g],
  4160. h.SolveVelocityConstraints(b);
  4161. c.SolveVelocityConstraints()
  4162. }
  4163. for (e = 0; e < this.m_jointCount; ++e) h = this.m_joints[e], h.FinalizeVelocityConstraints();
  4164. c.FinalizeVelocityConstraints();
  4165. for (e = 0; e < this.m_bodyCount; ++e)
  4166. if (g = this.m_bodies[e], g.GetType() != H.b2_staticBody) {
  4167. var l = b.dt * g.m_linearVelocity.x,
  4168. m = b.dt * g.m_linearVelocity.y;
  4169. l * l + m * m > f.b2_maxTranslationSquared && (g.m_linearVelocity.Normalize(), g.m_linearVelocity.x = g.m_linearVelocity.x * f.b2_maxTranslation * b.inv_dt, g.m_linearVelocity.y = g.m_linearVelocity.y * f.b2_maxTranslation *
  4170. b.inv_dt);
  4171. l = b.dt * g.m_angularVelocity;
  4172. l * l > f.b2_maxRotationSquared && (g.m_angularVelocity = 0 > g.m_angularVelocity ? -f.b2_maxRotation * b.inv_dt : f.b2_maxRotation * b.inv_dt);
  4173. g.m_sweep.c0.SetV(g.m_sweep.c);
  4174. g.m_sweep.a0 = g.m_sweep.a;
  4175. g.m_sweep.c.x += b.dt * g.m_linearVelocity.x;
  4176. g.m_sweep.c.y += b.dt * g.m_linearVelocity.y;
  4177. g.m_sweep.a += b.dt * g.m_angularVelocity;
  4178. g.SynchronizeTransform()
  4179. }
  4180. for (e = 0; e < b.positionIterations; ++e) {
  4181. l = c.SolvePositionConstraints(f.b2_contactBaumgarte);
  4182. m = !0;
  4183. for (g = 0; g < this.m_jointCount; ++g) h = this.m_joints[g],
  4184. h = h.SolvePositionConstraints(f.b2_contactBaumgarte), m = m && h;
  4185. if (l && m) break
  4186. }
  4187. this.Report(c.m_constraints);
  4188. if (d) {
  4189. d = Number.MAX_VALUE;
  4190. c = f.b2_linearSleepTolerance * f.b2_linearSleepTolerance;
  4191. l = f.b2_angularSleepTolerance * f.b2_angularSleepTolerance;
  4192. for (e = 0; e < this.m_bodyCount; ++e) g = this.m_bodies[e], g.GetType() != H.b2_staticBody && (0 == (g.m_flags & H.e_allowSleepFlag) && (d = g.m_sleepTime = 0), 0 == (g.m_flags & H.e_allowSleepFlag) || g.m_angularVelocity * g.m_angularVelocity > l || a.Dot(g.m_linearVelocity, g.m_linearVelocity) > c ? d = g.m_sleepTime =
  4193. 0 : (g.m_sleepTime += b.dt, d = a.Min(d, g.m_sleepTime)));
  4194. if (d >= f.b2_timeToSleep)
  4195. for (e = 0; e < this.m_bodyCount; ++e) g = this.m_bodies[e], g.SetAwake(!1)
  4196. }
  4197. };
  4198. jc.prototype.SolveTOI = function(a) {
  4199. var b, c;
  4200. this.m_contactSolver.Initialize(a, this.m_contacts, this.m_contactCount, this.m_allocator);
  4201. var d = this.m_contactSolver;
  4202. for (b = 0; b < this.m_jointCount; ++b) this.m_joints[b].InitVelocityConstraints(a);
  4203. for (b = 0; b < a.velocityIterations; ++b)
  4204. for (d.SolveVelocityConstraints(), c = 0; c < this.m_jointCount; ++c) this.m_joints[c].SolveVelocityConstraints(a);
  4205. for (b = 0; b < this.m_bodyCount; ++b)
  4206. if (c = this.m_bodies[b], c.GetType() != H.b2_staticBody) {
  4207. var e = a.dt * c.m_linearVelocity.x,
  4208. g = a.dt * c.m_linearVelocity.y;
  4209. e * e + g * g > f.b2_maxTranslationSquared && (c.m_linearVelocity.Normalize(), c.m_linearVelocity.x = c.m_linearVelocity.x * f.b2_maxTranslation * a.inv_dt, c.m_linearVelocity.y = c.m_linearVelocity.y * f.b2_maxTranslation * a.inv_dt);
  4210. e = a.dt * c.m_angularVelocity;
  4211. e * e > f.b2_maxRotationSquared && (c.m_angularVelocity = 0 > c.m_angularVelocity ? -f.b2_maxRotation * a.inv_dt : f.b2_maxRotation * a.inv_dt);
  4212. c.m_sweep.c0.SetV(c.m_sweep.c);
  4213. c.m_sweep.a0 = c.m_sweep.a;
  4214. c.m_sweep.c.x += a.dt * c.m_linearVelocity.x;
  4215. c.m_sweep.c.y += a.dt * c.m_linearVelocity.y;
  4216. c.m_sweep.a += a.dt * c.m_angularVelocity;
  4217. c.SynchronizeTransform()
  4218. }
  4219. for (b = 0; b < a.positionIterations; ++b) {
  4220. e = d.SolvePositionConstraints(.75);
  4221. g = !0;
  4222. for (c = 0; c < this.m_jointCount; ++c) var h = this.m_joints[c].SolvePositionConstraints(f.b2_contactBaumgarte),
  4223. g = g && h;
  4224. if (e && g) break
  4225. }
  4226. this.Report(d.m_constraints)
  4227. };
  4228. jc.prototype.Report = function(a) {
  4229. if (null != this.m_listener)
  4230. for (var b = 0; b <
  4231. this.m_contactCount; ++b) {
  4232. for (var c = this.m_contacts[b], d = a[b], e = 0; e < d.pointCount; ++e) jc.s_impulse.normalImpulses[e] = d.points[e].normalImpulse, jc.s_impulse.tangentImpulses[e] = d.points[e].tangentImpulse;
  4233. this.m_listener.PostSolve(c, jc.s_impulse)
  4234. }
  4235. };
  4236. jc.prototype.AddBody = function(a) {
  4237. a.m_islandIndex = this.m_bodyCount;
  4238. this.m_bodies[this.m_bodyCount++] = a
  4239. };
  4240. jc.prototype.AddContact = function(a) {
  4241. this.m_contacts[this.m_contactCount++] = a
  4242. };
  4243. jc.prototype.AddJoint = function(a) {
  4244. this.m_joints[this.m_jointCount++] = a
  4245. };
  4246. Box2D.postDefs.push(function() {
  4247. Box2D.Dynamics.b2Island.s_impulse =
  4248. new Xb
  4249. });
  4250. cc.b2TimeStep = function() {};
  4251. cc.prototype.Set = function(a) {
  4252. this.dt = a.dt;
  4253. this.inv_dt = a.inv_dt;
  4254. this.positionIterations = a.positionIterations;
  4255. this.velocityIterations = a.velocityIterations;
  4256. this.warmStarting = a.warmStarting
  4257. };
  4258. dc.b2World = function() {
  4259. this.s_stack = new Vector;
  4260. this.m_contactManager = new aa;
  4261. this.m_contactSolver = new fc;
  4262. this.m_island = new jc
  4263. };
  4264. dc.prototype.b2World = function(a, b) {
  4265. this.m_controllerList = this.m_jointList = this.m_contactList = this.m_bodyList = this.m_debugDraw = this.m_destructionListener =
  4266. null;
  4267. this.m_controllerCount = this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0;
  4268. dc.m_warmStarting = !0;
  4269. dc.m_continuousPhysics = !0;
  4270. this.m_allowSleep = b;
  4271. this.m_gravity = a;
  4272. this.m_inv_dt0 = 0;
  4273. this.m_contactManager.m_world = this;
  4274. this.m_groundBody = this.CreateBody(new E)
  4275. };
  4276. dc.prototype.SetDestructionListener = function(a) {
  4277. this.m_destructionListener = a
  4278. };
  4279. dc.prototype.SetContactFilter = function(a) {
  4280. this.m_contactManager.m_contactFilter = a
  4281. };
  4282. dc.prototype.SetContactListener = function(a) {
  4283. this.m_contactManager.m_contactListener =
  4284. a
  4285. };
  4286. dc.prototype.SetDebugDraw = function(a) {
  4287. this.m_debugDraw = a
  4288. };
  4289. dc.prototype.SetBroadPhase = function(a) {
  4290. var b = this.m_contactManager.m_broadPhase;
  4291. this.m_contactManager.m_broadPhase = a;
  4292. for (var c = this.m_bodyList; c; c = c.m_next)
  4293. for (var d = c.m_fixtureList; d; d = d.m_next) d.m_proxy = a.CreateProxy(b.GetFatAABB(d.m_proxy), d)
  4294. };
  4295. dc.prototype.Validate = function() {
  4296. this.m_contactManager.m_broadPhase.Validate()
  4297. };
  4298. dc.prototype.GetProxyCount = function() {
  4299. return this.m_contactManager.m_broadPhase.GetProxyCount()
  4300. };
  4301. dc.prototype.CreateBody =
  4302. function(a) {
  4303. if (1 == this.IsLocked()) return null;
  4304. a = new H(a, this);
  4305. a.m_prev = null;
  4306. if (a.m_next = this.m_bodyList) this.m_bodyList.m_prev = a;
  4307. this.m_bodyList = a;
  4308. ++this.m_bodyCount;
  4309. return a
  4310. };
  4311. dc.prototype.DestroyBody = function(a) {
  4312. if (1 != this.IsLocked()) {
  4313. for (var b = a.m_jointList; b;) {
  4314. var c = b,
  4315. b = b.next;
  4316. this.m_destructionListener && this.m_destructionListener.SayGoodbyeJoint(c.joint);
  4317. this.DestroyJoint(c.joint)
  4318. }
  4319. for (b = a.m_controllerList; b;) c = b, b = b.nextController, c.controller.RemoveBody(a);
  4320. for (b = a.m_contactList; b;) c = b, b = b.next,
  4321. this.m_contactManager.Destroy(c.contact);
  4322. a.m_contactList = null;
  4323. for (b = a.m_fixtureList; b;) c = b, b = b.m_next, this.m_destructionListener && this.m_destructionListener.SayGoodbyeFixture(c), c.DestroyProxy(this.m_contactManager.m_broadPhase), c.Destroy();
  4324. a.m_fixtureList = null;
  4325. a.m_fixtureCount = 0;
  4326. a.m_prev && (a.m_prev.m_next = a.m_next);
  4327. a.m_next && (a.m_next.m_prev = a.m_prev);
  4328. a == this.m_bodyList && (this.m_bodyList = a.m_next);
  4329. --this.m_bodyCount
  4330. }
  4331. };
  4332. dc.prototype.CreateJoint = function(a) {
  4333. var b = kc.Create(a, null);
  4334. b.m_prev = null;
  4335. if (b.m_next =
  4336. this.m_jointList) this.m_jointList.m_prev = b;
  4337. this.m_jointList = b;
  4338. ++this.m_jointCount;
  4339. b.m_edgeA.joint = b;
  4340. b.m_edgeA.other = b.m_bodyB;
  4341. b.m_edgeA.prev = null;
  4342. if (b.m_edgeA.next = b.m_bodyA.m_jointList) b.m_bodyA.m_jointList.prev = b.m_edgeA;
  4343. b.m_bodyA.m_jointList = b.m_edgeA;
  4344. b.m_edgeB.joint = b;
  4345. b.m_edgeB.other = b.m_bodyA;
  4346. b.m_edgeB.prev = null;
  4347. if (b.m_edgeB.next = b.m_bodyB.m_jointList) b.m_bodyB.m_jointList.prev = b.m_edgeB;
  4348. b.m_bodyB.m_jointList = b.m_edgeB;
  4349. var c = a.bodyA,
  4350. d = a.bodyB;
  4351. if (0 == a.collideConnected)
  4352. for (a = d.GetContactList(); a;) a.other ==
  4353. c && a.contact.FlagForFiltering(), a = a.next;
  4354. return b
  4355. };
  4356. dc.prototype.DestroyJoint = function(a) {
  4357. var b = a.m_collideConnected;
  4358. a.m_prev && (a.m_prev.m_next = a.m_next);
  4359. a.m_next && (a.m_next.m_prev = a.m_prev);
  4360. a == this.m_jointList && (this.m_jointList = a.m_next);
  4361. var c = a.m_bodyA,
  4362. d = a.m_bodyB;
  4363. c.SetAwake(!0);
  4364. d.SetAwake(!0);
  4365. a.m_edgeA.prev && (a.m_edgeA.prev.next = a.m_edgeA.next);
  4366. a.m_edgeA.next && (a.m_edgeA.next.prev = a.m_edgeA.prev);
  4367. a.m_edgeA == c.m_jointList && (c.m_jointList = a.m_edgeA.next);
  4368. a.m_edgeA.prev = null;
  4369. a.m_edgeA.next = null;
  4370. a.m_edgeB.prev &&
  4371. (a.m_edgeB.prev.next = a.m_edgeB.next);
  4372. a.m_edgeB.next && (a.m_edgeB.next.prev = a.m_edgeB.prev);
  4373. a.m_edgeB == d.m_jointList && (d.m_jointList = a.m_edgeB.next);
  4374. a.m_edgeB.prev = null;
  4375. a.m_edgeB.next = null;
  4376. kc.Destroy(a, null);
  4377. --this.m_jointCount;
  4378. if (0 == b)
  4379. for (a = d.GetContactList(); a;) a.other == c && a.contact.FlagForFiltering(), a = a.next
  4380. };
  4381. dc.prototype.AddController = function(a) {
  4382. a.m_next = this.m_controllerList;
  4383. a.m_prev = null;
  4384. this.m_controllerList = a;
  4385. a.m_world = this;
  4386. this.m_controllerCount++;
  4387. return a
  4388. };
  4389. dc.prototype.RemoveController =
  4390. function(a) {
  4391. a.m_prev && (a.m_prev.m_next = a.m_next);
  4392. a.m_next && (a.m_next.m_prev = a.m_prev);
  4393. this.m_controllerList == a && (this.m_controllerList = a.m_next);
  4394. this.m_controllerCount--
  4395. };
  4396. dc.prototype.CreateController = function(a) {
  4397. if (a.m_world != this) throw Error("Controller can only be a member of one world");
  4398. a.m_next = this.m_controllerList;
  4399. a.m_prev = null;
  4400. this.m_controllerList && (this.m_controllerList.m_prev = a);
  4401. this.m_controllerList = a;
  4402. ++this.m_controllerCount;
  4403. a.m_world = this;
  4404. return a
  4405. };
  4406. dc.prototype.DestroyController = function(a) {
  4407. a.Clear();
  4408. a.m_next && (a.m_next.m_prev = a.m_prev);
  4409. a.m_prev && (a.m_prev.m_next = a.m_next);
  4410. a == this.m_controllerList && (this.m_controllerList = a.m_next);
  4411. --this.m_controllerCount
  4412. };
  4413. dc.prototype.SetWarmStarting = function(a) {
  4414. dc.m_warmStarting = a
  4415. };
  4416. dc.prototype.SetContinuousPhysics = function(a) {
  4417. dc.m_continuousPhysics = a
  4418. };
  4419. dc.prototype.GetBodyCount = function() {
  4420. return this.m_bodyCount
  4421. };
  4422. dc.prototype.GetJointCount = function() {
  4423. return this.m_jointCount
  4424. };
  4425. dc.prototype.GetContactCount = function() {
  4426. return this.m_contactCount
  4427. };
  4428. dc.prototype.SetGravity =
  4429. function(a) {
  4430. this.m_gravity = a
  4431. };
  4432. dc.prototype.GetGravity = function() {
  4433. return this.m_gravity
  4434. };
  4435. dc.prototype.GetGroundBody = function() {
  4436. return this.m_groundBody
  4437. };
  4438. dc.prototype.Step = function(a, b, c) {
  4439. void 0 === a && (a = 0);
  4440. void 0 === b && (b = 0);
  4441. void 0 === c && (c = 0);
  4442. this.m_flags & dc.e_newFixture && (this.m_contactManager.FindNewContacts(), this.m_flags &= ~dc.e_newFixture);
  4443. this.m_flags |= dc.e_locked;
  4444. var d = dc.s_timestep2;
  4445. d.dt = a;
  4446. d.velocityIterations = b;
  4447. d.positionIterations = c;
  4448. d.inv_dt = 0 < a ? 1 / a : 0;
  4449. d.dtRatio = this.m_inv_dt0 * a;
  4450. d.warmStarting =
  4451. dc.m_warmStarting;
  4452. this.m_contactManager.Collide();
  4453. 0 < d.dt && this.Solve(d);
  4454. dc.m_continuousPhysics && 0 < d.dt && this.SolveTOI(d);
  4455. 0 < d.dt && (this.m_inv_dt0 = d.inv_dt);
  4456. this.m_flags &= ~dc.e_locked
  4457. };
  4458. dc.prototype.ClearForces = function() {
  4459. for (var a = this.m_bodyList; a; a = a.m_next) a.m_force.SetZero(), a.m_torque = 0
  4460. };
  4461. dc.prototype.DrawDebugData = function() {
  4462. if (null != this.m_debugDraw) {
  4463. this.m_debugDraw.m_sprite.graphics.clear();
  4464. var a = this.m_debugDraw.GetFlags(),
  4465. b, c, f;
  4466. new d;
  4467. new d;
  4468. new d;
  4469. var h;
  4470. new g;
  4471. new g;
  4472. new d;
  4473. new d;
  4474. new d;
  4475. new d;
  4476. var l =
  4477. new e(0, 0, 0);
  4478. if (a & Yb.e_shapeBit)
  4479. for (b = this.m_bodyList; b; b = b.m_next)
  4480. for (h = b.m_xf, c = b.GetFixtureList(); c; c = c.m_next) f = c.GetShape(), 0 == b.IsActive() ? l.Set(.5, .5, .3) : b.GetType() == H.b2_staticBody ? l.Set(.5, .9, .5) : b.GetType() == H.b2_kinematicBody ? l.Set(.5, .5, .9) : 0 == b.IsAwake() ? l.Set(.6, .6, .6) : l.Set(.9, .7, .7), this.DrawShape(f, h, l);
  4481. if (a & Yb.e_jointBit)
  4482. for (b = this.m_jointList; b; b = b.m_next) this.DrawJoint(b);
  4483. if (a & Yb.e_controllerBit)
  4484. for (b = this.m_controllerList; b; b = b.m_next) b.Draw(this.m_debugDraw);
  4485. if (a & Yb.e_pairBit)
  4486. for (l.Set(.3,
  4487. .9, .9), b = this.m_contactManager.m_contactList; b; b = b.GetNext()) f = b.GetFixtureA(), c = b.GetFixtureB(), f = f.GetAABB().GetCenter(), c = c.GetAABB().GetCenter(), this.m_debugDraw.DrawSegment(f, c, l);
  4488. if (a & Yb.e_aabbBit)
  4489. for (f = this.m_contactManager.m_broadPhase, h = [new d, new d, new d, new d], b = this.m_bodyList; b; b = b.GetNext())
  4490. if (0 != b.IsActive())
  4491. for (c = b.GetFixtureList(); c; c = c.GetNext()) {
  4492. var m = f.GetFatAABB(c.m_proxy);
  4493. h[0].Set(m.lowerBound.x, m.lowerBound.y);
  4494. h[1].Set(m.upperBound.x, m.lowerBound.y);
  4495. h[2].Set(m.upperBound.x,
  4496. m.upperBound.y);
  4497. h[3].Set(m.lowerBound.x, m.upperBound.y);
  4498. this.m_debugDraw.DrawPolygon(h, 4, l)
  4499. }
  4500. if (a & Yb.e_centerOfMassBit)
  4501. for (b = this.m_bodyList; b; b = b.m_next) h = dc.s_xf, h.R = b.m_xf.R, h.position = b.GetWorldCenter(), this.m_debugDraw.DrawTransform(h)
  4502. }
  4503. };
  4504. dc.prototype.QueryAABB = function(a, b) {
  4505. var c = this.m_contactManager.m_broadPhase;
  4506. c.Query(function(b) {
  4507. return a(c.GetUserData(b))
  4508. }, b)
  4509. };
  4510. dc.prototype.QueryShape = function(a, c, d) {
  4511. void 0 === d && (d = null);
  4512. null == d && (d = new b, d.SetIdentity());
  4513. var e = this.m_contactManager.m_broadPhase,
  4514. f = new g;
  4515. c.ComputeAABB(f, d);
  4516. e.Query(function(b) {
  4517. b = e.GetUserData(b) instanceof bc ? e.GetUserData(b) : null;
  4518. return K.TestOverlap(c, d, b.GetShape(), b.GetBody().GetTransform()) ? a(b) : !0
  4519. }, f)
  4520. };
  4521. dc.prototype.QueryPoint = function(a, b) {
  4522. var c = this.m_contactManager.m_broadPhase,
  4523. d = new g;
  4524. d.lowerBound.Set(b.x - f.b2_linearSlop, b.y - f.b2_linearSlop);
  4525. d.upperBound.Set(b.x + f.b2_linearSlop, b.y + f.b2_linearSlop);
  4526. c.Query(function(d) {
  4527. d = c.GetUserData(d) instanceof bc ? c.GetUserData(d) : null;
  4528. return d.TestPoint(b) ? a(d) : !0
  4529. }, d)
  4530. };
  4531. dc.prototype.RayCast =
  4532. function(a, b, c) {
  4533. var e = this.m_contactManager.m_broadPhase,
  4534. f = new q,
  4535. g = new m(b, c);
  4536. e.RayCast(function(g, h) {
  4537. var l = e.GetUserData(h),
  4538. l = l instanceof bc ? l : null;
  4539. if (l.RayCast(f, g)) {
  4540. var m = f.fraction,
  4541. p = new d((1 - m) * b.x + m * c.x, (1 - m) * b.y + m * c.y);
  4542. return a(l, p, f.normal, m)
  4543. }
  4544. return g.maxFraction
  4545. }, g)
  4546. };
  4547. dc.prototype.RayCastOne = function(a, b) {
  4548. var c;
  4549. this.RayCast(function(a, b, d, e) {
  4550. void 0 === e && (e = 0);
  4551. c = a;
  4552. return e
  4553. }, a, b);
  4554. return c
  4555. };
  4556. dc.prototype.RayCastAll = function(a, b) {
  4557. var c = new Vector;
  4558. this.RayCast(function(a) {
  4559. c[c.length] = a;
  4560. return 1
  4561. },
  4562. a, b);
  4563. return c
  4564. };
  4565. dc.prototype.GetBodyList = function() {
  4566. return this.m_bodyList
  4567. };
  4568. dc.prototype.GetJointList = function() {
  4569. return this.m_jointList
  4570. };
  4571. dc.prototype.GetContactList = function() {
  4572. return this.m_contactList
  4573. };
  4574. dc.prototype.IsLocked = function() {
  4575. return 0 < (this.m_flags & dc.e_locked)
  4576. };
  4577. dc.prototype.Solve = function(a) {
  4578. for (var b, c = this.m_controllerList; c; c = c.m_next) c.Step(a);
  4579. c = this.m_island;
  4580. c.Initialize(this.m_bodyCount, this.m_contactCount, this.m_jointCount, null, this.m_contactManager.m_contactListener, this.m_contactSolver);
  4581. for (b = this.m_bodyList; b; b = b.m_next) b.m_flags &= ~H.e_islandFlag;
  4582. for (var d = this.m_contactList; d; d = d.m_next) d.m_flags &= ~gc.e_islandFlag;
  4583. for (d = this.m_jointList; d; d = d.m_next) d.m_islandFlag = !1;
  4584. parseInt(this.m_bodyCount);
  4585. for (var d = this.s_stack, e = this.m_bodyList; e; e = e.m_next)
  4586. if (!(e.m_flags & H.e_islandFlag) && 0 != e.IsAwake() && 0 != e.IsActive() && e.GetType() != H.b2_staticBody) {
  4587. c.Clear();
  4588. var f = 0;
  4589. d[f++] = e;
  4590. for (e.m_flags |= H.e_islandFlag; 0 < f;)
  4591. if (b = d[--f], c.AddBody(b), 0 == b.IsAwake() && b.SetAwake(!0), b.GetType() != H.b2_staticBody) {
  4592. for (var g,
  4593. h = b.m_contactList; h; h = h.next) h.contact.m_flags & gc.e_islandFlag || 1 == h.contact.IsSensor() || 0 == h.contact.IsEnabled() || 0 == h.contact.IsTouching() || (c.AddContact(h.contact), h.contact.m_flags |= gc.e_islandFlag, g = h.other, g.m_flags & H.e_islandFlag || (d[f++] = g, g.m_flags |= H.e_islandFlag));
  4594. for (b = b.m_jointList; b; b = b.next) 1 != b.joint.m_islandFlag && (g = b.other, 0 != g.IsActive() && (c.AddJoint(b.joint), b.joint.m_islandFlag = !0, g.m_flags & H.e_islandFlag || (d[f++] = g, g.m_flags |= H.e_islandFlag)))
  4595. }
  4596. c.Solve(a, this.m_gravity, this.m_allowSleep);
  4597. for (f = 0; f < c.m_bodyCount; ++f) b = c.m_bodies[f], b.GetType() == H.b2_staticBody && (b.m_flags &= ~H.e_islandFlag)
  4598. }
  4599. for (f = 0; f < d.length && d[f]; ++f) d[f] = null;
  4600. for (b = this.m_bodyList; b; b = b.m_next) 0 == b.IsAwake() || 0 == b.IsActive() || b.GetType() != H.b2_staticBody && b.SynchronizeFixtures();
  4601. this.m_contactManager.FindNewContacts()
  4602. };
  4603. dc.prototype.SolveTOI = function(a) {
  4604. var b, c, d, e = this.m_island;
  4605. e.Initialize(this.m_bodyCount, f.b2_maxTOIContactsPerIsland, f.b2_maxTOIJointsPerIsland, null, this.m_contactManager.m_contactListener, this.m_contactSolver);
  4606. var g = dc.s_queue;
  4607. for (b = this.m_bodyList; b; b = b.m_next) b.m_flags &= ~H.e_islandFlag, b.m_sweep.t0 = 0;
  4608. for (d = this.m_contactList; d; d = d.m_next) d.m_flags &= ~(gc.e_toiFlag | gc.e_islandFlag);
  4609. for (d = this.m_jointList; d; d = d.m_next) d.m_islandFlag = !1;
  4610. for (;;) {
  4611. var h = null,
  4612. l = 1;
  4613. for (d = this.m_contactList; d; d = d.m_next)
  4614. if (1 != d.IsSensor() && 0 != d.IsEnabled() && 0 != d.IsContinuous()) {
  4615. if (d.m_flags & gc.e_toiFlag) b = d.m_toi;
  4616. else {
  4617. b = d.m_fixtureA;
  4618. c = d.m_fixtureB;
  4619. b = b.m_body;
  4620. c = c.m_body;
  4621. if (!(b.GetType() == H.b2_dynamicBody && 0 != b.IsAwake() || c.GetType() ==
  4622. H.b2_dynamicBody && 0 != c.IsAwake())) continue;
  4623. var m = b.m_sweep.t0;
  4624. b.m_sweep.t0 < c.m_sweep.t0 ? (m = c.m_sweep.t0, b.m_sweep.Advance(m)) : c.m_sweep.t0 < b.m_sweep.t0 && (m = b.m_sweep.t0, c.m_sweep.Advance(m));
  4625. b = d.ComputeTOI(b.m_sweep, c.m_sweep);
  4626. f.b2Assert(0 <= b && 1 >= b);
  4627. 0 < b && 1 > b && (b = (1 - b) * m + b, 1 < b && (b = 1));
  4628. d.m_toi = b;
  4629. d.m_flags |= gc.e_toiFlag
  4630. }
  4631. Number.MIN_VALUE < b && b < l && (h = d, l = b)
  4632. }
  4633. if (null == h || 1 - 100 * Number.MIN_VALUE < l) break;
  4634. b = h.m_fixtureA;
  4635. c = h.m_fixtureB;
  4636. b = b.m_body;
  4637. c = c.m_body;
  4638. dc.s_backupA.Set(b.m_sweep);
  4639. dc.s_backupB.Set(c.m_sweep);
  4640. b.Advance(l);
  4641. c.Advance(l);
  4642. h.Update(this.m_contactManager.m_contactListener);
  4643. h.m_flags &= ~gc.e_toiFlag;
  4644. if (1 == h.IsSensor() || 0 == h.IsEnabled()) b.m_sweep.Set(dc.s_backupA), c.m_sweep.Set(dc.s_backupB), b.SynchronizeTransform(), c.SynchronizeTransform();
  4645. else if (0 != h.IsTouching()) {
  4646. b.GetType() != H.b2_dynamicBody && (b = c);
  4647. e.Clear();
  4648. h = d = 0;
  4649. g[d + h++] = b;
  4650. for (b.m_flags |= H.e_islandFlag; 0 < h;)
  4651. if (b = g[d++], --h, e.AddBody(b), 0 == b.IsAwake() && b.SetAwake(!0), b.GetType() == H.b2_dynamicBody) {
  4652. for (c = b.m_contactList; c && e.m_contactCount !=
  4653. e.m_contactCapacity; c = c.next) c.contact.m_flags & gc.e_islandFlag || 1 == c.contact.IsSensor() || 0 == c.contact.IsEnabled() || 0 == c.contact.IsTouching() || (e.AddContact(c.contact), c.contact.m_flags |= gc.e_islandFlag, m = c.other, m.m_flags & H.e_islandFlag || (m.GetType() != H.b2_staticBody && (m.Advance(l), m.SetAwake(!0)), g[d + h] = m, ++h, m.m_flags |= H.e_islandFlag));
  4654. for (b = b.m_jointList; b; b = b.next) e.m_jointCount != e.m_jointCapacity && 1 != b.joint.m_islandFlag && (m = b.other, 0 != m.IsActive() && (e.AddJoint(b.joint), b.joint.m_islandFlag = !0, m.m_flags & H.e_islandFlag || (m.GetType() != H.b2_staticBody && (m.Advance(l), m.SetAwake(!0)), g[d + h] = m, ++h, m.m_flags |= H.e_islandFlag)))
  4655. }
  4656. d = dc.s_timestep;
  4657. d.warmStarting = !1;
  4658. d.dt = (1 - l) * a.dt;
  4659. d.inv_dt = 1 / d.dt;
  4660. d.dtRatio = 0;
  4661. d.velocityIterations = a.velocityIterations;
  4662. d.positionIterations = a.positionIterations;
  4663. e.SolveTOI(d);
  4664. for (l = l = 0; l < e.m_bodyCount; ++l)
  4665. if (b = e.m_bodies[l], b.m_flags &= ~H.e_islandFlag, 0 != b.IsAwake() && b.GetType() == H.b2_dynamicBody)
  4666. for (b.SynchronizeFixtures(), c = b.m_contactList; c; c = c.next) c.contact.m_flags &=
  4667. ~gc.e_toiFlag;
  4668. for (l = 0; l < e.m_contactCount; ++l) d = e.m_contacts[l], d.m_flags &= ~(gc.e_toiFlag | gc.e_islandFlag);
  4669. for (l = 0; l < e.m_jointCount; ++l) d = e.m_joints[l], d.m_islandFlag = !1;
  4670. this.m_contactManager.FindNewContacts()
  4671. }
  4672. }
  4673. };
  4674. dc.prototype.DrawJoint = function(a) {
  4675. var b = a.GetBodyA(),
  4676. c = a.GetBodyB(),
  4677. d = b.m_xf.position,
  4678. e = c.m_xf.position,
  4679. f = a.GetAnchorA(),
  4680. g = a.GetAnchorB(),
  4681. h = dc.s_jointColor;
  4682. switch (a.m_type) {
  4683. case kc.e_distanceJoint:
  4684. this.m_debugDraw.DrawSegment(f, g, h);
  4685. break;
  4686. case kc.e_pulleyJoint:
  4687. b = a instanceof lc ? a : null;
  4688. a =
  4689. b.GetGroundAnchorA();
  4690. b = b.GetGroundAnchorB();
  4691. this.m_debugDraw.DrawSegment(a, f, h);
  4692. this.m_debugDraw.DrawSegment(b, g, h);
  4693. this.m_debugDraw.DrawSegment(a, b, h);
  4694. break;
  4695. case kc.e_mouseJoint:
  4696. this.m_debugDraw.DrawSegment(f, g, h);
  4697. break;
  4698. default:
  4699. b != this.m_groundBody && this.m_debugDraw.DrawSegment(d, f, h), this.m_debugDraw.DrawSegment(f, g, h), c != this.m_groundBody && this.m_debugDraw.DrawSegment(e, g, h)
  4700. }
  4701. };
  4702. dc.prototype.DrawShape = function(b, c, d) {
  4703. switch (b.m_type) {
  4704. case K.e_circleShape:
  4705. var e = b instanceof p ? b : null;
  4706. this.m_debugDraw.DrawSolidCircle(a.MulX(c,
  4707. e.m_p), e.m_radius, c.R.col1, d);
  4708. break;
  4709. case K.e_polygonShape:
  4710. e = b instanceof B ? b : null;
  4711. b = parseInt(e.GetVertexCount());
  4712. for (var f = e.GetVertices(), g = new Vector(b), e = 0; e < b; ++e) g[e] = a.MulX(c, f[e]);
  4713. this.m_debugDraw.DrawSolidPolygon(g, b, d);
  4714. break;
  4715. case K.e_edgeShape:
  4716. e = b instanceof y ? b : null, this.m_debugDraw.DrawSegment(a.MulX(c, e.GetVertex1()), a.MulX(c, e.GetVertex2()), d)
  4717. }
  4718. };
  4719. Box2D.postDefs.push(function() {
  4720. Box2D.Dynamics.b2World.s_timestep2 = new cc;
  4721. Box2D.Dynamics.b2World.s_xf = new b;
  4722. Box2D.Dynamics.b2World.s_backupA =
  4723. new c;
  4724. Box2D.Dynamics.b2World.s_backupB = new c;
  4725. Box2D.Dynamics.b2World.s_timestep = new cc;
  4726. Box2D.Dynamics.b2World.s_queue = new Vector;
  4727. Box2D.Dynamics.b2World.s_jointColor = new e(.5, .8, .8);
  4728. Box2D.Dynamics.b2World.e_newFixture = 1;
  4729. Box2D.Dynamics.b2World.e_locked = 2
  4730. })
  4731. })();
  4732. (function() {
  4733. var a = Box2D.Collision.Shapes.b2CircleShape,
  4734. c = Box2D.Collision.Shapes.b2EdgeShape,
  4735. b = Box2D.Collision.Shapes.b2PolygonShape,
  4736. d = Box2D.Collision.Shapes.b2Shape,
  4737. e = Box2D.Dynamics.Contacts.b2CircleContact,
  4738. f = Box2D.Dynamics.Contacts.b2Contact,
  4739. g = Box2D.Dynamics.Contacts.b2ContactConstraint,
  4740. h = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,
  4741. l = Box2D.Dynamics.Contacts.b2ContactEdge,
  4742. m = Box2D.Dynamics.Contacts.b2ContactFactory,
  4743. q = Box2D.Dynamics.Contacts.b2ContactRegister,
  4744. p = Box2D.Dynamics.Contacts.b2ContactResult,
  4745. y = Box2D.Dynamics.Contacts.b2ContactSolver,
  4746. A = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,
  4747. B = Box2D.Dynamics.Contacts.b2NullContact,
  4748. K = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,
  4749. H = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,
  4750. E = Box2D.Dynamics.Contacts.b2PolygonContact,
  4751. M = Box2D.Dynamics.Contacts.b2PositionSolverManifold,
  4752. Xb = Box2D.Dynamics.b2Body,
  4753. Zb = Box2D.Dynamics.b2TimeStep,
  4754. aa = Box2D.Common.b2Settings,
  4755. Yb = Box2D.Common.Math.b2Mat22,
  4756. $b = Box2D.Common.Math.b2Math,
  4757. ac = Box2D.Common.Math.b2Vec2,
  4758. bc = Box2D.Collision.b2Collision,
  4759. ec = Box2D.Collision.b2ContactID,
  4760. jc = Box2D.Collision.b2Manifold,
  4761. cc = Box2D.Collision.b2TimeOfImpact,
  4762. dc = Box2D.Collision.b2TOIInput,
  4763. gc = Box2D.Collision.b2WorldManifold;
  4764. Box2D.inherit(e, Box2D.Dynamics.Contacts.b2Contact);
  4765. e.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  4766. e.b2CircleContact = function() {
  4767. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  4768. };
  4769. e.Create = function() {
  4770. return new e
  4771. };
  4772. e.Destroy = function() {};
  4773. e.prototype.Reset = function(a, b) {
  4774. this.__super.Reset.call(this, a, b)
  4775. };
  4776. e.prototype.Evaluate =
  4777. function() {
  4778. var b = this.m_fixtureA.GetBody(),
  4779. c = this.m_fixtureB.GetBody();
  4780. bc.CollideCircles(this.m_manifold, this.m_fixtureA.GetShape() instanceof a ? this.m_fixtureA.GetShape() : null, b.m_xf, this.m_fixtureB.GetShape() instanceof a ? this.m_fixtureB.GetShape() : null, c.m_xf)
  4781. };
  4782. f.b2Contact = function() {
  4783. this.m_nodeA = new l;
  4784. this.m_nodeB = new l;
  4785. this.m_manifold = new jc;
  4786. this.m_oldManifold = new jc
  4787. };
  4788. f.prototype.GetManifold = function() {
  4789. return this.m_manifold
  4790. };
  4791. f.prototype.GetWorldManifold = function(a) {
  4792. var b = this.m_fixtureA.GetBody(),
  4793. c = this.m_fixtureB.GetBody(),
  4794. d = this.m_fixtureA.GetShape(),
  4795. e = this.m_fixtureB.GetShape();
  4796. a.Initialize(this.m_manifold, b.GetTransform(), d.m_radius, c.GetTransform(), e.m_radius)
  4797. };
  4798. f.prototype.IsTouching = function() {
  4799. return (this.m_flags & f.e_touchingFlag) == f.e_touchingFlag
  4800. };
  4801. f.prototype.IsContinuous = function() {
  4802. return (this.m_flags & f.e_continuousFlag) == f.e_continuousFlag
  4803. };
  4804. f.prototype.SetSensor = function(a) {
  4805. this.m_flags = a ? this.m_flags | f.e_sensorFlag : this.m_flags & ~f.e_sensorFlag
  4806. };
  4807. f.prototype.IsSensor = function() {
  4808. return (this.m_flags &
  4809. f.e_sensorFlag) == f.e_sensorFlag
  4810. };
  4811. f.prototype.SetEnabled = function(a) {
  4812. this.m_flags = a ? this.m_flags | f.e_enabledFlag : this.m_flags & ~f.e_enabledFlag
  4813. };
  4814. f.prototype.IsEnabled = function() {
  4815. return (this.m_flags & f.e_enabledFlag) == f.e_enabledFlag
  4816. };
  4817. f.prototype.GetNext = function() {
  4818. return this.m_next
  4819. };
  4820. f.prototype.GetFixtureA = function() {
  4821. return this.m_fixtureA
  4822. };
  4823. f.prototype.GetFixtureB = function() {
  4824. return this.m_fixtureB
  4825. };
  4826. f.prototype.FlagForFiltering = function() {
  4827. this.m_flags |= f.e_filterFlag
  4828. };
  4829. f.prototype.b2Contact = function() {};
  4830. f.prototype.Reset = function(a, b) {
  4831. void 0 === a && (a = null);
  4832. void 0 === b && (b = null);
  4833. this.m_flags = f.e_enabledFlag;
  4834. if (a && b) {
  4835. if (a.IsSensor() || b.IsSensor()) this.m_flags |= f.e_sensorFlag;
  4836. var c = a.GetBody(),
  4837. d = b.GetBody();
  4838. if (c.GetType() != Xb.b2_dynamicBody || c.IsBullet() || d.GetType() != Xb.b2_dynamicBody || d.IsBullet()) this.m_flags |= f.e_continuousFlag;
  4839. this.m_fixtureA = a;
  4840. this.m_fixtureB = b;
  4841. this.m_manifold.m_pointCount = 0;
  4842. this.m_next = this.m_prev = null;
  4843. this.m_nodeA.contact = null;
  4844. this.m_nodeA.prev = null;
  4845. this.m_nodeA.next = null;
  4846. this.m_nodeA.other =
  4847. null;
  4848. this.m_nodeB.contact = null;
  4849. this.m_nodeB.prev = null;
  4850. this.m_nodeB.next = null;
  4851. this.m_nodeB.other = null
  4852. } else this.m_fixtureB = this.m_fixtureA = null
  4853. };
  4854. f.prototype.Update = function(a) {
  4855. var b = this.m_oldManifold;
  4856. this.m_oldManifold = this.m_manifold;
  4857. this.m_manifold = b;
  4858. this.m_flags |= f.e_enabledFlag;
  4859. var c = !1,
  4860. b = (this.m_flags & f.e_touchingFlag) == f.e_touchingFlag,
  4861. e = this.m_fixtureA.m_body,
  4862. g = this.m_fixtureB.m_body,
  4863. h = this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);
  4864. if (this.m_flags & f.e_sensorFlag) h && (c = this.m_fixtureA.GetShape(),
  4865. h = this.m_fixtureB.GetShape(), e = e.GetTransform(), g = g.GetTransform(), c = d.TestOverlap(c, e, h, g)), this.m_manifold.m_pointCount = 0;
  4866. else {
  4867. e.GetType() != Xb.b2_dynamicBody || e.IsBullet() || g.GetType() != Xb.b2_dynamicBody || g.IsBullet() ? this.m_flags |= f.e_continuousFlag : this.m_flags &= ~f.e_continuousFlag;
  4868. if (h)
  4869. for (this.Evaluate(), c = 0 < this.m_manifold.m_pointCount, h = 0; h < this.m_manifold.m_pointCount; ++h) {
  4870. var l = this.m_manifold.m_points[h];
  4871. l.m_normalImpulse = 0;
  4872. l.m_tangentImpulse = 0;
  4873. for (var m = l.m_id, p = 0; p < this.m_oldManifold.m_pointCount; ++p) {
  4874. var q =
  4875. this.m_oldManifold.m_points[p];
  4876. if (q.m_id.key == m.key) {
  4877. l.m_normalImpulse = q.m_normalImpulse;
  4878. l.m_tangentImpulse = q.m_tangentImpulse;
  4879. break
  4880. }
  4881. }
  4882. } else this.m_manifold.m_pointCount = 0;
  4883. c != b && (e.SetAwake(!0), g.SetAwake(!0))
  4884. }
  4885. this.m_flags = c ? this.m_flags | f.e_touchingFlag : this.m_flags & ~f.e_touchingFlag;
  4886. 0 == b && 1 == c && a.BeginContact(this);
  4887. 1 == b && 0 == c && a.EndContact(this);
  4888. 0 == (this.m_flags & f.e_sensorFlag) && a.PreSolve(this, this.m_oldManifold)
  4889. };
  4890. f.prototype.Evaluate = function() {};
  4891. f.prototype.ComputeTOI = function(a, b) {
  4892. f.s_input.proxyA.Set(this.m_fixtureA.GetShape());
  4893. f.s_input.proxyB.Set(this.m_fixtureB.GetShape());
  4894. f.s_input.sweepA = a;
  4895. f.s_input.sweepB = b;
  4896. f.s_input.tolerance = aa.b2_linearSlop;
  4897. return cc.TimeOfImpact(f.s_input)
  4898. };
  4899. Box2D.postDefs.push(function() {
  4900. Box2D.Dynamics.Contacts.b2Contact.e_sensorFlag = 1;
  4901. Box2D.Dynamics.Contacts.b2Contact.e_continuousFlag = 2;
  4902. Box2D.Dynamics.Contacts.b2Contact.e_islandFlag = 4;
  4903. Box2D.Dynamics.Contacts.b2Contact.e_toiFlag = 8;
  4904. Box2D.Dynamics.Contacts.b2Contact.e_touchingFlag = 16;
  4905. Box2D.Dynamics.Contacts.b2Contact.e_enabledFlag = 32;
  4906. Box2D.Dynamics.Contacts.b2Contact.e_filterFlag =
  4907. 64;
  4908. Box2D.Dynamics.Contacts.b2Contact.s_input = new dc
  4909. });
  4910. g.b2ContactConstraint = function() {
  4911. this.localPlaneNormal = new ac;
  4912. this.localPoint = new ac;
  4913. this.normal = new ac;
  4914. this.normalMass = new Yb;
  4915. this.K = new Yb
  4916. };
  4917. g.prototype.b2ContactConstraint = function() {
  4918. this.points = new Vector(aa.b2_maxManifoldPoints);
  4919. for (var a = 0; a < aa.b2_maxManifoldPoints; a++) this.points[a] = new h
  4920. };
  4921. h.b2ContactConstraintPoint = function() {
  4922. this.localPoint = new ac;
  4923. this.rA = new ac;
  4924. this.rB = new ac
  4925. };
  4926. l.b2ContactEdge = function() {};
  4927. m.b2ContactFactory = function() {};
  4928. m.prototype.b2ContactFactory = function(a) {
  4929. this.m_allocator = a;
  4930. this.InitializeRegisters()
  4931. };
  4932. m.prototype.AddType = function(a, b, c, d) {
  4933. void 0 === c && (c = 0);
  4934. void 0 === d && (d = 0);
  4935. this.m_registers[c][d].createFcn = a;
  4936. this.m_registers[c][d].destroyFcn = b;
  4937. this.m_registers[c][d].primary = !0;
  4938. c != d && (this.m_registers[d][c].createFcn = a, this.m_registers[d][c].destroyFcn = b, this.m_registers[d][c].primary = !1)
  4939. };
  4940. m.prototype.InitializeRegisters = function() {
  4941. this.m_registers = new Vector(d.e_shapeTypeCount);
  4942. for (var a = 0; a < d.e_shapeTypeCount; a++) {
  4943. this.m_registers[a] =
  4944. new Vector(d.e_shapeTypeCount);
  4945. for (var b = 0; b < d.e_shapeTypeCount; b++) this.m_registers[a][b] = new q
  4946. }
  4947. this.AddType(e.Create, e.Destroy, d.e_circleShape, d.e_circleShape);
  4948. this.AddType(K.Create, K.Destroy, d.e_polygonShape, d.e_circleShape);
  4949. this.AddType(E.Create, E.Destroy, d.e_polygonShape, d.e_polygonShape);
  4950. this.AddType(A.Create, A.Destroy, d.e_edgeShape, d.e_circleShape);
  4951. this.AddType(H.Create, H.Destroy, d.e_polygonShape, d.e_edgeShape)
  4952. };
  4953. m.prototype.Create = function(a, b) {
  4954. var c = parseInt(a.GetType()),
  4955. d = parseInt(b.GetType()),
  4956. c = this.m_registers[c][d];
  4957. if (c.pool) return d = c.pool, c.pool = d.m_next, c.poolCount--, d.Reset(a, b), d;
  4958. d = c.createFcn;
  4959. return null != d ? (c.primary ? (d = d(this.m_allocator), d.Reset(a, b)) : (d = d(this.m_allocator), d.Reset(b, a)), d) : null
  4960. };
  4961. m.prototype.Destroy = function(a) {
  4962. 0 < a.m_manifold.m_pointCount && (a.m_fixtureA.m_body.SetAwake(!0), a.m_fixtureB.m_body.SetAwake(!0));
  4963. var b = parseInt(a.m_fixtureA.GetType()),
  4964. c = parseInt(a.m_fixtureB.GetType()),
  4965. b = this.m_registers[b][c];
  4966. b.poolCount++;
  4967. a.m_next = b.pool;
  4968. b.pool = a;
  4969. b = b.destroyFcn;
  4970. b(a, this.m_allocator)
  4971. };
  4972. q.b2ContactRegister = function() {};
  4973. p.b2ContactResult = function() {
  4974. this.position = new ac;
  4975. this.normal = new ac;
  4976. this.id = new ec
  4977. };
  4978. y.b2ContactSolver = function() {
  4979. this.m_step = new Zb;
  4980. this.m_constraints = new Vector
  4981. };
  4982. y.prototype.b2ContactSolver = function() {};
  4983. y.prototype.Initialize = function(a, b, c, d) {
  4984. void 0 === c && (c = 0);
  4985. var e;
  4986. this.m_step.Set(a);
  4987. this.m_allocator = d;
  4988. for (this.m_constraintCount = c; this.m_constraints.length < this.m_constraintCount;) this.m_constraints[this.m_constraints.length] = new g;
  4989. for (a =
  4990. 0; a < c; ++a) {
  4991. e = b[a];
  4992. d = e.m_fixtureA;
  4993. var f = e.m_fixtureB,
  4994. h = d.m_shape.m_radius,
  4995. l = f.m_shape.m_radius,
  4996. m = d.m_body,
  4997. p = f.m_body,
  4998. q = e.GetManifold(),
  4999. A = aa.b2MixFriction(d.GetFriction(), f.GetFriction()),
  5000. B = aa.b2MixRestitution(d.GetRestitution(), f.GetRestitution()),
  5001. H = m.m_linearVelocity.x,
  5002. E = m.m_linearVelocity.y,
  5003. K = p.m_linearVelocity.x,
  5004. M = p.m_linearVelocity.y,
  5005. Yb = m.m_angularVelocity,
  5006. Xb = p.m_angularVelocity;
  5007. aa.b2Assert(0 < q.m_pointCount);
  5008. y.s_worldManifold.Initialize(q, m.m_xf, h, p.m_xf, l);
  5009. f = y.s_worldManifold.m_normal.x;
  5010. e = y.s_worldManifold.m_normal.y;
  5011. d = this.m_constraints[a];
  5012. d.bodyA = m;
  5013. d.bodyB = p;
  5014. d.manifold = q;
  5015. d.normal.x = f;
  5016. d.normal.y = e;
  5017. d.pointCount = q.m_pointCount;
  5018. d.friction = A;
  5019. d.restitution = B;
  5020. d.localPlaneNormal.x = q.m_localPlaneNormal.x;
  5021. d.localPlaneNormal.y = q.m_localPlaneNormal.y;
  5022. d.localPoint.x = q.m_localPoint.x;
  5023. d.localPoint.y = q.m_localPoint.y;
  5024. d.radius = h + l;
  5025. d.type = q.m_type;
  5026. for (h = 0; h < d.pointCount; ++h) {
  5027. A = q.m_points[h];
  5028. l = d.points[h];
  5029. l.normalImpulse = A.m_normalImpulse;
  5030. l.tangentImpulse = A.m_tangentImpulse;
  5031. l.localPoint.SetV(A.m_localPoint);
  5032. var A = l.rA.x = y.s_worldManifold.m_points[h].x -
  5033. m.m_sweep.c.x,
  5034. B = l.rA.y = y.s_worldManifold.m_points[h].y - m.m_sweep.c.y,
  5035. Zb = l.rB.x = y.s_worldManifold.m_points[h].x - p.m_sweep.c.x,
  5036. $b = l.rB.y = y.s_worldManifold.m_points[h].y - p.m_sweep.c.y,
  5037. cc = A * e - B * f,
  5038. ac = Zb * e - $b * f,
  5039. cc = cc * cc,
  5040. ac = ac * ac;
  5041. l.normalMass = 1 / (m.m_invMass + p.m_invMass + m.m_invI * cc + p.m_invI * ac);
  5042. var dc = m.m_mass * m.m_invMass + p.m_mass * p.m_invMass,
  5043. dc = dc + (m.m_mass * m.m_invI * cc + p.m_mass * p.m_invI * ac);
  5044. l.equalizedMass = 1 / dc;
  5045. ac = e;
  5046. dc = -f;
  5047. cc = A * dc - B * ac;
  5048. ac = Zb * dc - $b * ac;
  5049. cc *= cc;
  5050. ac *= ac;
  5051. l.tangentMass = 1 / (m.m_invMass + p.m_invMass +
  5052. m.m_invI * cc + p.m_invI * ac);
  5053. l.velocityBias = 0;
  5054. A = d.normal.x * (K + -Xb * $b - H - -Yb * B) + d.normal.y * (M + Xb * Zb - E - Yb * A);
  5055. A < -aa.b2_velocityThreshold && (l.velocityBias += -d.restitution * A)
  5056. }
  5057. 2 == d.pointCount && (M = d.points[0], K = d.points[1], q = m.m_invMass, m = m.m_invI, H = p.m_invMass, p = p.m_invI, E = M.rA.x * e - M.rA.y * f, M = M.rB.x * e - M.rB.y * f, Yb = K.rA.x * e - K.rA.y * f, K = K.rB.x * e - K.rB.y * f, f = q + H + m * E * E + p * M * M, e = q + H + m * Yb * Yb + p * K * K, p = q + H + m * E * Yb + p * M * K, f * f < 100 * (f * e - p * p) ? (d.K.col1.Set(f, p), d.K.col2.Set(p, e), d.K.GetInverse(d.normalMass)) : d.pointCount = 1)
  5058. }
  5059. };
  5060. y.prototype.InitVelocityConstraints = function(a) {
  5061. for (var b = 0; b < this.m_constraintCount; ++b) {
  5062. var c = this.m_constraints[b],
  5063. d = c.bodyA,
  5064. e = c.bodyB,
  5065. f = d.m_invMass,
  5066. g = d.m_invI,
  5067. h = e.m_invMass,
  5068. l = e.m_invI,
  5069. m = c.normal.x,
  5070. p = c.normal.y,
  5071. q = p,
  5072. y = -m,
  5073. A, B;
  5074. if (a.warmStarting)
  5075. for (B = c.pointCount, A = 0; A < B; ++A) {
  5076. var H = c.points[A];
  5077. H.normalImpulse *= a.dtRatio;
  5078. H.tangentImpulse *= a.dtRatio;
  5079. var E = H.normalImpulse * m + H.tangentImpulse * q,
  5080. K = H.normalImpulse * p + H.tangentImpulse * y;
  5081. d.m_angularVelocity -= g * (H.rA.x * K - H.rA.y * E);
  5082. d.m_linearVelocity.x -= f * E;
  5083. d.m_linearVelocity.y -= f * K;
  5084. e.m_angularVelocity += l * (H.rB.x * K - H.rB.y * E);
  5085. e.m_linearVelocity.x += h * E;
  5086. e.m_linearVelocity.y += h * K
  5087. } else
  5088. for (B = c.pointCount, A = 0; A < B; ++A) d = c.points[A], d.normalImpulse = 0, d.tangentImpulse = 0
  5089. }
  5090. };
  5091. y.prototype.SolveVelocityConstraints = function() {
  5092. for (var a, b, c, d, e, f, g, h, l, m, p = 0; p < this.m_constraintCount; ++p) {
  5093. e = this.m_constraints[p];
  5094. var q = e.bodyA,
  5095. y = e.bodyB,
  5096. A = q.m_angularVelocity,
  5097. B = y.m_angularVelocity,
  5098. H = q.m_linearVelocity,
  5099. E = y.m_linearVelocity,
  5100. K = q.m_invMass,
  5101. M = q.m_invI,
  5102. aa = y.m_invMass,
  5103. Yb = y.m_invI;
  5104. h = e.normal.x;
  5105. var Xb = l = e.normal.y;
  5106. m = -h;
  5107. g = e.friction;
  5108. for (a = 0; a < e.pointCount; a++) b = e.points[a], c = E.x - B * b.rB.y - H.x + A * b.rA.y, d = E.y + B * b.rB.x - H.y - A * b.rA.x, c = c * Xb + d * m, c = b.tangentMass * -c, d = g * b.normalImpulse, d = $b.Clamp(b.tangentImpulse + c, -d, d), c = d - b.tangentImpulse, f = c * Xb, c *= m, H.x -= K * f, H.y -= K * c, A -= M * (b.rA.x * c - b.rA.y * f), E.x += aa * f, E.y += aa * c, B += Yb * (b.rB.x * c - b.rB.y * f), b.tangentImpulse = d;
  5109. parseInt(e.pointCount);
  5110. if (1 == e.pointCount) b = e.points[0], c = E.x + -B * b.rB.y - H.x - -A * b.rA.y, d = E.y + B * b.rB.x - H.y - A * b.rA.x, e = c * h + d * l, c = -b.normalMass * (e - b.velocityBias), d = b.normalImpulse + c, d = 0 < d ? d : 0, c = d - b.normalImpulse, f = c * h, c *= l, H.x -= K * f, H.y -= K * c, A -= M * (b.rA.x * c - b.rA.y * f), E.x += aa * f, E.y += aa * c, B += Yb * (b.rB.x * c - b.rB.y * f), b.normalImpulse = d;
  5111. else {
  5112. b = e.points[0];
  5113. a = e.points[1];
  5114. c = b.normalImpulse;
  5115. g = a.normalImpulse;
  5116. var Zb = (E.x - B * b.rB.y - H.x + A * b.rA.y) * h + (E.y + B * b.rB.x - H.y - A * b.rA.x) * l,
  5117. cc = (E.x - B * a.rB.y - H.x + A * a.rA.y) * h + (E.y + B * a.rB.x - H.y - A * a.rA.x) * l;
  5118. d = Zb - b.velocityBias;
  5119. f = cc - a.velocityBias;
  5120. m = e.K;
  5121. d -= m.col1.x * c + m.col2.x * g;
  5122. for (f -= m.col1.y * c + m.col2.y * g;;) {
  5123. m =
  5124. e.normalMass;
  5125. Xb = -(m.col1.x * d + m.col2.x * f);
  5126. m = -(m.col1.y * d + m.col2.y * f);
  5127. if (0 <= Xb && 0 <= m) {
  5128. c = Xb - c;
  5129. g = m - g;
  5130. e = c * h;
  5131. c *= l;
  5132. h *= g;
  5133. l *= g;
  5134. H.x -= K * (e + h);
  5135. H.y -= K * (c + l);
  5136. A -= M * (b.rA.x * c - b.rA.y * e + a.rA.x * l - a.rA.y * h);
  5137. E.x += aa * (e + h);
  5138. E.y += aa * (c + l);
  5139. B += Yb * (b.rB.x * c - b.rB.y * e + a.rB.x * l - a.rB.y * h);
  5140. b.normalImpulse = Xb;
  5141. a.normalImpulse = m;
  5142. break
  5143. }
  5144. Xb = -b.normalMass * d;
  5145. m = 0;
  5146. cc = e.K.col1.y * Xb + f;
  5147. if (0 <= Xb && 0 <= cc) {
  5148. c = Xb - c;
  5149. g = m - g;
  5150. e = c * h;
  5151. c *= l;
  5152. h *= g;
  5153. l *= g;
  5154. H.x -= K * (e + h);
  5155. H.y -= K * (c + l);
  5156. A -= M * (b.rA.x * c - b.rA.y * e + a.rA.x * l - a.rA.y * h);
  5157. E.x += aa * (e + h);
  5158. E.y += aa * (c + l);
  5159. B += Yb * (b.rB.x *
  5160. c - b.rB.y * e + a.rB.x * l - a.rB.y * h);
  5161. b.normalImpulse = Xb;
  5162. a.normalImpulse = m;
  5163. break
  5164. }
  5165. Xb = 0;
  5166. m = -a.normalMass * f;
  5167. Zb = e.K.col2.x * m + d;
  5168. if (0 <= m && 0 <= Zb) {
  5169. c = Xb - c;
  5170. g = m - g;
  5171. e = c * h;
  5172. c *= l;
  5173. h *= g;
  5174. l *= g;
  5175. H.x -= K * (e + h);
  5176. H.y -= K * (c + l);
  5177. A -= M * (b.rA.x * c - b.rA.y * e + a.rA.x * l - a.rA.y * h);
  5178. E.x += aa * (e + h);
  5179. E.y += aa * (c + l);
  5180. B += Yb * (b.rB.x * c - b.rB.y * e + a.rB.x * l - a.rB.y * h);
  5181. b.normalImpulse = Xb;
  5182. a.normalImpulse = m;
  5183. break
  5184. }
  5185. m = Xb = 0;
  5186. Zb = d;
  5187. cc = f;
  5188. if (0 <= Zb && 0 <= cc) {
  5189. c = Xb - c;
  5190. g = m - g;
  5191. e = c * h;
  5192. c *= l;
  5193. h *= g;
  5194. l *= g;
  5195. H.x -= K * (e + h);
  5196. H.y -= K * (c + l);
  5197. A -= M * (b.rA.x * c - b.rA.y * e + a.rA.x * l - a.rA.y * h);
  5198. E.x += aa * (e + h);
  5199. E.y +=
  5200. aa * (c + l);
  5201. B += Yb * (b.rB.x * c - b.rB.y * e + a.rB.x * l - a.rB.y * h);
  5202. b.normalImpulse = Xb;
  5203. a.normalImpulse = m;
  5204. break
  5205. }
  5206. break
  5207. }
  5208. }
  5209. q.m_angularVelocity = A;
  5210. y.m_angularVelocity = B
  5211. }
  5212. };
  5213. y.prototype.FinalizeVelocityConstraints = function() {
  5214. for (var a = 0; a < this.m_constraintCount; ++a)
  5215. for (var b = this.m_constraints[a], c = b.manifold, d = 0; d < b.pointCount; ++d) {
  5216. var e = c.m_points[d],
  5217. f = b.points[d];
  5218. e.m_normalImpulse = f.normalImpulse;
  5219. e.m_tangentImpulse = f.tangentImpulse
  5220. }
  5221. };
  5222. y.prototype.SolvePositionConstraints = function(a) {
  5223. void 0 === a && (a = 0);
  5224. for (var b = 0, c = 0; c <
  5225. this.m_constraintCount; c++) {
  5226. var d = this.m_constraints[c],
  5227. e = d.bodyA,
  5228. f = d.bodyB,
  5229. g = e.m_mass * e.m_invMass,
  5230. h = e.m_mass * e.m_invI,
  5231. l = f.m_mass * f.m_invMass,
  5232. m = f.m_mass * f.m_invI;
  5233. y.s_psm.Initialize(d);
  5234. for (var p = y.s_psm.m_normal, q = 0; q < d.pointCount; q++) {
  5235. var A = d.points[q],
  5236. B = y.s_psm.m_points[q],
  5237. H = y.s_psm.m_separations[q],
  5238. E = B.x - e.m_sweep.c.x,
  5239. K = B.y - e.m_sweep.c.y,
  5240. M = B.x - f.m_sweep.c.x,
  5241. B = B.y - f.m_sweep.c.y,
  5242. b = b < H ? b : H,
  5243. H = $b.Clamp(a * (H + aa.b2_linearSlop), -aa.b2_maxLinearCorrection, 0),
  5244. H = -A.equalizedMass * H,
  5245. A = H * p.x,
  5246. H = H * p.y;
  5247. e.m_sweep.c.x -=
  5248. g * A;
  5249. e.m_sweep.c.y -= g * H;
  5250. e.m_sweep.a -= h * (E * H - K * A);
  5251. e.SynchronizeTransform();
  5252. f.m_sweep.c.x += l * A;
  5253. f.m_sweep.c.y += l * H;
  5254. f.m_sweep.a += m * (M * H - B * A);
  5255. f.SynchronizeTransform()
  5256. }
  5257. }
  5258. return b > -1.5 * aa.b2_linearSlop
  5259. };
  5260. Box2D.postDefs.push(function() {
  5261. Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold = new gc;
  5262. Box2D.Dynamics.Contacts.b2ContactSolver.s_psm = new M
  5263. });
  5264. Box2D.inherit(A, Box2D.Dynamics.Contacts.b2Contact);
  5265. A.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5266. A.b2EdgeAndCircleContact = function() {
  5267. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,
  5268. arguments)
  5269. };
  5270. A.Create = function() {
  5271. return new A
  5272. };
  5273. A.Destroy = function() {};
  5274. A.prototype.Reset = function(a, b) {
  5275. this.__super.Reset.call(this, a, b)
  5276. };
  5277. A.prototype.Evaluate = function() {
  5278. var b = this.m_fixtureA.GetBody(),
  5279. d = this.m_fixtureB.GetBody();
  5280. this.b2CollideEdgeAndCircle(this.m_manifold, this.m_fixtureA.GetShape() instanceof c ? this.m_fixtureA.GetShape() : null, b.m_xf, this.m_fixtureB.GetShape() instanceof a ? this.m_fixtureB.GetShape() : null, d.m_xf)
  5281. };
  5282. A.prototype.b2CollideEdgeAndCircle = function() {};
  5283. Box2D.inherit(B, Box2D.Dynamics.Contacts.b2Contact);
  5284. B.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5285. B.b2NullContact = function() {
  5286. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  5287. };
  5288. B.prototype.b2NullContact = function() {
  5289. this.__super.b2Contact.call(this)
  5290. };
  5291. B.prototype.Evaluate = function() {};
  5292. Box2D.inherit(K, Box2D.Dynamics.Contacts.b2Contact);
  5293. K.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5294. K.b2PolyAndCircleContact = function() {
  5295. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  5296. };
  5297. K.Create = function() {
  5298. return new K
  5299. };
  5300. K.Destroy = function() {};
  5301. K.prototype.Reset = function(a, b) {
  5302. this.__super.Reset.call(this, a, b);
  5303. aa.b2Assert(a.GetType() == d.e_polygonShape);
  5304. aa.b2Assert(b.GetType() == d.e_circleShape)
  5305. };
  5306. K.prototype.Evaluate = function() {
  5307. var c = this.m_fixtureA.m_body,
  5308. d = this.m_fixtureB.m_body;
  5309. bc.CollidePolygonAndCircle(this.m_manifold, this.m_fixtureA.GetShape() instanceof b ? this.m_fixtureA.GetShape() : null, c.m_xf, this.m_fixtureB.GetShape() instanceof a ? this.m_fixtureB.GetShape() : null, d.m_xf)
  5310. };
  5311. Box2D.inherit(H, Box2D.Dynamics.Contacts.b2Contact);
  5312. H.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5313. H.b2PolyAndEdgeContact = function() {
  5314. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  5315. };
  5316. H.Create = function() {
  5317. return new H
  5318. };
  5319. H.Destroy = function() {};
  5320. H.prototype.Reset = function(a, b) {
  5321. this.__super.Reset.call(this, a, b);
  5322. aa.b2Assert(a.GetType() == d.e_polygonShape);
  5323. aa.b2Assert(b.GetType() == d.e_edgeShape)
  5324. };
  5325. H.prototype.Evaluate = function() {
  5326. var a = this.m_fixtureA.GetBody(),
  5327. d = this.m_fixtureB.GetBody();
  5328. this.b2CollidePolyAndEdge(this.m_manifold,
  5329. this.m_fixtureA.GetShape() instanceof b ? this.m_fixtureA.GetShape() : null, a.m_xf, this.m_fixtureB.GetShape() instanceof c ? this.m_fixtureB.GetShape() : null, d.m_xf)
  5330. };
  5331. H.prototype.b2CollidePolyAndEdge = function() {};
  5332. Box2D.inherit(E, Box2D.Dynamics.Contacts.b2Contact);
  5333. E.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5334. E.b2PolygonContact = function() {
  5335. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  5336. };
  5337. E.Create = function() {
  5338. return new E
  5339. };
  5340. E.Destroy = function() {};
  5341. E.prototype.Reset = function(a,
  5342. b) {
  5343. this.__super.Reset.call(this, a, b)
  5344. };
  5345. E.prototype.Evaluate = function() {
  5346. var a = this.m_fixtureA.GetBody(),
  5347. c = this.m_fixtureB.GetBody();
  5348. bc.CollidePolygons(this.m_manifold, this.m_fixtureA.GetShape() instanceof b ? this.m_fixtureA.GetShape() : null, a.m_xf, this.m_fixtureB.GetShape() instanceof b ? this.m_fixtureB.GetShape() : null, c.m_xf)
  5349. };
  5350. M.b2PositionSolverManifold = function() {};
  5351. M.prototype.b2PositionSolverManifold = function() {
  5352. this.m_normal = new ac;
  5353. this.m_separations = new Vector_a2j_Number(aa.b2_maxManifoldPoints);
  5354. this.m_points =
  5355. new Vector(aa.b2_maxManifoldPoints);
  5356. for (var a = 0; a < aa.b2_maxManifoldPoints; a++) this.m_points[a] = new ac
  5357. };
  5358. M.prototype.Initialize = function(a) {
  5359. aa.b2Assert(0 < a.pointCount);
  5360. var b, c, d, e, f, g;
  5361. switch (a.type) {
  5362. case jc.e_circles:
  5363. e = a.bodyA.m_xf.R;
  5364. d = a.localPoint;
  5365. b = a.bodyA.m_xf.position.x + (e.col1.x * d.x + e.col2.x * d.y);
  5366. c = a.bodyA.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y);
  5367. e = a.bodyB.m_xf.R;
  5368. d = a.points[0].localPoint;
  5369. f = a.bodyB.m_xf.position.x + (e.col1.x * d.x + e.col2.x * d.y);
  5370. e = a.bodyB.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y);
  5371. d = f - b;
  5372. g = e - c;
  5373. var h = d * d + g * g;
  5374. h > Number.MIN_VALUE * Number.MIN_VALUE ? (h = Math.sqrt(h), this.m_normal.x = d / h, this.m_normal.y = g / h) : (this.m_normal.x = 1, this.m_normal.y = 0);
  5375. this.m_points[0].x = .5 * (b + f);
  5376. this.m_points[0].y = .5 * (c + e);
  5377. this.m_separations[0] = d * this.m_normal.x + g * this.m_normal.y - a.radius;
  5378. break;
  5379. case jc.e_faceA:
  5380. e = a.bodyA.m_xf.R;
  5381. d = a.localPlaneNormal;
  5382. this.m_normal.x = e.col1.x * d.x + e.col2.x * d.y;
  5383. this.m_normal.y = e.col1.y * d.x + e.col2.y * d.y;
  5384. e = a.bodyA.m_xf.R;
  5385. d = a.localPoint;
  5386. f = a.bodyA.m_xf.position.x + (e.col1.x * d.x + e.col2.x *
  5387. d.y);
  5388. g = a.bodyA.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y);
  5389. e = a.bodyB.m_xf.R;
  5390. for (b = 0; b < a.pointCount; ++b) d = a.points[b].localPoint, c = a.bodyB.m_xf.position.x + (e.col1.x * d.x + e.col2.x * d.y), d = a.bodyB.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y), this.m_separations[b] = (c - f) * this.m_normal.x + (d - g) * this.m_normal.y - a.radius, this.m_points[b].x = c, this.m_points[b].y = d;
  5391. break;
  5392. case jc.e_faceB:
  5393. e = a.bodyB.m_xf.R;
  5394. d = a.localPlaneNormal;
  5395. this.m_normal.x = e.col1.x * d.x + e.col2.x * d.y;
  5396. this.m_normal.y = e.col1.y * d.x + e.col2.y * d.y;
  5397. e = a.bodyB.m_xf.R;
  5398. d = a.localPoint;
  5399. f = a.bodyB.m_xf.position.x + (e.col1.x * d.x + e.col2.x * d.y);
  5400. g = a.bodyB.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y);
  5401. e = a.bodyA.m_xf.R;
  5402. for (b = 0; b < a.pointCount; ++b) d = a.points[b].localPoint, c = a.bodyA.m_xf.position.x + (e.col1.x * d.x + e.col2.x * d.y), d = a.bodyA.m_xf.position.y + (e.col1.y * d.x + e.col2.y * d.y), this.m_separations[b] = (c - f) * this.m_normal.x + (d - g) * this.m_normal.y - a.radius, this.m_points[b].Set(c, d);
  5403. this.m_normal.x *= -1;
  5404. this.m_normal.y *= -1
  5405. }
  5406. };
  5407. Box2D.postDefs.push(function() {
  5408. Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointA =
  5409. new ac;
  5410. Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointB = new ac
  5411. })
  5412. })();
  5413. (function() {
  5414. var a = Box2D.Common.Math.b2Mat22,
  5415. c = Box2D.Common.Math.b2Math,
  5416. b = Box2D.Common.Math.b2Vec2,
  5417. d = Box2D.Common.b2Color,
  5418. e = Box2D.Dynamics.Controllers.b2BuoyancyController,
  5419. f = Box2D.Dynamics.Controllers.b2ConstantAccelController,
  5420. g = Box2D.Dynamics.Controllers.b2ConstantForceController,
  5421. h = Box2D.Dynamics.Controllers.b2Controller,
  5422. l = Box2D.Dynamics.Controllers.b2ControllerEdge,
  5423. m = Box2D.Dynamics.Controllers.b2GravityController,
  5424. q = Box2D.Dynamics.Controllers.b2TensorDampingController;
  5425. Box2D.inherit(e, Box2D.Dynamics.Controllers.b2Controller);
  5426. e.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  5427. e.b2BuoyancyController = function() {
  5428. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  5429. this.normal = new b(0, -1);
  5430. this.density = this.offset = 0;
  5431. this.velocity = new b(0, 0);
  5432. this.linearDrag = 2;
  5433. this.angularDrag = 1;
  5434. this.useDensity = !1;
  5435. this.useWorldGravity = !0;
  5436. this.gravity = null
  5437. };
  5438. e.prototype.Step = function() {
  5439. if (this.m_bodyList) {
  5440. this.useWorldGravity && (this.gravity = this.GetWorld().GetGravity().Copy());
  5441. for (var a = this.m_bodyList; a; a =
  5442. a.nextBody) {
  5443. var c = a.body;
  5444. if (0 != c.IsAwake()) {
  5445. for (var d = new b, e = new b, f = 0, g = 0, h = c.GetFixtureList(); h; h = h.GetNext()) {
  5446. var l = new b,
  5447. m = h.GetShape().ComputeSubmergedArea(this.normal, this.offset, c.GetTransform(), l),
  5448. f = f + m;
  5449. d.x += m * l.x;
  5450. d.y += m * l.y;
  5451. g += 1 * m;
  5452. e.x += m * l.x * 1;
  5453. e.y += m * l.y * 1
  5454. }
  5455. d.x /= f;
  5456. d.y /= f;
  5457. e.x /= g;
  5458. e.y /= g;
  5459. f < Number.MIN_VALUE || (g = this.gravity.GetNegative(), g.Multiply(this.density * f), c.ApplyForce(g, e), e = c.GetLinearVelocityFromWorldPoint(d), e.Subtract(this.velocity), e.Multiply(-this.linearDrag * f), c.ApplyForce(e,
  5460. d), c.ApplyTorque(-c.GetInertia() / c.GetMass() * f * c.GetAngularVelocity() * this.angularDrag))
  5461. }
  5462. }
  5463. }
  5464. };
  5465. e.prototype.Draw = function(a) {
  5466. var c = new b,
  5467. e = new b;
  5468. c.x = this.normal.x * this.offset + 1E3 * this.normal.y;
  5469. c.y = this.normal.y * this.offset - 1E3 * this.normal.x;
  5470. e.x = this.normal.x * this.offset - 1E3 * this.normal.y;
  5471. e.y = this.normal.y * this.offset + 1E3 * this.normal.x;
  5472. var f = new d(0, 0, 1);
  5473. a.DrawSegment(c, e, f)
  5474. };
  5475. Box2D.inherit(f, Box2D.Dynamics.Controllers.b2Controller);
  5476. f.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  5477. f.b2ConstantAccelController = function() {
  5478. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  5479. this.A = new b(0, 0)
  5480. };
  5481. f.prototype.Step = function(a) {
  5482. a = new b(this.A.x * a.dt, this.A.y * a.dt);
  5483. for (var c = this.m_bodyList; c; c = c.nextBody) {
  5484. var d = c.body;
  5485. d.IsAwake() && d.SetLinearVelocity(new b(d.GetLinearVelocity().x + a.x, d.GetLinearVelocity().y + a.y))
  5486. }
  5487. };
  5488. Box2D.inherit(g, Box2D.Dynamics.Controllers.b2Controller);
  5489. g.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  5490. g.b2ConstantForceController =
  5491. function() {
  5492. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  5493. this.F = new b(0, 0)
  5494. };
  5495. g.prototype.Step = function() {
  5496. for (var a = this.m_bodyList; a; a = a.nextBody) {
  5497. var b = a.body;
  5498. b.IsAwake() && b.ApplyForce(this.F, b.GetWorldCenter())
  5499. }
  5500. };
  5501. h.b2Controller = function() {};
  5502. h.prototype.Step = function() {};
  5503. h.prototype.Draw = function() {};
  5504. h.prototype.AddBody = function(a) {
  5505. var b = new l;
  5506. b.controller = this;
  5507. b.body = a;
  5508. b.nextBody = this.m_bodyList;
  5509. b.prevBody = null;
  5510. this.m_bodyList = b;
  5511. b.nextBody && (b.nextBody.prevBody = b);
  5512. this.m_bodyCount++;
  5513. b.nextController = a.m_controllerList;
  5514. b.prevController = null;
  5515. a.m_controllerList = b;
  5516. b.nextController && (b.nextController.prevController = b);
  5517. a.m_controllerCount++
  5518. };
  5519. h.prototype.RemoveBody = function(a) {
  5520. for (var b = a.m_controllerList; b && b.controller != this;) b = b.nextController;
  5521. b.prevBody && (b.prevBody.nextBody = b.nextBody);
  5522. b.nextBody && (b.nextBody.prevBody = b.prevBody);
  5523. b.nextController && (b.nextController.prevController = b.prevController);
  5524. b.prevController && (b.prevController.nextController = b.nextController);
  5525. this.m_bodyList ==
  5526. b && (this.m_bodyList = b.nextBody);
  5527. a.m_controllerList == b && (a.m_controllerList = b.nextController);
  5528. a.m_controllerCount--;
  5529. this.m_bodyCount--
  5530. };
  5531. h.prototype.Clear = function() {
  5532. for (; this.m_bodyList;) this.RemoveBody(this.m_bodyList.body)
  5533. };
  5534. h.prototype.GetNext = function() {
  5535. return this.m_next
  5536. };
  5537. h.prototype.GetWorld = function() {
  5538. return this.m_world
  5539. };
  5540. h.prototype.GetBodyList = function() {
  5541. return this.m_bodyList
  5542. };
  5543. l.b2ControllerEdge = function() {};
  5544. Box2D.inherit(m, Box2D.Dynamics.Controllers.b2Controller);
  5545. m.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  5546. m.b2GravityController = function() {
  5547. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  5548. this.G = 1;
  5549. this.invSqr = !0
  5550. };
  5551. m.prototype.Step = function() {
  5552. var a, c, d, e, f, g, h, l, m, q;
  5553. if (this.invSqr)
  5554. for (a = this.m_bodyList; a; a = a.nextBody)
  5555. for (c = a.body, d = c.GetWorldCenter(), e = c.GetMass(), f = this.m_bodyList; f != a; f = f.nextBody) g = f.body, h = g.GetWorldCenter(), l = h.x - d.x, m = h.y - d.y, q = l * l + m * m, q < Number.MIN_VALUE || (l = new b(l, m), l.Multiply(this.G / q / Math.sqrt(q) * e * g.GetMass()), c.IsAwake() && c.ApplyForce(l, d), l.Multiply(-1),
  5556. g.IsAwake() && g.ApplyForce(l, h));
  5557. else
  5558. for (a = this.m_bodyList; a; a = a.nextBody)
  5559. for (c = a.body, d = c.GetWorldCenter(), e = c.GetMass(), f = this.m_bodyList; f != a; f = f.nextBody) g = f.body, h = g.GetWorldCenter(), l = h.x - d.x, m = h.y - d.y, q = l * l + m * m, q < Number.MIN_VALUE || (l = new b(l, m), l.Multiply(this.G / q * e * g.GetMass()), c.IsAwake() && c.ApplyForce(l, d), l.Multiply(-1), g.IsAwake() && g.ApplyForce(l, h))
  5560. };
  5561. Box2D.inherit(q, Box2D.Dynamics.Controllers.b2Controller);
  5562. q.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  5563. q.b2TensorDampingController =
  5564. function() {
  5565. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  5566. this.T = new a;
  5567. this.maxTimestep = 0
  5568. };
  5569. q.prototype.SetAxisAligned = function(a, b) {
  5570. void 0 === a && (a = 0);
  5571. void 0 === b && (b = 0);
  5572. this.T.col1.x = -a;
  5573. this.T.col1.y = 0;
  5574. this.T.col2.x = 0;
  5575. this.T.col2.y = -b;
  5576. this.maxTimestep = 0 < a || 0 < b ? 1 / Math.max(a, b) : 0
  5577. };
  5578. q.prototype.Step = function(a) {
  5579. a = a.dt;
  5580. if (!(a <= Number.MIN_VALUE)) {
  5581. a > this.maxTimestep && 0 < this.maxTimestep && (a = this.maxTimestep);
  5582. for (var d = this.m_bodyList; d; d = d.nextBody) {
  5583. var e = d.body;
  5584. if (e.IsAwake()) {
  5585. var f =
  5586. e.GetWorldVector(c.MulMV(this.T, e.GetLocalVector(e.GetLinearVelocity())));
  5587. e.SetLinearVelocity(new b(e.GetLinearVelocity().x + f.x * a, e.GetLinearVelocity().y + f.y * a))
  5588. }
  5589. }
  5590. }
  5591. }
  5592. })();
  5593. (function() {
  5594. var a = Box2D.Common.b2Settings,
  5595. c = Box2D.Common.Math.b2Mat22,
  5596. b = Box2D.Common.Math.b2Mat33,
  5597. d = Box2D.Common.Math.b2Math,
  5598. e = Box2D.Common.Math.b2Vec2,
  5599. f = Box2D.Common.Math.b2Vec3,
  5600. g = Box2D.Dynamics.Joints.b2DistanceJoint,
  5601. h = Box2D.Dynamics.Joints.b2DistanceJointDef,
  5602. l = Box2D.Dynamics.Joints.b2FrictionJoint,
  5603. m = Box2D.Dynamics.Joints.b2FrictionJointDef,
  5604. q = Box2D.Dynamics.Joints.b2GearJoint,
  5605. p = Box2D.Dynamics.Joints.b2GearJointDef,
  5606. y = Box2D.Dynamics.Joints.b2Jacobian,
  5607. A = Box2D.Dynamics.Joints.b2Joint,
  5608. B = Box2D.Dynamics.Joints.b2JointDef,
  5609. K = Box2D.Dynamics.Joints.b2JointEdge,
  5610. H = Box2D.Dynamics.Joints.b2LineJoint,
  5611. E = Box2D.Dynamics.Joints.b2LineJointDef,
  5612. M = Box2D.Dynamics.Joints.b2MouseJoint,
  5613. Xb = Box2D.Dynamics.Joints.b2MouseJointDef,
  5614. Zb = Box2D.Dynamics.Joints.b2PrismaticJoint,
  5615. aa = Box2D.Dynamics.Joints.b2PrismaticJointDef,
  5616. Yb = Box2D.Dynamics.Joints.b2PulleyJoint,
  5617. $b = Box2D.Dynamics.Joints.b2PulleyJointDef,
  5618. ac = Box2D.Dynamics.Joints.b2RevoluteJoint,
  5619. bc = Box2D.Dynamics.Joints.b2RevoluteJointDef,
  5620. ec = Box2D.Dynamics.Joints.b2WeldJoint,
  5621. jc = Box2D.Dynamics.Joints.b2WeldJointDef;
  5622. Box2D.inherit(g, Box2D.Dynamics.Joints.b2Joint);
  5623. g.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  5624. g.b2DistanceJoint = function() {
  5625. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  5626. this.m_localAnchor1 = new e;
  5627. this.m_localAnchor2 = new e;
  5628. this.m_u = new e
  5629. };
  5630. g.prototype.GetAnchorA = function() {
  5631. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  5632. };
  5633. g.prototype.GetAnchorB = function() {
  5634. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  5635. };
  5636. g.prototype.GetReactionForce = function(a) {
  5637. void 0 === a && (a = 0);
  5638. return new e(a * this.m_impulse * this.m_u.x, a * this.m_impulse * this.m_u.y)
  5639. };
  5640. g.prototype.GetReactionTorque = function() {
  5641. return 0
  5642. };
  5643. g.prototype.GetLength = function() {
  5644. return this.m_length
  5645. };
  5646. g.prototype.SetLength = function(a) {
  5647. void 0 === a && (a = 0);
  5648. this.m_length = a
  5649. };
  5650. g.prototype.GetFrequency = function() {
  5651. return this.m_frequencyHz
  5652. };
  5653. g.prototype.SetFrequency = function(a) {
  5654. void 0 === a && (a = 0);
  5655. this.m_frequencyHz = a
  5656. };
  5657. g.prototype.GetDampingRatio = function() {
  5658. return this.m_dampingRatio
  5659. };
  5660. g.prototype.SetDampingRatio = function(a) {
  5661. void 0 ===
  5662. a && (a = 0);
  5663. this.m_dampingRatio = a
  5664. };
  5665. g.prototype.b2DistanceJoint = function(a) {
  5666. this.__super.b2Joint.call(this, a);
  5667. this.m_localAnchor1.SetV(a.localAnchorA);
  5668. this.m_localAnchor2.SetV(a.localAnchorB);
  5669. this.m_length = a.length;
  5670. this.m_frequencyHz = a.frequencyHz;
  5671. this.m_dampingRatio = a.dampingRatio;
  5672. this.m_bias = this.m_gamma = this.m_impulse = 0
  5673. };
  5674. g.prototype.InitVelocityConstraints = function(b) {
  5675. var c, d, e = this.m_bodyA,
  5676. f = this.m_bodyB;
  5677. c = e.m_xf.R;
  5678. var g = this.m_localAnchor1.x - e.m_sweep.localCenter.x,
  5679. h = this.m_localAnchor1.y - e.m_sweep.localCenter.y;
  5680. d = c.col1.x * g + c.col2.x * h;
  5681. h = c.col1.y * g + c.col2.y * h;
  5682. g = d;
  5683. c = f.m_xf.R;
  5684. var l = this.m_localAnchor2.x - f.m_sweep.localCenter.x,
  5685. m = this.m_localAnchor2.y - f.m_sweep.localCenter.y;
  5686. d = c.col1.x * l + c.col2.x * m;
  5687. m = c.col1.y * l + c.col2.y * m;
  5688. l = d;
  5689. this.m_u.x = f.m_sweep.c.x + l - e.m_sweep.c.x - g;
  5690. this.m_u.y = f.m_sweep.c.y + m - e.m_sweep.c.y - h;
  5691. d = Math.sqrt(this.m_u.x * this.m_u.x + this.m_u.y * this.m_u.y);
  5692. d > a.b2_linearSlop ? this.m_u.Multiply(1 / d) : this.m_u.SetZero();
  5693. c = g * this.m_u.y - h * this.m_u.x;
  5694. var p = l * this.m_u.y - m * this.m_u.x;
  5695. c = e.m_invMass + e.m_invI *
  5696. c * c + f.m_invMass + f.m_invI * p * p;
  5697. this.m_mass = 0 != c ? 1 / c : 0;
  5698. if (0 < this.m_frequencyHz) {
  5699. d -= this.m_length;
  5700. var p = 2 * Math.PI * this.m_frequencyHz,
  5701. q = this.m_mass * p * p;
  5702. this.m_gamma = b.dt * (2 * this.m_mass * this.m_dampingRatio * p + b.dt * q);
  5703. this.m_gamma = 0 != this.m_gamma ? 1 / this.m_gamma : 0;
  5704. this.m_bias = d * b.dt * q * this.m_gamma;
  5705. this.m_mass = c + this.m_gamma;
  5706. this.m_mass = 0 != this.m_mass ? 1 / this.m_mass : 0
  5707. }
  5708. b.warmStarting ? (this.m_impulse *= b.dtRatio, b = this.m_impulse * this.m_u.x, c = this.m_impulse * this.m_u.y, e.m_linearVelocity.x -= e.m_invMass * b, e.m_linearVelocity.y -=
  5709. e.m_invMass * c, e.m_angularVelocity -= e.m_invI * (g * c - h * b), f.m_linearVelocity.x += f.m_invMass * b, f.m_linearVelocity.y += f.m_invMass * c, f.m_angularVelocity += f.m_invI * (l * c - m * b)) : this.m_impulse = 0
  5710. };
  5711. g.prototype.SolveVelocityConstraints = function() {
  5712. var a, b = this.m_bodyA,
  5713. c = this.m_bodyB;
  5714. a = b.m_xf.R;
  5715. var d = this.m_localAnchor1.x - b.m_sweep.localCenter.x,
  5716. e = this.m_localAnchor1.y - b.m_sweep.localCenter.y,
  5717. f = a.col1.x * d + a.col2.x * e,
  5718. e = a.col1.y * d + a.col2.y * e,
  5719. d = f;
  5720. a = c.m_xf.R;
  5721. var g = this.m_localAnchor2.x - c.m_sweep.localCenter.x,
  5722. h = this.m_localAnchor2.y -
  5723. c.m_sweep.localCenter.y,
  5724. f = a.col1.x * g + a.col2.x * h,
  5725. h = a.col1.y * g + a.col2.y * h,
  5726. g = f,
  5727. f = -this.m_mass * (this.m_u.x * (c.m_linearVelocity.x + -c.m_angularVelocity * h - (b.m_linearVelocity.x + -b.m_angularVelocity * e)) + this.m_u.y * (c.m_linearVelocity.y + c.m_angularVelocity * g - (b.m_linearVelocity.y + b.m_angularVelocity * d)) + this.m_bias + this.m_gamma * this.m_impulse);
  5728. this.m_impulse += f;
  5729. a = f * this.m_u.x;
  5730. f *= this.m_u.y;
  5731. b.m_linearVelocity.x -= b.m_invMass * a;
  5732. b.m_linearVelocity.y -= b.m_invMass * f;
  5733. b.m_angularVelocity -= b.m_invI * (d * f - e * a);
  5734. c.m_linearVelocity.x +=
  5735. c.m_invMass * a;
  5736. c.m_linearVelocity.y += c.m_invMass * f;
  5737. c.m_angularVelocity += c.m_invI * (g * f - h * a)
  5738. };
  5739. g.prototype.SolvePositionConstraints = function() {
  5740. var b;
  5741. if (0 < this.m_frequencyHz) return !0;
  5742. var c = this.m_bodyA,
  5743. e = this.m_bodyB;
  5744. b = c.m_xf.R;
  5745. var f = this.m_localAnchor1.x - c.m_sweep.localCenter.x,
  5746. g = this.m_localAnchor1.y - c.m_sweep.localCenter.y,
  5747. h = b.col1.x * f + b.col2.x * g,
  5748. g = b.col1.y * f + b.col2.y * g,
  5749. f = h;
  5750. b = e.m_xf.R;
  5751. var l = this.m_localAnchor2.x - e.m_sweep.localCenter.x,
  5752. m = this.m_localAnchor2.y - e.m_sweep.localCenter.y,
  5753. h = b.col1.x * l + b.col2.x *
  5754. m,
  5755. m = b.col1.y * l + b.col2.y * m,
  5756. l = h,
  5757. h = e.m_sweep.c.x + l - c.m_sweep.c.x - f,
  5758. p = e.m_sweep.c.y + m - c.m_sweep.c.y - g;
  5759. b = Math.sqrt(h * h + p * p);
  5760. h /= b;
  5761. p /= b;
  5762. b -= this.m_length;
  5763. b = d.Clamp(b, -a.b2_maxLinearCorrection, a.b2_maxLinearCorrection);
  5764. var q = -this.m_mass * b;
  5765. this.m_u.Set(h, p);
  5766. h = q * this.m_u.x;
  5767. p = q * this.m_u.y;
  5768. c.m_sweep.c.x -= c.m_invMass * h;
  5769. c.m_sweep.c.y -= c.m_invMass * p;
  5770. c.m_sweep.a -= c.m_invI * (f * p - g * h);
  5771. e.m_sweep.c.x += e.m_invMass * h;
  5772. e.m_sweep.c.y += e.m_invMass * p;
  5773. e.m_sweep.a += e.m_invI * (l * p - m * h);
  5774. c.SynchronizeTransform();
  5775. e.SynchronizeTransform();
  5776. return d.Abs(b) < a.b2_linearSlop
  5777. };
  5778. Box2D.inherit(h, Box2D.Dynamics.Joints.b2JointDef);
  5779. h.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  5780. h.b2DistanceJointDef = function() {
  5781. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  5782. this.localAnchorA = new e;
  5783. this.localAnchorB = new e
  5784. };
  5785. h.prototype.b2DistanceJointDef = function() {
  5786. this.__super.b2JointDef.call(this);
  5787. this.type = A.e_distanceJoint;
  5788. this.length = 1;
  5789. this.dampingRatio = this.frequencyHz = 0
  5790. };
  5791. h.prototype.Initialize = function(a, b, c, d) {
  5792. this.bodyA =
  5793. a;
  5794. this.bodyB = b;
  5795. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));
  5796. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(d));
  5797. a = d.x - c.x;
  5798. c = d.y - c.y;
  5799. this.length = Math.sqrt(a * a + c * c);
  5800. this.dampingRatio = this.frequencyHz = 0
  5801. };
  5802. Box2D.inherit(l, Box2D.Dynamics.Joints.b2Joint);
  5803. l.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  5804. l.b2FrictionJoint = function() {
  5805. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  5806. this.m_localAnchorA = new e;
  5807. this.m_localAnchorB = new e;
  5808. this.m_linearMass = new c;
  5809. this.m_linearImpulse =
  5810. new e
  5811. };
  5812. l.prototype.GetAnchorA = function() {
  5813. return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)
  5814. };
  5815. l.prototype.GetAnchorB = function() {
  5816. return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)
  5817. };
  5818. l.prototype.GetReactionForce = function(a) {
  5819. void 0 === a && (a = 0);
  5820. return new e(a * this.m_linearImpulse.x, a * this.m_linearImpulse.y)
  5821. };
  5822. l.prototype.GetReactionTorque = function(a) {
  5823. void 0 === a && (a = 0);
  5824. return a * this.m_angularImpulse
  5825. };
  5826. l.prototype.SetMaxForce = function(a) {
  5827. void 0 === a && (a = 0);
  5828. this.m_maxForce = a
  5829. };
  5830. l.prototype.GetMaxForce = function() {
  5831. return this.m_maxForce
  5832. };
  5833. l.prototype.SetMaxTorque = function(a) {
  5834. void 0 === a && (a = 0);
  5835. this.m_maxTorque = a
  5836. };
  5837. l.prototype.GetMaxTorque = function() {
  5838. return this.m_maxTorque
  5839. };
  5840. l.prototype.b2FrictionJoint = function(a) {
  5841. this.__super.b2Joint.call(this, a);
  5842. this.m_localAnchorA.SetV(a.localAnchorA);
  5843. this.m_localAnchorB.SetV(a.localAnchorB);
  5844. this.m_linearMass.SetZero();
  5845. this.m_angularMass = 0;
  5846. this.m_linearImpulse.SetZero();
  5847. this.m_angularImpulse = 0;
  5848. this.m_maxForce = a.maxForce;
  5849. this.m_maxTorque = a.maxTorque
  5850. };
  5851. l.prototype.InitVelocityConstraints = function(a) {
  5852. var b,
  5853. d, e = this.m_bodyA,
  5854. f = this.m_bodyB;
  5855. b = e.m_xf.R;
  5856. var g = this.m_localAnchorA.x - e.m_sweep.localCenter.x,
  5857. h = this.m_localAnchorA.y - e.m_sweep.localCenter.y;
  5858. d = b.col1.x * g + b.col2.x * h;
  5859. h = b.col1.y * g + b.col2.y * h;
  5860. g = d;
  5861. b = f.m_xf.R;
  5862. var l = this.m_localAnchorB.x - f.m_sweep.localCenter.x,
  5863. m = this.m_localAnchorB.y - f.m_sweep.localCenter.y;
  5864. d = b.col1.x * l + b.col2.x * m;
  5865. m = b.col1.y * l + b.col2.y * m;
  5866. l = d;
  5867. b = e.m_invMass;
  5868. d = f.m_invMass;
  5869. var p = e.m_invI,
  5870. q = f.m_invI,
  5871. y = new c;
  5872. y.col1.x = b + d;
  5873. y.col2.x = 0;
  5874. y.col1.y = 0;
  5875. y.col2.y = b + d;
  5876. y.col1.x += p * h * h;
  5877. y.col2.x += -p * g * h;
  5878. y.col1.y += -p * g * h;
  5879. y.col2.y += p * g * g;
  5880. y.col1.x += q * m * m;
  5881. y.col2.x += -q * l * m;
  5882. y.col1.y += -q * l * m;
  5883. y.col2.y += q * l * l;
  5884. y.GetInverse(this.m_linearMass);
  5885. this.m_angularMass = p + q;
  5886. 0 < this.m_angularMass && (this.m_angularMass = 1 / this.m_angularMass);
  5887. a.warmStarting ? (this.m_linearImpulse.x *= a.dtRatio, this.m_linearImpulse.y *= a.dtRatio, this.m_angularImpulse *= a.dtRatio, a = this.m_linearImpulse, e.m_linearVelocity.x -= b * a.x, e.m_linearVelocity.y -= b * a.y, e.m_angularVelocity -= p * (g * a.y - h * a.x + this.m_angularImpulse), f.m_linearVelocity.x += d * a.x,
  5888. f.m_linearVelocity.y += d * a.y, f.m_angularVelocity += q * (l * a.y - m * a.x + this.m_angularImpulse)) : (this.m_linearImpulse.SetZero(), this.m_angularImpulse = 0)
  5889. };
  5890. l.prototype.SolveVelocityConstraints = function(a) {
  5891. var b, c, f = this.m_bodyA,
  5892. g = this.m_bodyB,
  5893. h = f.m_linearVelocity,
  5894. l = f.m_angularVelocity,
  5895. m = g.m_linearVelocity,
  5896. p = g.m_angularVelocity,
  5897. q = f.m_invMass,
  5898. y = g.m_invMass,
  5899. A = f.m_invI,
  5900. B = g.m_invI;
  5901. b = f.m_xf.R;
  5902. var H = this.m_localAnchorA.x - f.m_sweep.localCenter.x,
  5903. E = this.m_localAnchorA.y - f.m_sweep.localCenter.y;
  5904. c = b.col1.x * H + b.col2.x *
  5905. E;
  5906. E = b.col1.y * H + b.col2.y * E;
  5907. H = c;
  5908. b = g.m_xf.R;
  5909. var K = this.m_localAnchorB.x - g.m_sweep.localCenter.x,
  5910. M = this.m_localAnchorB.y - g.m_sweep.localCenter.y;
  5911. c = b.col1.x * K + b.col2.x * M;
  5912. M = b.col1.y * K + b.col2.y * M;
  5913. K = c;
  5914. c = -this.m_angularMass * (p - l);
  5915. var aa = this.m_angularImpulse;
  5916. b = a.dt * this.m_maxTorque;
  5917. this.m_angularImpulse = d.Clamp(this.m_angularImpulse + c, -b, b);
  5918. c = this.m_angularImpulse - aa;
  5919. l -= A * c;
  5920. p += B * c;
  5921. b = d.MulMV(this.m_linearMass, new e(-(m.x - p * M - h.x + l * E), -(m.y + p * K - h.y - l * H)));
  5922. c = this.m_linearImpulse.Copy();
  5923. this.m_linearImpulse.Add(b);
  5924. b = a.dt * this.m_maxForce;
  5925. this.m_linearImpulse.LengthSquared() > b * b && (this.m_linearImpulse.Normalize(), this.m_linearImpulse.Multiply(b));
  5926. b = d.SubtractVV(this.m_linearImpulse, c);
  5927. h.x -= q * b.x;
  5928. h.y -= q * b.y;
  5929. l -= A * (H * b.y - E * b.x);
  5930. m.x += y * b.x;
  5931. m.y += y * b.y;
  5932. p += B * (K * b.y - M * b.x);
  5933. f.m_angularVelocity = l;
  5934. g.m_angularVelocity = p
  5935. };
  5936. l.prototype.SolvePositionConstraints = function() {
  5937. return !0
  5938. };
  5939. Box2D.inherit(m, Box2D.Dynamics.Joints.b2JointDef);
  5940. m.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  5941. m.b2FrictionJointDef = function() {
  5942. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
  5943. arguments);
  5944. this.localAnchorA = new e;
  5945. this.localAnchorB = new e
  5946. };
  5947. m.prototype.b2FrictionJointDef = function() {
  5948. this.__super.b2JointDef.call(this);
  5949. this.type = A.e_frictionJoint;
  5950. this.maxTorque = this.maxForce = 0
  5951. };
  5952. m.prototype.Initialize = function(a, b, c) {
  5953. this.bodyA = a;
  5954. this.bodyB = b;
  5955. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));
  5956. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c))
  5957. };
  5958. Box2D.inherit(q, Box2D.Dynamics.Joints.b2Joint);
  5959. q.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  5960. q.b2GearJoint = function() {
  5961. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,
  5962. arguments);
  5963. this.m_groundAnchor1 = new e;
  5964. this.m_groundAnchor2 = new e;
  5965. this.m_localAnchor1 = new e;
  5966. this.m_localAnchor2 = new e;
  5967. this.m_J = new y
  5968. };
  5969. q.prototype.GetAnchorA = function() {
  5970. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  5971. };
  5972. q.prototype.GetAnchorB = function() {
  5973. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  5974. };
  5975. q.prototype.GetReactionForce = function(a) {
  5976. void 0 === a && (a = 0);
  5977. return new e(a * this.m_impulse * this.m_J.linearB.x, a * this.m_impulse * this.m_J.linearB.y)
  5978. };
  5979. q.prototype.GetReactionTorque = function(a) {
  5980. void 0 ===
  5981. a && (a = 0);
  5982. var b = this.m_bodyB.m_xf.R,
  5983. c = this.m_localAnchor1.x - this.m_bodyB.m_sweep.localCenter.x,
  5984. d = this.m_localAnchor1.y - this.m_bodyB.m_sweep.localCenter.y,
  5985. e = b.col1.x * c + b.col2.x * d,
  5986. d = b.col1.y * c + b.col2.y * d;
  5987. return a * (this.m_impulse * this.m_J.angularB - e * this.m_impulse * this.m_J.linearB.y + d * this.m_impulse * this.m_J.linearB.x)
  5988. };
  5989. q.prototype.GetRatio = function() {
  5990. return this.m_ratio
  5991. };
  5992. q.prototype.SetRatio = function(a) {
  5993. void 0 === a && (a = 0);
  5994. this.m_ratio = a
  5995. };
  5996. q.prototype.b2GearJoint = function(a) {
  5997. this.__super.b2Joint.call(this,
  5998. a);
  5999. var b = parseInt(a.joint1.m_type),
  6000. c = parseInt(a.joint2.m_type);
  6001. this.m_prismatic2 = this.m_revolute2 = this.m_prismatic1 = this.m_revolute1 = null;
  6002. this.m_ground1 = a.joint1.GetBodyA();
  6003. this.m_bodyA = a.joint1.GetBodyB();
  6004. b == A.e_revoluteJoint ? (this.m_revolute1 = a.joint1 instanceof ac ? a.joint1 : null, this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1), this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2), b = this.m_revolute1.GetJointAngle()) : (this.m_prismatic1 = a.joint1 instanceof Zb ? a.joint1 : null, this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1),
  6005. this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2), b = this.m_prismatic1.GetJointTranslation());
  6006. this.m_ground2 = a.joint2.GetBodyA();
  6007. this.m_bodyB = a.joint2.GetBodyB();
  6008. c == A.e_revoluteJoint ? (this.m_revolute2 = a.joint2 instanceof ac ? a.joint2 : null, this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1), this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2), c = this.m_revolute2.GetJointAngle()) : (this.m_prismatic2 = a.joint2 instanceof Zb ? a.joint2 : null, this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1),
  6009. this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2), c = this.m_prismatic2.GetJointTranslation());
  6010. this.m_ratio = a.ratio;
  6011. this.m_constant = b + this.m_ratio * c;
  6012. this.m_impulse = 0
  6013. };
  6014. q.prototype.InitVelocityConstraints = function(a) {
  6015. var b = this.m_ground1,
  6016. c = this.m_ground2,
  6017. d = this.m_bodyA,
  6018. e = this.m_bodyB,
  6019. f, g, h, l, m, p = 0;
  6020. this.m_J.SetZero();
  6021. this.m_revolute1 ? (this.m_J.angularA = -1, p += d.m_invI) : (b = b.m_xf.R, g = this.m_prismatic1.m_localXAxis1, f = b.col1.x * g.x + b.col2.x * g.y, g = b.col1.y * g.x + b.col2.y * g.y, b = d.m_xf.R, h = this.m_localAnchor1.x -
  6022. d.m_sweep.localCenter.x, l = this.m_localAnchor1.y - d.m_sweep.localCenter.y, m = b.col1.x * h + b.col2.x * l, l = b.col1.y * h + b.col2.y * l, h = m * g - l * f, this.m_J.linearA.Set(-f, -g), this.m_J.angularA = -h, p += d.m_invMass + d.m_invI * h * h);
  6023. this.m_revolute2 ? (this.m_J.angularB = -this.m_ratio, p += this.m_ratio * this.m_ratio * e.m_invI) : (b = c.m_xf.R, g = this.m_prismatic2.m_localXAxis1, f = b.col1.x * g.x + b.col2.x * g.y, g = b.col1.y * g.x + b.col2.y * g.y, b = e.m_xf.R, h = this.m_localAnchor2.x - e.m_sweep.localCenter.x, l = this.m_localAnchor2.y - e.m_sweep.localCenter.y,
  6024. m = b.col1.x * h + b.col2.x * l, l = b.col1.y * h + b.col2.y * l, h = m * g - l * f, this.m_J.linearB.Set(-this.m_ratio * f, -this.m_ratio * g), this.m_J.angularB = -this.m_ratio * h, p += this.m_ratio * this.m_ratio * (e.m_invMass + e.m_invI * h * h));
  6025. this.m_mass = 0 < p ? 1 / p : 0;
  6026. a.warmStarting ? (d.m_linearVelocity.x += d.m_invMass * this.m_impulse * this.m_J.linearA.x, d.m_linearVelocity.y += d.m_invMass * this.m_impulse * this.m_J.linearA.y, d.m_angularVelocity += d.m_invI * this.m_impulse * this.m_J.angularA, e.m_linearVelocity.x += e.m_invMass * this.m_impulse * this.m_J.linearB.x,
  6027. e.m_linearVelocity.y += e.m_invMass * this.m_impulse * this.m_J.linearB.y, e.m_angularVelocity += e.m_invI * this.m_impulse * this.m_J.angularB) : this.m_impulse = 0
  6028. };
  6029. q.prototype.SolveVelocityConstraints = function() {
  6030. var a = this.m_bodyA,
  6031. b = this.m_bodyB,
  6032. c = -this.m_mass * this.m_J.Compute(a.m_linearVelocity, a.m_angularVelocity, b.m_linearVelocity, b.m_angularVelocity);
  6033. this.m_impulse += c;
  6034. a.m_linearVelocity.x += a.m_invMass * c * this.m_J.linearA.x;
  6035. a.m_linearVelocity.y += a.m_invMass * c * this.m_J.linearA.y;
  6036. a.m_angularVelocity += a.m_invI *
  6037. c * this.m_J.angularA;
  6038. b.m_linearVelocity.x += b.m_invMass * c * this.m_J.linearB.x;
  6039. b.m_linearVelocity.y += b.m_invMass * c * this.m_J.linearB.y;
  6040. b.m_angularVelocity += b.m_invI * c * this.m_J.angularB
  6041. };
  6042. q.prototype.SolvePositionConstraints = function() {
  6043. var b = this.m_bodyA,
  6044. c = this.m_bodyB,
  6045. d, e;
  6046. d = this.m_revolute1 ? this.m_revolute1.GetJointAngle() : this.m_prismatic1.GetJointTranslation();
  6047. e = this.m_revolute2 ? this.m_revolute2.GetJointAngle() : this.m_prismatic2.GetJointTranslation();
  6048. d = -this.m_mass * (this.m_constant - (d + this.m_ratio * e));
  6049. b.m_sweep.c.x += b.m_invMass * d * this.m_J.linearA.x;
  6050. b.m_sweep.c.y += b.m_invMass * d * this.m_J.linearA.y;
  6051. b.m_sweep.a += b.m_invI * d * this.m_J.angularA;
  6052. c.m_sweep.c.x += c.m_invMass * d * this.m_J.linearB.x;
  6053. c.m_sweep.c.y += c.m_invMass * d * this.m_J.linearB.y;
  6054. c.m_sweep.a += c.m_invI * d * this.m_J.angularB;
  6055. b.SynchronizeTransform();
  6056. c.SynchronizeTransform();
  6057. return 0 < a.b2_linearSlop
  6058. };
  6059. Box2D.inherit(p, Box2D.Dynamics.Joints.b2JointDef);
  6060. p.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  6061. p.b2GearJointDef = function() {
  6062. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
  6063. arguments)
  6064. };
  6065. p.prototype.b2GearJointDef = function() {
  6066. this.__super.b2JointDef.call(this);
  6067. this.type = A.e_gearJoint;
  6068. this.joint2 = this.joint1 = null;
  6069. this.ratio = 1
  6070. };
  6071. y.b2Jacobian = function() {
  6072. this.linearA = new e;
  6073. this.linearB = new e
  6074. };
  6075. y.prototype.SetZero = function() {
  6076. this.linearA.SetZero();
  6077. this.angularA = 0;
  6078. this.linearB.SetZero();
  6079. this.angularB = 0
  6080. };
  6081. y.prototype.Set = function(a, b, c, d) {
  6082. void 0 === b && (b = 0);
  6083. void 0 === d && (d = 0);
  6084. this.linearA.SetV(a);
  6085. this.angularA = b;
  6086. this.linearB.SetV(c);
  6087. this.angularB = d
  6088. };
  6089. y.prototype.Compute = function(a,
  6090. b, c, d) {
  6091. void 0 === b && (b = 0);
  6092. void 0 === d && (d = 0);
  6093. return this.linearA.x * a.x + this.linearA.y * a.y + this.angularA * b + (this.linearB.x * c.x + this.linearB.y * c.y) + this.angularB * d
  6094. };
  6095. A.b2Joint = function() {
  6096. this.m_edgeA = new K;
  6097. this.m_edgeB = new K;
  6098. this.m_localCenterA = new e;
  6099. this.m_localCenterB = new e
  6100. };
  6101. A.prototype.GetType = function() {
  6102. return this.m_type
  6103. };
  6104. A.prototype.GetAnchorA = function() {
  6105. return null
  6106. };
  6107. A.prototype.GetAnchorB = function() {
  6108. return null
  6109. };
  6110. A.prototype.GetReactionForce = function() {
  6111. return null
  6112. };
  6113. A.prototype.GetReactionTorque =
  6114. function() {
  6115. return 0
  6116. };
  6117. A.prototype.GetBodyA = function() {
  6118. return this.m_bodyA
  6119. };
  6120. A.prototype.GetBodyB = function() {
  6121. return this.m_bodyB
  6122. };
  6123. A.prototype.GetNext = function() {
  6124. return this.m_next
  6125. };
  6126. A.prototype.GetUserData = function() {
  6127. return this.m_userData
  6128. };
  6129. A.prototype.SetUserData = function(a) {
  6130. this.m_userData = a
  6131. };
  6132. A.prototype.IsActive = function() {
  6133. return this.m_bodyA.IsActive() && this.m_bodyB.IsActive()
  6134. };
  6135. A.Create = function(a) {
  6136. var b = null;
  6137. switch (a.type) {
  6138. case A.e_distanceJoint:
  6139. b = new g(a instanceof h ? a : null);
  6140. break;
  6141. case A.e_mouseJoint:
  6142. b =
  6143. new M(a instanceof Xb ? a : null);
  6144. break;
  6145. case A.e_prismaticJoint:
  6146. b = new Zb(a instanceof aa ? a : null);
  6147. break;
  6148. case A.e_revoluteJoint:
  6149. b = new ac(a instanceof bc ? a : null);
  6150. break;
  6151. case A.e_pulleyJoint:
  6152. b = new Yb(a instanceof $b ? a : null);
  6153. break;
  6154. case A.e_gearJoint:
  6155. b = new q(a instanceof p ? a : null);
  6156. break;
  6157. case A.e_lineJoint:
  6158. b = new H(a instanceof E ? a : null);
  6159. break;
  6160. case A.e_weldJoint:
  6161. b = new ec(a instanceof jc ? a : null);
  6162. break;
  6163. case A.e_frictionJoint:
  6164. b = new l(a instanceof m ? a : null)
  6165. }
  6166. return b
  6167. };
  6168. A.Destroy = function() {};
  6169. A.prototype.b2Joint = function(b) {
  6170. a.b2Assert(b.bodyA !=
  6171. b.bodyB);
  6172. this.m_type = b.type;
  6173. this.m_next = this.m_prev = null;
  6174. this.m_bodyA = b.bodyA;
  6175. this.m_bodyB = b.bodyB;
  6176. this.m_collideConnected = b.collideConnected;
  6177. this.m_islandFlag = !1;
  6178. this.m_userData = b.userData
  6179. };
  6180. A.prototype.InitVelocityConstraints = function() {};
  6181. A.prototype.SolveVelocityConstraints = function() {};
  6182. A.prototype.FinalizeVelocityConstraints = function() {};
  6183. A.prototype.SolvePositionConstraints = function() {
  6184. return !1
  6185. };
  6186. Box2D.postDefs.push(function() {
  6187. Box2D.Dynamics.Joints.b2Joint.e_unknownJoint = 0;
  6188. Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint =
  6189. 1;
  6190. Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint = 2;
  6191. Box2D.Dynamics.Joints.b2Joint.e_distanceJoint = 3;
  6192. Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint = 4;
  6193. Box2D.Dynamics.Joints.b2Joint.e_mouseJoint = 5;
  6194. Box2D.Dynamics.Joints.b2Joint.e_gearJoint = 6;
  6195. Box2D.Dynamics.Joints.b2Joint.e_lineJoint = 7;
  6196. Box2D.Dynamics.Joints.b2Joint.e_weldJoint = 8;
  6197. Box2D.Dynamics.Joints.b2Joint.e_frictionJoint = 9;
  6198. Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit = 0;
  6199. Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit = 1;
  6200. Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit =
  6201. 2;
  6202. Box2D.Dynamics.Joints.b2Joint.e_equalLimits = 3
  6203. });
  6204. B.b2JointDef = function() {};
  6205. B.prototype.b2JointDef = function() {
  6206. this.type = A.e_unknownJoint;
  6207. this.bodyB = this.bodyA = this.userData = null;
  6208. this.collideConnected = !1
  6209. };
  6210. K.b2JointEdge = function() {};
  6211. Box2D.inherit(H, Box2D.Dynamics.Joints.b2Joint);
  6212. H.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6213. H.b2LineJoint = function() {
  6214. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6215. this.m_localAnchor1 = new e;
  6216. this.m_localAnchor2 = new e;
  6217. this.m_localXAxis1 = new e;
  6218. this.m_localYAxis1 =
  6219. new e;
  6220. this.m_axis = new e;
  6221. this.m_perp = new e;
  6222. this.m_K = new c;
  6223. this.m_impulse = new e
  6224. };
  6225. H.prototype.GetAnchorA = function() {
  6226. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  6227. };
  6228. H.prototype.GetAnchorB = function() {
  6229. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  6230. };
  6231. H.prototype.GetReactionForce = function(a) {
  6232. void 0 === a && (a = 0);
  6233. return new e(a * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x), a * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y))
  6234. };
  6235. H.prototype.GetReactionTorque = function(a) {
  6236. void 0 === a && (a = 0);
  6237. return a * this.m_impulse.y
  6238. };
  6239. H.prototype.GetJointTranslation = function() {
  6240. var a = this.m_bodyA,
  6241. b = this.m_bodyB,
  6242. c = a.GetWorldPoint(this.m_localAnchor1),
  6243. d = b.GetWorldPoint(this.m_localAnchor2),
  6244. b = d.x - c.x,
  6245. c = d.y - c.y,
  6246. a = a.GetWorldVector(this.m_localXAxis1);
  6247. return a.x * b + a.y * c
  6248. };
  6249. H.prototype.GetJointSpeed = function() {
  6250. var a = this.m_bodyA,
  6251. b = this.m_bodyB,
  6252. c;
  6253. c = a.m_xf.R;
  6254. var d = this.m_localAnchor1.x - a.m_sweep.localCenter.x,
  6255. e = this.m_localAnchor1.y - a.m_sweep.localCenter.y,
  6256. f = c.col1.x * d + c.col2.x * e,
  6257. e = c.col1.y * d + c.col2.y * e,
  6258. d = f;
  6259. c = b.m_xf.R;
  6260. var g = this.m_localAnchor2.x - b.m_sweep.localCenter.x,
  6261. h = this.m_localAnchor2.y - b.m_sweep.localCenter.y,
  6262. f = c.col1.x * g + c.col2.x * h,
  6263. h = c.col1.y * g + c.col2.y * h,
  6264. g = f;
  6265. c = b.m_sweep.c.x + g - (a.m_sweep.c.x + d);
  6266. var f = b.m_sweep.c.y + h - (a.m_sweep.c.y + e),
  6267. l = a.GetWorldVector(this.m_localXAxis1),
  6268. m = a.m_linearVelocity,
  6269. p = b.m_linearVelocity,
  6270. a = a.m_angularVelocity,
  6271. b = b.m_angularVelocity;
  6272. return c * -a * l.y + f * a * l.x + (l.x * (p.x + -b * h - m.x - -a * e) + l.y * (p.y + b * g - m.y - a * d))
  6273. };
  6274. H.prototype.IsLimitEnabled =
  6275. function() {
  6276. return this.m_enableLimit
  6277. };
  6278. H.prototype.EnableLimit = function(a) {
  6279. this.m_bodyA.SetAwake(!0);
  6280. this.m_bodyB.SetAwake(!0);
  6281. this.m_enableLimit = a
  6282. };
  6283. H.prototype.GetLowerLimit = function() {
  6284. return this.m_lowerTranslation
  6285. };
  6286. H.prototype.GetUpperLimit = function() {
  6287. return this.m_upperTranslation
  6288. };
  6289. H.prototype.SetLimits = function(a, b) {
  6290. void 0 === a && (a = 0);
  6291. void 0 === b && (b = 0);
  6292. this.m_bodyA.SetAwake(!0);
  6293. this.m_bodyB.SetAwake(!0);
  6294. this.m_lowerTranslation = a;
  6295. this.m_upperTranslation = b
  6296. };
  6297. H.prototype.IsMotorEnabled = function() {
  6298. return this.m_enableMotor
  6299. };
  6300. H.prototype.EnableMotor = function(a) {
  6301. this.m_bodyA.SetAwake(!0);
  6302. this.m_bodyB.SetAwake(!0);
  6303. this.m_enableMotor = a
  6304. };
  6305. H.prototype.SetMotorSpeed = function(a) {
  6306. void 0 === a && (a = 0);
  6307. this.m_bodyA.SetAwake(!0);
  6308. this.m_bodyB.SetAwake(!0);
  6309. this.m_motorSpeed = a
  6310. };
  6311. H.prototype.GetMotorSpeed = function() {
  6312. return this.m_motorSpeed
  6313. };
  6314. H.prototype.SetMaxMotorForce = function(a) {
  6315. void 0 === a && (a = 0);
  6316. this.m_bodyA.SetAwake(!0);
  6317. this.m_bodyB.SetAwake(!0);
  6318. this.m_maxMotorForce = a
  6319. };
  6320. H.prototype.GetMaxMotorForce = function() {
  6321. return this.m_maxMotorForce
  6322. };
  6323. H.prototype.GetMotorForce = function() {
  6324. return this.m_motorImpulse
  6325. };
  6326. H.prototype.b2LineJoint = function(a) {
  6327. this.__super.b2Joint.call(this, a);
  6328. this.m_localAnchor1.SetV(a.localAnchorA);
  6329. this.m_localAnchor2.SetV(a.localAnchorB);
  6330. this.m_localXAxis1.SetV(a.localAxisA);
  6331. this.m_localYAxis1.x = -this.m_localXAxis1.y;
  6332. this.m_localYAxis1.y = this.m_localXAxis1.x;
  6333. this.m_impulse.SetZero();
  6334. this.m_motorImpulse = this.m_motorMass = 0;
  6335. this.m_lowerTranslation = a.lowerTranslation;
  6336. this.m_upperTranslation = a.upperTranslation;
  6337. this.m_maxMotorForce =
  6338. a.maxMotorForce;
  6339. this.m_motorSpeed = a.motorSpeed;
  6340. this.m_enableLimit = a.enableLimit;
  6341. this.m_enableMotor = a.enableMotor;
  6342. this.m_limitState = A.e_inactiveLimit;
  6343. this.m_axis.SetZero();
  6344. this.m_perp.SetZero()
  6345. };
  6346. H.prototype.InitVelocityConstraints = function(b) {
  6347. var c = this.m_bodyA,
  6348. e = this.m_bodyB,
  6349. f, g;
  6350. this.m_localCenterA.SetV(c.GetLocalCenter());
  6351. this.m_localCenterB.SetV(e.GetLocalCenter());
  6352. var h = c.GetTransform();
  6353. e.GetTransform();
  6354. f = c.m_xf.R;
  6355. var l = this.m_localAnchor1.x - this.m_localCenterA.x,
  6356. m = this.m_localAnchor1.y - this.m_localCenterA.y;
  6357. g = f.col1.x * l + f.col2.x * m;
  6358. m = f.col1.y * l + f.col2.y * m;
  6359. l = g;
  6360. f = e.m_xf.R;
  6361. var p = this.m_localAnchor2.x - this.m_localCenterB.x,
  6362. q = this.m_localAnchor2.y - this.m_localCenterB.y;
  6363. g = f.col1.x * p + f.col2.x * q;
  6364. q = f.col1.y * p + f.col2.y * q;
  6365. p = g;
  6366. f = e.m_sweep.c.x + p - c.m_sweep.c.x - l;
  6367. g = e.m_sweep.c.y + q - c.m_sweep.c.y - m;
  6368. this.m_invMassA = c.m_invMass;
  6369. this.m_invMassB = e.m_invMass;
  6370. this.m_invIA = c.m_invI;
  6371. this.m_invIB = e.m_invI;
  6372. this.m_axis.SetV(d.MulMV(h.R, this.m_localXAxis1));
  6373. this.m_a1 = (f + l) * this.m_axis.y - (g + m) * this.m_axis.x;
  6374. this.m_a2 = p * this.m_axis.y -
  6375. q * this.m_axis.x;
  6376. this.m_motorMass = this.m_invMassA + this.m_invMassB + this.m_invIA * this.m_a1 * this.m_a1 + this.m_invIB * this.m_a2 * this.m_a2;
  6377. this.m_motorMass = this.m_motorMass > Number.MIN_VALUE ? 1 / this.m_motorMass : 0;
  6378. this.m_perp.SetV(d.MulMV(h.R, this.m_localYAxis1));
  6379. this.m_s1 = (f + l) * this.m_perp.y - (g + m) * this.m_perp.x;
  6380. this.m_s2 = p * this.m_perp.y - q * this.m_perp.x;
  6381. h = this.m_invMassA;
  6382. l = this.m_invMassB;
  6383. m = this.m_invIA;
  6384. p = this.m_invIB;
  6385. this.m_K.col1.x = h + l + m * this.m_s1 * this.m_s1 + p * this.m_s2 * this.m_s2;
  6386. this.m_K.col1.y = m * this.m_s1 *
  6387. this.m_a1 + p * this.m_s2 * this.m_a2;
  6388. this.m_K.col2.x = this.m_K.col1.y;
  6389. this.m_K.col2.y = h + l + m * this.m_a1 * this.m_a1 + p * this.m_a2 * this.m_a2;
  6390. this.m_enableLimit ? (f = this.m_axis.x * f + this.m_axis.y * g, d.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * a.b2_linearSlop ? this.m_limitState = A.e_equalLimits : f <= this.m_lowerTranslation ? this.m_limitState != A.e_atLowerLimit && (this.m_limitState = A.e_atLowerLimit, this.m_impulse.y = 0) : f >= this.m_upperTranslation ? this.m_limitState != A.e_atUpperLimit && (this.m_limitState = A.e_atUpperLimit,
  6391. this.m_impulse.y = 0) : (this.m_limitState = A.e_inactiveLimit, this.m_impulse.y = 0)) : this.m_limitState = A.e_inactiveLimit;
  6392. 0 == this.m_enableMotor && (this.m_motorImpulse = 0);
  6393. b.warmStarting ? (this.m_impulse.x *= b.dtRatio, this.m_impulse.y *= b.dtRatio, this.m_motorImpulse *= b.dtRatio, b = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x, f = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y, g = this.m_impulse.x * this.m_s1 + (this.m_motorImpulse + this.m_impulse.y) *
  6394. this.m_a1, h = this.m_impulse.x * this.m_s2 + (this.m_motorImpulse + this.m_impulse.y) * this.m_a2, c.m_linearVelocity.x -= this.m_invMassA * b, c.m_linearVelocity.y -= this.m_invMassA * f, c.m_angularVelocity -= this.m_invIA * g, e.m_linearVelocity.x += this.m_invMassB * b, e.m_linearVelocity.y += this.m_invMassB * f, e.m_angularVelocity += this.m_invIB * h) : (this.m_impulse.SetZero(), this.m_motorImpulse = 0)
  6395. };
  6396. H.prototype.SolveVelocityConstraints = function(a) {
  6397. var b = this.m_bodyA,
  6398. c = this.m_bodyB,
  6399. f = b.m_linearVelocity,
  6400. g = b.m_angularVelocity,
  6401. h = c.m_linearVelocity,
  6402. l = c.m_angularVelocity,
  6403. m, p, q, y;
  6404. this.m_enableMotor && this.m_limitState != A.e_equalLimits && (y = this.m_motorMass * (this.m_motorSpeed - (this.m_axis.x * (h.x - f.x) + this.m_axis.y * (h.y - f.y) + this.m_a2 * l - this.m_a1 * g)), m = this.m_motorImpulse, p = a.dt * this.m_maxMotorForce, this.m_motorImpulse = d.Clamp(this.m_motorImpulse + y, -p, p), y = this.m_motorImpulse - m, m = y * this.m_axis.x, p = y * this.m_axis.y, q = y * this.m_a1, y *= this.m_a2, f.x -= this.m_invMassA * m, f.y -= this.m_invMassA * p, g -= this.m_invIA * q, h.x += this.m_invMassB * m, h.y += this.m_invMassB *
  6405. p, l += this.m_invIB * y);
  6406. p = this.m_perp.x * (h.x - f.x) + this.m_perp.y * (h.y - f.y) + this.m_s2 * l - this.m_s1 * g;
  6407. this.m_enableLimit && this.m_limitState != A.e_inactiveLimit ? (q = this.m_axis.x * (h.x - f.x) + this.m_axis.y * (h.y - f.y) + this.m_a2 * l - this.m_a1 * g, m = this.m_impulse.Copy(), a = this.m_K.Solve(new e, -p, -q), this.m_impulse.Add(a), this.m_limitState == A.e_atLowerLimit ? this.m_impulse.y = d.Max(this.m_impulse.y, 0) : this.m_limitState == A.e_atUpperLimit && (this.m_impulse.y = d.Min(this.m_impulse.y, 0)), p = -p - (this.m_impulse.y - m.y) * this.m_K.col2.x,
  6408. q = 0 != this.m_K.col1.x ? p / this.m_K.col1.x + m.x : m.x, this.m_impulse.x = q, a.x = this.m_impulse.x - m.x, a.y = this.m_impulse.y - m.y, m = a.x * this.m_perp.x + a.y * this.m_axis.x, p = a.x * this.m_perp.y + a.y * this.m_axis.y, q = a.x * this.m_s1 + a.y * this.m_a1, y = a.x * this.m_s2 + a.y * this.m_a2) : (a = 0 != this.m_K.col1.x ? -p / this.m_K.col1.x : 0, this.m_impulse.x += a, m = a * this.m_perp.x, p = a * this.m_perp.y, q = a * this.m_s1, y = a * this.m_s2);
  6409. f.x -= this.m_invMassA * m;
  6410. f.y -= this.m_invMassA * p;
  6411. g -= this.m_invIA * q;
  6412. h.x += this.m_invMassB * m;
  6413. h.y += this.m_invMassB * p;
  6414. l += this.m_invIB *
  6415. y;
  6416. b.m_linearVelocity.SetV(f);
  6417. b.m_angularVelocity = g;
  6418. c.m_linearVelocity.SetV(h);
  6419. c.m_angularVelocity = l
  6420. };
  6421. H.prototype.SolvePositionConstraints = function() {
  6422. var b = this.m_bodyA,
  6423. f = this.m_bodyB,
  6424. g = b.m_sweep.c,
  6425. h = b.m_sweep.a,
  6426. l = f.m_sweep.c,
  6427. m = f.m_sweep.a,
  6428. p, q, y, A, B, H = 0,
  6429. E;
  6430. y = !1;
  6431. var K = 0,
  6432. M = c.FromAngle(h);
  6433. A = c.FromAngle(m);
  6434. p = M;
  6435. E = this.m_localAnchor1.x - this.m_localCenterA.x;
  6436. var aa = this.m_localAnchor1.y - this.m_localCenterA.y;
  6437. q = p.col1.x * E + p.col2.x * aa;
  6438. aa = p.col1.y * E + p.col2.y * aa;
  6439. E = q;
  6440. p = A;
  6441. A = this.m_localAnchor2.x - this.m_localCenterB.x;
  6442. B = this.m_localAnchor2.y - this.m_localCenterB.y;
  6443. q = p.col1.x * A + p.col2.x * B;
  6444. B = p.col1.y * A + p.col2.y * B;
  6445. A = q;
  6446. p = l.x + A - g.x - E;
  6447. q = l.y + B - g.y - aa;
  6448. if (this.m_enableLimit) {
  6449. this.m_axis = d.MulMV(M, this.m_localXAxis1);
  6450. this.m_a1 = (p + E) * this.m_axis.y - (q + aa) * this.m_axis.x;
  6451. this.m_a2 = A * this.m_axis.y - B * this.m_axis.x;
  6452. var Yb = this.m_axis.x * p + this.m_axis.y * q;
  6453. d.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * a.b2_linearSlop ? (K = d.Clamp(Yb, -a.b2_maxLinearCorrection, a.b2_maxLinearCorrection), H = d.Abs(Yb), y = !0) : Yb <= this.m_lowerTranslation ?
  6454. (K = d.Clamp(Yb - this.m_lowerTranslation + a.b2_linearSlop, -a.b2_maxLinearCorrection, 0), H = this.m_lowerTranslation - Yb, y = !0) : Yb >= this.m_upperTranslation && (K = d.Clamp(Yb - this.m_upperTranslation + a.b2_linearSlop, 0, a.b2_maxLinearCorrection), H = Yb - this.m_upperTranslation, y = !0)
  6455. }
  6456. this.m_perp = d.MulMV(M, this.m_localYAxis1);
  6457. this.m_s1 = (p + E) * this.m_perp.y - (q + aa) * this.m_perp.x;
  6458. this.m_s2 = A * this.m_perp.y - B * this.m_perp.x;
  6459. M = new e;
  6460. aa = this.m_perp.x * p + this.m_perp.y * q;
  6461. H = d.Max(H, d.Abs(aa));
  6462. E = 0;
  6463. y ? (y = this.m_invMassA, A = this.m_invMassB,
  6464. B = this.m_invIA, p = this.m_invIB, this.m_K.col1.x = y + A + B * this.m_s1 * this.m_s1 + p * this.m_s2 * this.m_s2, this.m_K.col1.y = B * this.m_s1 * this.m_a1 + p * this.m_s2 * this.m_a2, this.m_K.col2.x = this.m_K.col1.y, this.m_K.col2.y = y + A + B * this.m_a1 * this.m_a1 + p * this.m_a2 * this.m_a2, this.m_K.Solve(M, -aa, -K)) : (y = this.m_invMassA, A = this.m_invMassB, B = this.m_invIA, p = this.m_invIB, K = y + A + B * this.m_s1 * this.m_s1 + p * this.m_s2 * this.m_s2, M.x = 0 != K ? -aa / K : 0, M.y = 0);
  6465. K = M.x * this.m_perp.x + M.y * this.m_axis.x;
  6466. y = M.x * this.m_perp.y + M.y * this.m_axis.y;
  6467. aa = M.x * this.m_s1 +
  6468. M.y * this.m_a1;
  6469. M = M.x * this.m_s2 + M.y * this.m_a2;
  6470. g.x -= this.m_invMassA * K;
  6471. g.y -= this.m_invMassA * y;
  6472. h -= this.m_invIA * aa;
  6473. l.x += this.m_invMassB * K;
  6474. l.y += this.m_invMassB * y;
  6475. m += this.m_invIB * M;
  6476. b.m_sweep.a = h;
  6477. f.m_sweep.a = m;
  6478. b.SynchronizeTransform();
  6479. f.SynchronizeTransform();
  6480. return H <= a.b2_linearSlop && E <= a.b2_angularSlop
  6481. };
  6482. Box2D.inherit(E, Box2D.Dynamics.Joints.b2JointDef);
  6483. E.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  6484. E.b2LineJointDef = function() {
  6485. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  6486. this.localAnchorA = new e;
  6487. this.localAnchorB = new e;
  6488. this.localAxisA = new e
  6489. };
  6490. E.prototype.b2LineJointDef = function() {
  6491. this.__super.b2JointDef.call(this);
  6492. this.type = A.e_lineJoint;
  6493. this.localAxisA.Set(1, 0);
  6494. this.enableLimit = !1;
  6495. this.upperTranslation = this.lowerTranslation = 0;
  6496. this.enableMotor = !1;
  6497. this.motorSpeed = this.maxMotorForce = 0
  6498. };
  6499. E.prototype.Initialize = function(a, b, c, d) {
  6500. this.bodyA = a;
  6501. this.bodyB = b;
  6502. this.localAnchorA = this.bodyA.GetLocalPoint(c);
  6503. this.localAnchorB = this.bodyB.GetLocalPoint(c);
  6504. this.localAxisA = this.bodyA.GetLocalVector(d)
  6505. };
  6506. Box2D.inherit(M, Box2D.Dynamics.Joints.b2Joint);
  6507. M.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6508. M.b2MouseJoint = function() {
  6509. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6510. this.K = new c;
  6511. this.K1 = new c;
  6512. this.K2 = new c;
  6513. this.m_localAnchor = new e;
  6514. this.m_target = new e;
  6515. this.m_impulse = new e;
  6516. this.m_mass = new c;
  6517. this.m_C = new e
  6518. };
  6519. M.prototype.GetAnchorA = function() {
  6520. return this.m_target
  6521. };
  6522. M.prototype.GetAnchorB = function() {
  6523. return this.m_bodyB.GetWorldPoint(this.m_localAnchor)
  6524. };
  6525. M.prototype.GetReactionForce =
  6526. function(a) {
  6527. void 0 === a && (a = 0);
  6528. return new e(a * this.m_impulse.x, a * this.m_impulse.y)
  6529. };
  6530. M.prototype.GetReactionTorque = function() {
  6531. return 0
  6532. };
  6533. M.prototype.GetTarget = function() {
  6534. return this.m_target
  6535. };
  6536. M.prototype.SetTarget = function(a) {
  6537. 0 == this.m_bodyB.IsAwake() && this.m_bodyB.SetAwake(!0);
  6538. this.m_target = a
  6539. };
  6540. M.prototype.GetMaxForce = function() {
  6541. return this.m_maxForce
  6542. };
  6543. M.prototype.SetMaxForce = function(a) {
  6544. void 0 === a && (a = 0);
  6545. this.m_maxForce = a
  6546. };
  6547. M.prototype.GetFrequency = function() {
  6548. return this.m_frequencyHz
  6549. };
  6550. M.prototype.SetFrequency =
  6551. function(a) {
  6552. void 0 === a && (a = 0);
  6553. this.m_frequencyHz = a
  6554. };
  6555. M.prototype.GetDampingRatio = function() {
  6556. return this.m_dampingRatio
  6557. };
  6558. M.prototype.SetDampingRatio = function(a) {
  6559. void 0 === a && (a = 0);
  6560. this.m_dampingRatio = a
  6561. };
  6562. M.prototype.b2MouseJoint = function(a) {
  6563. this.__super.b2Joint.call(this, a);
  6564. this.m_target.SetV(a.target);
  6565. var b = this.m_target.x - this.m_bodyB.m_xf.position.x,
  6566. c = this.m_target.y - this.m_bodyB.m_xf.position.y,
  6567. d = this.m_bodyB.m_xf.R;
  6568. this.m_localAnchor.x = b * d.col1.x + c * d.col1.y;
  6569. this.m_localAnchor.y = b * d.col2.x + c * d.col2.y;
  6570. this.m_maxForce = a.maxForce;
  6571. this.m_impulse.SetZero();
  6572. this.m_frequencyHz = a.frequencyHz;
  6573. this.m_dampingRatio = a.dampingRatio;
  6574. this.m_gamma = this.m_beta = 0
  6575. };
  6576. M.prototype.InitVelocityConstraints = function(a) {
  6577. var b = this.m_bodyB,
  6578. c = b.GetMass(),
  6579. d = 2 * Math.PI * this.m_frequencyHz,
  6580. e = c * d * d;
  6581. this.m_gamma = a.dt * (2 * c * this.m_dampingRatio * d + a.dt * e);
  6582. this.m_gamma = 0 != this.m_gamma ? 1 / this.m_gamma : 0;
  6583. this.m_beta = a.dt * e * this.m_gamma;
  6584. var e = b.m_xf.R,
  6585. c = this.m_localAnchor.x - b.m_sweep.localCenter.x,
  6586. d = this.m_localAnchor.y - b.m_sweep.localCenter.y,
  6587. f = e.col1.x * c + e.col2.x * d,
  6588. d = e.col1.y * c + e.col2.y * d,
  6589. c = f,
  6590. e = b.m_invMass,
  6591. f = b.m_invI;
  6592. this.K1.col1.x = e;
  6593. this.K1.col2.x = 0;
  6594. this.K1.col1.y = 0;
  6595. this.K1.col2.y = e;
  6596. this.K2.col1.x = f * d * d;
  6597. this.K2.col2.x = -f * c * d;
  6598. this.K2.col1.y = -f * c * d;
  6599. this.K2.col2.y = f * c * c;
  6600. this.K.SetM(this.K1);
  6601. this.K.AddM(this.K2);
  6602. this.K.col1.x += this.m_gamma;
  6603. this.K.col2.y += this.m_gamma;
  6604. this.K.GetInverse(this.m_mass);
  6605. this.m_C.x = b.m_sweep.c.x + c - this.m_target.x;
  6606. this.m_C.y = b.m_sweep.c.y + d - this.m_target.y;
  6607. b.m_angularVelocity *= .98;
  6608. this.m_impulse.x *= a.dtRatio;
  6609. this.m_impulse.y *=
  6610. a.dtRatio;
  6611. b.m_linearVelocity.x += e * this.m_impulse.x;
  6612. b.m_linearVelocity.y += e * this.m_impulse.y;
  6613. b.m_angularVelocity += f * (c * this.m_impulse.y - d * this.m_impulse.x)
  6614. };
  6615. M.prototype.SolveVelocityConstraints = function(a) {
  6616. var b = this.m_bodyB,
  6617. c, d, e;
  6618. c = b.m_xf.R;
  6619. var f = this.m_localAnchor.x - b.m_sweep.localCenter.x,
  6620. g = this.m_localAnchor.y - b.m_sweep.localCenter.y;
  6621. d = c.col1.x * f + c.col2.x * g;
  6622. g = c.col1.y * f + c.col2.y * g;
  6623. f = d;
  6624. d = b.m_linearVelocity.x + -b.m_angularVelocity * g;
  6625. var h = b.m_linearVelocity.y + b.m_angularVelocity * f;
  6626. c = this.m_mass;
  6627. d =
  6628. d + this.m_beta * this.m_C.x + this.m_gamma * this.m_impulse.x;
  6629. e = h + this.m_beta * this.m_C.y + this.m_gamma * this.m_impulse.y;
  6630. h = -(c.col1.x * d + c.col2.x * e);
  6631. e = -(c.col1.y * d + c.col2.y * e);
  6632. c = this.m_impulse.x;
  6633. d = this.m_impulse.y;
  6634. this.m_impulse.x += h;
  6635. this.m_impulse.y += e;
  6636. a = a.dt * this.m_maxForce;
  6637. this.m_impulse.LengthSquared() > a * a && this.m_impulse.Multiply(a / this.m_impulse.Length());
  6638. h = this.m_impulse.x - c;
  6639. e = this.m_impulse.y - d;
  6640. b.m_linearVelocity.x += b.m_invMass * h;
  6641. b.m_linearVelocity.y += b.m_invMass * e;
  6642. b.m_angularVelocity += b.m_invI * (f *
  6643. e - g * h)
  6644. };
  6645. M.prototype.SolvePositionConstraints = function() {
  6646. return !0
  6647. };
  6648. Box2D.inherit(Xb, Box2D.Dynamics.Joints.b2JointDef);
  6649. Xb.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  6650. Xb.b2MouseJointDef = function() {
  6651. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  6652. this.target = new e
  6653. };
  6654. Xb.prototype.b2MouseJointDef = function() {
  6655. this.__super.b2JointDef.call(this);
  6656. this.type = A.e_mouseJoint;
  6657. this.maxForce = 0;
  6658. this.frequencyHz = 5;
  6659. this.dampingRatio = .7
  6660. };
  6661. Box2D.inherit(Zb, Box2D.Dynamics.Joints.b2Joint);
  6662. Zb.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6663. Zb.b2PrismaticJoint = function() {
  6664. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6665. this.m_localAnchor1 = new e;
  6666. this.m_localAnchor2 = new e;
  6667. this.m_localXAxis1 = new e;
  6668. this.m_localYAxis1 = new e;
  6669. this.m_axis = new e;
  6670. this.m_perp = new e;
  6671. this.m_K = new b;
  6672. this.m_impulse = new f
  6673. };
  6674. Zb.prototype.GetAnchorA = function() {
  6675. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  6676. };
  6677. Zb.prototype.GetAnchorB = function() {
  6678. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  6679. };
  6680. Zb.prototype.GetReactionForce = function(a) {
  6681. void 0 === a && (a = 0);
  6682. return new e(a * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x), a * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y))
  6683. };
  6684. Zb.prototype.GetReactionTorque = function(a) {
  6685. void 0 === a && (a = 0);
  6686. return a * this.m_impulse.y
  6687. };
  6688. Zb.prototype.GetJointTranslation = function() {
  6689. var a = this.m_bodyA,
  6690. b = this.m_bodyB,
  6691. c = a.GetWorldPoint(this.m_localAnchor1),
  6692. d = b.GetWorldPoint(this.m_localAnchor2),
  6693. b = d.x -
  6694. c.x,
  6695. c = d.y - c.y,
  6696. a = a.GetWorldVector(this.m_localXAxis1);
  6697. return a.x * b + a.y * c
  6698. };
  6699. Zb.prototype.GetJointSpeed = function() {
  6700. var a = this.m_bodyA,
  6701. b = this.m_bodyB,
  6702. c;
  6703. c = a.m_xf.R;
  6704. var d = this.m_localAnchor1.x - a.m_sweep.localCenter.x,
  6705. e = this.m_localAnchor1.y - a.m_sweep.localCenter.y,
  6706. f = c.col1.x * d + c.col2.x * e,
  6707. e = c.col1.y * d + c.col2.y * e,
  6708. d = f;
  6709. c = b.m_xf.R;
  6710. var g = this.m_localAnchor2.x - b.m_sweep.localCenter.x,
  6711. h = this.m_localAnchor2.y - b.m_sweep.localCenter.y,
  6712. f = c.col1.x * g + c.col2.x * h,
  6713. h = c.col1.y * g + c.col2.y * h,
  6714. g = f;
  6715. c = b.m_sweep.c.x + g - (a.m_sweep.c.x +
  6716. d);
  6717. var f = b.m_sweep.c.y + h - (a.m_sweep.c.y + e),
  6718. l = a.GetWorldVector(this.m_localXAxis1),
  6719. m = a.m_linearVelocity,
  6720. p = b.m_linearVelocity,
  6721. a = a.m_angularVelocity,
  6722. b = b.m_angularVelocity;
  6723. return c * -a * l.y + f * a * l.x + (l.x * (p.x + -b * h - m.x - -a * e) + l.y * (p.y + b * g - m.y - a * d))
  6724. };
  6725. Zb.prototype.IsLimitEnabled = function() {
  6726. return this.m_enableLimit
  6727. };
  6728. Zb.prototype.EnableLimit = function(a) {
  6729. this.m_bodyA.SetAwake(!0);
  6730. this.m_bodyB.SetAwake(!0);
  6731. this.m_enableLimit = a
  6732. };
  6733. Zb.prototype.GetLowerLimit = function() {
  6734. return this.m_lowerTranslation
  6735. };
  6736. Zb.prototype.GetUpperLimit =
  6737. function() {
  6738. return this.m_upperTranslation
  6739. };
  6740. Zb.prototype.SetLimits = function(a, b) {
  6741. void 0 === a && (a = 0);
  6742. void 0 === b && (b = 0);
  6743. this.m_bodyA.SetAwake(!0);
  6744. this.m_bodyB.SetAwake(!0);
  6745. this.m_lowerTranslation = a;
  6746. this.m_upperTranslation = b
  6747. };
  6748. Zb.prototype.IsMotorEnabled = function() {
  6749. return this.m_enableMotor
  6750. };
  6751. Zb.prototype.EnableMotor = function(a) {
  6752. this.m_bodyA.SetAwake(!0);
  6753. this.m_bodyB.SetAwake(!0);
  6754. this.m_enableMotor = a
  6755. };
  6756. Zb.prototype.SetMotorSpeed = function(a) {
  6757. void 0 === a && (a = 0);
  6758. this.m_bodyA.SetAwake(!0);
  6759. this.m_bodyB.SetAwake(!0);
  6760. this.m_motorSpeed = a
  6761. };
  6762. Zb.prototype.GetMotorSpeed = function() {
  6763. return this.m_motorSpeed
  6764. };
  6765. Zb.prototype.SetMaxMotorForce = function(a) {
  6766. void 0 === a && (a = 0);
  6767. this.m_bodyA.SetAwake(!0);
  6768. this.m_bodyB.SetAwake(!0);
  6769. this.m_maxMotorForce = a
  6770. };
  6771. Zb.prototype.GetMotorForce = function() {
  6772. return this.m_motorImpulse
  6773. };
  6774. Zb.prototype.b2PrismaticJoint = function(a) {
  6775. this.__super.b2Joint.call(this, a);
  6776. this.m_localAnchor1.SetV(a.localAnchorA);
  6777. this.m_localAnchor2.SetV(a.localAnchorB);
  6778. this.m_localXAxis1.SetV(a.localAxisA);
  6779. this.m_localYAxis1.x = -this.m_localXAxis1.y;
  6780. this.m_localYAxis1.y = this.m_localXAxis1.x;
  6781. this.m_refAngle = a.referenceAngle;
  6782. this.m_impulse.SetZero();
  6783. this.m_motorImpulse = this.m_motorMass = 0;
  6784. this.m_lowerTranslation = a.lowerTranslation;
  6785. this.m_upperTranslation = a.upperTranslation;
  6786. this.m_maxMotorForce = a.maxMotorForce;
  6787. this.m_motorSpeed = a.motorSpeed;
  6788. this.m_enableLimit = a.enableLimit;
  6789. this.m_enableMotor = a.enableMotor;
  6790. this.m_limitState = A.e_inactiveLimit;
  6791. this.m_axis.SetZero();
  6792. this.m_perp.SetZero()
  6793. };
  6794. Zb.prototype.InitVelocityConstraints = function(b) {
  6795. var c =
  6796. this.m_bodyA,
  6797. e = this.m_bodyB,
  6798. f, g;
  6799. this.m_localCenterA.SetV(c.GetLocalCenter());
  6800. this.m_localCenterB.SetV(e.GetLocalCenter());
  6801. var h = c.GetTransform();
  6802. e.GetTransform();
  6803. f = c.m_xf.R;
  6804. var l = this.m_localAnchor1.x - this.m_localCenterA.x,
  6805. m = this.m_localAnchor1.y - this.m_localCenterA.y;
  6806. g = f.col1.x * l + f.col2.x * m;
  6807. m = f.col1.y * l + f.col2.y * m;
  6808. l = g;
  6809. f = e.m_xf.R;
  6810. var p = this.m_localAnchor2.x - this.m_localCenterB.x,
  6811. q = this.m_localAnchor2.y - this.m_localCenterB.y;
  6812. g = f.col1.x * p + f.col2.x * q;
  6813. q = f.col1.y * p + f.col2.y * q;
  6814. p = g;
  6815. f = e.m_sweep.c.x + p - c.m_sweep.c.x -
  6816. l;
  6817. g = e.m_sweep.c.y + q - c.m_sweep.c.y - m;
  6818. this.m_invMassA = c.m_invMass;
  6819. this.m_invMassB = e.m_invMass;
  6820. this.m_invIA = c.m_invI;
  6821. this.m_invIB = e.m_invI;
  6822. this.m_axis.SetV(d.MulMV(h.R, this.m_localXAxis1));
  6823. this.m_a1 = (f + l) * this.m_axis.y - (g + m) * this.m_axis.x;
  6824. this.m_a2 = p * this.m_axis.y - q * this.m_axis.x;
  6825. this.m_motorMass = this.m_invMassA + this.m_invMassB + this.m_invIA * this.m_a1 * this.m_a1 + this.m_invIB * this.m_a2 * this.m_a2;
  6826. this.m_motorMass > Number.MIN_VALUE && (this.m_motorMass = 1 / this.m_motorMass);
  6827. this.m_perp.SetV(d.MulMV(h.R, this.m_localYAxis1));
  6828. this.m_s1 = (f + l) * this.m_perp.y - (g + m) * this.m_perp.x;
  6829. this.m_s2 = p * this.m_perp.y - q * this.m_perp.x;
  6830. h = this.m_invMassA;
  6831. l = this.m_invMassB;
  6832. m = this.m_invIA;
  6833. p = this.m_invIB;
  6834. this.m_K.col1.x = h + l + m * this.m_s1 * this.m_s1 + p * this.m_s2 * this.m_s2;
  6835. this.m_K.col1.y = m * this.m_s1 + p * this.m_s2;
  6836. this.m_K.col1.z = m * this.m_s1 * this.m_a1 + p * this.m_s2 * this.m_a2;
  6837. this.m_K.col2.x = this.m_K.col1.y;
  6838. this.m_K.col2.y = m + p;
  6839. this.m_K.col2.z = m * this.m_a1 + p * this.m_a2;
  6840. this.m_K.col3.x = this.m_K.col1.z;
  6841. this.m_K.col3.y = this.m_K.col2.z;
  6842. this.m_K.col3.z = h + l + m * this.m_a1 *
  6843. this.m_a1 + p * this.m_a2 * this.m_a2;
  6844. this.m_enableLimit ? (f = this.m_axis.x * f + this.m_axis.y * g, d.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * a.b2_linearSlop ? this.m_limitState = A.e_equalLimits : f <= this.m_lowerTranslation ? this.m_limitState != A.e_atLowerLimit && (this.m_limitState = A.e_atLowerLimit, this.m_impulse.z = 0) : f >= this.m_upperTranslation ? this.m_limitState != A.e_atUpperLimit && (this.m_limitState = A.e_atUpperLimit, this.m_impulse.z = 0) : (this.m_limitState = A.e_inactiveLimit, this.m_impulse.z = 0)) : this.m_limitState =
  6845. A.e_inactiveLimit;
  6846. 0 == this.m_enableMotor && (this.m_motorImpulse = 0);
  6847. b.warmStarting ? (this.m_impulse.x *= b.dtRatio, this.m_impulse.y *= b.dtRatio, this.m_motorImpulse *= b.dtRatio, b = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x, f = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y, g = this.m_impulse.x * this.m_s1 + this.m_impulse.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_a1, h = this.m_impulse.x * this.m_s2 + this.m_impulse.y + (this.m_motorImpulse +
  6848. this.m_impulse.z) * this.m_a2, c.m_linearVelocity.x -= this.m_invMassA * b, c.m_linearVelocity.y -= this.m_invMassA * f, c.m_angularVelocity -= this.m_invIA * g, e.m_linearVelocity.x += this.m_invMassB * b, e.m_linearVelocity.y += this.m_invMassB * f, e.m_angularVelocity += this.m_invIB * h) : (this.m_impulse.SetZero(), this.m_motorImpulse = 0)
  6849. };
  6850. Zb.prototype.SolveVelocityConstraints = function(a) {
  6851. var b = this.m_bodyA,
  6852. c = this.m_bodyB,
  6853. g = b.m_linearVelocity,
  6854. h = b.m_angularVelocity,
  6855. l = c.m_linearVelocity,
  6856. m = c.m_angularVelocity,
  6857. p, q, y, B;
  6858. this.m_enableMotor &&
  6859. this.m_limitState != A.e_equalLimits && (B = this.m_motorMass * (this.m_motorSpeed - (this.m_axis.x * (l.x - g.x) + this.m_axis.y * (l.y - g.y) + this.m_a2 * m - this.m_a1 * h)), p = this.m_motorImpulse, a = a.dt * this.m_maxMotorForce, this.m_motorImpulse = d.Clamp(this.m_motorImpulse + B, -a, a), B = this.m_motorImpulse - p, p = B * this.m_axis.x, q = B * this.m_axis.y, y = B * this.m_a1, B *= this.m_a2, g.x -= this.m_invMassA * p, g.y -= this.m_invMassA * q, h -= this.m_invIA * y, l.x += this.m_invMassB * p, l.y += this.m_invMassB * q, m += this.m_invIB * B);
  6860. y = this.m_perp.x * (l.x - g.x) + this.m_perp.y *
  6861. (l.y - g.y) + this.m_s2 * m - this.m_s1 * h;
  6862. q = m - h;
  6863. this.m_enableLimit && this.m_limitState != A.e_inactiveLimit ? (a = this.m_axis.x * (l.x - g.x) + this.m_axis.y * (l.y - g.y) + this.m_a2 * m - this.m_a1 * h, p = this.m_impulse.Copy(), a = this.m_K.Solve33(new f, -y, -q, -a), this.m_impulse.Add(a), this.m_limitState == A.e_atLowerLimit ? this.m_impulse.z = d.Max(this.m_impulse.z, 0) : this.m_limitState == A.e_atUpperLimit && (this.m_impulse.z = d.Min(this.m_impulse.z, 0)), y = -y - (this.m_impulse.z - p.z) * this.m_K.col3.x, q = -q - (this.m_impulse.z - p.z) * this.m_K.col3.y,
  6864. q = this.m_K.Solve22(new e, y, q), q.x += p.x, q.y += p.y, this.m_impulse.x = q.x, this.m_impulse.y = q.y, a.x = this.m_impulse.x - p.x, a.y = this.m_impulse.y - p.y, a.z = this.m_impulse.z - p.z, p = a.x * this.m_perp.x + a.z * this.m_axis.x, q = a.x * this.m_perp.y + a.z * this.m_axis.y, y = a.x * this.m_s1 + a.y + a.z * this.m_a1, B = a.x * this.m_s2 + a.y + a.z * this.m_a2) : (a = this.m_K.Solve22(new e, -y, -q), this.m_impulse.x += a.x, this.m_impulse.y += a.y, p = a.x * this.m_perp.x, q = a.x * this.m_perp.y, y = a.x * this.m_s1 + a.y, B = a.x * this.m_s2 + a.y);
  6865. g.x -= this.m_invMassA * p;
  6866. g.y -= this.m_invMassA *
  6867. q;
  6868. h -= this.m_invIA * y;
  6869. l.x += this.m_invMassB * p;
  6870. l.y += this.m_invMassB * q;
  6871. m += this.m_invIB * B;
  6872. b.m_linearVelocity.SetV(g);
  6873. b.m_angularVelocity = h;
  6874. c.m_linearVelocity.SetV(l);
  6875. c.m_angularVelocity = m
  6876. };
  6877. Zb.prototype.SolvePositionConstraints = function() {
  6878. var b = this.m_bodyA,
  6879. g = this.m_bodyB,
  6880. h = b.m_sweep.c,
  6881. l = b.m_sweep.a,
  6882. m = g.m_sweep.c,
  6883. p = g.m_sweep.a,
  6884. q, y, A, B, H = 0,
  6885. E;
  6886. A = !1;
  6887. var K = 0,
  6888. M = c.FromAngle(l),
  6889. aa = c.FromAngle(p);
  6890. q = M;
  6891. E = this.m_localAnchor1.x - this.m_localCenterA.x;
  6892. var Yb = this.m_localAnchor1.y - this.m_localCenterA.y;
  6893. y = q.col1.x * E + q.col2.x *
  6894. Yb;
  6895. Yb = q.col1.y * E + q.col2.y * Yb;
  6896. E = y;
  6897. q = aa;
  6898. aa = this.m_localAnchor2.x - this.m_localCenterB.x;
  6899. B = this.m_localAnchor2.y - this.m_localCenterB.y;
  6900. y = q.col1.x * aa + q.col2.x * B;
  6901. B = q.col1.y * aa + q.col2.y * B;
  6902. aa = y;
  6903. q = m.x + aa - h.x - E;
  6904. y = m.y + B - h.y - Yb;
  6905. if (this.m_enableLimit) {
  6906. this.m_axis = d.MulMV(M, this.m_localXAxis1);
  6907. this.m_a1 = (q + E) * this.m_axis.y - (y + Yb) * this.m_axis.x;
  6908. this.m_a2 = aa * this.m_axis.y - B * this.m_axis.x;
  6909. var Xb = this.m_axis.x * q + this.m_axis.y * y;
  6910. d.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * a.b2_linearSlop ? (K = d.Clamp(Xb, -a.b2_maxLinearCorrection, a.b2_maxLinearCorrection), H = d.Abs(Xb), A = !0) : Xb <= this.m_lowerTranslation ? (K = d.Clamp(Xb - this.m_lowerTranslation + a.b2_linearSlop, -a.b2_maxLinearCorrection, 0), H = this.m_lowerTranslation - Xb, A = !0) : Xb >= this.m_upperTranslation && (K = d.Clamp(Xb - this.m_upperTranslation + a.b2_linearSlop, 0, a.b2_maxLinearCorrection), H = Xb - this.m_upperTranslation, A = !0)
  6911. }
  6912. this.m_perp = d.MulMV(M, this.m_localYAxis1);
  6913. this.m_s1 = (q + E) * this.m_perp.y - (y + Yb) * this.m_perp.x;
  6914. this.m_s2 = aa * this.m_perp.y - B * this.m_perp.x;
  6915. M = new f;
  6916. Yb = this.m_perp.x * q + this.m_perp.y * y;
  6917. aa = p - l - this.m_refAngle;
  6918. H = d.Max(H, d.Abs(Yb));
  6919. E = d.Abs(aa);
  6920. A ? (A = this.m_invMassA, B = this.m_invMassB, q = this.m_invIA, y = this.m_invIB, this.m_K.col1.x = A + B + q * this.m_s1 * this.m_s1 + y * this.m_s2 * this.m_s2, this.m_K.col1.y = q * this.m_s1 + y * this.m_s2, this.m_K.col1.z = q * this.m_s1 * this.m_a1 + y * this.m_s2 * this.m_a2, this.m_K.col2.x = this.m_K.col1.y, this.m_K.col2.y = q + y, this.m_K.col2.z = q * this.m_a1 + y * this.m_a2, this.m_K.col3.x = this.m_K.col1.z, this.m_K.col3.y = this.m_K.col2.z, this.m_K.col3.z = A + B + q *
  6921. this.m_a1 * this.m_a1 + y * this.m_a2 * this.m_a2, this.m_K.Solve33(M, -Yb, -aa, -K)) : (A = this.m_invMassA, B = this.m_invMassB, q = this.m_invIA, y = this.m_invIB, K = q * this.m_s1 + y * this.m_s2, Xb = q + y, this.m_K.col1.Set(A + B + q * this.m_s1 * this.m_s1 + y * this.m_s2 * this.m_s2, K, 0), this.m_K.col2.Set(K, Xb, 0), K = this.m_K.Solve22(new e, -Yb, -aa), M.x = K.x, M.y = K.y, M.z = 0);
  6922. K = M.x * this.m_perp.x + M.z * this.m_axis.x;
  6923. A = M.x * this.m_perp.y + M.z * this.m_axis.y;
  6924. Yb = M.x * this.m_s1 + M.y + M.z * this.m_a1;
  6925. M = M.x * this.m_s2 + M.y + M.z * this.m_a2;
  6926. h.x -= this.m_invMassA * K;
  6927. h.y -=
  6928. this.m_invMassA * A;
  6929. l -= this.m_invIA * Yb;
  6930. m.x += this.m_invMassB * K;
  6931. m.y += this.m_invMassB * A;
  6932. p += this.m_invIB * M;
  6933. b.m_sweep.a = l;
  6934. g.m_sweep.a = p;
  6935. b.SynchronizeTransform();
  6936. g.SynchronizeTransform();
  6937. return H <= a.b2_linearSlop && E <= a.b2_angularSlop
  6938. };
  6939. Box2D.inherit(aa, Box2D.Dynamics.Joints.b2JointDef);
  6940. aa.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  6941. aa.b2PrismaticJointDef = function() {
  6942. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  6943. this.localAnchorA = new e;
  6944. this.localAnchorB = new e;
  6945. this.localAxisA =
  6946. new e
  6947. };
  6948. aa.prototype.b2PrismaticJointDef = function() {
  6949. this.__super.b2JointDef.call(this);
  6950. this.type = A.e_prismaticJoint;
  6951. this.localAxisA.Set(1, 0);
  6952. this.referenceAngle = 0;
  6953. this.enableLimit = !1;
  6954. this.upperTranslation = this.lowerTranslation = 0;
  6955. this.enableMotor = !1;
  6956. this.motorSpeed = this.maxMotorForce = 0
  6957. };
  6958. aa.prototype.Initialize = function(a, b, c, d) {
  6959. this.bodyA = a;
  6960. this.bodyB = b;
  6961. this.localAnchorA = this.bodyA.GetLocalPoint(c);
  6962. this.localAnchorB = this.bodyB.GetLocalPoint(c);
  6963. this.localAxisA = this.bodyA.GetLocalVector(d);
  6964. this.referenceAngle =
  6965. this.bodyB.GetAngle() - this.bodyA.GetAngle()
  6966. };
  6967. Box2D.inherit(Yb, Box2D.Dynamics.Joints.b2Joint);
  6968. Yb.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6969. Yb.b2PulleyJoint = function() {
  6970. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6971. this.m_groundAnchor1 = new e;
  6972. this.m_groundAnchor2 = new e;
  6973. this.m_localAnchor1 = new e;
  6974. this.m_localAnchor2 = new e;
  6975. this.m_u1 = new e;
  6976. this.m_u2 = new e
  6977. };
  6978. Yb.prototype.GetAnchorA = function() {
  6979. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  6980. };
  6981. Yb.prototype.GetAnchorB = function() {
  6982. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  6983. };
  6984. Yb.prototype.GetReactionForce = function(a) {
  6985. void 0 === a && (a = 0);
  6986. return new e(a * this.m_impulse * this.m_u2.x, a * this.m_impulse * this.m_u2.y)
  6987. };
  6988. Yb.prototype.GetReactionTorque = function() {
  6989. return 0
  6990. };
  6991. Yb.prototype.GetGroundAnchorA = function() {
  6992. var a = this.m_ground.m_xf.position.Copy();
  6993. a.Add(this.m_groundAnchor1);
  6994. return a
  6995. };
  6996. Yb.prototype.GetGroundAnchorB = function() {
  6997. var a = this.m_ground.m_xf.position.Copy();
  6998. a.Add(this.m_groundAnchor2);
  6999. return a
  7000. };
  7001. Yb.prototype.GetLength1 = function() {
  7002. var a = this.m_bodyA.GetWorldPoint(this.m_localAnchor1),
  7003. b = a.x - (this.m_ground.m_xf.position.x + this.m_groundAnchor1.x),
  7004. a = a.y - (this.m_ground.m_xf.position.y + this.m_groundAnchor1.y);
  7005. return Math.sqrt(b * b + a * a)
  7006. };
  7007. Yb.prototype.GetLength2 = function() {
  7008. var a = this.m_bodyB.GetWorldPoint(this.m_localAnchor2),
  7009. b = a.x - (this.m_ground.m_xf.position.x + this.m_groundAnchor2.x),
  7010. a = a.y - (this.m_ground.m_xf.position.y + this.m_groundAnchor2.y);
  7011. return Math.sqrt(b * b + a * a)
  7012. };
  7013. Yb.prototype.GetRatio = function() {
  7014. return this.m_ratio
  7015. };
  7016. Yb.prototype.b2PulleyJoint = function(a) {
  7017. this.__super.b2Joint.call(this,
  7018. a);
  7019. this.m_ground = this.m_bodyA.m_world.m_groundBody;
  7020. this.m_groundAnchor1.x = a.groundAnchorA.x - this.m_ground.m_xf.position.x;
  7021. this.m_groundAnchor1.y = a.groundAnchorA.y - this.m_ground.m_xf.position.y;
  7022. this.m_groundAnchor2.x = a.groundAnchorB.x - this.m_ground.m_xf.position.x;
  7023. this.m_groundAnchor2.y = a.groundAnchorB.y - this.m_ground.m_xf.position.y;
  7024. this.m_localAnchor1.SetV(a.localAnchorA);
  7025. this.m_localAnchor2.SetV(a.localAnchorB);
  7026. this.m_ratio = a.ratio;
  7027. this.m_constant = a.lengthA + this.m_ratio * a.lengthB;
  7028. this.m_maxLength1 =
  7029. d.Min(a.maxLengthA, this.m_constant - this.m_ratio * Yb.b2_minPulleyLength);
  7030. this.m_maxLength2 = d.Min(a.maxLengthB, (this.m_constant - Yb.b2_minPulleyLength) / this.m_ratio);
  7031. this.m_limitImpulse2 = this.m_limitImpulse1 = this.m_impulse = 0
  7032. };
  7033. Yb.prototype.InitVelocityConstraints = function(b) {
  7034. var c = this.m_bodyA,
  7035. d = this.m_bodyB,
  7036. e;
  7037. e = c.m_xf.R;
  7038. var f = this.m_localAnchor1.x - c.m_sweep.localCenter.x,
  7039. g = this.m_localAnchor1.y - c.m_sweep.localCenter.y,
  7040. h = e.col1.x * f + e.col2.x * g,
  7041. g = e.col1.y * f + e.col2.y * g,
  7042. f = h;
  7043. e = d.m_xf.R;
  7044. var l = this.m_localAnchor2.x -
  7045. d.m_sweep.localCenter.x,
  7046. m = this.m_localAnchor2.y - d.m_sweep.localCenter.y,
  7047. h = e.col1.x * l + e.col2.x * m,
  7048. m = e.col1.y * l + e.col2.y * m,
  7049. l = h;
  7050. e = d.m_sweep.c.x + l;
  7051. var h = d.m_sweep.c.y + m,
  7052. p = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x,
  7053. q = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;
  7054. this.m_u1.Set(c.m_sweep.c.x + f - (this.m_ground.m_xf.position.x + this.m_groundAnchor1.x), c.m_sweep.c.y + g - (this.m_ground.m_xf.position.y + this.m_groundAnchor1.y));
  7055. this.m_u2.Set(e - p, h - q);
  7056. e = this.m_u1.Length();
  7057. h = this.m_u2.Length();
  7058. e > a.b2_linearSlop ?
  7059. this.m_u1.Multiply(1 / e) : this.m_u1.SetZero();
  7060. h > a.b2_linearSlop ? this.m_u2.Multiply(1 / h) : this.m_u2.SetZero();
  7061. 0 < this.m_constant - e - this.m_ratio * h ? (this.m_state = A.e_inactiveLimit, this.m_impulse = 0) : this.m_state = A.e_atUpperLimit;
  7062. e < this.m_maxLength1 ? (this.m_limitState1 = A.e_inactiveLimit, this.m_limitImpulse1 = 0) : this.m_limitState1 = A.e_atUpperLimit;
  7063. h < this.m_maxLength2 ? (this.m_limitState2 = A.e_inactiveLimit, this.m_limitImpulse2 = 0) : this.m_limitState2 = A.e_atUpperLimit;
  7064. e = f * this.m_u1.y - g * this.m_u1.x;
  7065. h = l * this.m_u2.y -
  7066. m * this.m_u2.x;
  7067. this.m_limitMass1 = c.m_invMass + c.m_invI * e * e;
  7068. this.m_limitMass2 = d.m_invMass + d.m_invI * h * h;
  7069. this.m_pulleyMass = this.m_limitMass1 + this.m_ratio * this.m_ratio * this.m_limitMass2;
  7070. this.m_limitMass1 = 1 / this.m_limitMass1;
  7071. this.m_limitMass2 = 1 / this.m_limitMass2;
  7072. this.m_pulleyMass = 1 / this.m_pulleyMass;
  7073. b.warmStarting ? (this.m_impulse *= b.dtRatio, this.m_limitImpulse1 *= b.dtRatio, this.m_limitImpulse2 *= b.dtRatio, b = (-this.m_impulse - this.m_limitImpulse1) * this.m_u1.x, e = (-this.m_impulse - this.m_limitImpulse1) * this.m_u1.y,
  7074. h = (-this.m_ratio * this.m_impulse - this.m_limitImpulse2) * this.m_u2.x, p = (-this.m_ratio * this.m_impulse - this.m_limitImpulse2) * this.m_u2.y, c.m_linearVelocity.x += c.m_invMass * b, c.m_linearVelocity.y += c.m_invMass * e, c.m_angularVelocity += c.m_invI * (f * e - g * b), d.m_linearVelocity.x += d.m_invMass * h, d.m_linearVelocity.y += d.m_invMass * p, d.m_angularVelocity += d.m_invI * (l * p - m * h)) : this.m_limitImpulse2 = this.m_limitImpulse1 = this.m_impulse = 0
  7075. };
  7076. Yb.prototype.SolveVelocityConstraints = function() {
  7077. var a = this.m_bodyA,
  7078. b = this.m_bodyB,
  7079. c;
  7080. c = a.m_xf.R;
  7081. var e = this.m_localAnchor1.x - a.m_sweep.localCenter.x,
  7082. f = this.m_localAnchor1.y - a.m_sweep.localCenter.y,
  7083. g = c.col1.x * e + c.col2.x * f,
  7084. f = c.col1.y * e + c.col2.y * f,
  7085. e = g;
  7086. c = b.m_xf.R;
  7087. var h = this.m_localAnchor2.x - b.m_sweep.localCenter.x,
  7088. l = this.m_localAnchor2.y - b.m_sweep.localCenter.y,
  7089. g = c.col1.x * h + c.col2.x * l,
  7090. l = c.col1.y * h + c.col2.y * l,
  7091. h = g,
  7092. m, p;
  7093. this.m_state == A.e_atUpperLimit && (c = a.m_linearVelocity.x + -a.m_angularVelocity * f, g = a.m_linearVelocity.y + a.m_angularVelocity * e, m = b.m_linearVelocity.x + -b.m_angularVelocity * l, p =
  7094. b.m_linearVelocity.y + b.m_angularVelocity * h, c = -(this.m_u1.x * c + this.m_u1.y * g) - this.m_ratio * (this.m_u2.x * m + this.m_u2.y * p), p = this.m_pulleyMass * -c, c = this.m_impulse, this.m_impulse = d.Max(0, this.m_impulse + p), p = this.m_impulse - c, c = -p * this.m_u1.x, g = -p * this.m_u1.y, m = -this.m_ratio * p * this.m_u2.x, p = -this.m_ratio * p * this.m_u2.y, a.m_linearVelocity.x += a.m_invMass * c, a.m_linearVelocity.y += a.m_invMass * g, a.m_angularVelocity += a.m_invI * (e * g - f * c), b.m_linearVelocity.x += b.m_invMass * m, b.m_linearVelocity.y += b.m_invMass * p, b.m_angularVelocity +=
  7095. b.m_invI * (h * p - l * m));
  7096. this.m_limitState1 == A.e_atUpperLimit && (c = a.m_linearVelocity.x + -a.m_angularVelocity * f, g = a.m_linearVelocity.y + a.m_angularVelocity * e, c = -(this.m_u1.x * c + this.m_u1.y * g), p = -this.m_limitMass1 * c, c = this.m_limitImpulse1, this.m_limitImpulse1 = d.Max(0, this.m_limitImpulse1 + p), p = this.m_limitImpulse1 - c, c = -p * this.m_u1.x, g = -p * this.m_u1.y, a.m_linearVelocity.x += a.m_invMass * c, a.m_linearVelocity.y += a.m_invMass * g, a.m_angularVelocity += a.m_invI * (e * g - f * c));
  7097. this.m_limitState2 == A.e_atUpperLimit && (m = b.m_linearVelocity.x +
  7098. -b.m_angularVelocity * l, p = b.m_linearVelocity.y + b.m_angularVelocity * h, c = -(this.m_u2.x * m + this.m_u2.y * p), p = -this.m_limitMass2 * c, c = this.m_limitImpulse2, this.m_limitImpulse2 = d.Max(0, this.m_limitImpulse2 + p), p = this.m_limitImpulse2 - c, m = -p * this.m_u2.x, p = -p * this.m_u2.y, b.m_linearVelocity.x += b.m_invMass * m, b.m_linearVelocity.y += b.m_invMass * p, b.m_angularVelocity += b.m_invI * (h * p - l * m))
  7099. };
  7100. Yb.prototype.SolvePositionConstraints = function() {
  7101. var b = this.m_bodyA,
  7102. c = this.m_bodyB,
  7103. e, f = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x,
  7104. g = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y,
  7105. h = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x,
  7106. l = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y,
  7107. m, p, q, y, B, H, E, K = 0;
  7108. this.m_state == A.e_atUpperLimit && (e = b.m_xf.R, m = this.m_localAnchor1.x - b.m_sweep.localCenter.x, p = this.m_localAnchor1.y - b.m_sweep.localCenter.y, B = e.col1.x * m + e.col2.x * p, p = e.col1.y * m + e.col2.y * p, m = B, e = c.m_xf.R, q = this.m_localAnchor2.x - c.m_sweep.localCenter.x, y = this.m_localAnchor2.y - c.m_sweep.localCenter.y, B = e.col1.x * q + e.col2.x *
  7109. y, y = e.col1.y * q + e.col2.y * y, q = B, e = b.m_sweep.c.x + m, B = b.m_sweep.c.y + p, H = c.m_sweep.c.x + q, E = c.m_sweep.c.y + y, this.m_u1.Set(e - f, B - g), this.m_u2.Set(H - h, E - l), e = this.m_u1.Length(), B = this.m_u2.Length(), e > a.b2_linearSlop ? this.m_u1.Multiply(1 / e) : this.m_u1.SetZero(), B > a.b2_linearSlop ? this.m_u2.Multiply(1 / B) : this.m_u2.SetZero(), e = this.m_constant - e - this.m_ratio * B, K = d.Max(K, -e), e = d.Clamp(e + a.b2_linearSlop, -a.b2_maxLinearCorrection, 0), E = -this.m_pulleyMass * e, e = -E * this.m_u1.x, B = -E * this.m_u1.y, H = -this.m_ratio * E * this.m_u2.x,
  7110. E = -this.m_ratio * E * this.m_u2.y, b.m_sweep.c.x += b.m_invMass * e, b.m_sweep.c.y += b.m_invMass * B, b.m_sweep.a += b.m_invI * (m * B - p * e), c.m_sweep.c.x += c.m_invMass * H, c.m_sweep.c.y += c.m_invMass * E, c.m_sweep.a += c.m_invI * (q * E - y * H), b.SynchronizeTransform(), c.SynchronizeTransform());
  7111. this.m_limitState1 == A.e_atUpperLimit && (e = b.m_xf.R, m = this.m_localAnchor1.x - b.m_sweep.localCenter.x, p = this.m_localAnchor1.y - b.m_sweep.localCenter.y, B = e.col1.x * m + e.col2.x * p, p = e.col1.y * m + e.col2.y * p, m = B, e = b.m_sweep.c.x + m, B = b.m_sweep.c.y + p, this.m_u1.Set(e -
  7112. f, B - g), e = this.m_u1.Length(), e > a.b2_linearSlop ? (this.m_u1.x *= 1 / e, this.m_u1.y *= 1 / e) : this.m_u1.SetZero(), e = this.m_maxLength1 - e, K = d.Max(K, -e), e = d.Clamp(e + a.b2_linearSlop, -a.b2_maxLinearCorrection, 0), E = -this.m_limitMass1 * e, e = -E * this.m_u1.x, B = -E * this.m_u1.y, b.m_sweep.c.x += b.m_invMass * e, b.m_sweep.c.y += b.m_invMass * B, b.m_sweep.a += b.m_invI * (m * B - p * e), b.SynchronizeTransform());
  7113. this.m_limitState2 == A.e_atUpperLimit && (e = c.m_xf.R, q = this.m_localAnchor2.x - c.m_sweep.localCenter.x, y = this.m_localAnchor2.y - c.m_sweep.localCenter.y,
  7114. B = e.col1.x * q + e.col2.x * y, y = e.col1.y * q + e.col2.y * y, q = B, H = c.m_sweep.c.x + q, E = c.m_sweep.c.y + y, this.m_u2.Set(H - h, E - l), B = this.m_u2.Length(), B > a.b2_linearSlop ? (this.m_u2.x *= 1 / B, this.m_u2.y *= 1 / B) : this.m_u2.SetZero(), e = this.m_maxLength2 - B, K = d.Max(K, -e), e = d.Clamp(e + a.b2_linearSlop, -a.b2_maxLinearCorrection, 0), E = -this.m_limitMass2 * e, H = -E * this.m_u2.x, E = -E * this.m_u2.y, c.m_sweep.c.x += c.m_invMass * H, c.m_sweep.c.y += c.m_invMass * E, c.m_sweep.a += c.m_invI * (q * E - y * H), c.SynchronizeTransform());
  7115. return K < a.b2_linearSlop
  7116. };
  7117. Box2D.postDefs.push(function() {
  7118. Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength =
  7119. 2
  7120. });
  7121. Box2D.inherit($b, Box2D.Dynamics.Joints.b2JointDef);
  7122. $b.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7123. $b.b2PulleyJointDef = function() {
  7124. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  7125. this.groundAnchorA = new e;
  7126. this.groundAnchorB = new e;
  7127. this.localAnchorA = new e;
  7128. this.localAnchorB = new e
  7129. };
  7130. $b.prototype.b2PulleyJointDef = function() {
  7131. this.__super.b2JointDef.call(this);
  7132. this.type = A.e_pulleyJoint;
  7133. this.groundAnchorA.Set(-1, 1);
  7134. this.groundAnchorB.Set(1, 1);
  7135. this.localAnchorA.Set(-1, 0);
  7136. this.localAnchorB.Set(1, 0);
  7137. this.maxLengthB = this.lengthB = this.maxLengthA = this.lengthA = 0;
  7138. this.ratio = 1;
  7139. this.collideConnected = !0
  7140. };
  7141. $b.prototype.Initialize = function(a, b, c, d, e, f, g) {
  7142. void 0 === g && (g = 0);
  7143. this.bodyA = a;
  7144. this.bodyB = b;
  7145. this.groundAnchorA.SetV(c);
  7146. this.groundAnchorB.SetV(d);
  7147. this.localAnchorA = this.bodyA.GetLocalPoint(e);
  7148. this.localAnchorB = this.bodyB.GetLocalPoint(f);
  7149. a = e.x - c.x;
  7150. c = e.y - c.y;
  7151. this.lengthA = Math.sqrt(a * a + c * c);
  7152. c = f.x - d.x;
  7153. d = f.y - d.y;
  7154. this.lengthB = Math.sqrt(c * c + d * d);
  7155. this.ratio = g;
  7156. g = this.lengthA + this.ratio *
  7157. this.lengthB;
  7158. this.maxLengthA = g - this.ratio * Yb.b2_minPulleyLength;
  7159. this.maxLengthB = (g - Yb.b2_minPulleyLength) / this.ratio
  7160. };
  7161. Box2D.inherit(ac, Box2D.Dynamics.Joints.b2Joint);
  7162. ac.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7163. ac.b2RevoluteJoint = function() {
  7164. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7165. this.K = new c;
  7166. this.K1 = new c;
  7167. this.K2 = new c;
  7168. this.K3 = new c;
  7169. this.impulse3 = new f;
  7170. this.impulse2 = new e;
  7171. this.reduced = new e;
  7172. this.m_localAnchor1 = new e;
  7173. this.m_localAnchor2 = new e;
  7174. this.m_impulse = new f;
  7175. this.m_mass = new b
  7176. };
  7177. ac.prototype.GetAnchorA = function() {
  7178. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  7179. };
  7180. ac.prototype.GetAnchorB = function() {
  7181. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  7182. };
  7183. ac.prototype.GetReactionForce = function(a) {
  7184. void 0 === a && (a = 0);
  7185. return new e(a * this.m_impulse.x, a * this.m_impulse.y)
  7186. };
  7187. ac.prototype.GetReactionTorque = function(a) {
  7188. void 0 === a && (a = 0);
  7189. return a * this.m_impulse.z
  7190. };
  7191. ac.prototype.GetJointAngle = function() {
  7192. return this.m_bodyB.m_sweep.a - this.m_bodyA.m_sweep.a - this.m_referenceAngle
  7193. };
  7194. ac.prototype.GetJointSpeed = function() {
  7195. return this.m_bodyB.m_angularVelocity - this.m_bodyA.m_angularVelocity
  7196. };
  7197. ac.prototype.IsLimitEnabled = function() {
  7198. return this.m_enableLimit
  7199. };
  7200. ac.prototype.EnableLimit = function(a) {
  7201. this.m_enableLimit = a
  7202. };
  7203. ac.prototype.GetLowerLimit = function() {
  7204. return this.m_lowerAngle
  7205. };
  7206. ac.prototype.GetUpperLimit = function() {
  7207. return this.m_upperAngle
  7208. };
  7209. ac.prototype.SetLimits = function(a, b) {
  7210. void 0 === a && (a = 0);
  7211. void 0 === b && (b = 0);
  7212. this.m_lowerAngle = a;
  7213. this.m_upperAngle = b
  7214. };
  7215. ac.prototype.IsMotorEnabled =
  7216. function() {
  7217. this.m_bodyA.SetAwake(!0);
  7218. this.m_bodyB.SetAwake(!0);
  7219. return this.m_enableMotor
  7220. };
  7221. ac.prototype.EnableMotor = function(a) {
  7222. this.m_enableMotor = a
  7223. };
  7224. ac.prototype.SetMotorSpeed = function(a) {
  7225. void 0 === a && (a = 0);
  7226. this.m_bodyA.SetAwake(!0);
  7227. this.m_bodyB.SetAwake(!0);
  7228. this.m_motorSpeed = a
  7229. };
  7230. ac.prototype.GetMotorSpeed = function() {
  7231. return this.m_motorSpeed
  7232. };
  7233. ac.prototype.SetMaxMotorTorque = function(a) {
  7234. void 0 === a && (a = 0);
  7235. this.m_maxMotorTorque = a
  7236. };
  7237. ac.prototype.GetMotorTorque = function() {
  7238. return this.m_maxMotorTorque
  7239. };
  7240. ac.prototype.b2RevoluteJoint =
  7241. function(a) {
  7242. this.__super.b2Joint.call(this, a);
  7243. this.m_localAnchor1.SetV(a.localAnchorA);
  7244. this.m_localAnchor2.SetV(a.localAnchorB);
  7245. this.m_referenceAngle = a.referenceAngle;
  7246. this.m_impulse.SetZero();
  7247. this.m_motorImpulse = 0;
  7248. this.m_lowerAngle = a.lowerAngle;
  7249. this.m_upperAngle = a.upperAngle;
  7250. this.m_maxMotorTorque = a.maxMotorTorque;
  7251. this.m_motorSpeed = a.motorSpeed;
  7252. this.m_enableLimit = a.enableLimit;
  7253. this.m_enableMotor = a.enableMotor;
  7254. this.m_limitState = A.e_inactiveLimit
  7255. };
  7256. ac.prototype.InitVelocityConstraints = function(b) {
  7257. var c =
  7258. this.m_bodyA,
  7259. e = this.m_bodyB,
  7260. f, g;
  7261. f = c.m_xf.R;
  7262. var h = this.m_localAnchor1.x - c.m_sweep.localCenter.x,
  7263. l = this.m_localAnchor1.y - c.m_sweep.localCenter.y;
  7264. g = f.col1.x * h + f.col2.x * l;
  7265. l = f.col1.y * h + f.col2.y * l;
  7266. h = g;
  7267. f = e.m_xf.R;
  7268. var m = this.m_localAnchor2.x - e.m_sweep.localCenter.x,
  7269. p = this.m_localAnchor2.y - e.m_sweep.localCenter.y;
  7270. g = f.col1.x * m + f.col2.x * p;
  7271. p = f.col1.y * m + f.col2.y * p;
  7272. m = g;
  7273. f = c.m_invMass;
  7274. g = e.m_invMass;
  7275. var q = c.m_invI,
  7276. y = e.m_invI;
  7277. this.m_mass.col1.x = f + g + l * l * q + p * p * y;
  7278. this.m_mass.col2.x = -l * h * q - p * m * y;
  7279. this.m_mass.col3.x = -l *
  7280. q - p * y;
  7281. this.m_mass.col1.y = this.m_mass.col2.x;
  7282. this.m_mass.col2.y = f + g + h * h * q + m * m * y;
  7283. this.m_mass.col3.y = h * q + m * y;
  7284. this.m_mass.col1.z = this.m_mass.col3.x;
  7285. this.m_mass.col2.z = this.m_mass.col3.y;
  7286. this.m_mass.col3.z = q + y;
  7287. this.m_motorMass = 1 / (q + y);
  7288. 0 == this.m_enableMotor && (this.m_motorImpulse = 0);
  7289. if (this.m_enableLimit) {
  7290. var B = e.m_sweep.a - c.m_sweep.a - this.m_referenceAngle;
  7291. d.Abs(this.m_upperAngle - this.m_lowerAngle) < 2 * a.b2_angularSlop ? this.m_limitState = A.e_equalLimits : B <= this.m_lowerAngle ? (this.m_limitState != A.e_atLowerLimit &&
  7292. (this.m_impulse.z = 0), this.m_limitState = A.e_atLowerLimit) : B >= this.m_upperAngle ? (this.m_limitState != A.e_atUpperLimit && (this.m_impulse.z = 0), this.m_limitState = A.e_atUpperLimit) : (this.m_limitState = A.e_inactiveLimit, this.m_impulse.z = 0)
  7293. } else this.m_limitState = A.e_inactiveLimit;
  7294. b.warmStarting ? (this.m_impulse.x *= b.dtRatio, this.m_impulse.y *= b.dtRatio, this.m_motorImpulse *= b.dtRatio, b = this.m_impulse.x, B = this.m_impulse.y, c.m_linearVelocity.x -= f * b, c.m_linearVelocity.y -= f * B, c.m_angularVelocity -= q * (h * B - l * b + this.m_motorImpulse +
  7295. this.m_impulse.z), e.m_linearVelocity.x += g * b, e.m_linearVelocity.y += g * B, e.m_angularVelocity += y * (m * B - p * b + this.m_motorImpulse + this.m_impulse.z)) : (this.m_impulse.SetZero(), this.m_motorImpulse = 0)
  7296. };
  7297. ac.prototype.SolveVelocityConstraints = function(a) {
  7298. var b = this.m_bodyA,
  7299. c = this.m_bodyB,
  7300. e, f, g, h, l, m = b.m_linearVelocity,
  7301. p = b.m_angularVelocity,
  7302. q = c.m_linearVelocity,
  7303. y = c.m_angularVelocity,
  7304. B = b.m_invMass,
  7305. H = c.m_invMass,
  7306. E = b.m_invI,
  7307. K = c.m_invI;
  7308. this.m_enableMotor && this.m_limitState != A.e_equalLimits && (f = this.m_motorMass * -(y -
  7309. p - this.m_motorSpeed), g = this.m_motorImpulse, h = a.dt * this.m_maxMotorTorque, this.m_motorImpulse = d.Clamp(this.m_motorImpulse + f, -h, h), f = this.m_motorImpulse - g, p -= E * f, y += K * f);
  7310. if (this.m_enableLimit && this.m_limitState != A.e_inactiveLimit) {
  7311. a = b.m_xf.R;
  7312. f = this.m_localAnchor1.x - b.m_sweep.localCenter.x;
  7313. g = this.m_localAnchor1.y - b.m_sweep.localCenter.y;
  7314. e = a.col1.x * f + a.col2.x * g;
  7315. g = a.col1.y * f + a.col2.y * g;
  7316. f = e;
  7317. a = c.m_xf.R;
  7318. h = this.m_localAnchor2.x - c.m_sweep.localCenter.x;
  7319. l = this.m_localAnchor2.y - c.m_sweep.localCenter.y;
  7320. e = a.col1.x *
  7321. h + a.col2.x * l;
  7322. l = a.col1.y * h + a.col2.y * l;
  7323. h = e;
  7324. a = q.x + -y * l - m.x - -p * g;
  7325. var M = q.y + y * h - m.y - p * f;
  7326. this.m_mass.Solve33(this.impulse3, -a, -M, -(y - p));
  7327. this.m_limitState == A.e_equalLimits ? this.m_impulse.Add(this.impulse3) : this.m_limitState == A.e_atLowerLimit ? (e = this.m_impulse.z + this.impulse3.z, 0 > e && (this.m_mass.Solve22(this.reduced, -a, -M), this.impulse3.x = this.reduced.x, this.impulse3.y = this.reduced.y, this.impulse3.z = -this.m_impulse.z, this.m_impulse.x += this.reduced.x, this.m_impulse.y += this.reduced.y, this.m_impulse.z = 0)) :
  7328. this.m_limitState == A.e_atUpperLimit && (e = this.m_impulse.z + this.impulse3.z, 0 < e && (this.m_mass.Solve22(this.reduced, -a, -M), this.impulse3.x = this.reduced.x, this.impulse3.y = this.reduced.y, this.impulse3.z = -this.m_impulse.z, this.m_impulse.x += this.reduced.x, this.m_impulse.y += this.reduced.y, this.m_impulse.z = 0));
  7329. m.x -= B * this.impulse3.x;
  7330. m.y -= B * this.impulse3.y;
  7331. p -= E * (f * this.impulse3.y - g * this.impulse3.x + this.impulse3.z);
  7332. q.x += H * this.impulse3.x;
  7333. q.y += H * this.impulse3.y;
  7334. y += K * (h * this.impulse3.y - l * this.impulse3.x + this.impulse3.z)
  7335. } else a =
  7336. b.m_xf.R, f = this.m_localAnchor1.x - b.m_sweep.localCenter.x, g = this.m_localAnchor1.y - b.m_sweep.localCenter.y, e = a.col1.x * f + a.col2.x * g, g = a.col1.y * f + a.col2.y * g, f = e, a = c.m_xf.R, h = this.m_localAnchor2.x - c.m_sweep.localCenter.x, l = this.m_localAnchor2.y - c.m_sweep.localCenter.y, e = a.col1.x * h + a.col2.x * l, l = a.col1.y * h + a.col2.y * l, h = e, this.m_mass.Solve22(this.impulse2, -(q.x + -y * l - m.x - -p * g), -(q.y + y * h - m.y - p * f)), this.m_impulse.x += this.impulse2.x, this.m_impulse.y += this.impulse2.y, m.x -= B * this.impulse2.x, m.y -= B * this.impulse2.y,
  7337. p -= E * (f * this.impulse2.y - g * this.impulse2.x), q.x += H * this.impulse2.x, q.y += H * this.impulse2.y, y += K * (h * this.impulse2.y - l * this.impulse2.x);
  7338. b.m_linearVelocity.SetV(m);
  7339. b.m_angularVelocity = p;
  7340. c.m_linearVelocity.SetV(q);
  7341. c.m_angularVelocity = y
  7342. };
  7343. ac.prototype.SolvePositionConstraints = function() {
  7344. var b, c, e = this.m_bodyA,
  7345. f = this.m_bodyB,
  7346. g = 0,
  7347. h, l, m;
  7348. if (this.m_enableLimit && this.m_limitState != A.e_inactiveLimit) {
  7349. b = f.m_sweep.a - e.m_sweep.a - this.m_referenceAngle;
  7350. var p = 0;
  7351. this.m_limitState == A.e_equalLimits ? (b = d.Clamp(b - this.m_lowerAngle, -a.b2_maxAngularCorrection, a.b2_maxAngularCorrection), p = -this.m_motorMass * b, g = d.Abs(b)) : this.m_limitState == A.e_atLowerLimit ? (b -= this.m_lowerAngle, g = -b, b = d.Clamp(b + a.b2_angularSlop, -a.b2_maxAngularCorrection, 0), p = -this.m_motorMass * b) : this.m_limitState == A.e_atUpperLimit && (g = b -= this.m_upperAngle, b = d.Clamp(b - a.b2_angularSlop, 0, a.b2_maxAngularCorrection), p = -this.m_motorMass * b);
  7352. e.m_sweep.a -= e.m_invI * p;
  7353. f.m_sweep.a += f.m_invI * p;
  7354. e.SynchronizeTransform();
  7355. f.SynchronizeTransform()
  7356. }
  7357. c = e.m_xf.R;
  7358. p = this.m_localAnchor1.x -
  7359. e.m_sweep.localCenter.x;
  7360. b = this.m_localAnchor1.y - e.m_sweep.localCenter.y;
  7361. h = c.col1.x * p + c.col2.x * b;
  7362. b = c.col1.y * p + c.col2.y * b;
  7363. p = h;
  7364. c = f.m_xf.R;
  7365. var q = this.m_localAnchor2.x - f.m_sweep.localCenter.x,
  7366. y = this.m_localAnchor2.y - f.m_sweep.localCenter.y;
  7367. h = c.col1.x * q + c.col2.x * y;
  7368. y = c.col1.y * q + c.col2.y * y;
  7369. q = h;
  7370. l = f.m_sweep.c.x + q - e.m_sweep.c.x - p;
  7371. m = f.m_sweep.c.y + y - e.m_sweep.c.y - b;
  7372. var B = l * l + m * m;
  7373. c = Math.sqrt(B);
  7374. h = e.m_invMass;
  7375. var H = f.m_invMass,
  7376. E = e.m_invI,
  7377. K = f.m_invI,
  7378. M = 10 * a.b2_linearSlop;
  7379. B > M * M && (B = 1 / (h + H), l = B * -l, m = B * -m, e.m_sweep.c.x -=
  7380. .5 * h * l, e.m_sweep.c.y -= .5 * h * m, f.m_sweep.c.x += .5 * H * l, f.m_sweep.c.y += .5 * H * m, l = f.m_sweep.c.x + q - e.m_sweep.c.x - p, m = f.m_sweep.c.y + y - e.m_sweep.c.y - b);
  7381. this.K1.col1.x = h + H;
  7382. this.K1.col2.x = 0;
  7383. this.K1.col1.y = 0;
  7384. this.K1.col2.y = h + H;
  7385. this.K2.col1.x = E * b * b;
  7386. this.K2.col2.x = -E * p * b;
  7387. this.K2.col1.y = -E * p * b;
  7388. this.K2.col2.y = E * p * p;
  7389. this.K3.col1.x = K * y * y;
  7390. this.K3.col2.x = -K * q * y;
  7391. this.K3.col1.y = -K * q * y;
  7392. this.K3.col2.y = K * q * q;
  7393. this.K.SetM(this.K1);
  7394. this.K.AddM(this.K2);
  7395. this.K.AddM(this.K3);
  7396. this.K.Solve(ac.tImpulse, -l, -m);
  7397. l = ac.tImpulse.x;
  7398. m = ac.tImpulse.y;
  7399. e.m_sweep.c.x -= e.m_invMass * l;
  7400. e.m_sweep.c.y -= e.m_invMass * m;
  7401. e.m_sweep.a -= e.m_invI * (p * m - b * l);
  7402. f.m_sweep.c.x += f.m_invMass * l;
  7403. f.m_sweep.c.y += f.m_invMass * m;
  7404. f.m_sweep.a += f.m_invI * (q * m - y * l);
  7405. e.SynchronizeTransform();
  7406. f.SynchronizeTransform();
  7407. return c <= a.b2_linearSlop && g <= a.b2_angularSlop
  7408. };
  7409. Box2D.postDefs.push(function() {
  7410. Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse = new e
  7411. });
  7412. Box2D.inherit(bc, Box2D.Dynamics.Joints.b2JointDef);
  7413. bc.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7414. bc.b2RevoluteJointDef =
  7415. function() {
  7416. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  7417. this.localAnchorA = new e;
  7418. this.localAnchorB = new e
  7419. };
  7420. bc.prototype.b2RevoluteJointDef = function() {
  7421. this.__super.b2JointDef.call(this);
  7422. this.type = A.e_revoluteJoint;
  7423. this.localAnchorA.Set(0, 0);
  7424. this.localAnchorB.Set(0, 0);
  7425. this.motorSpeed = this.maxMotorTorque = this.upperAngle = this.lowerAngle = this.referenceAngle = 0;
  7426. this.enableMotor = this.enableLimit = !1
  7427. };
  7428. bc.prototype.Initialize = function(a, b, c) {
  7429. this.bodyA = a;
  7430. this.bodyB = b;
  7431. this.localAnchorA = this.bodyA.GetLocalPoint(c);
  7432. this.localAnchorB = this.bodyB.GetLocalPoint(c);
  7433. this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle()
  7434. };
  7435. Box2D.inherit(ec, Box2D.Dynamics.Joints.b2Joint);
  7436. ec.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7437. ec.b2WeldJoint = function() {
  7438. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7439. this.m_localAnchorA = new e;
  7440. this.m_localAnchorB = new e;
  7441. this.m_impulse = new f;
  7442. this.m_mass = new b
  7443. };
  7444. ec.prototype.GetAnchorA = function() {
  7445. return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)
  7446. };
  7447. ec.prototype.GetAnchorB =
  7448. function() {
  7449. return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)
  7450. };
  7451. ec.prototype.GetReactionForce = function(a) {
  7452. void 0 === a && (a = 0);
  7453. return new e(a * this.m_impulse.x, a * this.m_impulse.y)
  7454. };
  7455. ec.prototype.GetReactionTorque = function(a) {
  7456. void 0 === a && (a = 0);
  7457. return a * this.m_impulse.z
  7458. };
  7459. ec.prototype.b2WeldJoint = function(a) {
  7460. this.__super.b2Joint.call(this, a);
  7461. this.m_localAnchorA.SetV(a.localAnchorA);
  7462. this.m_localAnchorB.SetV(a.localAnchorB);
  7463. this.m_referenceAngle = a.referenceAngle;
  7464. this.m_impulse.SetZero();
  7465. this.m_mass = new b
  7466. };
  7467. ec.prototype.InitVelocityConstraints = function(a) {
  7468. var b, c, d = this.m_bodyA,
  7469. e = this.m_bodyB;
  7470. b = d.m_xf.R;
  7471. var f = this.m_localAnchorA.x - d.m_sweep.localCenter.x,
  7472. g = this.m_localAnchorA.y - d.m_sweep.localCenter.y;
  7473. c = b.col1.x * f + b.col2.x * g;
  7474. g = b.col1.y * f + b.col2.y * g;
  7475. f = c;
  7476. b = e.m_xf.R;
  7477. var h = this.m_localAnchorB.x - e.m_sweep.localCenter.x,
  7478. l = this.m_localAnchorB.y - e.m_sweep.localCenter.y;
  7479. c = b.col1.x * h + b.col2.x * l;
  7480. l = b.col1.y * h + b.col2.y * l;
  7481. h = c;
  7482. b = d.m_invMass;
  7483. c = e.m_invMass;
  7484. var m = d.m_invI,
  7485. p = e.m_invI;
  7486. this.m_mass.col1.x = b + c + g * g * m + l * l * p;
  7487. this.m_mass.col2.x = -g * f * m - l * h * p;
  7488. this.m_mass.col3.x = -g * m - l * p;
  7489. this.m_mass.col1.y = this.m_mass.col2.x;
  7490. this.m_mass.col2.y = b + c + f * f * m + h * h * p;
  7491. this.m_mass.col3.y = f * m + h * p;
  7492. this.m_mass.col1.z = this.m_mass.col3.x;
  7493. this.m_mass.col2.z = this.m_mass.col3.y;
  7494. this.m_mass.col3.z = m + p;
  7495. a.warmStarting ? (this.m_impulse.x *= a.dtRatio, this.m_impulse.y *= a.dtRatio, this.m_impulse.z *= a.dtRatio, d.m_linearVelocity.x -= b * this.m_impulse.x, d.m_linearVelocity.y -= b * this.m_impulse.y, d.m_angularVelocity -= m * (f * this.m_impulse.y - g * this.m_impulse.x +
  7496. this.m_impulse.z), e.m_linearVelocity.x += c * this.m_impulse.x, e.m_linearVelocity.y += c * this.m_impulse.y, e.m_angularVelocity += p * (h * this.m_impulse.y - l * this.m_impulse.x + this.m_impulse.z)) : this.m_impulse.SetZero()
  7497. };
  7498. ec.prototype.SolveVelocityConstraints = function() {
  7499. var a, b, c = this.m_bodyA,
  7500. d = this.m_bodyB,
  7501. e = c.m_linearVelocity,
  7502. g = c.m_angularVelocity,
  7503. h = d.m_linearVelocity,
  7504. l = d.m_angularVelocity,
  7505. m = c.m_invMass,
  7506. p = d.m_invMass,
  7507. q = c.m_invI,
  7508. y = d.m_invI;
  7509. a = c.m_xf.R;
  7510. var A = this.m_localAnchorA.x - c.m_sweep.localCenter.x,
  7511. B = this.m_localAnchorA.y -
  7512. c.m_sweep.localCenter.y;
  7513. b = a.col1.x * A + a.col2.x * B;
  7514. B = a.col1.y * A + a.col2.y * B;
  7515. A = b;
  7516. a = d.m_xf.R;
  7517. var H = this.m_localAnchorB.x - d.m_sweep.localCenter.x,
  7518. E = this.m_localAnchorB.y - d.m_sweep.localCenter.y;
  7519. b = a.col1.x * H + a.col2.x * E;
  7520. E = a.col1.y * H + a.col2.y * E;
  7521. H = b;
  7522. a = h.x - l * E - e.x + g * B;
  7523. b = h.y + l * H - e.y - g * A;
  7524. var K = l - g,
  7525. M = new f;
  7526. this.m_mass.Solve33(M, -a, -b, -K);
  7527. this.m_impulse.Add(M);
  7528. e.x -= m * M.x;
  7529. e.y -= m * M.y;
  7530. g -= q * (A * M.y - B * M.x + M.z);
  7531. h.x += p * M.x;
  7532. h.y += p * M.y;
  7533. l += y * (H * M.y - E * M.x + M.z);
  7534. c.m_angularVelocity = g;
  7535. d.m_angularVelocity = l
  7536. };
  7537. ec.prototype.SolvePositionConstraints =
  7538. function() {
  7539. var b, c, e = this.m_bodyA,
  7540. g = this.m_bodyB;
  7541. b = e.m_xf.R;
  7542. var h = this.m_localAnchorA.x - e.m_sweep.localCenter.x,
  7543. l = this.m_localAnchorA.y - e.m_sweep.localCenter.y;
  7544. c = b.col1.x * h + b.col2.x * l;
  7545. l = b.col1.y * h + b.col2.y * l;
  7546. h = c;
  7547. b = g.m_xf.R;
  7548. var m = this.m_localAnchorB.x - g.m_sweep.localCenter.x,
  7549. p = this.m_localAnchorB.y - g.m_sweep.localCenter.y;
  7550. c = b.col1.x * m + b.col2.x * p;
  7551. p = b.col1.y * m + b.col2.y * p;
  7552. m = c;
  7553. b = e.m_invMass;
  7554. c = g.m_invMass;
  7555. var q = e.m_invI,
  7556. y = g.m_invI,
  7557. A = g.m_sweep.c.x + m - e.m_sweep.c.x - h,
  7558. B = g.m_sweep.c.y + p - e.m_sweep.c.y - l,
  7559. H = g.m_sweep.a -
  7560. e.m_sweep.a - this.m_referenceAngle,
  7561. E = 10 * a.b2_linearSlop,
  7562. K = Math.sqrt(A * A + B * B),
  7563. M = d.Abs(H);
  7564. K > E && (q *= 1, y *= 1);
  7565. this.m_mass.col1.x = b + c + l * l * q + p * p * y;
  7566. this.m_mass.col2.x = -l * h * q - p * m * y;
  7567. this.m_mass.col3.x = -l * q - p * y;
  7568. this.m_mass.col1.y = this.m_mass.col2.x;
  7569. this.m_mass.col2.y = b + c + h * h * q + m * m * y;
  7570. this.m_mass.col3.y = h * q + m * y;
  7571. this.m_mass.col1.z = this.m_mass.col3.x;
  7572. this.m_mass.col2.z = this.m_mass.col3.y;
  7573. this.m_mass.col3.z = q + y;
  7574. E = new f;
  7575. this.m_mass.Solve33(E, -A, -B, -H);
  7576. e.m_sweep.c.x -= b * E.x;
  7577. e.m_sweep.c.y -= b * E.y;
  7578. e.m_sweep.a -= q * (h * E.y -
  7579. l * E.x + E.z);
  7580. g.m_sweep.c.x += c * E.x;
  7581. g.m_sweep.c.y += c * E.y;
  7582. g.m_sweep.a += y * (m * E.y - p * E.x + E.z);
  7583. e.SynchronizeTransform();
  7584. g.SynchronizeTransform();
  7585. return K <= a.b2_linearSlop && M <= a.b2_angularSlop
  7586. };
  7587. Box2D.inherit(jc, Box2D.Dynamics.Joints.b2JointDef);
  7588. jc.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7589. jc.b2WeldJointDef = function() {
  7590. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  7591. this.localAnchorA = new e;
  7592. this.localAnchorB = new e
  7593. };
  7594. jc.prototype.b2WeldJointDef = function() {
  7595. this.__super.b2JointDef.call(this);
  7596. this.type = A.e_weldJoint;
  7597. this.referenceAngle = 0
  7598. };
  7599. jc.prototype.Initialize = function(a, b, c) {
  7600. this.bodyA = a;
  7601. this.bodyB = b;
  7602. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));
  7603. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c));
  7604. this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle()
  7605. }
  7606. })();
  7607. (function() {
  7608. var a = Box2D.Dynamics.b2DebugDraw;
  7609. a.b2DebugDraw = function() {
  7610. this.m_xformScale = this.m_fillAlpha = this.m_alpha = this.m_lineThickness = this.m_drawScale = 1;
  7611. var a = this;
  7612. this.m_sprite = {
  7613. graphics: {
  7614. clear: function() {
  7615. a.m_ctx.clearRect(0, 0, a.m_ctx.canvas.width, a.m_ctx.canvas.height)
  7616. }
  7617. }
  7618. }
  7619. };
  7620. a.prototype._color = function(a, b) {
  7621. return "rgba(" + ((a & 16711680) >> 16) + "," + ((a & 65280) >> 8) + "," + (a & 255) + "," + b + ")"
  7622. };
  7623. a.prototype.b2DebugDraw = function() {
  7624. this.m_drawFlags = 0
  7625. };
  7626. a.prototype.SetFlags = function(a) {
  7627. void 0 === a && (a = 0);
  7628. this.m_drawFlags =
  7629. a
  7630. };
  7631. a.prototype.GetFlags = function() {
  7632. return this.m_drawFlags
  7633. };
  7634. a.prototype.AppendFlags = function(a) {
  7635. void 0 === a && (a = 0);
  7636. this.m_drawFlags |= a
  7637. };
  7638. a.prototype.ClearFlags = function(a) {
  7639. void 0 === a && (a = 0);
  7640. this.m_drawFlags &= ~a
  7641. };
  7642. a.prototype.SetSprite = function(a) {
  7643. this.m_ctx = a
  7644. };
  7645. a.prototype.GetSprite = function() {
  7646. return this.m_ctx
  7647. };
  7648. a.prototype.SetDrawScale = function(a) {
  7649. void 0 === a && (a = 0);
  7650. this.m_drawScale = a
  7651. };
  7652. a.prototype.GetDrawScale = function() {
  7653. return this.m_drawScale
  7654. };
  7655. a.prototype.SetLineThickness = function(a) {
  7656. void 0 === a && (a =
  7657. 0);
  7658. this.m_lineThickness = a;
  7659. this.m_ctx.strokeWidth = a
  7660. };
  7661. a.prototype.GetLineThickness = function() {
  7662. return this.m_lineThickness
  7663. };
  7664. a.prototype.SetAlpha = function(a) {
  7665. void 0 === a && (a = 0);
  7666. this.m_alpha = a
  7667. };
  7668. a.prototype.GetAlpha = function() {
  7669. return this.m_alpha
  7670. };
  7671. a.prototype.SetFillAlpha = function(a) {
  7672. void 0 === a && (a = 0);
  7673. this.m_fillAlpha = a
  7674. };
  7675. a.prototype.GetFillAlpha = function() {
  7676. return this.m_fillAlpha
  7677. };
  7678. a.prototype.SetXFormScale = function(a) {
  7679. void 0 === a && (a = 0);
  7680. this.m_xformScale = a
  7681. };
  7682. a.prototype.GetXFormScale = function() {
  7683. return this.m_xformScale
  7684. };
  7685. a.prototype.DrawPolygon = function(a, b, d) {
  7686. if (b) {
  7687. var e = this.m_ctx,
  7688. f = this.m_drawScale;
  7689. e.beginPath();
  7690. e.strokeStyle = this._color(d.color, this.m_alpha);
  7691. e.moveTo(a[0].x * f, a[0].y * f);
  7692. for (d = 1; d < b; d++) e.lineTo(a[d].x * f, a[d].y * f);
  7693. e.lineTo(a[0].x * f, a[0].y * f);
  7694. e.closePath();
  7695. e.stroke()
  7696. }
  7697. };
  7698. a.prototype.DrawSolidPolygon = function(a, b, d) {
  7699. if (b) {
  7700. var e = this.m_ctx,
  7701. f = this.m_drawScale;
  7702. e.beginPath();
  7703. e.strokeStyle = this._color(d.color, this.m_alpha);
  7704. e.fillStyle = this._color(d.color, this.m_fillAlpha);
  7705. e.moveTo(a[0].x * f, a[0].y * f);
  7706. for (d =
  7707. 1; d < b; d++) e.lineTo(a[d].x * f, a[d].y * f);
  7708. e.lineTo(a[0].x * f, a[0].y * f);
  7709. e.closePath();
  7710. e.fill();
  7711. e.stroke()
  7712. }
  7713. };
  7714. a.prototype.DrawCircle = function(a, b, d) {
  7715. if (b) {
  7716. var e = this.m_ctx,
  7717. f = this.m_drawScale;
  7718. e.beginPath();
  7719. e.strokeStyle = this._color(d.color, this.m_alpha);
  7720. e.arc(a.x * f, a.y * f, b * f, 0, 2 * Math.PI, !0);
  7721. e.closePath();
  7722. e.stroke()
  7723. }
  7724. };
  7725. a.prototype.DrawSolidCircle = function(a, b, d, e) {
  7726. if (b) {
  7727. var f = this.m_ctx,
  7728. g = this.m_drawScale,
  7729. h = a.x * g,
  7730. l = a.y * g;
  7731. f.moveTo(0, 0);
  7732. f.beginPath();
  7733. f.strokeStyle = this._color(e.color, this.m_alpha);
  7734. f.fillStyle =
  7735. this._color(e.color, this.m_fillAlpha);
  7736. f.arc(h, l, b * g, 0, 2 * Math.PI, !0);
  7737. f.moveTo(h, l);
  7738. f.lineTo((a.x + d.x * b) * g, (a.y + d.y * b) * g);
  7739. f.closePath();
  7740. f.fill();
  7741. f.stroke()
  7742. }
  7743. };
  7744. a.prototype.DrawSegment = function(a, b, d) {
  7745. var e = this.m_ctx,
  7746. f = this.m_drawScale;
  7747. e.strokeStyle = this._color(d.color, this.m_alpha);
  7748. e.beginPath();
  7749. e.moveTo(a.x * f, a.y * f);
  7750. e.lineTo(b.x * f, b.y * f);
  7751. e.closePath();
  7752. e.stroke()
  7753. };
  7754. a.prototype.DrawTransform = function(a) {
  7755. var b = this.m_ctx,
  7756. d = this.m_drawScale;
  7757. b.beginPath();
  7758. b.strokeStyle = this._color(16711680, this.m_alpha);
  7759. b.moveTo(a.position.x * d, a.position.y * d);
  7760. b.lineTo((a.position.x + this.m_xformScale * a.R.col1.x) * d, (a.position.y + this.m_xformScale * a.R.col1.y) * d);
  7761. b.strokeStyle = this._color(65280, this.m_alpha);
  7762. b.moveTo(a.position.x * d, a.position.y * d);
  7763. b.lineTo((a.position.x + this.m_xformScale * a.R.col2.x) * d, (a.position.y + this.m_xformScale * a.R.col2.y) * d);
  7764. b.closePath();
  7765. b.stroke()
  7766. }
  7767. })();
  7768. var i;
  7769. for (i = 0; i < Box2D.postDefs.length; ++i) Box2D.postDefs[i]();
  7770. delete Box2D.postDefs;
  7771. function MakeNewWorld() {
  7772. var a = Box2D.Common.Math.b2Vec2,
  7773. c = Box2D.Dynamics.b2BodyDef,
  7774. b = Box2D.Dynamics.b2Body,
  7775. d = Box2D.Dynamics.b2FixtureDef,
  7776. e = Box2D.Dynamics.b2World,
  7777. f = Box2D.Collision.Shapes.b2PolygonShape,
  7778. g = new a(0, -10),
  7779. e = new e(g, !0),
  7780. g = new f;
  7781. g.SetAsEdge(new a(-40, 0), new a(40, 0));
  7782. var h = new d;
  7783. h.density = 0;
  7784. h.shape = g;
  7785. var l = new c;
  7786. e.CreateBody(l).CreateFixture(h);
  7787. g = new f;
  7788. g.SetAsBox(.5, .5);
  7789. for (var f = new a(-7, .75), m = new a, q = new a(.5625, 1), a = new a(1.125, 0), p = 0; 10 > p; ++p) {
  7790. m.Set(f.x, f.y);
  7791. for (var y = 0; 5 > y; ++y) h = new d,
  7792. h.density = 5, h.shape = g, l = new c, l.type = b.b2_dynamicBody, l.position.Set(m.x, m.y), e.CreateBody(l).CreateFixture(h), m.Add(a);
  7793. f.Add(q)
  7794. }
  7795. return e
  7796. }
  7797. var world = null,
  7798. Box2DBenchmark = new BenchmarkSuite("Box2D", [5432788], [new Benchmark("Box2D", !1, !1, 60, runBox2D, setupBox2D, tearDownBox2D, null, 8)]);
  7799. function runBox2D() {
  7800. for (var a = MakeNewWorld(), c = 0; 20 > c; c++) a.Step(1 / 60, 10, 3)
  7801. }
  7802. function setupBox2D() {}
  7803. function tearDownBox2D() {
  7804. Box2D = world = null
  7805. };
  7806. ////////////////////////////////////////////////////////////////////////////////
  7807. // Runner
  7808. ////////////////////////////////////////////////////////////////////////////////
  7809. var success = true;
  7810. function NotifyStart(name) {}
  7811. function NotifyError(name, error) {
  7812. WScript.Echo(name + " : ERROR : " + error.stack);
  7813. success = false;
  7814. }
  7815. function NotifyResult(name, score) {
  7816. if (success) {
  7817. WScript.Echo("### SCORE:", score);
  7818. }
  7819. }
  7820. function NotifyScore(score) {}
  7821. BenchmarkSuite.RunSuites({
  7822. NotifyStart: NotifyStart,
  7823. NotifyError: NotifyError,
  7824. NotifyResult: NotifyResult,
  7825. NotifyScore: NotifyScore
  7826. });