box2d.js 360 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // base.js
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2013 the V8 project authors. All rights reserved.
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following
  13. // disclaimer in the documentation and/or other materials provided
  14. // with the distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived
  17. // from this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. if(typeof(WScript) === "undefined")
  31. {
  32. var WScript = {
  33. Echo: print
  34. }
  35. }
  36. // Performance.now is used in latency benchmarks, the fallback is Date.now.
  37. var performance = performance || {};
  38. performance.now = (function() {
  39. return performance.now ||
  40. performance.mozNow ||
  41. performance.msNow ||
  42. performance.oNow ||
  43. performance.webkitNow ||
  44. Date.now;
  45. })();
  46. // Simple framework for running the benchmark suites and
  47. // computing a score based on the timing measurements.
  48. // A benchmark has a name (string) and a function that will be run to
  49. // do the performance measurement. The optional setup and tearDown
  50. // arguments are functions that will be invoked before and after
  51. // running the benchmark, but the running time of these functions will
  52. // not be accounted for in the benchmark score.
  53. function Benchmark(name, doWarmup, doDeterministic, deterministicIterations,
  54. run, setup, tearDown, rmsResult, minIterations) {
  55. this.name = name;
  56. this.doWarmup = doWarmup;
  57. this.doDeterministic = doDeterministic;
  58. this.deterministicIterations = deterministicIterations;
  59. this.run = run;
  60. this.Setup = setup ? setup : function() { };
  61. this.TearDown = tearDown ? tearDown : function() { };
  62. this.rmsResult = rmsResult ? rmsResult : null;
  63. this.minIterations = minIterations ? minIterations : 32;
  64. }
  65. // Benchmark results hold the benchmark and the measured time used to
  66. // run the benchmark. The benchmark score is computed later once a
  67. // full benchmark suite has run to completion. If latency is set to 0
  68. // then there is no latency score for this benchmark.
  69. function BenchmarkResult(benchmark, time, latency) {
  70. this.benchmark = benchmark;
  71. this.time = time;
  72. this.latency = latency;
  73. }
  74. // Automatically convert results to numbers. Used by the geometric
  75. // mean computation.
  76. BenchmarkResult.prototype.valueOf = function() {
  77. return this.time;
  78. }
  79. // Suites of benchmarks consist of a name and the set of benchmarks in
  80. // addition to the reference timing that the final score will be based
  81. // on. This way, all scores are relative to a reference run and higher
  82. // scores implies better performance.
  83. function BenchmarkSuite(name, reference, benchmarks) {
  84. this.name = name;
  85. this.reference = reference;
  86. this.benchmarks = benchmarks;
  87. BenchmarkSuite.suites.push(this);
  88. }
  89. // Keep track of all declared benchmark suites.
  90. BenchmarkSuite.suites = [];
  91. // Scores are not comparable across versions. Bump the version if
  92. // you're making changes that will affect that scores, e.g. if you add
  93. // a new benchmark or change an existing one.
  94. BenchmarkSuite.version = '9';
  95. // Defines global benchsuite running mode that overrides benchmark suite
  96. // behavior. Intended to be set by the benchmark driver. Undefined
  97. // values here allow a benchmark to define behaviour itself.
  98. BenchmarkSuite.config = {
  99. doWarmup: undefined,
  100. doDeterministic: undefined
  101. };
  102. // Override the alert function to throw an exception instead.
  103. alert = function(s) {
  104. throw "Alert called with argument: " + s;
  105. };
  106. // To make the benchmark results predictable, we replace Math.random
  107. // with a 100% deterministic alternative.
  108. BenchmarkSuite.ResetRNG = function() {
  109. Math.random = (function() {
  110. var seed = 49734321;
  111. return function() {
  112. // Robert Jenkins' 32 bit integer hash function.
  113. seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
  114. seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
  115. seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
  116. seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
  117. seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
  118. seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
  119. return (seed & 0xfffffff) / 0x10000000;
  120. };
  121. })();
  122. }
  123. // Runs all registered benchmark suites and optionally yields between
  124. // each individual benchmark to avoid running for too long in the
  125. // context of browsers. Once done, the final score is reported to the
  126. // runner.
  127. BenchmarkSuite.RunSuites = function(runner, skipBenchmarks) {
  128. skipBenchmarks = typeof skipBenchmarks === 'undefined' ? [] : skipBenchmarks;
  129. var continuation = null;
  130. var suites = BenchmarkSuite.suites;
  131. var length = suites.length;
  132. BenchmarkSuite.scores = [];
  133. var index = 0;
  134. function RunStep() {
  135. while (continuation || index < length) {
  136. if (continuation) {
  137. continuation = continuation();
  138. } else {
  139. var suite = suites[index++];
  140. if (runner.NotifyStart) runner.NotifyStart(suite.name);
  141. if (skipBenchmarks.indexOf(suite.name) > -1) {
  142. suite.NotifySkipped(runner);
  143. } else {
  144. continuation = suite.RunStep(runner);
  145. }
  146. }
  147. if (continuation && typeof window != 'undefined' && window.setTimeout) {
  148. window.setTimeout(RunStep, 25);
  149. return;
  150. }
  151. }
  152. // show final result
  153. if (runner.NotifyScore) {
  154. var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores);
  155. var formatted = BenchmarkSuite.FormatScore(100 * score);
  156. runner.NotifyScore(formatted);
  157. }
  158. }
  159. RunStep();
  160. }
  161. // Counts the total number of registered benchmarks. Useful for
  162. // showing progress as a percentage.
  163. BenchmarkSuite.CountBenchmarks = function() {
  164. var result = 0;
  165. var suites = BenchmarkSuite.suites;
  166. for (var i = 0; i < suites.length; i++) {
  167. result += suites[i].benchmarks.length;
  168. }
  169. return result;
  170. }
  171. // Computes the geometric mean of a set of numbers.
  172. BenchmarkSuite.GeometricMean = function(numbers) {
  173. var log = 0;
  174. for (var i = 0; i < numbers.length; i++) {
  175. log += Math.log(numbers[i]);
  176. }
  177. return Math.pow(Math.E, log / numbers.length);
  178. }
  179. // Computes the geometric mean of a set of throughput time measurements.
  180. BenchmarkSuite.GeometricMeanTime = function(measurements) {
  181. var log = 0;
  182. for (var i = 0; i < measurements.length; i++) {
  183. log += Math.log(measurements[i].time);
  184. }
  185. return Math.pow(Math.E, log / measurements.length);
  186. }
  187. // Computes the geometric mean of a set of rms measurements.
  188. BenchmarkSuite.GeometricMeanLatency = function(measurements) {
  189. var log = 0;
  190. var hasLatencyResult = false;
  191. for (var i = 0; i < measurements.length; i++) {
  192. if (measurements[i].latency != 0) {
  193. log += Math.log(measurements[i].latency);
  194. hasLatencyResult = true;
  195. }
  196. }
  197. if (hasLatencyResult) {
  198. return Math.pow(Math.E, log / measurements.length);
  199. } else {
  200. return 0;
  201. }
  202. }
  203. // Converts a score value to a string with at least three significant
  204. // digits.
  205. BenchmarkSuite.FormatScore = function(value) {
  206. if (value > 100) {
  207. return value.toFixed(0);
  208. } else {
  209. return value.toPrecision(3);
  210. }
  211. }
  212. // Notifies the runner that we're done running a single benchmark in
  213. // the benchmark suite. This can be useful to report progress.
  214. BenchmarkSuite.prototype.NotifyStep = function(result) {
  215. this.results.push(result);
  216. if (this.runner.NotifyStep) this.runner.NotifyStep(result.benchmark.name);
  217. }
  218. // Notifies the runner that we're done with running a suite and that
  219. // we have a result which can be reported to the user if needed.
  220. BenchmarkSuite.prototype.NotifyResult = function() {
  221. var mean = BenchmarkSuite.GeometricMeanTime(this.results);
  222. var score = this.reference[0] / mean;
  223. BenchmarkSuite.scores.push(score);
  224. if (this.runner.NotifyResult) {
  225. var formatted = BenchmarkSuite.FormatScore(100 * score);
  226. this.runner.NotifyResult(this.name, formatted);
  227. }
  228. if (this.reference.length == 2) {
  229. var meanLatency = BenchmarkSuite.GeometricMeanLatency(this.results);
  230. if (meanLatency != 0) {
  231. var scoreLatency = this.reference[1] / meanLatency;
  232. BenchmarkSuite.scores.push(scoreLatency);
  233. if (this.runner.NotifyResult) {
  234. var formattedLatency = BenchmarkSuite.FormatScore(100 * scoreLatency)
  235. this.runner.NotifyResult(this.name + "Latency", formattedLatency);
  236. }
  237. }
  238. }
  239. }
  240. BenchmarkSuite.prototype.NotifySkipped = function(runner) {
  241. BenchmarkSuite.scores.push(1); // push default reference score.
  242. if (runner.NotifyResult) {
  243. runner.NotifyResult(this.name, "Skipped");
  244. }
  245. }
  246. // Notifies the runner that running a benchmark resulted in an error.
  247. BenchmarkSuite.prototype.NotifyError = function(error) {
  248. if (this.runner.NotifyError) {
  249. this.runner.NotifyError(this.name, error);
  250. }
  251. if (this.runner.NotifyStep) {
  252. this.runner.NotifyStep(this.name);
  253. }
  254. }
  255. // Runs a single benchmark for at least a second and computes the
  256. // average time it takes to run a single iteration.
  257. BenchmarkSuite.prototype.RunSingleBenchmark = function(benchmark, data) {
  258. var config = BenchmarkSuite.config;
  259. var doWarmup = config.doWarmup !== undefined
  260. ? config.doWarmup
  261. : benchmark.doWarmup;
  262. var doDeterministic = config.doDeterministic !== undefined
  263. ? config.doDeterministic
  264. : benchmark.doDeterministic;
  265. function Measure(data) {
  266. var elapsed = 0;
  267. var start = new Date();
  268. // Run either for 1 second or for the number of iterations specified
  269. // by minIterations, depending on the config flag doDeterministic.
  270. for (var i = 0; (doDeterministic ?
  271. i<benchmark.deterministicIterations : elapsed < 1000); i++) {
  272. benchmark.run();
  273. elapsed = new Date() - start;
  274. }
  275. if (data != null) {
  276. data.runs += i;
  277. data.elapsed += elapsed;
  278. }
  279. }
  280. // Sets up data in order to skip or not the warmup phase.
  281. if (!doWarmup && data == null) {
  282. data = { runs: 0, elapsed: 0 };
  283. }
  284. if (data == null) {
  285. Measure(null);
  286. return { runs: 0, elapsed: 0 };
  287. } else {
  288. Measure(data);
  289. // If we've run too few iterations, we continue for another second.
  290. if (data.runs < benchmark.minIterations) return data;
  291. var usec = (data.elapsed * 1000) / data.runs;
  292. var rms = (benchmark.rmsResult != null) ? benchmark.rmsResult() : 0;
  293. this.NotifyStep(new BenchmarkResult(benchmark, usec, rms));
  294. return null;
  295. }
  296. }
  297. // This function starts running a suite, but stops between each
  298. // individual benchmark in the suite and returns a continuation
  299. // function which can be invoked to run the next benchmark. Once the
  300. // last benchmark has been executed, null is returned.
  301. BenchmarkSuite.prototype.RunStep = function(runner) {
  302. BenchmarkSuite.ResetRNG();
  303. this.results = [];
  304. this.runner = runner;
  305. var length = this.benchmarks.length;
  306. var index = 0;
  307. var suite = this;
  308. var data;
  309. // Run the setup, the actual benchmark, and the tear down in three
  310. // separate steps to allow the framework to yield between any of the
  311. // steps.
  312. function RunNextSetup() {
  313. if (index < length) {
  314. try {
  315. suite.benchmarks[index].Setup();
  316. } catch (e) {
  317. suite.NotifyError(e);
  318. return null;
  319. }
  320. return RunNextBenchmark;
  321. }
  322. suite.NotifyResult();
  323. return null;
  324. }
  325. function RunNextBenchmark() {
  326. try {
  327. data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
  328. } catch (e) {
  329. suite.NotifyError(e);
  330. return null;
  331. }
  332. // If data is null, we're done with this benchmark.
  333. return (data == null) ? RunNextTearDown : RunNextBenchmark();
  334. }
  335. function RunNextTearDown() {
  336. try {
  337. suite.benchmarks[index++].TearDown();
  338. } catch (e) {
  339. suite.NotifyError(e);
  340. return null;
  341. }
  342. return RunNextSetup;
  343. }
  344. // Start out running the setup.
  345. return RunNextSetup();
  346. }
  347. /////////////////////////////////////////////////////////////
  348. // box2d.js
  349. /////////////////////////////////////////////////////////////
  350. // Portions copyright 2013 Google, Inc
  351. /*
  352. * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
  353. *
  354. * This software is provided 'as-is', without any express or implied
  355. * warranty. In no event will the authors be held liable for any damages
  356. * arising from the use of this software.
  357. * Permission is granted to anyone to use this software for any purpose,
  358. * including commercial applications, and to alter it and redistribute it
  359. * freely, subject to the following restrictions:
  360. * 1. The origin of this software must not be misrepresented; you must not
  361. * claim that you wrote the original software. If you use this software
  362. * in a product, an acknowledgment in the product documentation would be
  363. * appreciated but is not required.
  364. * 2. Altered source versions must be plainly marked as such, and must not be
  365. * misrepresented as being the original software.
  366. * 3. This notice may not be removed or altered from any source distribution.
  367. */
  368. /*
  369. * Following code is beautified using http://jsbeautifier.org/
  370. */
  371. var Box2D = {};
  372. (function (F, G) {
  373. function K() {}
  374. if (!(Object.defineProperty instanceof Function) && Object.prototype.__defineGetter__ instanceof Function && Object.prototype.__defineSetter__ instanceof Function) Object.defineProperty = function (y, w, A) {
  375. A.get instanceof Function && y.__defineGetter__(w, A.get);
  376. A.set instanceof Function && y.__defineSetter__(w, A.set)
  377. };
  378. F.inherit = function (y, w) {
  379. K.prototype = w.prototype;
  380. y.prototype = new K;
  381. y.prototype.constructor = y
  382. };
  383. F.generateCallback = function (y, w) {
  384. return function () {
  385. w.apply(y, arguments)
  386. }
  387. };
  388. F.NVector = function (y) {
  389. if (y === G) y = 0;
  390. for (var w = Array(y || 0), A = 0; A < y; ++A) w[A] = 0;
  391. return w
  392. };
  393. F.is = function (y, w) {
  394. if (y === null) return false;
  395. if (w instanceof Function && y instanceof w) return true;
  396. if (y.constructor.__implements != G && y.constructor.__implements[w]) return true;
  397. return false
  398. };
  399. F.parseUInt = function (y) {
  400. return Math.abs(parseInt(y))
  401. }
  402. })(Box2D);
  403. var Vector = Array,
  404. Vector_a2j_Number = Box2D.NVector;
  405. if (typeof Box2D === "undefined") Box2D = {};
  406. if (typeof Box2D.Collision === "undefined") Box2D.Collision = {};
  407. if (typeof Box2D.Collision.Shapes === "undefined") Box2D.Collision.Shapes = {};
  408. if (typeof Box2D.Common === "undefined") Box2D.Common = {};
  409. if (typeof Box2D.Common.Math === "undefined") Box2D.Common.Math = {};
  410. if (typeof Box2D.Dynamics === "undefined") Box2D.Dynamics = {};
  411. if (typeof Box2D.Dynamics.Contacts === "undefined") Box2D.Dynamics.Contacts = {};
  412. if (typeof Box2D.Dynamics.Controllers === "undefined") Box2D.Dynamics.Controllers = {};
  413. if (typeof Box2D.Dynamics.Joints === "undefined") Box2D.Dynamics.Joints = {};
  414. (function () {
  415. function F() {
  416. F.b2AABB.apply(this, arguments)
  417. }
  418. function G() {
  419. G.b2Bound.apply(this, arguments)
  420. }
  421. function K() {
  422. K.b2BoundValues.apply(this, arguments);
  423. this.constructor === K && this.b2BoundValues.apply(this, arguments)
  424. }
  425. function y() {
  426. y.b2Collision.apply(this, arguments)
  427. }
  428. function w() {
  429. w.b2ContactID.apply(this, arguments);
  430. this.constructor === w && this.b2ContactID.apply(this, arguments)
  431. }
  432. function A() {
  433. A.b2ContactPoint.apply(this, arguments)
  434. }
  435. function U() {
  436. U.b2Distance.apply(this, arguments)
  437. }
  438. function p() {
  439. p.b2DistanceInput.apply(this,
  440. arguments)
  441. }
  442. function B() {
  443. B.b2DistanceOutput.apply(this, arguments)
  444. }
  445. function Q() {
  446. Q.b2DistanceProxy.apply(this, arguments)
  447. }
  448. function V() {
  449. V.b2DynamicTree.apply(this, arguments);
  450. this.constructor === V && this.b2DynamicTree.apply(this, arguments)
  451. }
  452. function M() {
  453. M.b2DynamicTreeBroadPhase.apply(this, arguments)
  454. }
  455. function L() {
  456. L.b2DynamicTreeNode.apply(this, arguments)
  457. }
  458. function I() {
  459. I.b2DynamicTreePair.apply(this, arguments)
  460. }
  461. function W() {
  462. W.b2Manifold.apply(this, arguments);
  463. this.constructor === W && this.b2Manifold.apply(this, arguments)
  464. }
  465. function Y() {
  466. Y.b2ManifoldPoint.apply(this, arguments);
  467. this.constructor === Y && this.b2ManifoldPoint.apply(this, arguments)
  468. }
  469. function k() {
  470. k.b2Point.apply(this, arguments)
  471. }
  472. function z() {
  473. z.b2RayCastInput.apply(this, arguments);
  474. this.constructor === z && this.b2RayCastInput.apply(this, arguments)
  475. }
  476. function u() {
  477. u.b2RayCastOutput.apply(this, arguments)
  478. }
  479. function D() {
  480. D.b2Segment.apply(this, arguments)
  481. }
  482. function H() {
  483. H.b2SeparationFunction.apply(this, arguments)
  484. }
  485. function O() {
  486. O.b2Simplex.apply(this, arguments);
  487. this.constructor === O && this.b2Simplex.apply(this, arguments)
  488. }
  489. function E() {
  490. E.b2SimplexCache.apply(this, arguments)
  491. }
  492. function R() {
  493. R.b2SimplexVertex.apply(this, arguments)
  494. }
  495. function N() {
  496. N.b2TimeOfImpact.apply(this, arguments)
  497. }
  498. function S() {
  499. S.b2TOIInput.apply(this, arguments)
  500. }
  501. function aa() {
  502. aa.b2WorldManifold.apply(this, arguments);
  503. this.constructor === aa && this.b2WorldManifold.apply(this, arguments)
  504. }
  505. function Z() {
  506. Z.ClipVertex.apply(this, arguments)
  507. }
  508. function d() {
  509. d.Features.apply(this, arguments)
  510. }
  511. function h() {
  512. h.b2CircleShape.apply(this, arguments);
  513. this.constructor === h && this.b2CircleShape.apply(this, arguments)
  514. }
  515. function l() {
  516. l.b2EdgeChainDef.apply(this, arguments);
  517. this.constructor === l && this.b2EdgeChainDef.apply(this, arguments)
  518. }
  519. function j() {
  520. j.b2EdgeShape.apply(this, arguments);
  521. this.constructor === j && this.b2EdgeShape.apply(this, arguments)
  522. }
  523. function o() {
  524. o.b2MassData.apply(this, arguments)
  525. }
  526. function q() {
  527. q.b2PolygonShape.apply(this, arguments);
  528. this.constructor === q && this.b2PolygonShape.apply(this, arguments)
  529. }
  530. function n() {
  531. n.b2Shape.apply(this, arguments);
  532. this.constructor === n && this.b2Shape.apply(this, arguments)
  533. }
  534. function a() {
  535. a.b2Color.apply(this, arguments);
  536. this.constructor === a && this.b2Color.apply(this, arguments)
  537. }
  538. function c() {
  539. c.b2Settings.apply(this, arguments)
  540. }
  541. function g() {
  542. g.b2Mat22.apply(this, arguments);
  543. this.constructor === g && this.b2Mat22.apply(this, arguments)
  544. }
  545. function b() {
  546. b.b2Mat33.apply(this, arguments);
  547. this.constructor === b && this.b2Mat33.apply(this, arguments)
  548. }
  549. function e() {
  550. e.b2Math.apply(this, arguments)
  551. }
  552. function f() {
  553. f.b2Sweep.apply(this, arguments)
  554. }
  555. function m() {
  556. m.b2Transform.apply(this,
  557. arguments);
  558. this.constructor === m && this.b2Transform.apply(this, arguments)
  559. }
  560. function r() {
  561. r.b2Vec2.apply(this, arguments);
  562. this.constructor === r && this.b2Vec2.apply(this, arguments)
  563. }
  564. function s() {
  565. s.b2Vec3.apply(this, arguments);
  566. this.constructor === s && this.b2Vec3.apply(this, arguments)
  567. }
  568. function v() {
  569. v.b2Body.apply(this, arguments);
  570. this.constructor === v && this.b2Body.apply(this, arguments)
  571. }
  572. function t() {
  573. t.b2BodyDef.apply(this, arguments);
  574. this.constructor === t && this.b2BodyDef.apply(this, arguments)
  575. }
  576. function x() {
  577. x.b2ContactFilter.apply(this,
  578. arguments)
  579. }
  580. function C() {
  581. C.b2ContactImpulse.apply(this, arguments)
  582. }
  583. function J() {
  584. J.b2ContactListener.apply(this, arguments)
  585. }
  586. function T() {
  587. T.b2ContactManager.apply(this, arguments);
  588. this.constructor === T && this.b2ContactManager.apply(this, arguments)
  589. }
  590. function P() {
  591. P.b2DebugDraw.apply(this, arguments);
  592. this.constructor === P && this.b2DebugDraw.apply(this, arguments)
  593. }
  594. function X() {
  595. X.b2DestructionListener.apply(this, arguments)
  596. }
  597. function $() {
  598. $.b2FilterData.apply(this, arguments)
  599. }
  600. function ba() {
  601. ba.b2Fixture.apply(this, arguments);
  602. this.constructor === ba && this.b2Fixture.apply(this, arguments)
  603. }
  604. function ca() {
  605. ca.b2FixtureDef.apply(this, arguments);
  606. this.constructor === ca && this.b2FixtureDef.apply(this, arguments)
  607. }
  608. function da() {
  609. da.b2Island.apply(this, arguments);
  610. this.constructor === da && this.b2Island.apply(this, arguments)
  611. }
  612. function Fa() {
  613. Fa.b2TimeStep.apply(this, arguments)
  614. }
  615. function ea() {
  616. ea.b2World.apply(this, arguments);
  617. this.constructor === ea && this.b2World.apply(this, arguments)
  618. }
  619. function Ga() {
  620. Ga.b2CircleContact.apply(this, arguments)
  621. }
  622. function fa() {
  623. fa.b2Contact.apply(this,
  624. arguments);
  625. this.constructor === fa && this.b2Contact.apply(this, arguments)
  626. }
  627. function ga() {
  628. ga.b2ContactConstraint.apply(this, arguments);
  629. this.constructor === ga && this.b2ContactConstraint.apply(this, arguments)
  630. }
  631. function Ha() {
  632. Ha.b2ContactConstraintPoint.apply(this, arguments)
  633. }
  634. function Ia() {
  635. Ia.b2ContactEdge.apply(this, arguments)
  636. }
  637. function ha() {
  638. ha.b2ContactFactory.apply(this, arguments);
  639. this.constructor === ha && this.b2ContactFactory.apply(this, arguments)
  640. }
  641. function Ja() {
  642. Ja.b2ContactRegister.apply(this, arguments)
  643. }
  644. function Ka() {
  645. Ka.b2ContactResult.apply(this,
  646. arguments)
  647. }
  648. function ia() {
  649. ia.b2ContactSolver.apply(this, arguments);
  650. this.constructor === ia && this.b2ContactSolver.apply(this, arguments)
  651. }
  652. function La() {
  653. La.b2EdgeAndCircleContact.apply(this, arguments)
  654. }
  655. function ja() {
  656. ja.b2NullContact.apply(this, arguments);
  657. this.constructor === ja && this.b2NullContact.apply(this, arguments)
  658. }
  659. function Ma() {
  660. Ma.b2PolyAndCircleContact.apply(this, arguments)
  661. }
  662. function Na() {
  663. Na.b2PolyAndEdgeContact.apply(this, arguments)
  664. }
  665. function Oa() {
  666. Oa.b2PolygonContact.apply(this, arguments)
  667. }
  668. function ka() {
  669. ka.b2PositionSolverManifold.apply(this,
  670. arguments);
  671. this.constructor === ka && this.b2PositionSolverManifold.apply(this, arguments)
  672. }
  673. function Pa() {
  674. Pa.b2BuoyancyController.apply(this, arguments)
  675. }
  676. function Qa() {
  677. Qa.b2ConstantAccelController.apply(this, arguments)
  678. }
  679. function Ra() {
  680. Ra.b2ConstantForceController.apply(this, arguments)
  681. }
  682. function Sa() {
  683. Sa.b2Controller.apply(this, arguments)
  684. }
  685. function Ta() {
  686. Ta.b2ControllerEdge.apply(this, arguments)
  687. }
  688. function Ua() {
  689. Ua.b2GravityController.apply(this, arguments)
  690. }
  691. function Va() {
  692. Va.b2TensorDampingController.apply(this, arguments)
  693. }
  694. function la() {
  695. la.b2DistanceJoint.apply(this, arguments);
  696. this.constructor === la && this.b2DistanceJoint.apply(this, arguments)
  697. }
  698. function ma() {
  699. ma.b2DistanceJointDef.apply(this, arguments);
  700. this.constructor === ma && this.b2DistanceJointDef.apply(this, arguments)
  701. }
  702. function na() {
  703. na.b2FrictionJoint.apply(this, arguments);
  704. this.constructor === na && this.b2FrictionJoint.apply(this, arguments)
  705. }
  706. function oa() {
  707. oa.b2FrictionJointDef.apply(this, arguments);
  708. this.constructor === oa && this.b2FrictionJointDef.apply(this, arguments)
  709. }
  710. function pa() {
  711. pa.b2GearJoint.apply(this,
  712. arguments);
  713. this.constructor === pa && this.b2GearJoint.apply(this, arguments)
  714. }
  715. function qa() {
  716. qa.b2GearJointDef.apply(this, arguments);
  717. this.constructor === qa && this.b2GearJointDef.apply(this, arguments)
  718. }
  719. function Wa() {
  720. Wa.b2Jacobian.apply(this, arguments)
  721. }
  722. function ra() {
  723. ra.b2Joint.apply(this, arguments);
  724. this.constructor === ra && this.b2Joint.apply(this, arguments)
  725. }
  726. function sa() {
  727. sa.b2JointDef.apply(this, arguments);
  728. this.constructor === sa && this.b2JointDef.apply(this, arguments)
  729. }
  730. function Xa() {
  731. Xa.b2JointEdge.apply(this, arguments)
  732. }
  733. function ta() {
  734. ta.b2LineJoint.apply(this, arguments);
  735. this.constructor === ta && this.b2LineJoint.apply(this, arguments)
  736. }
  737. function ua() {
  738. ua.b2LineJointDef.apply(this, arguments);
  739. this.constructor === ua && this.b2LineJointDef.apply(this, arguments)
  740. }
  741. function va() {
  742. va.b2MouseJoint.apply(this, arguments);
  743. this.constructor === va && this.b2MouseJoint.apply(this, arguments)
  744. }
  745. function wa() {
  746. wa.b2MouseJointDef.apply(this, arguments);
  747. this.constructor === wa && this.b2MouseJointDef.apply(this, arguments)
  748. }
  749. function xa() {
  750. xa.b2PrismaticJoint.apply(this,
  751. arguments);
  752. this.constructor === xa && this.b2PrismaticJoint.apply(this, arguments)
  753. }
  754. function ya() {
  755. ya.b2PrismaticJointDef.apply(this, arguments);
  756. this.constructor === ya && this.b2PrismaticJointDef.apply(this, arguments)
  757. }
  758. function za() {
  759. za.b2PulleyJoint.apply(this, arguments);
  760. this.constructor === za && this.b2PulleyJoint.apply(this, arguments)
  761. }
  762. function Aa() {
  763. Aa.b2PulleyJointDef.apply(this, arguments);
  764. this.constructor === Aa && this.b2PulleyJointDef.apply(this, arguments)
  765. }
  766. function Ba() {
  767. Ba.b2RevoluteJoint.apply(this, arguments);
  768. this.constructor === Ba && this.b2RevoluteJoint.apply(this, arguments)
  769. }
  770. function Ca() {
  771. Ca.b2RevoluteJointDef.apply(this, arguments);
  772. this.constructor === Ca && this.b2RevoluteJointDef.apply(this, arguments)
  773. }
  774. function Da() {
  775. Da.b2WeldJoint.apply(this, arguments);
  776. this.constructor === Da && this.b2WeldJoint.apply(this, arguments)
  777. }
  778. function Ea() {
  779. Ea.b2WeldJointDef.apply(this, arguments);
  780. this.constructor === Ea && this.b2WeldJointDef.apply(this, arguments)
  781. }
  782. Box2D.Collision.IBroadPhase = "Box2D.Collision.IBroadPhase";
  783. Box2D.Collision.b2AABB = F;
  784. Box2D.Collision.b2Bound = G;
  785. Box2D.Collision.b2BoundValues = K;
  786. Box2D.Collision.b2Collision = y;
  787. Box2D.Collision.b2ContactID = w;
  788. Box2D.Collision.b2ContactPoint = A;
  789. Box2D.Collision.b2Distance = U;
  790. Box2D.Collision.b2DistanceInput = p;
  791. Box2D.Collision.b2DistanceOutput = B;
  792. Box2D.Collision.b2DistanceProxy = Q;
  793. Box2D.Collision.b2DynamicTree = V;
  794. Box2D.Collision.b2DynamicTreeBroadPhase = M;
  795. Box2D.Collision.b2DynamicTreeNode = L;
  796. Box2D.Collision.b2DynamicTreePair = I;
  797. Box2D.Collision.b2Manifold = W;
  798. Box2D.Collision.b2ManifoldPoint = Y;
  799. Box2D.Collision.b2Point = k;
  800. Box2D.Collision.b2RayCastInput = z;
  801. Box2D.Collision.b2RayCastOutput = u;
  802. Box2D.Collision.b2Segment = D;
  803. Box2D.Collision.b2SeparationFunction = H;
  804. Box2D.Collision.b2Simplex = O;
  805. Box2D.Collision.b2SimplexCache = E;
  806. Box2D.Collision.b2SimplexVertex = R;
  807. Box2D.Collision.b2TimeOfImpact = N;
  808. Box2D.Collision.b2TOIInput = S;
  809. Box2D.Collision.b2WorldManifold = aa;
  810. Box2D.Collision.ClipVertex = Z;
  811. Box2D.Collision.Features = d;
  812. Box2D.Collision.Shapes.b2CircleShape = h;
  813. Box2D.Collision.Shapes.b2EdgeChainDef = l;
  814. Box2D.Collision.Shapes.b2EdgeShape = j;
  815. Box2D.Collision.Shapes.b2MassData = o;
  816. Box2D.Collision.Shapes.b2PolygonShape = q;
  817. Box2D.Collision.Shapes.b2Shape = n;
  818. Box2D.Common.b2internal = "Box2D.Common.b2internal";
  819. Box2D.Common.b2Color = a;
  820. Box2D.Common.b2Settings = c;
  821. Box2D.Common.Math.b2Mat22 = g;
  822. Box2D.Common.Math.b2Mat33 = b;
  823. Box2D.Common.Math.b2Math = e;
  824. Box2D.Common.Math.b2Sweep = f;
  825. Box2D.Common.Math.b2Transform = m;
  826. Box2D.Common.Math.b2Vec2 = r;
  827. Box2D.Common.Math.b2Vec3 = s;
  828. Box2D.Dynamics.b2Body = v;
  829. Box2D.Dynamics.b2BodyDef = t;
  830. Box2D.Dynamics.b2ContactFilter = x;
  831. Box2D.Dynamics.b2ContactImpulse = C;
  832. Box2D.Dynamics.b2ContactListener = J;
  833. Box2D.Dynamics.b2ContactManager = T;
  834. Box2D.Dynamics.b2DebugDraw = P;
  835. Box2D.Dynamics.b2DestructionListener = X;
  836. Box2D.Dynamics.b2FilterData = $;
  837. Box2D.Dynamics.b2Fixture = ba;
  838. Box2D.Dynamics.b2FixtureDef = ca;
  839. Box2D.Dynamics.b2Island = da;
  840. Box2D.Dynamics.b2TimeStep = Fa;
  841. Box2D.Dynamics.b2World = ea;
  842. Box2D.Dynamics.Contacts.b2CircleContact = Ga;
  843. Box2D.Dynamics.Contacts.b2Contact = fa;
  844. Box2D.Dynamics.Contacts.b2ContactConstraint = ga;
  845. Box2D.Dynamics.Contacts.b2ContactConstraintPoint = Ha;
  846. Box2D.Dynamics.Contacts.b2ContactEdge = Ia;
  847. Box2D.Dynamics.Contacts.b2ContactFactory = ha;
  848. Box2D.Dynamics.Contacts.b2ContactRegister = Ja;
  849. Box2D.Dynamics.Contacts.b2ContactResult = Ka;
  850. Box2D.Dynamics.Contacts.b2ContactSolver = ia;
  851. Box2D.Dynamics.Contacts.b2EdgeAndCircleContact = La;
  852. Box2D.Dynamics.Contacts.b2NullContact = ja;
  853. Box2D.Dynamics.Contacts.b2PolyAndCircleContact = Ma;
  854. Box2D.Dynamics.Contacts.b2PolyAndEdgeContact = Na;
  855. Box2D.Dynamics.Contacts.b2PolygonContact = Oa;
  856. Box2D.Dynamics.Contacts.b2PositionSolverManifold = ka;
  857. Box2D.Dynamics.Controllers.b2BuoyancyController = Pa;
  858. Box2D.Dynamics.Controllers.b2ConstantAccelController = Qa;
  859. Box2D.Dynamics.Controllers.b2ConstantForceController = Ra;
  860. Box2D.Dynamics.Controllers.b2Controller = Sa;
  861. Box2D.Dynamics.Controllers.b2ControllerEdge = Ta;
  862. Box2D.Dynamics.Controllers.b2GravityController = Ua;
  863. Box2D.Dynamics.Controllers.b2TensorDampingController = Va;
  864. Box2D.Dynamics.Joints.b2DistanceJoint = la;
  865. Box2D.Dynamics.Joints.b2DistanceJointDef = ma;
  866. Box2D.Dynamics.Joints.b2FrictionJoint = na;
  867. Box2D.Dynamics.Joints.b2FrictionJointDef = oa;
  868. Box2D.Dynamics.Joints.b2GearJoint = pa;
  869. Box2D.Dynamics.Joints.b2GearJointDef = qa;
  870. Box2D.Dynamics.Joints.b2Jacobian = Wa;
  871. Box2D.Dynamics.Joints.b2Joint = ra;
  872. Box2D.Dynamics.Joints.b2JointDef = sa;
  873. Box2D.Dynamics.Joints.b2JointEdge = Xa;
  874. Box2D.Dynamics.Joints.b2LineJoint = ta;
  875. Box2D.Dynamics.Joints.b2LineJointDef = ua;
  876. Box2D.Dynamics.Joints.b2MouseJoint = va;
  877. Box2D.Dynamics.Joints.b2MouseJointDef = wa;
  878. Box2D.Dynamics.Joints.b2PrismaticJoint = xa;
  879. Box2D.Dynamics.Joints.b2PrismaticJointDef = ya;
  880. Box2D.Dynamics.Joints.b2PulleyJoint = za;
  881. Box2D.Dynamics.Joints.b2PulleyJointDef = Aa;
  882. Box2D.Dynamics.Joints.b2RevoluteJoint = Ba;
  883. Box2D.Dynamics.Joints.b2RevoluteJointDef = Ca;
  884. Box2D.Dynamics.Joints.b2WeldJoint = Da;
  885. Box2D.Dynamics.Joints.b2WeldJointDef = Ea
  886. })();
  887. Box2D.postDefs = [];
  888. (function () {
  889. var F = Box2D.Collision.Shapes.b2CircleShape,
  890. G = Box2D.Collision.Shapes.b2PolygonShape,
  891. K = Box2D.Collision.Shapes.b2Shape,
  892. y = Box2D.Common.b2Settings,
  893. w = Box2D.Common.Math.b2Math,
  894. A = Box2D.Common.Math.b2Sweep,
  895. U = Box2D.Common.Math.b2Transform,
  896. p = Box2D.Common.Math.b2Vec2,
  897. B = Box2D.Collision.b2AABB,
  898. Q = Box2D.Collision.b2Bound,
  899. V = Box2D.Collision.b2BoundValues,
  900. M = Box2D.Collision.b2Collision,
  901. L = Box2D.Collision.b2ContactID,
  902. I = Box2D.Collision.b2ContactPoint,
  903. W = Box2D.Collision.b2Distance,
  904. Y = Box2D.Collision.b2DistanceInput,
  905. k = Box2D.Collision.b2DistanceOutput,
  906. z = Box2D.Collision.b2DistanceProxy,
  907. u = Box2D.Collision.b2DynamicTree,
  908. D = Box2D.Collision.b2DynamicTreeBroadPhase,
  909. H = Box2D.Collision.b2DynamicTreeNode,
  910. O = Box2D.Collision.b2DynamicTreePair,
  911. E = Box2D.Collision.b2Manifold,
  912. R = Box2D.Collision.b2ManifoldPoint,
  913. N = Box2D.Collision.b2Point,
  914. S = Box2D.Collision.b2RayCastInput,
  915. aa = Box2D.Collision.b2RayCastOutput,
  916. Z = Box2D.Collision.b2Segment,
  917. d = Box2D.Collision.b2SeparationFunction,
  918. h = Box2D.Collision.b2Simplex,
  919. l = Box2D.Collision.b2SimplexCache,
  920. j = Box2D.Collision.b2SimplexVertex,
  921. o = Box2D.Collision.b2TimeOfImpact,
  922. q = Box2D.Collision.b2TOIInput,
  923. n = Box2D.Collision.b2WorldManifold,
  924. a = Box2D.Collision.ClipVertex,
  925. c = Box2D.Collision.Features,
  926. g = Box2D.Collision.IBroadPhase;
  927. B.b2AABB = function () {
  928. this.lowerBound = new p;
  929. this.upperBound = new p
  930. };
  931. B.prototype.IsValid = function () {
  932. var b = this.upperBound.y - this.lowerBound.y;
  933. return b = (b = this.upperBound.x - this.lowerBound.x >= 0 && b >= 0) && this.lowerBound.IsValid() && this.upperBound.IsValid()
  934. };
  935. B.prototype.GetCenter = function () {
  936. return new p((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2)
  937. };
  938. B.prototype.GetExtents = function () {
  939. return new p((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2)
  940. };
  941. B.prototype.Contains = function (b) {
  942. var e = true;
  943. return e = (e = (e = (e = e && this.lowerBound.x <= b.lowerBound.x) && this.lowerBound.y <= b.lowerBound.y) && b.upperBound.x <= this.upperBound.x) && b.upperBound.y <= this.upperBound.y
  944. };
  945. B.prototype.RayCast = function (b, e) {
  946. var f = -Number.MAX_VALUE,
  947. m = Number.MAX_VALUE,
  948. r = e.p1.x,
  949. s = e.p1.y,
  950. v = e.p2.x - e.p1.x,
  951. t = e.p2.y - e.p1.y,
  952. x = Math.abs(t),
  953. C = b.normal,
  954. J = 0,
  955. T = 0,
  956. P = J = 0;
  957. P = 0;
  958. if (Math.abs(v) < Number.MIN_VALUE) {
  959. if (r < this.lowerBound.x || this.upperBound.x < r) return false
  960. } else {
  961. J = 1 / v;
  962. T = (this.lowerBound.x - r) * J;
  963. J = (this.upperBound.x - r) * J;
  964. P = -1;
  965. if (T > J) {
  966. P = T;
  967. T = J;
  968. J = P;
  969. P = 1
  970. }
  971. if (T > f) {
  972. C.x = P;
  973. C.y = 0;
  974. f = T
  975. }
  976. m = Math.min(m, J);
  977. if (f > m) return false
  978. } if (x < Number.MIN_VALUE) {
  979. if (s < this.lowerBound.y || this.upperBound.y < s) return false
  980. } else {
  981. J = 1 / t;
  982. T = (this.lowerBound.y - s) * J;
  983. J = (this.upperBound.y - s) * J;
  984. P = -1;
  985. if (T > J) {
  986. P = T;
  987. T = J;
  988. J = P;
  989. P = 1
  990. }
  991. if (T > f) {
  992. C.y = P;
  993. C.x = 0;
  994. f = T
  995. }
  996. m = Math.min(m, J);
  997. if (f > m) return false
  998. }
  999. b.fraction = f;
  1000. return true
  1001. };
  1002. B.prototype.TestOverlap = function (b) {
  1003. var e = b.lowerBound.y - this.upperBound.y,
  1004. f = this.lowerBound.y - b.upperBound.y;
  1005. if (b.lowerBound.x - this.upperBound.x > 0 || e > 0) return false;
  1006. if (this.lowerBound.x - b.upperBound.x > 0 || f > 0) return false;
  1007. return true
  1008. };
  1009. B.Combine = function (b, e) {
  1010. var f = new B;
  1011. f.Combine(b, e);
  1012. return f
  1013. };
  1014. B.prototype.Combine = function (b, e) {
  1015. this.lowerBound.x = Math.min(b.lowerBound.x, e.lowerBound.x);
  1016. this.lowerBound.y = Math.min(b.lowerBound.y, e.lowerBound.y);
  1017. this.upperBound.x = Math.max(b.upperBound.x, e.upperBound.x);
  1018. this.upperBound.y = Math.max(b.upperBound.y, e.upperBound.y)
  1019. };
  1020. Q.b2Bound = function () {};
  1021. Q.prototype.IsLower = function () {
  1022. return (this.value & 1) == 0
  1023. };
  1024. Q.prototype.IsUpper = function () {
  1025. return (this.value & 1) == 1
  1026. };
  1027. Q.prototype.Swap = function (b) {
  1028. var e = this.value,
  1029. f = this.proxy,
  1030. m = this.stabbingCount;
  1031. this.value = b.value;
  1032. this.proxy = b.proxy;
  1033. this.stabbingCount = b.stabbingCount;
  1034. b.value = e;
  1035. b.proxy = f;
  1036. b.stabbingCount = m
  1037. };
  1038. V.b2BoundValues = function () {};
  1039. V.prototype.b2BoundValues = function () {
  1040. this.lowerValues = new Vector_a2j_Number;
  1041. this.lowerValues[0] = 0;
  1042. this.lowerValues[1] = 0;
  1043. this.upperValues = new Vector_a2j_Number;
  1044. this.upperValues[0] = 0;
  1045. this.upperValues[1] = 0
  1046. };
  1047. M.b2Collision = function () {};
  1048. M.ClipSegmentToLine = function (b, e, f, m) {
  1049. if (m === undefined) m = 0;
  1050. var r, s = 0;
  1051. r = e[0];
  1052. var v = r.v;
  1053. r = e[1];
  1054. var t = r.v,
  1055. x = f.x * v.x + f.y * v.y - m;
  1056. r = f.x * t.x + f.y * t.y - m;
  1057. x <= 0 && b[s++].Set(e[0]);
  1058. r <= 0 && b[s++].Set(e[1]);
  1059. if (x * r < 0) {
  1060. f = x / (x - r);
  1061. r = b[s];
  1062. r = r.v;
  1063. r.x = v.x + f * (t.x - v.x);
  1064. r.y = v.y + f * (t.y - v.y);
  1065. r = b[s];
  1066. r.id = (x > 0 ? e[0] : e[1]).id;
  1067. ++s
  1068. }
  1069. return s
  1070. };
  1071. M.EdgeSeparation = function (b, e, f, m, r) {
  1072. if (f === undefined) f = 0;
  1073. parseInt(b.m_vertexCount);
  1074. var s = b.m_vertices;
  1075. b = b.m_normals;
  1076. var v = parseInt(m.m_vertexCount),
  1077. t = m.m_vertices,
  1078. x, C;
  1079. x = e.R;
  1080. C = b[f];
  1081. b = x.col1.x * C.x + x.col2.x * C.y;
  1082. m = x.col1.y * C.x + x.col2.y * C.y;
  1083. x = r.R;
  1084. var J = x.col1.x * b + x.col1.y * m;
  1085. x = x.col2.x * b + x.col2.y * m;
  1086. for (var T = 0, P = Number.MAX_VALUE, X = 0; X < v; ++X) {
  1087. C = t[X];
  1088. C = C.x * J + C.y * x;
  1089. if (C < P) {
  1090. P = C;
  1091. T = X
  1092. }
  1093. }
  1094. C = s[f];
  1095. x = e.R;
  1096. f = e.position.x + (x.col1.x * C.x + x.col2.x * C.y);
  1097. e = e.position.y + (x.col1.y * C.x + x.col2.y * C.y);
  1098. C = t[T];
  1099. x = r.R;
  1100. s = r.position.x + (x.col1.x * C.x + x.col2.x * C.y);
  1101. r = r.position.y + (x.col1.y * C.x + x.col2.y * C.y);
  1102. s -= f;
  1103. r -= e;
  1104. return s * b + r * m
  1105. };
  1106. M.FindMaxSeparation = function (b, e, f, m, r) {
  1107. var s = parseInt(e.m_vertexCount),
  1108. v = e.m_normals,
  1109. t, x;
  1110. x = r.R;
  1111. t = m.m_centroid;
  1112. var C = r.position.x + (x.col1.x * t.x + x.col2.x * t.y),
  1113. J = r.position.y + (x.col1.y * t.x + x.col2.y * t.y);
  1114. x = f.R;
  1115. t = e.m_centroid;
  1116. C -= f.position.x + (x.col1.x * t.x + x.col2.x * t.y);
  1117. J -= f.position.y + (x.col1.y * t.x + x.col2.y * t.y);
  1118. x = C * f.R.col1.x + J * f.R.col1.y;
  1119. J = C * f.R.col2.x + J * f.R.col2.y;
  1120. C = 0;
  1121. for (var T = -Number.MAX_VALUE, P = 0; P < s; ++P) {
  1122. t = v[P];
  1123. t = t.x * x + t.y * J;
  1124. if (t > T) {
  1125. T = t;
  1126. C = P
  1127. }
  1128. }
  1129. v = M.EdgeSeparation(e, f, C, m, r);
  1130. t = parseInt(C - 1 >= 0 ? C - 1 : s - 1);
  1131. x = M.EdgeSeparation(e, f, t, m, r);
  1132. J = parseInt(C + 1 < s ? C + 1 : 0);
  1133. T = M.EdgeSeparation(e, f, J, m, r);
  1134. var X = P = 0,
  1135. $ = 0;
  1136. if (x > v && x > T) {
  1137. $ = -1;
  1138. P = t;
  1139. X = x
  1140. } else if (T > v) {
  1141. $ = 1;
  1142. P = J;
  1143. X = T
  1144. } else {
  1145. b[0] = C;
  1146. return v
  1147. }
  1148. for (;;) {
  1149. C = $ == -1 ? P - 1 >= 0 ? P - 1 : s - 1 : P + 1 < s ? P + 1 : 0;
  1150. v = M.EdgeSeparation(e, f, C, m, r);
  1151. if (v > X) {
  1152. P = C;
  1153. X = v
  1154. } else break
  1155. }
  1156. b[0] = P;
  1157. return X
  1158. };
  1159. M.FindIncidentEdge = function (b, e, f, m, r, s) {
  1160. if (m === undefined) m = 0;
  1161. parseInt(e.m_vertexCount);
  1162. var v = e.m_normals,
  1163. t = parseInt(r.m_vertexCount);
  1164. e = r.m_vertices;
  1165. r = r.m_normals;
  1166. var x;
  1167. x = f.R;
  1168. f = v[m];
  1169. v = x.col1.x * f.x + x.col2.x * f.y;
  1170. var C = x.col1.y * f.x + x.col2.y * f.y;
  1171. x = s.R;
  1172. f = x.col1.x * v + x.col1.y * C;
  1173. C = x.col2.x * v + x.col2.y * C;
  1174. v = f;
  1175. x = 0;
  1176. for (var J = Number.MAX_VALUE, T = 0; T < t; ++T) {
  1177. f = r[T];
  1178. f = v * f.x + C * f.y;
  1179. if (f < J) {
  1180. J = f;
  1181. x = T
  1182. }
  1183. }
  1184. r = parseInt(x);
  1185. v = parseInt(r + 1 < t ? r + 1 : 0);
  1186. t = b[0];
  1187. f = e[r];
  1188. x = s.R;
  1189. t.v.x = s.position.x + (x.col1.x * f.x + x.col2.x * f.y);
  1190. t.v.y = s.position.y + (x.col1.y * f.x + x.col2.y * f.y);
  1191. t.id.features.referenceEdge = m;
  1192. t.id.features.incidentEdge = r;
  1193. t.id.features.incidentVertex = 0;
  1194. t = b[1];
  1195. f = e[v];
  1196. x = s.R;
  1197. t.v.x = s.position.x + (x.col1.x * f.x + x.col2.x * f.y);
  1198. t.v.y = s.position.y + (x.col1.y * f.x + x.col2.y * f.y);
  1199. t.id.features.referenceEdge = m;
  1200. t.id.features.incidentEdge = v;
  1201. t.id.features.incidentVertex = 1
  1202. };
  1203. M.MakeClipPointVector = function () {
  1204. var b = new Vector(2);
  1205. b[0] = new a;
  1206. b[1] = new a;
  1207. return b
  1208. };
  1209. M.CollidePolygons = function (b, e, f, m, r) {
  1210. var s;
  1211. b.m_pointCount = 0;
  1212. var v = e.m_radius + m.m_radius;
  1213. s = 0;
  1214. M.s_edgeAO[0] = s;
  1215. var t = M.FindMaxSeparation(M.s_edgeAO, e, f, m, r);
  1216. s = M.s_edgeAO[0];
  1217. if (!(t > v)) {
  1218. var x = 0;
  1219. M.s_edgeBO[0] = x;
  1220. var C = M.FindMaxSeparation(M.s_edgeBO,
  1221. m, r, e, f);
  1222. x = M.s_edgeBO[0];
  1223. if (!(C > v)) {
  1224. var J = 0,
  1225. T = 0;
  1226. if (C > 0.98 * t + 0.0010) {
  1227. t = m;
  1228. m = e;
  1229. e = r;
  1230. f = f;
  1231. J = x;
  1232. b.m_type = E.e_faceB;
  1233. T = 1
  1234. } else {
  1235. t = e;
  1236. m = m;
  1237. e = f;
  1238. f = r;
  1239. J = s;
  1240. b.m_type = E.e_faceA;
  1241. T = 0
  1242. }
  1243. s = M.s_incidentEdge;
  1244. M.FindIncidentEdge(s, t, e, J, m, f);
  1245. x = parseInt(t.m_vertexCount);
  1246. r = t.m_vertices;
  1247. t = r[J];
  1248. var P;
  1249. P = J + 1 < x ? r[parseInt(J + 1)] : r[0];
  1250. J = M.s_localTangent;
  1251. J.Set(P.x - t.x, P.y - t.y);
  1252. J.Normalize();
  1253. r = M.s_localNormal;
  1254. r.x = J.y;
  1255. r.y = -J.x;
  1256. m = M.s_planePoint;
  1257. m.Set(0.5 * (t.x + P.x), 0.5 * (t.y + P.y));
  1258. C = M.s_tangent;
  1259. x = e.R;
  1260. C.x = x.col1.x * J.x + x.col2.x * J.y;
  1261. C.y = x.col1.y * J.x + x.col2.y * J.y;
  1262. var X = M.s_tangent2;
  1263. X.x = -C.x;
  1264. X.y = -C.y;
  1265. J = M.s_normal;
  1266. J.x = C.y;
  1267. J.y = -C.x;
  1268. var $ = M.s_v11,
  1269. ba = M.s_v12;
  1270. $.x = e.position.x + (x.col1.x * t.x + x.col2.x * t.y);
  1271. $.y = e.position.y + (x.col1.y * t.x + x.col2.y * t.y);
  1272. ba.x = e.position.x + (x.col1.x * P.x + x.col2.x * P.y);
  1273. ba.y = e.position.y + (x.col1.y * P.x + x.col2.y * P.y);
  1274. e = J.x * $.x + J.y * $.y;
  1275. x = C.x * ba.x + C.y * ba.y + v;
  1276. P = M.s_clipPoints1;
  1277. t = M.s_clipPoints2;
  1278. ba = 0;
  1279. ba = M.ClipSegmentToLine(P, s, X, -C.x * $.x - C.y * $.y + v);
  1280. if (!(ba < 2)) {
  1281. ba = M.ClipSegmentToLine(t, P, C, x);
  1282. if (!(ba < 2)) {
  1283. b.m_localPlaneNormal.SetV(r);
  1284. b.m_localPoint.SetV(m);
  1285. for (m = r = 0; m < y.b2_maxManifoldPoints; ++m) {
  1286. s = t[m];
  1287. if (J.x * s.v.x + J.y * s.v.y - e <= v) {
  1288. C = b.m_points[r];
  1289. x = f.R;
  1290. X = s.v.x - f.position.x;
  1291. $ = s.v.y - f.position.y;
  1292. C.m_localPoint.x = X * x.col1.x + $ * x.col1.y;
  1293. C.m_localPoint.y = X * x.col2.x + $ * x.col2.y;
  1294. C.m_id.Set(s.id);
  1295. C.m_id.features.flip = T;
  1296. ++r
  1297. }
  1298. }
  1299. b.m_pointCount = r
  1300. }
  1301. }
  1302. }
  1303. }
  1304. };
  1305. M.CollideCircles = function (b, e, f, m, r) {
  1306. b.m_pointCount = 0;
  1307. var s, v;
  1308. s = f.R;
  1309. v = e.m_p;
  1310. var t = f.position.x + (s.col1.x * v.x + s.col2.x * v.y);
  1311. f = f.position.y + (s.col1.y * v.x + s.col2.y * v.y);
  1312. s = r.R;
  1313. v = m.m_p;
  1314. t = r.position.x + (s.col1.x * v.x + s.col2.x * v.y) - t;
  1315. r = r.position.y + (s.col1.y * v.x + s.col2.y * v.y) - f;
  1316. s = e.m_radius + m.m_radius;
  1317. if (!(t * t + r * r > s * s)) {
  1318. b.m_type = E.e_circles;
  1319. b.m_localPoint.SetV(e.m_p);
  1320. b.m_localPlaneNormal.SetZero();
  1321. b.m_pointCount = 1;
  1322. b.m_points[0].m_localPoint.SetV(m.m_p);
  1323. b.m_points[0].m_id.key = 0
  1324. }
  1325. };
  1326. M.CollidePolygonAndCircle = function (b, e, f, m, r) {
  1327. var s = b.m_pointCount = 0,
  1328. v = 0,
  1329. t, x;
  1330. x = r.R;
  1331. t = m.m_p;
  1332. var C = r.position.y + (x.col1.y * t.x + x.col2.y * t.y);
  1333. s = r.position.x + (x.col1.x * t.x + x.col2.x * t.y) - f.position.x;
  1334. v = C - f.position.y;
  1335. x = f.R;
  1336. f = s * x.col1.x + v * x.col1.y;
  1337. x = s * x.col2.x + v * x.col2.y;
  1338. var J = 0;
  1339. C = -Number.MAX_VALUE;
  1340. r = e.m_radius + m.m_radius;
  1341. var T = parseInt(e.m_vertexCount),
  1342. P = e.m_vertices;
  1343. e = e.m_normals;
  1344. for (var X = 0; X < T; ++X) {
  1345. t = P[X];
  1346. s = f - t.x;
  1347. v = x - t.y;
  1348. t = e[X];
  1349. s = t.x * s + t.y * v;
  1350. if (s > r) return;
  1351. if (s > C) {
  1352. C = s;
  1353. J = X
  1354. }
  1355. }
  1356. s = parseInt(J);
  1357. v = parseInt(s + 1 < T ? s + 1 : 0);
  1358. t = P[s];
  1359. P = P[v];
  1360. if (C < Number.MIN_VALUE) {
  1361. b.m_pointCount = 1;
  1362. b.m_type = E.e_faceA;
  1363. b.m_localPlaneNormal.SetV(e[J]);
  1364. b.m_localPoint.x = 0.5 * (t.x + P.x);
  1365. b.m_localPoint.y = 0.5 * (t.y + P.y)
  1366. } else {
  1367. C = (f - P.x) * (t.x - P.x) + (x - P.y) * (t.y - P.y);
  1368. if ((f - t.x) * (P.x - t.x) + (x - t.y) * (P.y - t.y) <= 0) {
  1369. if ((f - t.x) * (f - t.x) + (x - t.y) * (x - t.y) > r * r) return;
  1370. b.m_pointCount = 1;
  1371. b.m_type = E.e_faceA;
  1372. b.m_localPlaneNormal.x = f - t.x;
  1373. b.m_localPlaneNormal.y = x - t.y;
  1374. b.m_localPlaneNormal.Normalize();
  1375. b.m_localPoint.SetV(t)
  1376. } else if (C <= 0) {
  1377. if ((f - P.x) * (f - P.x) + (x - P.y) * (x - P.y) > r * r) return;
  1378. b.m_pointCount = 1;
  1379. b.m_type = E.e_faceA;
  1380. b.m_localPlaneNormal.x = f - P.x;
  1381. b.m_localPlaneNormal.y = x - P.y;
  1382. b.m_localPlaneNormal.Normalize();
  1383. b.m_localPoint.SetV(P)
  1384. } else {
  1385. J = 0.5 * (t.x + P.x);
  1386. t = 0.5 * (t.y + P.y);
  1387. C = (f - J) * e[s].x + (x - t) * e[s].y;
  1388. if (C > r) return;
  1389. b.m_pointCount = 1;
  1390. b.m_type = E.e_faceA;
  1391. b.m_localPlaneNormal.x = e[s].x;
  1392. b.m_localPlaneNormal.y = e[s].y;
  1393. b.m_localPlaneNormal.Normalize();
  1394. b.m_localPoint.Set(J, t)
  1395. }
  1396. }
  1397. b.m_points[0].m_localPoint.SetV(m.m_p);
  1398. b.m_points[0].m_id.key = 0
  1399. };
  1400. M.TestOverlap = function (b, e) {
  1401. var f = e.lowerBound,
  1402. m = b.upperBound,
  1403. r = f.x - m.x,
  1404. s = f.y - m.y;
  1405. f = b.lowerBound;
  1406. m = e.upperBound;
  1407. var v = f.y - m.y;
  1408. if (r > 0 || s > 0) return false;
  1409. if (f.x - m.x > 0 || v > 0) return false;
  1410. return true
  1411. };
  1412. Box2D.postDefs.push(function () {
  1413. Box2D.Collision.b2Collision.s_incidentEdge = M.MakeClipPointVector();
  1414. Box2D.Collision.b2Collision.s_clipPoints1 = M.MakeClipPointVector();
  1415. Box2D.Collision.b2Collision.s_clipPoints2 = M.MakeClipPointVector();
  1416. Box2D.Collision.b2Collision.s_edgeAO = new Vector_a2j_Number(1);
  1417. Box2D.Collision.b2Collision.s_edgeBO = new Vector_a2j_Number(1);
  1418. Box2D.Collision.b2Collision.s_localTangent = new p;
  1419. Box2D.Collision.b2Collision.s_localNormal = new p;
  1420. Box2D.Collision.b2Collision.s_planePoint = new p;
  1421. Box2D.Collision.b2Collision.s_normal = new p;
  1422. Box2D.Collision.b2Collision.s_tangent = new p;
  1423. Box2D.Collision.b2Collision.s_tangent2 = new p;
  1424. Box2D.Collision.b2Collision.s_v11 = new p;
  1425. Box2D.Collision.b2Collision.s_v12 = new p;
  1426. Box2D.Collision.b2Collision.b2CollidePolyTempVec = new p;
  1427. Box2D.Collision.b2Collision.b2_nullFeature = 255
  1428. });
  1429. L.b2ContactID = function () {
  1430. this.features = new c
  1431. };
  1432. L.prototype.b2ContactID = function () {
  1433. this.features._m_id = this
  1434. };
  1435. L.prototype.Set = function (b) {
  1436. this.key = b._key
  1437. };
  1438. L.prototype.Copy = function () {
  1439. var b = new L;
  1440. b.key = this.key;
  1441. return b
  1442. };
  1443. Object.defineProperty(L.prototype, "key", {
  1444. enumerable: false,
  1445. configurable: true,
  1446. get: function () {
  1447. return this._key
  1448. }
  1449. });
  1450. Object.defineProperty(L.prototype, "key", {
  1451. enumerable: false,
  1452. configurable: true,
  1453. set: function (b) {
  1454. if (b === undefined) b = 0;
  1455. this._key = b;
  1456. this.features._referenceEdge = this._key & 255;
  1457. this.features._incidentEdge = (this._key & 65280) >> 8 & 255;
  1458. this.features._incidentVertex = (this._key & 16711680) >> 16 & 255;
  1459. this.features._flip = (this._key & 4278190080) >> 24 & 255
  1460. }
  1461. });
  1462. I.b2ContactPoint = function () {
  1463. this.position = new p;
  1464. this.velocity = new p;
  1465. this.normal = new p;
  1466. this.id = new L
  1467. };
  1468. W.b2Distance = function () {};
  1469. W.Distance = function (b, e, f) {
  1470. ++W.b2_gjkCalls;
  1471. var m = f.proxyA,
  1472. r = f.proxyB,
  1473. s = f.transformA,
  1474. v = f.transformB,
  1475. t = W.s_simplex;
  1476. t.ReadCache(e, m, s, r, v);
  1477. var x = t.m_vertices,
  1478. C = W.s_saveA,
  1479. J = W.s_saveB,
  1480. T = 0;
  1481. t.GetClosestPoint().LengthSquared();
  1482. for (var P = 0, X, $ = 0; $ < 20;) {
  1483. T = t.m_count;
  1484. for (P = 0; P < T; P++) {
  1485. C[P] = x[P].indexA;
  1486. J[P] = x[P].indexB
  1487. }
  1488. switch (t.m_count) {
  1489. case 1:
  1490. break;
  1491. case 2:
  1492. t.Solve2();
  1493. break;
  1494. case 3:
  1495. t.Solve3();
  1496. break;
  1497. default:
  1498. y.b2Assert(false)
  1499. }
  1500. if (t.m_count == 3) break;
  1501. X = t.GetClosestPoint();
  1502. X.LengthSquared();
  1503. P = t.GetSearchDirection();
  1504. if (P.LengthSquared() < Number.MIN_VALUE * Number.MIN_VALUE) break;
  1505. X = x[t.m_count];
  1506. X.indexA = m.GetSupport(w.MulTMV(s.R, P.GetNegative()));
  1507. X.wA = w.MulX(s, m.GetVertex(X.indexA));
  1508. X.indexB = r.GetSupport(w.MulTMV(v.R, P));
  1509. X.wB = w.MulX(v, r.GetVertex(X.indexB));
  1510. X.w = w.SubtractVV(X.wB, X.wA);
  1511. ++$;
  1512. ++W.b2_gjkIters;
  1513. var ba = false;
  1514. for (P = 0; P < T; P++)
  1515. if (X.indexA == C[P] && X.indexB == J[P]) {
  1516. ba = true;
  1517. break
  1518. }
  1519. if (ba) break;
  1520. ++t.m_count
  1521. }
  1522. W.b2_gjkMaxIters = w.Max(W.b2_gjkMaxIters, $);
  1523. t.GetWitnessPoints(b.pointA, b.pointB);
  1524. b.distance = w.SubtractVV(b.pointA,
  1525. b.pointB).Length();
  1526. b.iterations = $;
  1527. t.WriteCache(e);
  1528. if (f.useRadii) {
  1529. e = m.m_radius;
  1530. r = r.m_radius;
  1531. if (b.distance > e + r && b.distance > Number.MIN_VALUE) {
  1532. b.distance -= e + r;
  1533. f = w.SubtractVV(b.pointB, b.pointA);
  1534. f.Normalize();
  1535. b.pointA.x += e * f.x;
  1536. b.pointA.y += e * f.y;
  1537. b.pointB.x -= r * f.x;
  1538. b.pointB.y -= r * f.y
  1539. } else {
  1540. X = new p;
  1541. X.x = 0.5 * (b.pointA.x + b.pointB.x);
  1542. X.y = 0.5 * (b.pointA.y + b.pointB.y);
  1543. b.pointA.x = b.pointB.x = X.x;
  1544. b.pointA.y = b.pointB.y = X.y;
  1545. b.distance = 0
  1546. }
  1547. }
  1548. };
  1549. Box2D.postDefs.push(function () {
  1550. Box2D.Collision.b2Distance.s_simplex = new h;
  1551. Box2D.Collision.b2Distance.s_saveA = new Vector_a2j_Number(3);
  1552. Box2D.Collision.b2Distance.s_saveB = new Vector_a2j_Number(3)
  1553. });
  1554. Y.b2DistanceInput = function () {};
  1555. k.b2DistanceOutput = function () {
  1556. this.pointA = new p;
  1557. this.pointB = new p
  1558. };
  1559. z.b2DistanceProxy = function () {};
  1560. z.prototype.Set = function (b) {
  1561. switch (b.GetType()) {
  1562. case K.e_circleShape:
  1563. b = b instanceof F ? b : null;
  1564. this.m_vertices = new Vector(1, true);
  1565. this.m_vertices[0] = b.m_p;
  1566. this.m_count = 1;
  1567. this.m_radius = b.m_radius;
  1568. break;
  1569. case K.e_polygonShape:
  1570. b = b instanceof G ? b : null;
  1571. this.m_vertices = b.m_vertices;
  1572. this.m_count = b.m_vertexCount;
  1573. this.m_radius = b.m_radius;
  1574. break;
  1575. default:
  1576. y.b2Assert(false)
  1577. }
  1578. };
  1579. z.prototype.GetSupport = function (b) {
  1580. for (var e = 0, f = this.m_vertices[0].x * b.x + this.m_vertices[0].y * b.y, m = 1; m < this.m_count; ++m) {
  1581. var r = this.m_vertices[m].x * b.x + this.m_vertices[m].y * b.y;
  1582. if (r > f) {
  1583. e = m;
  1584. f = r
  1585. }
  1586. }
  1587. return e
  1588. };
  1589. z.prototype.GetSupportVertex = function (b) {
  1590. for (var e = 0, f = this.m_vertices[0].x * b.x + this.m_vertices[0].y * b.y, m = 1; m < this.m_count; ++m) {
  1591. var r = this.m_vertices[m].x * b.x + this.m_vertices[m].y * b.y;
  1592. if (r > f) {
  1593. e = m;
  1594. f = r
  1595. }
  1596. }
  1597. return this.m_vertices[e]
  1598. };
  1599. z.prototype.GetVertexCount = function () {
  1600. return this.m_count
  1601. };
  1602. z.prototype.GetVertex = function (b) {
  1603. if (b === undefined) b = 0;
  1604. y.b2Assert(0 <= b && b < this.m_count);
  1605. return this.m_vertices[b]
  1606. };
  1607. u.b2DynamicTree = function () {};
  1608. u.prototype.b2DynamicTree = function () {
  1609. this.m_freeList = this.m_root = null;
  1610. this.m_insertionCount = this.m_path = 0
  1611. };
  1612. u.prototype.CreateProxy = function (b, e) {
  1613. var f = this.AllocateNode(),
  1614. m = y.b2_aabbExtension,
  1615. r = y.b2_aabbExtension;
  1616. f.aabb.lowerBound.x = b.lowerBound.x - m;
  1617. f.aabb.lowerBound.y = b.lowerBound.y - r;
  1618. f.aabb.upperBound.x = b.upperBound.x + m;
  1619. f.aabb.upperBound.y = b.upperBound.y + r;
  1620. f.userData = e;
  1621. this.InsertLeaf(f);
  1622. return f
  1623. };
  1624. u.prototype.DestroyProxy = function (b) {
  1625. this.RemoveLeaf(b);
  1626. this.FreeNode(b)
  1627. };
  1628. u.prototype.MoveProxy = function (b, e, f) {
  1629. y.b2Assert(b.IsLeaf());
  1630. if (b.aabb.Contains(e)) return false;
  1631. this.RemoveLeaf(b);
  1632. var m = y.b2_aabbExtension + y.b2_aabbMultiplier * (f.x > 0 ? f.x : -f.x);
  1633. f = y.b2_aabbExtension + y.b2_aabbMultiplier * (f.y > 0 ? f.y : -f.y);
  1634. b.aabb.lowerBound.x = e.lowerBound.x - m;
  1635. b.aabb.lowerBound.y = e.lowerBound.y - f;
  1636. b.aabb.upperBound.x = e.upperBound.x + m;
  1637. b.aabb.upperBound.y = e.upperBound.y + f;
  1638. this.InsertLeaf(b);
  1639. return true
  1640. };
  1641. u.prototype.Rebalance = function (b) {
  1642. if (b === undefined) b = 0;
  1643. if (this.m_root != null) for (var e = 0; e < b; e++) {
  1644. for (var f = this.m_root, m = 0; f.IsLeaf() == false;) {
  1645. f = this.m_path >> m & 1 ? f.child2 : f.child1;
  1646. m = m + 1 & 31
  1647. }++this.m_path;
  1648. this.RemoveLeaf(f);
  1649. this.InsertLeaf(f)
  1650. }
  1651. };
  1652. u.prototype.GetFatAABB = function (b) {
  1653. return b.aabb
  1654. };
  1655. u.prototype.GetUserData = function (b) {
  1656. return b.userData
  1657. };
  1658. u.prototype.Query = function (b, e) {
  1659. if (this.m_root != null) {
  1660. var f = new Vector,
  1661. m = 0;
  1662. for (f[m++] = this.m_root; m > 0;) {
  1663. var r = f[--m];
  1664. if (r.aabb.TestOverlap(e))
  1665. if (r.IsLeaf()) {
  1666. if (!b(r)) break
  1667. } else {
  1668. f[m++] = r.child1;
  1669. f[m++] = r.child2
  1670. }
  1671. }
  1672. }
  1673. };
  1674. u.prototype.RayCast = function (b, e) {
  1675. if (this.m_root != null) {
  1676. var f = e.p1,
  1677. m = e.p2,
  1678. r = w.SubtractVV(f, m);
  1679. r.Normalize();
  1680. r = w.CrossFV(1, r);
  1681. var s = w.AbsV(r),
  1682. v = e.maxFraction,
  1683. t = new B,
  1684. x = 0,
  1685. C = 0;
  1686. x = f.x + v * (m.x - f.x);
  1687. C = f.y + v * (m.y - f.y);
  1688. t.lowerBound.x = Math.min(f.x, x);
  1689. t.lowerBound.y = Math.min(f.y, C);
  1690. t.upperBound.x = Math.max(f.x, x);
  1691. t.upperBound.y = Math.max(f.y, C);
  1692. var J = new Vector,
  1693. T = 0;
  1694. for (J[T++] = this.m_root; T > 0;) {
  1695. v = J[--T];
  1696. if (v.aabb.TestOverlap(t) != false) {
  1697. x = v.aabb.GetCenter();
  1698. C = v.aabb.GetExtents();
  1699. if (!(Math.abs(r.x * (f.x - x.x) + r.y * (f.y - x.y)) - s.x * C.x - s.y * C.y > 0))
  1700. if (v.IsLeaf()) {
  1701. x = new S;
  1702. x.p1 = e.p1;
  1703. x.p2 = e.p2;
  1704. x.maxFraction = e.maxFraction;
  1705. v = b(x, v);
  1706. if (v == 0) break;
  1707. if (v > 0) {
  1708. x = f.x + v * (m.x - f.x);
  1709. C = f.y + v * (m.y - f.y);
  1710. t.lowerBound.x = Math.min(f.x, x);
  1711. t.lowerBound.y = Math.min(f.y, C);
  1712. t.upperBound.x = Math.max(f.x, x);
  1713. t.upperBound.y = Math.max(f.y, C)
  1714. }
  1715. } else {
  1716. J[T++] = v.child1;
  1717. J[T++] = v.child2
  1718. }
  1719. }
  1720. }
  1721. }
  1722. };
  1723. u.prototype.AllocateNode = function () {
  1724. if (this.m_freeList) {
  1725. var b = this.m_freeList;
  1726. this.m_freeList = b.parent;
  1727. b.parent = null;
  1728. b.child1 = null;
  1729. b.child2 = null;
  1730. return b
  1731. }
  1732. return new H
  1733. };
  1734. u.prototype.FreeNode = function (b) {
  1735. b.parent = this.m_freeList;
  1736. this.m_freeList = b
  1737. };
  1738. u.prototype.InsertLeaf = function (b) {
  1739. ++this.m_insertionCount;
  1740. if (this.m_root == null) {
  1741. this.m_root = b;
  1742. this.m_root.parent = null
  1743. } else {
  1744. var e = b.aabb.GetCenter(),
  1745. f = this.m_root;
  1746. if (f.IsLeaf() == false) {
  1747. do {
  1748. var m = f.child1;
  1749. f = f.child2;
  1750. f = Math.abs((m.aabb.lowerBound.x + m.aabb.upperBound.x) / 2 - e.x) + Math.abs((m.aabb.lowerBound.y + m.aabb.upperBound.y) / 2 - e.y) < Math.abs((f.aabb.lowerBound.x + f.aabb.upperBound.x) / 2 - e.x) + Math.abs((f.aabb.lowerBound.y + f.aabb.upperBound.y) / 2 - e.y) ? m : f
  1751. } while (f.IsLeaf() == false)
  1752. }
  1753. e = f.parent;
  1754. m = this.AllocateNode();
  1755. m.parent = e;
  1756. m.userData = null;
  1757. m.aabb.Combine(b.aabb, f.aabb);
  1758. if (e) {
  1759. if (f.parent.child1 == f) e.child1 = m;
  1760. else e.child2 = m;
  1761. m.child1 = f;
  1762. m.child2 = b;
  1763. f.parent = m;
  1764. b.parent = m;
  1765. do {
  1766. if (e.aabb.Contains(m.aabb)) break;
  1767. e.aabb.Combine(e.child1.aabb, e.child2.aabb);
  1768. m = e;
  1769. e = e.parent
  1770. } while (e)
  1771. } else {
  1772. m.child1 = f;
  1773. m.child2 = b;
  1774. f.parent = m;
  1775. this.m_root = b.parent = m
  1776. }
  1777. }
  1778. };
  1779. u.prototype.RemoveLeaf = function (b) {
  1780. if (b == this.m_root) this.m_root = null;
  1781. else {
  1782. var e = b.parent,
  1783. f = e.parent;
  1784. b = e.child1 == b ? e.child2 : e.child1;
  1785. if (f) {
  1786. if (f.child1 == e) f.child1 = b;
  1787. else f.child2 = b;
  1788. b.parent = f;
  1789. for (this.FreeNode(e); f;) {
  1790. e = f.aabb;
  1791. f.aabb = B.Combine(f.child1.aabb, f.child2.aabb);
  1792. if (e.Contains(f.aabb)) break;
  1793. f = f.parent
  1794. }
  1795. } else {
  1796. this.m_root = b;
  1797. b.parent = null;
  1798. this.FreeNode(e)
  1799. }
  1800. }
  1801. };
  1802. D.b2DynamicTreeBroadPhase = function () {
  1803. this.m_tree = new u;
  1804. this.m_moveBuffer = new Vector;
  1805. this.m_pairBuffer = new Vector;
  1806. this.m_pairCount = 0
  1807. };
  1808. D.prototype.CreateProxy = function (b, e) {
  1809. var f = this.m_tree.CreateProxy(b, e);
  1810. ++this.m_proxyCount;
  1811. this.BufferMove(f);
  1812. return f
  1813. };
  1814. D.prototype.DestroyProxy = function (b) {
  1815. this.UnBufferMove(b);
  1816. --this.m_proxyCount;
  1817. this.m_tree.DestroyProxy(b)
  1818. };
  1819. D.prototype.MoveProxy = function (b, e, f) {
  1820. this.m_tree.MoveProxy(b, e, f) && this.BufferMove(b)
  1821. };
  1822. D.prototype.TestOverlap = function (b, e) {
  1823. var f = this.m_tree.GetFatAABB(b),
  1824. m = this.m_tree.GetFatAABB(e);
  1825. return f.TestOverlap(m)
  1826. };
  1827. D.prototype.GetUserData = function (b) {
  1828. return this.m_tree.GetUserData(b)
  1829. };
  1830. D.prototype.GetFatAABB = function (b) {
  1831. return this.m_tree.GetFatAABB(b)
  1832. };
  1833. D.prototype.GetProxyCount = function () {
  1834. return this.m_proxyCount
  1835. };
  1836. D.prototype.UpdatePairs = function (b) {
  1837. var e = this;
  1838. var f = e.m_pairCount = 0,
  1839. m;
  1840. for (f = 0; f < e.m_moveBuffer.length; ++f) {
  1841. m = e.m_moveBuffer[f];
  1842. var r = e.m_tree.GetFatAABB(m);
  1843. e.m_tree.Query(function (t) {
  1844. if (t == m) return true;
  1845. if (e.m_pairCount == e.m_pairBuffer.length) e.m_pairBuffer[e.m_pairCount] = new O;
  1846. var x = e.m_pairBuffer[e.m_pairCount];
  1847. x.proxyA = t < m ? t : m;
  1848. x.proxyB = t >= m ? t : m;
  1849. ++e.m_pairCount;
  1850. return true
  1851. },
  1852. r)
  1853. }
  1854. for (f = e.m_moveBuffer.length = 0; f < e.m_pairCount;) {
  1855. r = e.m_pairBuffer[f];
  1856. var s = e.m_tree.GetUserData(r.proxyA),
  1857. v = e.m_tree.GetUserData(r.proxyB);
  1858. b(s, v);
  1859. for (++f; f < e.m_pairCount;) {
  1860. s = e.m_pairBuffer[f];
  1861. if (s.proxyA != r.proxyA || s.proxyB != r.proxyB) break;
  1862. ++f
  1863. }
  1864. }
  1865. };
  1866. D.prototype.Query = function (b, e) {
  1867. this.m_tree.Query(b, e)
  1868. };
  1869. D.prototype.RayCast = function (b, e) {
  1870. this.m_tree.RayCast(b, e)
  1871. };
  1872. D.prototype.Validate = function () {};
  1873. D.prototype.Rebalance = function (b) {
  1874. if (b === undefined) b = 0;
  1875. this.m_tree.Rebalance(b)
  1876. };
  1877. D.prototype.BufferMove = function (b) {
  1878. this.m_moveBuffer[this.m_moveBuffer.length] = b
  1879. };
  1880. D.prototype.UnBufferMove = function (b) {
  1881. this.m_moveBuffer.splice(parseInt(this.m_moveBuffer.indexOf(b)), 1)
  1882. };
  1883. D.prototype.ComparePairs = function () {
  1884. return 0
  1885. };
  1886. D.__implements = {};
  1887. D.__implements[g] = true;
  1888. H.b2DynamicTreeNode = function () {
  1889. this.aabb = new B
  1890. };
  1891. H.prototype.IsLeaf = function () {
  1892. return this.child1 == null
  1893. };
  1894. O.b2DynamicTreePair = function () {};
  1895. E.b2Manifold = function () {
  1896. this.m_pointCount = 0
  1897. };
  1898. E.prototype.b2Manifold = function () {
  1899. this.m_points = new Vector(y.b2_maxManifoldPoints);
  1900. for (var b = 0; b < y.b2_maxManifoldPoints; b++) this.m_points[b] = new R;
  1901. this.m_localPlaneNormal = new p;
  1902. this.m_localPoint = new p
  1903. };
  1904. E.prototype.Reset = function () {
  1905. for (var b = 0; b < y.b2_maxManifoldPoints; b++)(this.m_points[b] instanceof R ? this.m_points[b] : null).Reset();
  1906. this.m_localPlaneNormal.SetZero();
  1907. this.m_localPoint.SetZero();
  1908. this.m_pointCount = this.m_type = 0
  1909. };
  1910. E.prototype.Set = function (b) {
  1911. this.m_pointCount = b.m_pointCount;
  1912. for (var e = 0; e < y.b2_maxManifoldPoints; e++)(this.m_points[e] instanceof R ? this.m_points[e] : null).Set(b.m_points[e]);
  1913. this.m_localPlaneNormal.SetV(b.m_localPlaneNormal);
  1914. this.m_localPoint.SetV(b.m_localPoint);
  1915. this.m_type = b.m_type
  1916. };
  1917. E.prototype.Copy = function () {
  1918. var b = new E;
  1919. b.Set(this);
  1920. return b
  1921. };
  1922. Box2D.postDefs.push(function () {
  1923. Box2D.Collision.b2Manifold.e_circles = 1;
  1924. Box2D.Collision.b2Manifold.e_faceA = 2;
  1925. Box2D.Collision.b2Manifold.e_faceB = 4
  1926. });
  1927. R.b2ManifoldPoint = function () {
  1928. this.m_localPoint = new p;
  1929. this.m_id = new L
  1930. };
  1931. R.prototype.b2ManifoldPoint = function () {
  1932. this.Reset()
  1933. };
  1934. R.prototype.Reset = function () {
  1935. this.m_localPoint.SetZero();
  1936. this.m_tangentImpulse = this.m_normalImpulse = 0;
  1937. this.m_id.key = 0
  1938. };
  1939. R.prototype.Set = function (b) {
  1940. this.m_localPoint.SetV(b.m_localPoint);
  1941. this.m_normalImpulse = b.m_normalImpulse;
  1942. this.m_tangentImpulse = b.m_tangentImpulse;
  1943. this.m_id.Set(b.m_id)
  1944. };
  1945. N.b2Point = function () {
  1946. this.p = new p
  1947. };
  1948. N.prototype.Support = function () {
  1949. return this.p
  1950. };
  1951. N.prototype.GetFirstVertex = function () {
  1952. return this.p
  1953. };
  1954. S.b2RayCastInput = function () {
  1955. this.p1 = new p;
  1956. this.p2 = new p
  1957. };
  1958. S.prototype.b2RayCastInput = function (b, e, f) {
  1959. if (b === undefined) b = null;
  1960. if (e === undefined) e = null;
  1961. if (f === undefined) f = 1;
  1962. b && this.p1.SetV(b);
  1963. e && this.p2.SetV(e);
  1964. this.maxFraction = f
  1965. };
  1966. aa.b2RayCastOutput = function () {
  1967. this.normal = new p
  1968. };
  1969. Z.b2Segment = function () {
  1970. this.p1 = new p;
  1971. this.p2 = new p
  1972. };
  1973. Z.prototype.TestSegment = function (b, e, f, m) {
  1974. if (m === undefined) m = 0;
  1975. var r = f.p1,
  1976. s = f.p2.x - r.x,
  1977. v = f.p2.y - r.y;
  1978. f = this.p2.y - this.p1.y;
  1979. var t = -(this.p2.x - this.p1.x),
  1980. x = 100 * Number.MIN_VALUE,
  1981. C = -(s * f + v * t);
  1982. if (C > x) {
  1983. var J = r.x - this.p1.x,
  1984. T = r.y - this.p1.y;
  1985. r = J * f + T * t;
  1986. if (0 <= r && r <= m * C) {
  1987. m = -s * T + v * J;
  1988. if (-x * C <= m && m <= C * (1 + x)) {
  1989. r /= C;
  1990. m = Math.sqrt(f * f + t * t);
  1991. f /= m;
  1992. t /= m;
  1993. b[0] = r;
  1994. e.Set(f,
  1995. t);
  1996. return true
  1997. }
  1998. }
  1999. }
  2000. return false
  2001. };
  2002. Z.prototype.Extend = function (b) {
  2003. this.ExtendForward(b);
  2004. this.ExtendBackward(b)
  2005. };
  2006. Z.prototype.ExtendForward = function (b) {
  2007. var e = this.p2.x - this.p1.x,
  2008. f = this.p2.y - this.p1.y;
  2009. b = Math.min(e > 0 ? (b.upperBound.x - this.p1.x) / e : e < 0 ? (b.lowerBound.x - this.p1.x) / e : Number.POSITIVE_INFINITY, f > 0 ? (b.upperBound.y - this.p1.y) / f : f < 0 ? (b.lowerBound.y - this.p1.y) / f : Number.POSITIVE_INFINITY);
  2010. this.p2.x = this.p1.x + e * b;
  2011. this.p2.y = this.p1.y + f * b
  2012. };
  2013. Z.prototype.ExtendBackward = function (b) {
  2014. var e = -this.p2.x + this.p1.x,
  2015. f = -this.p2.y + this.p1.y;
  2016. b = Math.min(e > 0 ? (b.upperBound.x - this.p2.x) / e : e < 0 ? (b.lowerBound.x - this.p2.x) / e : Number.POSITIVE_INFINITY, f > 0 ? (b.upperBound.y - this.p2.y) / f : f < 0 ? (b.lowerBound.y - this.p2.y) / f : Number.POSITIVE_INFINITY);
  2017. this.p1.x = this.p2.x + e * b;
  2018. this.p1.y = this.p2.y + f * b
  2019. };
  2020. d.b2SeparationFunction = function () {
  2021. this.m_localPoint = new p;
  2022. this.m_axis = new p
  2023. };
  2024. d.prototype.Initialize = function (b, e, f, m, r) {
  2025. this.m_proxyA = e;
  2026. this.m_proxyB = m;
  2027. var s = parseInt(b.count);
  2028. y.b2Assert(0 < s && s < 3);
  2029. var v, t, x, C, J = C = x = m = e = 0,
  2030. T = 0;
  2031. J = 0;
  2032. if (s == 1) {
  2033. this.m_type = d.e_points;
  2034. v = this.m_proxyA.GetVertex(b.indexA[0]);
  2035. t = this.m_proxyB.GetVertex(b.indexB[0]);
  2036. s = v;
  2037. b = f.R;
  2038. e = f.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2039. m = f.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2040. s = t;
  2041. b = r.R;
  2042. x = r.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2043. C = r.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2044. this.m_axis.x = x - e;
  2045. this.m_axis.y = C - m;
  2046. this.m_axis.Normalize()
  2047. } else {
  2048. if (b.indexB[0] == b.indexB[1]) {
  2049. this.m_type = d.e_faceA;
  2050. e = this.m_proxyA.GetVertex(b.indexA[0]);
  2051. m = this.m_proxyA.GetVertex(b.indexA[1]);
  2052. t = this.m_proxyB.GetVertex(b.indexB[0]);
  2053. this.m_localPoint.x = 0.5 * (e.x + m.x);
  2054. this.m_localPoint.y = 0.5 * (e.y + m.y);
  2055. this.m_axis = w.CrossVF(w.SubtractVV(m, e), 1);
  2056. this.m_axis.Normalize();
  2057. s = this.m_axis;
  2058. b = f.R;
  2059. J = b.col1.x * s.x + b.col2.x * s.y;
  2060. T = b.col1.y * s.x + b.col2.y * s.y;
  2061. s = this.m_localPoint;
  2062. b = f.R;
  2063. e = f.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2064. m = f.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2065. s = t;
  2066. b = r.R;
  2067. x = r.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2068. C = r.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2069. J = (x - e) * J + (C - m) * T
  2070. } else if (b.indexA[0] == b.indexA[0]) {
  2071. this.m_type = d.e_faceB;
  2072. x = this.m_proxyB.GetVertex(b.indexB[0]);
  2073. C = this.m_proxyB.GetVertex(b.indexB[1]);
  2074. v = this.m_proxyA.GetVertex(b.indexA[0]);
  2075. this.m_localPoint.x = 0.5 * (x.x + C.x);
  2076. this.m_localPoint.y = 0.5 * (x.y + C.y);
  2077. this.m_axis = w.CrossVF(w.SubtractVV(C, x), 1);
  2078. this.m_axis.Normalize();
  2079. s = this.m_axis;
  2080. b = r.R;
  2081. J = b.col1.x * s.x + b.col2.x * s.y;
  2082. T = b.col1.y * s.x + b.col2.y * s.y;
  2083. s = this.m_localPoint;
  2084. b = r.R;
  2085. x = r.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2086. C = r.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2087. s = v;
  2088. b = f.R;
  2089. e = f.position.x + (b.col1.x * s.x + b.col2.x * s.y);
  2090. m = f.position.y + (b.col1.y * s.x + b.col2.y * s.y);
  2091. J = (e - x) * J + (m - C) * T
  2092. } else {
  2093. e = this.m_proxyA.GetVertex(b.indexA[0]);
  2094. m = this.m_proxyA.GetVertex(b.indexA[1]);
  2095. x = this.m_proxyB.GetVertex(b.indexB[0]);
  2096. C = this.m_proxyB.GetVertex(b.indexB[1]);
  2097. w.MulX(f, v);
  2098. v = w.MulMV(f.R, w.SubtractVV(m, e));
  2099. w.MulX(r, t);
  2100. J = w.MulMV(r.R, w.SubtractVV(C, x));
  2101. r = v.x * v.x + v.y * v.y;
  2102. t = J.x * J.x + J.y * J.y;
  2103. b = w.SubtractVV(J, v);
  2104. f = v.x * b.x + v.y * b.y;
  2105. b = J.x * b.x + J.y * b.y;
  2106. v = v.x * J.x + v.y * J.y;
  2107. T = r * t - v * v;
  2108. J = 0;
  2109. if (T != 0) J = w.Clamp((v * b - f * t) / T, 0, 1);
  2110. if ((v * J + b) / t < 0) J = w.Clamp((v - f) / r, 0, 1);
  2111. v = new p;
  2112. v.x = e.x + J * (m.x - e.x);
  2113. v.y = e.y + J * (m.y - e.y);
  2114. t = new p;
  2115. t.x = x.x + J * (C.x - x.x);
  2116. t.y = x.y + J * (C.y - x.y);
  2117. if (J == 0 || J == 1) {
  2118. this.m_type = d.e_faceB;
  2119. this.m_axis = w.CrossVF(w.SubtractVV(C, x), 1);
  2120. this.m_axis.Normalize();
  2121. this.m_localPoint = t
  2122. } else {
  2123. this.m_type = d.e_faceA;
  2124. this.m_axis = w.CrossVF(w.SubtractVV(m, e), 1);
  2125. this.m_localPoint = v
  2126. }
  2127. }
  2128. J < 0 && this.m_axis.NegativeSelf()
  2129. }
  2130. };
  2131. d.prototype.Evaluate = function (b, e) {
  2132. var f, m, r = 0;
  2133. switch (this.m_type) {
  2134. case d.e_points:
  2135. f = w.MulTMV(b.R, this.m_axis);
  2136. m = w.MulTMV(e.R, this.m_axis.GetNegative());
  2137. f = this.m_proxyA.GetSupportVertex(f);
  2138. m = this.m_proxyB.GetSupportVertex(m);
  2139. f = w.MulX(b, f);
  2140. m = w.MulX(e, m);
  2141. return r = (m.x - f.x) * this.m_axis.x + (m.y - f.y) * this.m_axis.y;
  2142. case d.e_faceA:
  2143. r = w.MulMV(b.R, this.m_axis);
  2144. f = w.MulX(b, this.m_localPoint);
  2145. m = w.MulTMV(e.R, r.GetNegative());
  2146. m = this.m_proxyB.GetSupportVertex(m);
  2147. m = w.MulX(e, m);
  2148. return r = (m.x - f.x) * r.x + (m.y - f.y) * r.y;
  2149. case d.e_faceB:
  2150. r = w.MulMV(e.R, this.m_axis);
  2151. m = w.MulX(e, this.m_localPoint);
  2152. f = w.MulTMV(b.R, r.GetNegative());
  2153. f = this.m_proxyA.GetSupportVertex(f);
  2154. f = w.MulX(b, f);
  2155. return r = (f.x - m.x) * r.x + (f.y - m.y) * r.y;
  2156. default:
  2157. y.b2Assert(false);
  2158. return 0
  2159. }
  2160. };
  2161. Box2D.postDefs.push(function () {
  2162. Box2D.Collision.b2SeparationFunction.e_points = 1;
  2163. Box2D.Collision.b2SeparationFunction.e_faceA = 2;
  2164. Box2D.Collision.b2SeparationFunction.e_faceB = 4
  2165. });
  2166. h.b2Simplex = function () {
  2167. this.m_v1 = new j;
  2168. this.m_v2 = new j;
  2169. this.m_v3 = new j;
  2170. this.m_vertices = new Vector(3)
  2171. };
  2172. h.prototype.b2Simplex = function () {
  2173. this.m_vertices[0] = this.m_v1;
  2174. this.m_vertices[1] = this.m_v2;
  2175. this.m_vertices[2] = this.m_v3
  2176. };
  2177. h.prototype.ReadCache = function (b, e, f, m, r) {
  2178. y.b2Assert(0 <= b.count && b.count <= 3);
  2179. var s, v;
  2180. this.m_count = b.count;
  2181. for (var t = this.m_vertices, x = 0; x < this.m_count; x++) {
  2182. var C = t[x];
  2183. C.indexA = b.indexA[x];
  2184. C.indexB = b.indexB[x];
  2185. s = e.GetVertex(C.indexA);
  2186. v = m.GetVertex(C.indexB);
  2187. C.wA = w.MulX(f, s);
  2188. C.wB = w.MulX(r, v);
  2189. C.w = w.SubtractVV(C.wB, C.wA);
  2190. C.a = 0
  2191. }
  2192. if (this.m_count > 1) {
  2193. b = b.metric;
  2194. s = this.GetMetric();
  2195. if (s < 0.5 * b || 2 * b < s || s < Number.MIN_VALUE) this.m_count = 0
  2196. }
  2197. if (this.m_count == 0) {
  2198. C = t[0];
  2199. C.indexA = 0;
  2200. C.indexB = 0;
  2201. s = e.GetVertex(0);
  2202. v = m.GetVertex(0);
  2203. C.wA = w.MulX(f, s);
  2204. C.wB = w.MulX(r, v);
  2205. C.w = w.SubtractVV(C.wB, C.wA);
  2206. this.m_count = 1
  2207. }
  2208. };
  2209. h.prototype.WriteCache = function (b) {
  2210. b.metric = this.GetMetric();
  2211. b.count = Box2D.parseUInt(this.m_count);
  2212. for (var e = this.m_vertices, f = 0; f < this.m_count; f++) {
  2213. b.indexA[f] = Box2D.parseUInt(e[f].indexA);
  2214. b.indexB[f] = Box2D.parseUInt(e[f].indexB)
  2215. }
  2216. };
  2217. h.prototype.GetSearchDirection = function () {
  2218. switch (this.m_count) {
  2219. case 1:
  2220. return this.m_v1.w.GetNegative();
  2221. case 2:
  2222. var b = w.SubtractVV(this.m_v2.w, this.m_v1.w);
  2223. return w.CrossVV(b, this.m_v1.w.GetNegative()) > 0 ? w.CrossFV(1, b) : w.CrossVF(b, 1);
  2224. default:
  2225. y.b2Assert(false);
  2226. return new p
  2227. }
  2228. };
  2229. h.prototype.GetClosestPoint = function () {
  2230. switch (this.m_count) {
  2231. case 0:
  2232. y.b2Assert(false);
  2233. return new p;
  2234. case 1:
  2235. return this.m_v1.w;
  2236. case 2:
  2237. return new p(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);
  2238. default:
  2239. y.b2Assert(false);
  2240. return new p
  2241. }
  2242. };
  2243. h.prototype.GetWitnessPoints = function (b, e) {
  2244. switch (this.m_count) {
  2245. case 0:
  2246. y.b2Assert(false);
  2247. break;
  2248. case 1:
  2249. b.SetV(this.m_v1.wA);
  2250. e.SetV(this.m_v1.wB);
  2251. break;
  2252. case 2:
  2253. b.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x;
  2254. b.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y;
  2255. e.x = this.m_v1.a * this.m_v1.wB.x + this.m_v2.a * this.m_v2.wB.x;
  2256. e.y = this.m_v1.a * this.m_v1.wB.y + this.m_v2.a * this.m_v2.wB.y;
  2257. break;
  2258. case 3:
  2259. e.x = b.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;
  2260. e.y = b.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;
  2261. break;
  2262. default:
  2263. y.b2Assert(false)
  2264. }
  2265. };
  2266. h.prototype.GetMetric = function () {
  2267. switch (this.m_count) {
  2268. case 0:
  2269. y.b2Assert(false);
  2270. return 0;
  2271. case 1:
  2272. return 0;
  2273. case 2:
  2274. return w.SubtractVV(this.m_v1.w,
  2275. this.m_v2.w).Length();
  2276. case 3:
  2277. return w.CrossVV(w.SubtractVV(this.m_v2.w, this.m_v1.w), w.SubtractVV(this.m_v3.w, this.m_v1.w));
  2278. default:
  2279. y.b2Assert(false);
  2280. return 0
  2281. }
  2282. };
  2283. h.prototype.Solve2 = function () {
  2284. var b = this.m_v1.w,
  2285. e = this.m_v2.w,
  2286. f = w.SubtractVV(e, b);
  2287. b = -(b.x * f.x + b.y * f.y);
  2288. if (b <= 0) this.m_count = this.m_v1.a = 1;
  2289. else {
  2290. e = e.x * f.x + e.y * f.y;
  2291. if (e <= 0) {
  2292. this.m_count = this.m_v2.a = 1;
  2293. this.m_v1.Set(this.m_v2)
  2294. } else {
  2295. f = 1 / (e + b);
  2296. this.m_v1.a = e * f;
  2297. this.m_v2.a = b * f;
  2298. this.m_count = 2
  2299. }
  2300. }
  2301. };
  2302. h.prototype.Solve3 = function () {
  2303. var b = this.m_v1.w,
  2304. e = this.m_v2.w,
  2305. f = this.m_v3.w,
  2306. m = w.SubtractVV(e, b),
  2307. r = w.Dot(b, m),
  2308. s = w.Dot(e, m);
  2309. r = -r;
  2310. var v = w.SubtractVV(f, b),
  2311. t = w.Dot(b, v),
  2312. x = w.Dot(f, v);
  2313. t = -t;
  2314. var C = w.SubtractVV(f, e),
  2315. J = w.Dot(e, C);
  2316. C = w.Dot(f, C);
  2317. J = -J;
  2318. v = w.CrossVV(m, v);
  2319. m = v * w.CrossVV(e, f);
  2320. f = v * w.CrossVV(f, b);
  2321. b = v * w.CrossVV(b, e);
  2322. if (r <= 0 && t <= 0) this.m_count = this.m_v1.a = 1;
  2323. else if (s > 0 && r > 0 && b <= 0) {
  2324. x = 1 / (s + r);
  2325. this.m_v1.a = s * x;
  2326. this.m_v2.a = r * x;
  2327. this.m_count = 2
  2328. } else if (x > 0 && t > 0 && f <= 0) {
  2329. s = 1 / (x + t);
  2330. this.m_v1.a = x * s;
  2331. this.m_v3.a = t * s;
  2332. this.m_count = 2;
  2333. this.m_v2.Set(this.m_v3)
  2334. } else if (s <= 0 && J <= 0) {
  2335. this.m_count = this.m_v2.a = 1;
  2336. this.m_v1.Set(this.m_v2)
  2337. } else if (x <= 0 && C <= 0) {
  2338. this.m_count = this.m_v3.a = 1;
  2339. this.m_v1.Set(this.m_v3)
  2340. } else if (C > 0 && J > 0 && m <= 0) {
  2341. s = 1 / (C + J);
  2342. this.m_v2.a = C * s;
  2343. this.m_v3.a = J * s;
  2344. this.m_count = 2;
  2345. this.m_v1.Set(this.m_v3)
  2346. } else {
  2347. s = 1 / (m + f + b);
  2348. this.m_v1.a = m * s;
  2349. this.m_v2.a = f * s;
  2350. this.m_v3.a = b * s;
  2351. this.m_count = 3
  2352. }
  2353. };
  2354. l.b2SimplexCache = function () {
  2355. this.indexA = new Vector_a2j_Number(3);
  2356. this.indexB = new Vector_a2j_Number(3)
  2357. };
  2358. j.b2SimplexVertex = function () {};
  2359. j.prototype.Set = function (b) {
  2360. this.wA.SetV(b.wA);
  2361. this.wB.SetV(b.wB);
  2362. this.w.SetV(b.w);
  2363. this.a = b.a;
  2364. this.indexA = b.indexA;
  2365. this.indexB = b.indexB
  2366. };
  2367. o.b2TimeOfImpact = function () {};
  2368. o.TimeOfImpact = function (b) {
  2369. ++o.b2_toiCalls;
  2370. var e = b.proxyA,
  2371. f = b.proxyB,
  2372. m = b.sweepA,
  2373. r = b.sweepB;
  2374. y.b2Assert(m.t0 == r.t0);
  2375. y.b2Assert(1 - m.t0 > Number.MIN_VALUE);
  2376. var s = e.m_radius + f.m_radius;
  2377. b = b.tolerance;
  2378. var v = 0,
  2379. t = 0,
  2380. x = 0;
  2381. o.s_cache.count = 0;
  2382. for (o.s_distanceInput.useRadii = false;;) {
  2383. m.GetTransform(o.s_xfA, v);
  2384. r.GetTransform(o.s_xfB, v);
  2385. o.s_distanceInput.proxyA = e;
  2386. o.s_distanceInput.proxyB = f;
  2387. o.s_distanceInput.transformA = o.s_xfA;
  2388. o.s_distanceInput.transformB = o.s_xfB;
  2389. W.Distance(o.s_distanceOutput, o.s_cache, o.s_distanceInput);
  2390. if (o.s_distanceOutput.distance <= 0) {
  2391. v = 1;
  2392. break
  2393. }
  2394. o.s_fcn.Initialize(o.s_cache, e, o.s_xfA, f, o.s_xfB);
  2395. var C = o.s_fcn.Evaluate(o.s_xfA, o.s_xfB);
  2396. if (C <= 0) {
  2397. v = 1;
  2398. break
  2399. }
  2400. if (t == 0) x = C > s ? w.Max(s - b, 0.75 * s) : w.Max(C - b, 0.02 * s);
  2401. if (C - x < 0.5 * b) {
  2402. if (t == 0) {
  2403. v = 1;
  2404. break
  2405. }
  2406. break
  2407. }
  2408. var J = v,
  2409. T = v,
  2410. P = 1;
  2411. C = C;
  2412. m.GetTransform(o.s_xfA, P);
  2413. r.GetTransform(o.s_xfB, P);
  2414. var X = o.s_fcn.Evaluate(o.s_xfA, o.s_xfB);
  2415. if (X >= x) {
  2416. v = 1;
  2417. break
  2418. }
  2419. for (var $ = 0;;) {
  2420. var ba = 0;
  2421. ba = $ & 1 ? T + (x - C) * (P - T) / (X - C) : 0.5 * (T + P);
  2422. m.GetTransform(o.s_xfA, ba);
  2423. r.GetTransform(o.s_xfB, ba);
  2424. var ca = o.s_fcn.Evaluate(o.s_xfA, o.s_xfB);
  2425. if (w.Abs(ca - x) < 0.025 * b) {
  2426. J = ba;
  2427. break
  2428. }
  2429. if (ca > x) {
  2430. T = ba;
  2431. C = ca
  2432. } else {
  2433. P = ba;
  2434. X = ca
  2435. }++$;
  2436. ++o.b2_toiRootIters;
  2437. if ($ == 50) break
  2438. }
  2439. o.b2_toiMaxRootIters = w.Max(o.b2_toiMaxRootIters, $);
  2440. if (J < (1 + 100 * Number.MIN_VALUE) * v) break;
  2441. v = J;
  2442. t++;
  2443. ++o.b2_toiIters;
  2444. if (t == 1E3) break
  2445. }
  2446. o.b2_toiMaxIters = w.Max(o.b2_toiMaxIters, t);
  2447. return v
  2448. };
  2449. Box2D.postDefs.push(function () {
  2450. Box2D.Collision.b2TimeOfImpact.b2_toiCalls = 0;
  2451. Box2D.Collision.b2TimeOfImpact.b2_toiIters = 0;
  2452. Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters = 0;
  2453. Box2D.Collision.b2TimeOfImpact.b2_toiRootIters = 0;
  2454. Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters = 0;
  2455. Box2D.Collision.b2TimeOfImpact.s_cache = new l;
  2456. Box2D.Collision.b2TimeOfImpact.s_distanceInput = new Y;
  2457. Box2D.Collision.b2TimeOfImpact.s_xfA = new U;
  2458. Box2D.Collision.b2TimeOfImpact.s_xfB = new U;
  2459. Box2D.Collision.b2TimeOfImpact.s_fcn = new d;
  2460. Box2D.Collision.b2TimeOfImpact.s_distanceOutput = new k
  2461. });
  2462. q.b2TOIInput = function () {
  2463. this.proxyA = new z;
  2464. this.proxyB = new z;
  2465. this.sweepA = new A;
  2466. this.sweepB = new A
  2467. };
  2468. n.b2WorldManifold = function () {
  2469. this.m_normal = new p
  2470. };
  2471. n.prototype.b2WorldManifold = function () {
  2472. this.m_points = new Vector(y.b2_maxManifoldPoints);
  2473. for (var b = 0; b < y.b2_maxManifoldPoints; b++) this.m_points[b] = new p
  2474. };
  2475. n.prototype.Initialize = function (b, e, f, m, r) {
  2476. if (f === undefined) f = 0;
  2477. if (r === undefined) r = 0;
  2478. if (b.m_pointCount != 0) {
  2479. var s = 0,
  2480. v, t, x = 0,
  2481. C = 0,
  2482. J = 0,
  2483. T = 0,
  2484. P = 0;
  2485. v = 0;
  2486. switch (b.m_type) {
  2487. case E.e_circles:
  2488. t = e.R;
  2489. v = b.m_localPoint;
  2490. s = e.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2491. e = e.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2492. t = m.R;
  2493. v = b.m_points[0].m_localPoint;
  2494. b = m.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2495. m = m.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2496. v = b - s;
  2497. t = m - e;
  2498. x = v * v + t * t;
  2499. if (x > Number.MIN_VALUE * Number.MIN_VALUE) {
  2500. x = Math.sqrt(x);
  2501. this.m_normal.x = v / x;
  2502. this.m_normal.y = t / x
  2503. } else {
  2504. this.m_normal.x = 1;
  2505. this.m_normal.y = 0
  2506. }
  2507. v = e + f * this.m_normal.y;
  2508. m = m - r * this.m_normal.y;
  2509. this.m_points[0].x = 0.5 * (s + f * this.m_normal.x + (b - r * this.m_normal.x));
  2510. this.m_points[0].y = 0.5 * (v + m);
  2511. break;
  2512. case E.e_faceA:
  2513. t = e.R;
  2514. v = b.m_localPlaneNormal;
  2515. x = t.col1.x * v.x + t.col2.x * v.y;
  2516. C = t.col1.y * v.x + t.col2.y * v.y;
  2517. t = e.R;
  2518. v = b.m_localPoint;
  2519. J = e.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2520. T = e.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2521. this.m_normal.x = x;
  2522. this.m_normal.y = C;
  2523. for (s = 0; s < b.m_pointCount; s++) {
  2524. t = m.R;
  2525. v = b.m_points[s].m_localPoint;
  2526. P = m.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2527. v = m.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2528. this.m_points[s].x = P + 0.5 * (f - (P - J) * x - (v - T) * C - r) * x;
  2529. this.m_points[s].y = v + 0.5 * (f - (P - J) * x - (v - T) * C - r) * C
  2530. }
  2531. break;
  2532. case E.e_faceB:
  2533. t = m.R;
  2534. v = b.m_localPlaneNormal;
  2535. x = t.col1.x * v.x + t.col2.x * v.y;
  2536. C = t.col1.y * v.x + t.col2.y * v.y;
  2537. t = m.R;
  2538. v = b.m_localPoint;
  2539. J = m.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2540. T = m.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2541. this.m_normal.x = -x;
  2542. this.m_normal.y = -C;
  2543. for (s = 0; s < b.m_pointCount; s++) {
  2544. t = e.R;
  2545. v = b.m_points[s].m_localPoint;
  2546. P = e.position.x + t.col1.x * v.x + t.col2.x * v.y;
  2547. v = e.position.y + t.col1.y * v.x + t.col2.y * v.y;
  2548. this.m_points[s].x = P + 0.5 * (r - (P - J) * x - (v - T) * C - f) * x;
  2549. this.m_points[s].y = v + 0.5 * (r - (P - J) * x - (v - T) * C - f) * C
  2550. }
  2551. }
  2552. }
  2553. };
  2554. a.ClipVertex = function () {
  2555. this.v = new p;
  2556. this.id = new L
  2557. };
  2558. a.prototype.Set = function (b) {
  2559. this.v.SetV(b.v);
  2560. this.id.Set(b.id)
  2561. };
  2562. c.Features = function () {};
  2563. Object.defineProperty(c.prototype, "referenceEdge", {
  2564. enumerable: false,
  2565. configurable: true,
  2566. get: function () {
  2567. return this._referenceEdge
  2568. }
  2569. });
  2570. Object.defineProperty(c.prototype, "referenceEdge", {
  2571. enumerable: false,
  2572. configurable: true,
  2573. set: function (b) {
  2574. if (b === undefined) b = 0;
  2575. this._referenceEdge = b;
  2576. this._m_id._key = this._m_id._key & 4294967040 | this._referenceEdge & 255
  2577. }
  2578. });
  2579. Object.defineProperty(c.prototype, "incidentEdge", {
  2580. enumerable: false,
  2581. configurable: true,
  2582. get: function () {
  2583. return this._incidentEdge
  2584. }
  2585. });
  2586. Object.defineProperty(c.prototype,
  2587. "incidentEdge", {
  2588. enumerable: false,
  2589. configurable: true,
  2590. set: function (b) {
  2591. if (b === undefined) b = 0;
  2592. this._incidentEdge = b;
  2593. this._m_id._key = this._m_id._key & 4294902015 | this._incidentEdge << 8 & 65280
  2594. }
  2595. });
  2596. Object.defineProperty(c.prototype, "incidentVertex", {
  2597. enumerable: false,
  2598. configurable: true,
  2599. get: function () {
  2600. return this._incidentVertex
  2601. }
  2602. });
  2603. Object.defineProperty(c.prototype, "incidentVertex", {
  2604. enumerable: false,
  2605. configurable: true,
  2606. set: function (b) {
  2607. if (b === undefined) b = 0;
  2608. this._incidentVertex = b;
  2609. this._m_id._key = this._m_id._key & 4278255615 |
  2610. this._incidentVertex << 16 & 16711680
  2611. }
  2612. });
  2613. Object.defineProperty(c.prototype, "flip", {
  2614. enumerable: false,
  2615. configurable: true,
  2616. get: function () {
  2617. return this._flip
  2618. }
  2619. });
  2620. Object.defineProperty(c.prototype, "flip", {
  2621. enumerable: false,
  2622. configurable: true,
  2623. set: function (b) {
  2624. if (b === undefined) b = 0;
  2625. this._flip = b;
  2626. this._m_id._key = this._m_id._key & 16777215 | this._flip << 24 & 4278190080
  2627. }
  2628. })
  2629. })();
  2630. (function () {
  2631. var F = Box2D.Common.b2Settings,
  2632. G = Box2D.Collision.Shapes.b2CircleShape,
  2633. K = Box2D.Collision.Shapes.b2EdgeChainDef,
  2634. y = Box2D.Collision.Shapes.b2EdgeShape,
  2635. w = Box2D.Collision.Shapes.b2MassData,
  2636. A = Box2D.Collision.Shapes.b2PolygonShape,
  2637. U = Box2D.Collision.Shapes.b2Shape,
  2638. p = Box2D.Common.Math.b2Mat22,
  2639. B = Box2D.Common.Math.b2Math,
  2640. Q = Box2D.Common.Math.b2Transform,
  2641. V = Box2D.Common.Math.b2Vec2,
  2642. M = Box2D.Collision.b2Distance,
  2643. L = Box2D.Collision.b2DistanceInput,
  2644. I = Box2D.Collision.b2DistanceOutput,
  2645. W = Box2D.Collision.b2DistanceProxy,
  2646. Y = Box2D.Collision.b2SimplexCache;
  2647. Box2D.inherit(G, Box2D.Collision.Shapes.b2Shape);
  2648. G.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
  2649. G.b2CircleShape = function () {
  2650. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
  2651. this.m_p = new V
  2652. };
  2653. G.prototype.Copy = function () {
  2654. var k = new G;
  2655. k.Set(this);
  2656. return k
  2657. };
  2658. G.prototype.Set = function (k) {
  2659. this.__super.Set.call(this, k);
  2660. if (Box2D.is(k, G)) this.m_p.SetV((k instanceof G ? k : null).m_p)
  2661. };
  2662. G.prototype.TestPoint = function (k, z) {
  2663. var u = k.R,
  2664. D = k.position.x + (u.col1.x * this.m_p.x + u.col2.x * this.m_p.y);
  2665. u = k.position.y + (u.col1.y * this.m_p.x + u.col2.y * this.m_p.y);
  2666. D = z.x - D;
  2667. u = z.y - u;
  2668. return D * D + u * u <= this.m_radius * this.m_radius
  2669. };
  2670. G.prototype.RayCast = function (k, z, u) {
  2671. var D = u.R,
  2672. H = z.p1.x - (u.position.x + (D.col1.x * this.m_p.x + D.col2.x * this.m_p.y));
  2673. u = z.p1.y - (u.position.y + (D.col1.y * this.m_p.x + D.col2.y * this.m_p.y));
  2674. D = z.p2.x - z.p1.x;
  2675. var O = z.p2.y - z.p1.y,
  2676. E = H * D + u * O,
  2677. R = D * D + O * O,
  2678. N = E * E - R * (H * H + u * u - this.m_radius * this.m_radius);
  2679. if (N < 0 || R < Number.MIN_VALUE) return false;
  2680. E = -(E + Math.sqrt(N));
  2681. if (0 <= E && E <= z.maxFraction * R) {
  2682. E /= R;
  2683. k.fraction = E;
  2684. k.normal.x = H + E * D;
  2685. k.normal.y = u + E * O;
  2686. k.normal.Normalize();
  2687. return true
  2688. }
  2689. return false
  2690. };
  2691. G.prototype.ComputeAABB = function (k, z) {
  2692. var u = z.R,
  2693. D = z.position.x + (u.col1.x * this.m_p.x + u.col2.x * this.m_p.y);
  2694. u = z.position.y + (u.col1.y * this.m_p.x + u.col2.y * this.m_p.y);
  2695. k.lowerBound.Set(D - this.m_radius, u - this.m_radius);
  2696. k.upperBound.Set(D + this.m_radius, u + this.m_radius)
  2697. };
  2698. G.prototype.ComputeMass = function (k, z) {
  2699. if (z === undefined) z = 0;
  2700. k.mass = z * F.b2_pi * this.m_radius * this.m_radius;
  2701. k.center.SetV(this.m_p);
  2702. k.I = k.mass * (0.5 * this.m_radius * this.m_radius + (this.m_p.x * this.m_p.x + this.m_p.y * this.m_p.y))
  2703. };
  2704. G.prototype.ComputeSubmergedArea = function (k, z, u, D) {
  2705. if (z === undefined) z = 0;
  2706. u = B.MulX(u, this.m_p);
  2707. var H = -(B.Dot(k, u) - z);
  2708. if (H < -this.m_radius + Number.MIN_VALUE) return 0;
  2709. if (H > this.m_radius) {
  2710. D.SetV(u);
  2711. return Math.PI * this.m_radius * this.m_radius
  2712. }
  2713. z = this.m_radius * this.m_radius;
  2714. var O = H * H;
  2715. H = z * (Math.asin(H / this.m_radius) + Math.PI / 2) + H * Math.sqrt(z - O);
  2716. z = -2 / 3 * Math.pow(z - O, 1.5) / H;
  2717. D.x = u.x + k.x * z;
  2718. D.y = u.y + k.y * z;
  2719. return H
  2720. };
  2721. G.prototype.GetLocalPosition = function () {
  2722. return this.m_p
  2723. };
  2724. G.prototype.SetLocalPosition = function (k) {
  2725. this.m_p.SetV(k)
  2726. };
  2727. G.prototype.GetRadius = function () {
  2728. return this.m_radius
  2729. };
  2730. G.prototype.SetRadius = function (k) {
  2731. if (k === undefined) k = 0;
  2732. this.m_radius = k
  2733. };
  2734. G.prototype.b2CircleShape = function (k) {
  2735. if (k === undefined) k = 0;
  2736. this.__super.b2Shape.call(this);
  2737. this.m_type = U.e_circleShape;
  2738. this.m_radius = k
  2739. };
  2740. K.b2EdgeChainDef = function () {};
  2741. K.prototype.b2EdgeChainDef = function () {
  2742. this.vertexCount = 0;
  2743. this.isALoop = true;
  2744. this.vertices = []
  2745. };
  2746. Box2D.inherit(y, Box2D.Collision.Shapes.b2Shape);
  2747. y.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
  2748. y.b2EdgeShape = function () {
  2749. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
  2750. this.s_supportVec = new V;
  2751. this.m_v1 = new V;
  2752. this.m_v2 = new V;
  2753. this.m_coreV1 = new V;
  2754. this.m_coreV2 = new V;
  2755. this.m_normal = new V;
  2756. this.m_direction = new V;
  2757. this.m_cornerDir1 = new V;
  2758. this.m_cornerDir2 = new V
  2759. };
  2760. y.prototype.TestPoint = function () {
  2761. return false
  2762. };
  2763. y.prototype.RayCast = function (k, z, u) {
  2764. var D, H = z.p2.x - z.p1.x,
  2765. O = z.p2.y - z.p1.y;
  2766. D = u.R;
  2767. var E = u.position.x + (D.col1.x * this.m_v1.x + D.col2.x * this.m_v1.y),
  2768. R = u.position.y + (D.col1.y * this.m_v1.x + D.col2.y * this.m_v1.y),
  2769. N = u.position.y + (D.col1.y * this.m_v2.x + D.col2.y * this.m_v2.y) - R;
  2770. u = -(u.position.x + (D.col1.x * this.m_v2.x + D.col2.x * this.m_v2.y) - E);
  2771. D = 100 * Number.MIN_VALUE;
  2772. var S = -(H * N + O * u);
  2773. if (S > D) {
  2774. E = z.p1.x - E;
  2775. var aa = z.p1.y - R;
  2776. R = E * N + aa * u;
  2777. if (0 <= R && R <= z.maxFraction * S) {
  2778. z = -H * aa + O * E;
  2779. if (-D * S <= z && z <= S * (1 + D)) {
  2780. R /= S;
  2781. k.fraction = R;
  2782. z = Math.sqrt(N * N + u * u);
  2783. k.normal.x = N / z;
  2784. k.normal.y = u / z;
  2785. return true
  2786. }
  2787. }
  2788. }
  2789. return false
  2790. };
  2791. y.prototype.ComputeAABB = function (k, z) {
  2792. var u = z.R,
  2793. D = z.position.x + (u.col1.x * this.m_v1.x + u.col2.x * this.m_v1.y),
  2794. H = z.position.y + (u.col1.y * this.m_v1.x + u.col2.y * this.m_v1.y),
  2795. O = z.position.x + (u.col1.x * this.m_v2.x + u.col2.x * this.m_v2.y);
  2796. u = z.position.y + (u.col1.y * this.m_v2.x + u.col2.y * this.m_v2.y);
  2797. if (D < O) {
  2798. k.lowerBound.x = D;
  2799. k.upperBound.x = O
  2800. } else {
  2801. k.lowerBound.x = O;
  2802. k.upperBound.x = D
  2803. } if (H < u) {
  2804. k.lowerBound.y = H;
  2805. k.upperBound.y = u
  2806. } else {
  2807. k.lowerBound.y = u;
  2808. k.upperBound.y = H
  2809. }
  2810. };
  2811. y.prototype.ComputeMass = function (k) {
  2812. k.mass = 0;
  2813. k.center.SetV(this.m_v1);
  2814. k.I = 0
  2815. };
  2816. y.prototype.ComputeSubmergedArea = function (k, z, u, D) {
  2817. if (z === undefined) z = 0;
  2818. var H = new V(k.x * z, k.y * z),
  2819. O = B.MulX(u, this.m_v1);
  2820. u = B.MulX(u, this.m_v2);
  2821. var E = B.Dot(k, O) - z;
  2822. k = B.Dot(k, u) - z;
  2823. if (E > 0)
  2824. if (k > 0) return 0;
  2825. else {
  2826. O.x = -k / (E - k) * O.x + E / (E - k) * u.x;
  2827. O.y = -k / (E - k) * O.y + E / (E - k) * u.y
  2828. } else if (k > 0) {
  2829. u.x = -k / (E - k) * O.x + E / (E - k) * u.x;
  2830. u.y = -k / (E - k) * O.y + E / (E - k) * u.y
  2831. }
  2832. D.x = (H.x + O.x + u.x) / 3;
  2833. D.y = (H.y + O.y + u.y) / 3;
  2834. return 0.5 * ((O.x - H.x) * (u.y - H.y) - (O.y - H.y) * (u.x - H.x))
  2835. };
  2836. y.prototype.GetLength = function () {
  2837. return this.m_length
  2838. };
  2839. y.prototype.GetVertex1 = function () {
  2840. return this.m_v1
  2841. };
  2842. y.prototype.GetVertex2 = function () {
  2843. return this.m_v2
  2844. };
  2845. y.prototype.GetCoreVertex1 = function () {
  2846. return this.m_coreV1
  2847. };
  2848. y.prototype.GetCoreVertex2 = function () {
  2849. return this.m_coreV2
  2850. };
  2851. y.prototype.GetNormalVector = function () {
  2852. return this.m_normal
  2853. };
  2854. y.prototype.GetDirectionVector = function () {
  2855. return this.m_direction
  2856. };
  2857. y.prototype.GetCorner1Vector = function () {
  2858. return this.m_cornerDir1
  2859. };
  2860. y.prototype.GetCorner2Vector = function () {
  2861. return this.m_cornerDir2
  2862. };
  2863. y.prototype.Corner1IsConvex = function () {
  2864. return this.m_cornerConvex1
  2865. };
  2866. y.prototype.Corner2IsConvex = function () {
  2867. return this.m_cornerConvex2
  2868. };
  2869. y.prototype.GetFirstVertex = function (k) {
  2870. var z = k.R;
  2871. return new V(k.position.x + (z.col1.x * this.m_coreV1.x + z.col2.x * this.m_coreV1.y), k.position.y + (z.col1.y * this.m_coreV1.x + z.col2.y * this.m_coreV1.y))
  2872. };
  2873. y.prototype.GetNextEdge = function () {
  2874. return this.m_nextEdge
  2875. };
  2876. y.prototype.GetPrevEdge = function () {
  2877. return this.m_prevEdge
  2878. };
  2879. y.prototype.Support = function (k, z, u) {
  2880. if (z === undefined) z = 0;
  2881. if (u === undefined) u = 0;
  2882. var D = k.R,
  2883. H = k.position.x + (D.col1.x * this.m_coreV1.x + D.col2.x * this.m_coreV1.y),
  2884. O = k.position.y + (D.col1.y * this.m_coreV1.x + D.col2.y * this.m_coreV1.y),
  2885. E = k.position.x + (D.col1.x * this.m_coreV2.x + D.col2.x * this.m_coreV2.y);
  2886. k = k.position.y + (D.col1.y * this.m_coreV2.x + D.col2.y * this.m_coreV2.y);
  2887. if (H * z + O * u > E * z + k * u) {
  2888. this.s_supportVec.x = H;
  2889. this.s_supportVec.y = O
  2890. } else {
  2891. this.s_supportVec.x = E;
  2892. this.s_supportVec.y = k
  2893. }
  2894. return this.s_supportVec
  2895. };
  2896. y.prototype.b2EdgeShape = function (k, z) {
  2897. this.__super.b2Shape.call(this);
  2898. this.m_type = U.e_edgeShape;
  2899. this.m_nextEdge = this.m_prevEdge = null;
  2900. this.m_v1 = k;
  2901. this.m_v2 = z;
  2902. this.m_direction.Set(this.m_v2.x - this.m_v1.x, this.m_v2.y - this.m_v1.y);
  2903. this.m_length = this.m_direction.Normalize();
  2904. this.m_normal.Set(this.m_direction.y, -this.m_direction.x);
  2905. this.m_coreV1.Set(-F.b2_toiSlop * (this.m_normal.x - this.m_direction.x) + this.m_v1.x, -F.b2_toiSlop * (this.m_normal.y - this.m_direction.y) + this.m_v1.y);
  2906. this.m_coreV2.Set(-F.b2_toiSlop * (this.m_normal.x + this.m_direction.x) + this.m_v2.x, -F.b2_toiSlop * (this.m_normal.y + this.m_direction.y) + this.m_v2.y);
  2907. this.m_cornerDir1 = this.m_normal;
  2908. this.m_cornerDir2.Set(-this.m_normal.x, -this.m_normal.y)
  2909. };
  2910. y.prototype.SetPrevEdge = function (k, z, u, D) {
  2911. this.m_prevEdge = k;
  2912. this.m_coreV1 = z;
  2913. this.m_cornerDir1 = u;
  2914. this.m_cornerConvex1 = D
  2915. };
  2916. y.prototype.SetNextEdge = function (k, z, u, D) {
  2917. this.m_nextEdge = k;
  2918. this.m_coreV2 = z;
  2919. this.m_cornerDir2 = u;
  2920. this.m_cornerConvex2 = D
  2921. };
  2922. w.b2MassData = function () {
  2923. this.mass = 0;
  2924. this.center = new V(0, 0);
  2925. this.I = 0
  2926. };
  2927. Box2D.inherit(A, Box2D.Collision.Shapes.b2Shape);
  2928. A.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
  2929. A.b2PolygonShape = function () {
  2930. Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments)
  2931. };
  2932. A.prototype.Copy = function () {
  2933. var k = new A;
  2934. k.Set(this);
  2935. return k
  2936. };
  2937. A.prototype.Set = function (k) {
  2938. this.__super.Set.call(this, k);
  2939. if (Box2D.is(k, A)) {
  2940. k = k instanceof A ? k : null;
  2941. this.m_centroid.SetV(k.m_centroid);
  2942. this.m_vertexCount = k.m_vertexCount;
  2943. this.Reserve(this.m_vertexCount);
  2944. for (var z = 0; z < this.m_vertexCount; z++) {
  2945. this.m_vertices[z].SetV(k.m_vertices[z]);
  2946. this.m_normals[z].SetV(k.m_normals[z])
  2947. }
  2948. }
  2949. };
  2950. A.prototype.SetAsArray = function (k, z) {
  2951. if (z === undefined) z = 0;
  2952. var u = new Vector,
  2953. D = 0,
  2954. H;
  2955. for (D = 0; D < k.length; ++D) {
  2956. H = k[D];
  2957. u.push(H)
  2958. }
  2959. this.SetAsVector(u,
  2960. z)
  2961. };
  2962. A.AsArray = function (k, z) {
  2963. if (z === undefined) z = 0;
  2964. var u = new A;
  2965. u.SetAsArray(k, z);
  2966. return u
  2967. };
  2968. A.prototype.SetAsVector = function (k, z) {
  2969. if (z === undefined) z = 0;
  2970. if (z == 0) z = k.length;
  2971. F.b2Assert(2 <= z);
  2972. this.m_vertexCount = z;
  2973. this.Reserve(z);
  2974. var u = 0;
  2975. for (u = 0; u < this.m_vertexCount; u++) this.m_vertices[u].SetV(k[u]);
  2976. for (u = 0; u < this.m_vertexCount; ++u) {
  2977. var D = parseInt(u),
  2978. H = parseInt(u + 1 < this.m_vertexCount ? u + 1 : 0);
  2979. D = B.SubtractVV(this.m_vertices[H], this.m_vertices[D]);
  2980. F.b2Assert(D.LengthSquared() > Number.MIN_VALUE);
  2981. this.m_normals[u].SetV(B.CrossVF(D,
  2982. 1));
  2983. this.m_normals[u].Normalize()
  2984. }
  2985. this.m_centroid = A.ComputeCentroid(this.m_vertices, this.m_vertexCount)
  2986. };
  2987. A.AsVector = function (k, z) {
  2988. if (z === undefined) z = 0;
  2989. var u = new A;
  2990. u.SetAsVector(k, z);
  2991. return u
  2992. };
  2993. A.prototype.SetAsBox = function (k, z) {
  2994. if (k === undefined) k = 0;
  2995. if (z === undefined) z = 0;
  2996. this.m_vertexCount = 4;
  2997. this.Reserve(4);
  2998. this.m_vertices[0].Set(-k, -z);
  2999. this.m_vertices[1].Set(k, -z);
  3000. this.m_vertices[2].Set(k, z);
  3001. this.m_vertices[3].Set(-k, z);
  3002. this.m_normals[0].Set(0, -1);
  3003. this.m_normals[1].Set(1, 0);
  3004. this.m_normals[2].Set(0,
  3005. 1);
  3006. this.m_normals[3].Set(-1, 0);
  3007. this.m_centroid.SetZero()
  3008. };
  3009. A.AsBox = function (k, z) {
  3010. if (k === undefined) k = 0;
  3011. if (z === undefined) z = 0;
  3012. var u = new A;
  3013. u.SetAsBox(k, z);
  3014. return u
  3015. };
  3016. A.prototype.SetAsOrientedBox = function (k, z, u, D) {
  3017. if (k === undefined) k = 0;
  3018. if (z === undefined) z = 0;
  3019. if (u === undefined) u = null;
  3020. if (D === undefined) D = 0;
  3021. this.m_vertexCount = 4;
  3022. this.Reserve(4);
  3023. this.m_vertices[0].Set(-k, -z);
  3024. this.m_vertices[1].Set(k, -z);
  3025. this.m_vertices[2].Set(k, z);
  3026. this.m_vertices[3].Set(-k, z);
  3027. this.m_normals[0].Set(0, -1);
  3028. this.m_normals[1].Set(1, 0);
  3029. this.m_normals[2].Set(0, 1);
  3030. this.m_normals[3].Set(-1, 0);
  3031. this.m_centroid = u;
  3032. k = new Q;
  3033. k.position = u;
  3034. k.R.Set(D);
  3035. for (u = 0; u < this.m_vertexCount; ++u) {
  3036. this.m_vertices[u] = B.MulX(k, this.m_vertices[u]);
  3037. this.m_normals[u] = B.MulMV(k.R, this.m_normals[u])
  3038. }
  3039. };
  3040. A.AsOrientedBox = function (k, z, u, D) {
  3041. if (k === undefined) k = 0;
  3042. if (z === undefined) z = 0;
  3043. if (u === undefined) u = null;
  3044. if (D === undefined) D = 0;
  3045. var H = new A;
  3046. H.SetAsOrientedBox(k, z, u, D);
  3047. return H
  3048. };
  3049. A.prototype.SetAsEdge = function (k, z) {
  3050. this.m_vertexCount = 2;
  3051. this.Reserve(2);
  3052. this.m_vertices[0].SetV(k);
  3053. this.m_vertices[1].SetV(z);
  3054. this.m_centroid.x = 0.5 * (k.x + z.x);
  3055. this.m_centroid.y = 0.5 * (k.y + z.y);
  3056. this.m_normals[0] = B.CrossVF(B.SubtractVV(z, k), 1);
  3057. this.m_normals[0].Normalize();
  3058. this.m_normals[1].x = -this.m_normals[0].x;
  3059. this.m_normals[1].y = -this.m_normals[0].y
  3060. };
  3061. A.AsEdge = function (k, z) {
  3062. var u = new A;
  3063. u.SetAsEdge(k, z);
  3064. return u
  3065. };
  3066. A.prototype.TestPoint = function (k, z) {
  3067. var u;
  3068. u = k.R;
  3069. for (var D = z.x - k.position.x, H = z.y - k.position.y, O = D * u.col1.x + H * u.col1.y, E = D * u.col2.x + H * u.col2.y, R = 0; R < this.m_vertexCount; ++R) {
  3070. u = this.m_vertices[R];
  3071. D = O - u.x;
  3072. H = E - u.y;
  3073. u = this.m_normals[R];
  3074. if (u.x * D + u.y * H > 0) return false
  3075. }
  3076. return true
  3077. };
  3078. A.prototype.RayCast = function (k, z, u) {
  3079. var D = 0,
  3080. H = z.maxFraction,
  3081. O = 0,
  3082. E = 0,
  3083. R, N;
  3084. O = z.p1.x - u.position.x;
  3085. E = z.p1.y - u.position.y;
  3086. R = u.R;
  3087. var S = O * R.col1.x + E * R.col1.y,
  3088. aa = O * R.col2.x + E * R.col2.y;
  3089. O = z.p2.x - u.position.x;
  3090. E = z.p2.y - u.position.y;
  3091. R = u.R;
  3092. z = O * R.col1.x + E * R.col1.y - S;
  3093. R = O * R.col2.x + E * R.col2.y - aa;
  3094. for (var Z = parseInt(-1), d = 0; d < this.m_vertexCount; ++d) {
  3095. N = this.m_vertices[d];
  3096. O = N.x - S;
  3097. E = N.y - aa;
  3098. N = this.m_normals[d];
  3099. O = N.x * O + N.y * E;
  3100. E = N.x * z + N.y * R;
  3101. if (E == 0) {
  3102. if (O < 0) return false
  3103. } else if (E < 0 && O < D * E) {
  3104. D = O / E;
  3105. Z = d
  3106. } else if (E > 0 && O < H * E) H = O / E;
  3107. if (H < D - Number.MIN_VALUE) return false
  3108. }
  3109. if (Z >= 0) {
  3110. k.fraction = D;
  3111. R = u.R;
  3112. N = this.m_normals[Z];
  3113. k.normal.x = R.col1.x * N.x + R.col2.x * N.y;
  3114. k.normal.y = R.col1.y * N.x + R.col2.y * N.y;
  3115. return true
  3116. }
  3117. return false
  3118. };
  3119. A.prototype.ComputeAABB = function (k, z) {
  3120. for (var u = z.R, D = this.m_vertices[0], H = z.position.x + (u.col1.x * D.x + u.col2.x * D.y), O = z.position.y + (u.col1.y * D.x + u.col2.y * D.y), E = H, R = O, N = 1; N < this.m_vertexCount; ++N) {
  3121. D = this.m_vertices[N];
  3122. var S = z.position.x + (u.col1.x * D.x + u.col2.x * D.y);
  3123. D = z.position.y + (u.col1.y * D.x + u.col2.y * D.y);
  3124. H = H < S ? H : S;
  3125. O = O < D ? O : D;
  3126. E = E > S ? E : S;
  3127. R = R > D ? R : D
  3128. }
  3129. k.lowerBound.x = H - this.m_radius;
  3130. k.lowerBound.y = O - this.m_radius;
  3131. k.upperBound.x = E + this.m_radius;
  3132. k.upperBound.y = R + this.m_radius
  3133. };
  3134. A.prototype.ComputeMass = function (k, z) {
  3135. if (z === undefined) z = 0;
  3136. if (this.m_vertexCount == 2) {
  3137. k.center.x = 0.5 * (this.m_vertices[0].x + this.m_vertices[1].x);
  3138. k.center.y = 0.5 * (this.m_vertices[0].y + this.m_vertices[1].y);
  3139. k.mass = 0;
  3140. k.I = 0
  3141. } else {
  3142. for (var u = 0, D = 0, H = 0, O = 0, E = 1 / 3, R = 0; R < this.m_vertexCount; ++R) {
  3143. var N = this.m_vertices[R],
  3144. S = R + 1 < this.m_vertexCount ? this.m_vertices[parseInt(R + 1)] : this.m_vertices[0],
  3145. aa = N.x - 0,
  3146. Z = N.y - 0,
  3147. d = S.x - 0,
  3148. h = S.y - 0,
  3149. l = aa * h - Z * d,
  3150. j = 0.5 * l;
  3151. H += j;
  3152. u += j * E * (0 + N.x + S.x);
  3153. D += j * E * (0 + N.y + S.y);
  3154. N = aa;
  3155. Z = Z;
  3156. d = d;
  3157. h = h;
  3158. O += l * (E * (0.25 * (N * N + d * N + d * d) + (0 * N + 0 * d)) + 0 + (E * (0.25 * (Z * Z + h * Z + h * h) + (0 * Z + 0 * h)) + 0))
  3159. }
  3160. k.mass = z * H;
  3161. u *= 1 / H;
  3162. D *= 1 / H;
  3163. k.center.Set(u, D);
  3164. k.I = z * O
  3165. }
  3166. };
  3167. A.prototype.ComputeSubmergedArea = function (k, z, u, D) {
  3168. if (z === undefined) z = 0;
  3169. var H = B.MulTMV(u.R, k),
  3170. O = z - B.Dot(k, u.position),
  3171. E = new Vector_a2j_Number,
  3172. R = 0,
  3173. N = parseInt(-1);
  3174. z = parseInt(-1);
  3175. var S = false;
  3176. for (k = k = 0; k < this.m_vertexCount; ++k) {
  3177. E[k] = B.Dot(H, this.m_vertices[k]) - O;
  3178. var aa = E[k] < -Number.MIN_VALUE;
  3179. if (k > 0)
  3180. if (aa) {
  3181. if (!S) {
  3182. N = k - 1;
  3183. R++
  3184. }
  3185. } else if (S) {
  3186. z = k - 1;
  3187. R++
  3188. }
  3189. S = aa
  3190. }
  3191. switch (R) {
  3192. case 0:
  3193. if (S) {
  3194. k = new w;
  3195. this.ComputeMass(k, 1);
  3196. D.SetV(B.MulX(u, k.center));
  3197. return k.mass
  3198. } else return 0;
  3199. case 1:
  3200. if (N == -1) N = this.m_vertexCount - 1;
  3201. else z = this.m_vertexCount - 1
  3202. }
  3203. k = parseInt((N + 1) % this.m_vertexCount);
  3204. H = parseInt((z + 1) % this.m_vertexCount);
  3205. O = (0 - E[N]) / (E[k] - E[N]);
  3206. E = (0 - E[z]) / (E[H] - E[z]);
  3207. N = new V(this.m_vertices[N].x * (1 - O) + this.m_vertices[k].x * O, this.m_vertices[N].y * (1 - O) + this.m_vertices[k].y * O);
  3208. z = new V(this.m_vertices[z].x * (1 - E) + this.m_vertices[H].x * E, this.m_vertices[z].y * (1 - E) + this.m_vertices[H].y * E);
  3209. E = 0;
  3210. O = new V;
  3211. R = this.m_vertices[k];
  3212. for (k = k; k != H;) {
  3213. k = (k + 1) % this.m_vertexCount;
  3214. S = k == H ? z : this.m_vertices[k];
  3215. aa = 0.5 * ((R.x - N.x) * (S.y - N.y) - (R.y - N.y) * (S.x - N.x));
  3216. E += aa;
  3217. O.x += aa * (N.x + R.x + S.x) / 3;
  3218. O.y += aa * (N.y + R.y + S.y) / 3;
  3219. R = S
  3220. }
  3221. O.Multiply(1 / E);
  3222. D.SetV(B.MulX(u, O));
  3223. return E
  3224. };
  3225. A.prototype.GetVertexCount = function () {
  3226. return this.m_vertexCount
  3227. };
  3228. A.prototype.GetVertices = function () {
  3229. return this.m_vertices
  3230. };
  3231. A.prototype.GetNormals = function () {
  3232. return this.m_normals
  3233. };
  3234. A.prototype.GetSupport = function (k) {
  3235. for (var z = 0, u = this.m_vertices[0].x * k.x + this.m_vertices[0].y * k.y, D = 1; D < this.m_vertexCount; ++D) {
  3236. var H = this.m_vertices[D].x * k.x + this.m_vertices[D].y * k.y;
  3237. if (H > u) {
  3238. z = D;
  3239. u = H
  3240. }
  3241. }
  3242. return z
  3243. };
  3244. A.prototype.GetSupportVertex = function (k) {
  3245. for (var z = 0, u = this.m_vertices[0].x * k.x + this.m_vertices[0].y * k.y, D = 1; D < this.m_vertexCount; ++D) {
  3246. var H = this.m_vertices[D].x * k.x + this.m_vertices[D].y * k.y;
  3247. if (H > u) {
  3248. z = D;
  3249. u = H
  3250. }
  3251. }
  3252. return this.m_vertices[z]
  3253. };
  3254. A.prototype.Validate = function () {
  3255. return false
  3256. };
  3257. A.prototype.b2PolygonShape = function () {
  3258. this.__super.b2Shape.call(this);
  3259. this.m_type = U.e_polygonShape;
  3260. this.m_centroid = new V;
  3261. this.m_vertices = new Vector;
  3262. this.m_normals = new Vector
  3263. };
  3264. A.prototype.Reserve = function (k) {
  3265. if (k === undefined) k = 0;
  3266. for (var z = parseInt(this.m_vertices.length); z < k; z++) {
  3267. this.m_vertices[z] = new V;
  3268. this.m_normals[z] = new V
  3269. }
  3270. };
  3271. A.ComputeCentroid = function (k, z) {
  3272. if (z === undefined) z = 0;
  3273. for (var u = new V, D = 0, H = 1 / 3, O = 0; O < z; ++O) {
  3274. var E = k[O],
  3275. R = O + 1 < z ? k[parseInt(O + 1)] : k[0],
  3276. N = 0.5 * ((E.x - 0) * (R.y - 0) - (E.y - 0) * (R.x - 0));
  3277. D += N;
  3278. u.x += N * H * (0 + E.x + R.x);
  3279. u.y += N * H * (0 + E.y + R.y)
  3280. }
  3281. u.x *= 1 / D;
  3282. u.y *= 1 / D;
  3283. return u
  3284. };
  3285. A.ComputeOBB = function (k, z, u) {
  3286. if (u === undefined) u = 0;
  3287. var D = 0,
  3288. H = new Vector(u + 1);
  3289. for (D = 0; D < u; ++D) H[D] = z[D];
  3290. H[u] = H[0];
  3291. z = Number.MAX_VALUE;
  3292. for (D = 1; D <= u; ++D) {
  3293. var O = H[parseInt(D - 1)],
  3294. E = H[D].x - O.x,
  3295. R = H[D].y - O.y,
  3296. N = Math.sqrt(E * E + R * R);
  3297. E /= N;
  3298. R /= N;
  3299. for (var S = -R, aa = E, Z = N = Number.MAX_VALUE, d = -Number.MAX_VALUE, h = -Number.MAX_VALUE, l = 0; l < u; ++l) {
  3300. var j = H[l].x - O.x,
  3301. o = H[l].y - O.y,
  3302. q = E * j + R * o;
  3303. j = S * j + aa * o;
  3304. if (q < N) N = q;
  3305. if (j < Z) Z = j;
  3306. if (q > d) d = q;
  3307. if (j > h) h = j
  3308. }
  3309. l = (d - N) * (h - Z);
  3310. if (l < 0.95 * z) {
  3311. z = l;
  3312. k.R.col1.x = E;
  3313. k.R.col1.y = R;
  3314. k.R.col2.x = S;
  3315. k.R.col2.y = aa;
  3316. E = 0.5 * (N + d);
  3317. R = 0.5 * (Z + h);
  3318. S = k.R;
  3319. k.center.x = O.x + (S.col1.x * E + S.col2.x * R);
  3320. k.center.y = O.y + (S.col1.y * E + S.col2.y * R);
  3321. k.extents.x = 0.5 * (d - N);
  3322. k.extents.y = 0.5 * (h - Z)
  3323. }
  3324. }
  3325. };
  3326. Box2D.postDefs.push(function () {
  3327. Box2D.Collision.Shapes.b2PolygonShape.s_mat = new p
  3328. });
  3329. U.b2Shape = function () {};
  3330. U.prototype.Copy = function () {
  3331. return null
  3332. };
  3333. U.prototype.Set = function (k) {
  3334. this.m_radius = k.m_radius
  3335. };
  3336. U.prototype.GetType = function () {
  3337. return this.m_type
  3338. };
  3339. U.prototype.TestPoint = function () {
  3340. return false
  3341. };
  3342. U.prototype.RayCast = function () {
  3343. return false
  3344. };
  3345. U.prototype.ComputeAABB = function () {};
  3346. U.prototype.ComputeMass = function () {};
  3347. U.prototype.ComputeSubmergedArea = function () {
  3348. return 0
  3349. };
  3350. U.TestOverlap = function (k, z, u, D) {
  3351. var H = new L;
  3352. H.proxyA = new W;
  3353. H.proxyA.Set(k);
  3354. H.proxyB = new W;
  3355. H.proxyB.Set(u);
  3356. H.transformA = z;
  3357. H.transformB = D;
  3358. H.useRadii = true;
  3359. k = new Y;
  3360. k.count = 0;
  3361. z = new I;
  3362. M.Distance(z, k, H);
  3363. return z.distance < 10 * Number.MIN_VALUE
  3364. };
  3365. U.prototype.b2Shape = function () {
  3366. this.m_type = U.e_unknownShape;
  3367. this.m_radius = F.b2_linearSlop
  3368. };
  3369. Box2D.postDefs.push(function () {
  3370. Box2D.Collision.Shapes.b2Shape.e_unknownShape = parseInt(-1);
  3371. Box2D.Collision.Shapes.b2Shape.e_circleShape = 0;
  3372. Box2D.Collision.Shapes.b2Shape.e_polygonShape = 1;
  3373. Box2D.Collision.Shapes.b2Shape.e_edgeShape = 2;
  3374. Box2D.Collision.Shapes.b2Shape.e_shapeTypeCount = 3;
  3375. Box2D.Collision.Shapes.b2Shape.e_hitCollide = 1;
  3376. Box2D.Collision.Shapes.b2Shape.e_missCollide = 0;
  3377. Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide = parseInt(-1)
  3378. })
  3379. })();
  3380. (function () {
  3381. var F = Box2D.Common.b2Color,
  3382. G = Box2D.Common.b2Settings,
  3383. K = Box2D.Common.Math.b2Math;
  3384. F.b2Color = function () {
  3385. this._b = this._g = this._r = 0
  3386. };
  3387. F.prototype.b2Color = function (y, w, A) {
  3388. if (y === undefined) y = 0;
  3389. if (w === undefined) w = 0;
  3390. if (A === undefined) A = 0;
  3391. this._r = Box2D.parseUInt(255 * K.Clamp(y, 0, 1));
  3392. this._g = Box2D.parseUInt(255 * K.Clamp(w, 0, 1));
  3393. this._b = Box2D.parseUInt(255 * K.Clamp(A, 0, 1))
  3394. };
  3395. F.prototype.Set = function (y, w, A) {
  3396. if (y === undefined) y = 0;
  3397. if (w === undefined) w = 0;
  3398. if (A === undefined) A = 0;
  3399. this._r = Box2D.parseUInt(255 * K.Clamp(y,
  3400. 0, 1));
  3401. this._g = Box2D.parseUInt(255 * K.Clamp(w, 0, 1));
  3402. this._b = Box2D.parseUInt(255 * K.Clamp(A, 0, 1))
  3403. };
  3404. Object.defineProperty(F.prototype, "r", {
  3405. enumerable: false,
  3406. configurable: true,
  3407. set: function (y) {
  3408. if (y === undefined) y = 0;
  3409. this._r = Box2D.parseUInt(255 * K.Clamp(y, 0, 1))
  3410. }
  3411. });
  3412. Object.defineProperty(F.prototype, "g", {
  3413. enumerable: false,
  3414. configurable: true,
  3415. set: function (y) {
  3416. if (y === undefined) y = 0;
  3417. this._g = Box2D.parseUInt(255 * K.Clamp(y, 0, 1))
  3418. }
  3419. });
  3420. Object.defineProperty(F.prototype, "b", {
  3421. enumerable: false,
  3422. configurable: true,
  3423. set: function (y) {
  3424. if (y === undefined) y = 0;
  3425. this._b = Box2D.parseUInt(255 * K.Clamp(y, 0, 1))
  3426. }
  3427. });
  3428. Object.defineProperty(F.prototype, "color", {
  3429. enumerable: false,
  3430. configurable: true,
  3431. get: function () {
  3432. return this._r << 16 | this._g << 8 | this._b
  3433. }
  3434. });
  3435. G.b2Settings = function () {};
  3436. G.b2MixFriction = function (y, w) {
  3437. if (y === undefined) y = 0;
  3438. if (w === undefined) w = 0;
  3439. return Math.sqrt(y * w)
  3440. };
  3441. G.b2MixRestitution = function (y, w) {
  3442. if (y === undefined) y = 0;
  3443. if (w === undefined) w = 0;
  3444. return y > w ? y : w
  3445. };
  3446. G.b2Assert = function (y) {
  3447. if (!y) throw "Assertion Failed";
  3448. };
  3449. Box2D.postDefs.push(function () {
  3450. Box2D.Common.b2Settings.VERSION = "2.1alpha";
  3451. Box2D.Common.b2Settings.USHRT_MAX = 65535;
  3452. Box2D.Common.b2Settings.b2_pi = Math.PI;
  3453. Box2D.Common.b2Settings.b2_maxManifoldPoints = 2;
  3454. Box2D.Common.b2Settings.b2_aabbExtension = 0.1;
  3455. Box2D.Common.b2Settings.b2_aabbMultiplier = 2;
  3456. Box2D.Common.b2Settings.b2_polygonRadius = 2 * G.b2_linearSlop;
  3457. Box2D.Common.b2Settings.b2_linearSlop = 0.0050;
  3458. Box2D.Common.b2Settings.b2_angularSlop = 2 / 180 * G.b2_pi;
  3459. Box2D.Common.b2Settings.b2_toiSlop = 8 * G.b2_linearSlop;
  3460. Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland = 32;
  3461. Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland = 32;
  3462. Box2D.Common.b2Settings.b2_velocityThreshold = 1;
  3463. Box2D.Common.b2Settings.b2_maxLinearCorrection = 0.2;
  3464. Box2D.Common.b2Settings.b2_maxAngularCorrection = 8 / 180 * G.b2_pi;
  3465. Box2D.Common.b2Settings.b2_maxTranslation = 2;
  3466. Box2D.Common.b2Settings.b2_maxTranslationSquared = G.b2_maxTranslation * G.b2_maxTranslation;
  3467. Box2D.Common.b2Settings.b2_maxRotation = 0.5 * G.b2_pi;
  3468. Box2D.Common.b2Settings.b2_maxRotationSquared = G.b2_maxRotation * G.b2_maxRotation;
  3469. Box2D.Common.b2Settings.b2_contactBaumgarte = 0.2;
  3470. Box2D.Common.b2Settings.b2_timeToSleep = 0.5;
  3471. Box2D.Common.b2Settings.b2_linearSleepTolerance = 0.01;
  3472. Box2D.Common.b2Settings.b2_angularSleepTolerance = 2 / 180 * G.b2_pi
  3473. })
  3474. })();
  3475. (function () {
  3476. var F = Box2D.Common.Math.b2Mat22,
  3477. G = Box2D.Common.Math.b2Mat33,
  3478. K = Box2D.Common.Math.b2Math,
  3479. y = Box2D.Common.Math.b2Sweep,
  3480. w = Box2D.Common.Math.b2Transform,
  3481. A = Box2D.Common.Math.b2Vec2,
  3482. U = Box2D.Common.Math.b2Vec3;
  3483. F.b2Mat22 = function () {
  3484. this.col1 = new A;
  3485. this.col2 = new A
  3486. };
  3487. F.prototype.b2Mat22 = function () {
  3488. this.SetIdentity()
  3489. };
  3490. F.FromAngle = function (p) {
  3491. if (p === undefined) p = 0;
  3492. var B = new F;
  3493. B.Set(p);
  3494. return B
  3495. };
  3496. F.FromVV = function (p, B) {
  3497. var Q = new F;
  3498. Q.SetVV(p, B);
  3499. return Q
  3500. };
  3501. F.prototype.Set = function (p) {
  3502. if (p === undefined) p = 0;
  3503. var B = Math.cos(p);
  3504. p = Math.sin(p);
  3505. this.col1.x = B;
  3506. this.col2.x = -p;
  3507. this.col1.y = p;
  3508. this.col2.y = B
  3509. };
  3510. F.prototype.SetVV = function (p, B) {
  3511. this.col1.SetV(p);
  3512. this.col2.SetV(B)
  3513. };
  3514. F.prototype.Copy = function () {
  3515. var p = new F;
  3516. p.SetM(this);
  3517. return p
  3518. };
  3519. F.prototype.SetM = function (p) {
  3520. this.col1.SetV(p.col1);
  3521. this.col2.SetV(p.col2)
  3522. };
  3523. F.prototype.AddM = function (p) {
  3524. this.col1.x += p.col1.x;
  3525. this.col1.y += p.col1.y;
  3526. this.col2.x += p.col2.x;
  3527. this.col2.y += p.col2.y
  3528. };
  3529. F.prototype.SetIdentity = function () {
  3530. this.col1.x = 1;
  3531. this.col2.x = 0;
  3532. this.col1.y = 0;
  3533. this.col2.y = 1
  3534. };
  3535. F.prototype.SetZero = function () {
  3536. this.col1.x = 0;
  3537. this.col2.x = 0;
  3538. this.col1.y = 0;
  3539. this.col2.y = 0
  3540. };
  3541. F.prototype.GetAngle = function () {
  3542. return Math.atan2(this.col1.y, this.col1.x)
  3543. };
  3544. F.prototype.GetInverse = function (p) {
  3545. var B = this.col1.x,
  3546. Q = this.col2.x,
  3547. V = this.col1.y,
  3548. M = this.col2.y,
  3549. L = B * M - Q * V;
  3550. if (L != 0) L = 1 / L;
  3551. p.col1.x = L * M;
  3552. p.col2.x = -L * Q;
  3553. p.col1.y = -L * V;
  3554. p.col2.y = L * B;
  3555. return p
  3556. };
  3557. F.prototype.Solve = function (p, B, Q) {
  3558. if (B === undefined) B = 0;
  3559. if (Q === undefined) Q = 0;
  3560. var V = this.col1.x,
  3561. M = this.col2.x,
  3562. L = this.col1.y,
  3563. I = this.col2.y,
  3564. W = V * I - M * L;
  3565. if (W != 0) W = 1 / W;
  3566. p.x = W * (I * B - M * Q);
  3567. p.y = W * (V * Q - L * B);
  3568. return p
  3569. };
  3570. F.prototype.Abs = function () {
  3571. this.col1.Abs();
  3572. this.col2.Abs()
  3573. };
  3574. G.b2Mat33 = function () {
  3575. this.col1 = new U;
  3576. this.col2 = new U;
  3577. this.col3 = new U
  3578. };
  3579. G.prototype.b2Mat33 = function (p, B, Q) {
  3580. if (p === undefined) p = null;
  3581. if (B === undefined) B = null;
  3582. if (Q === undefined) Q = null;
  3583. if (!p && !B && !Q) {
  3584. this.col1.SetZero();
  3585. this.col2.SetZero();
  3586. this.col3.SetZero()
  3587. } else {
  3588. this.col1.SetV(p);
  3589. this.col2.SetV(B);
  3590. this.col3.SetV(Q)
  3591. }
  3592. };
  3593. G.prototype.SetVVV = function (p, B, Q) {
  3594. this.col1.SetV(p);
  3595. this.col2.SetV(B);
  3596. this.col3.SetV(Q)
  3597. };
  3598. G.prototype.Copy = function () {
  3599. return new G(this.col1, this.col2, this.col3)
  3600. };
  3601. G.prototype.SetM = function (p) {
  3602. this.col1.SetV(p.col1);
  3603. this.col2.SetV(p.col2);
  3604. this.col3.SetV(p.col3)
  3605. };
  3606. G.prototype.AddM = function (p) {
  3607. this.col1.x += p.col1.x;
  3608. this.col1.y += p.col1.y;
  3609. this.col1.z += p.col1.z;
  3610. this.col2.x += p.col2.x;
  3611. this.col2.y += p.col2.y;
  3612. this.col2.z += p.col2.z;
  3613. this.col3.x += p.col3.x;
  3614. this.col3.y += p.col3.y;
  3615. this.col3.z += p.col3.z
  3616. };
  3617. G.prototype.SetIdentity = function () {
  3618. this.col1.x = 1;
  3619. this.col2.x = 0;
  3620. this.col3.x = 0;
  3621. this.col1.y = 0;
  3622. this.col2.y = 1;
  3623. this.col3.y = 0;
  3624. this.col1.z = 0;
  3625. this.col2.z = 0;
  3626. this.col3.z = 1
  3627. };
  3628. G.prototype.SetZero = function () {
  3629. this.col1.x = 0;
  3630. this.col2.x = 0;
  3631. this.col3.x = 0;
  3632. this.col1.y = 0;
  3633. this.col2.y = 0;
  3634. this.col3.y = 0;
  3635. this.col1.z = 0;
  3636. this.col2.z = 0;
  3637. this.col3.z = 0
  3638. };
  3639. G.prototype.Solve22 = function (p, B, Q) {
  3640. if (B === undefined) B = 0;
  3641. if (Q === undefined) Q = 0;
  3642. var V = this.col1.x,
  3643. M = this.col2.x,
  3644. L = this.col1.y,
  3645. I = this.col2.y,
  3646. W = V * I - M * L;
  3647. if (W != 0) W = 1 / W;
  3648. p.x = W * (I * B - M * Q);
  3649. p.y = W * (V * Q - L * B);
  3650. return p
  3651. };
  3652. G.prototype.Solve33 = function (p, B, Q, V) {
  3653. if (B === undefined) B = 0;
  3654. if (Q === undefined) Q = 0;
  3655. if (V === undefined) V = 0;
  3656. var M = this.col1.x,
  3657. L = this.col1.y,
  3658. I = this.col1.z,
  3659. W = this.col2.x,
  3660. Y = this.col2.y,
  3661. k = this.col2.z,
  3662. z = this.col3.x,
  3663. u = this.col3.y,
  3664. D = this.col3.z,
  3665. H = M * (Y * D - k * u) + L * (k * z - W * D) + I * (W * u - Y * z);
  3666. if (H != 0) H = 1 / H;
  3667. p.x = H * (B * (Y * D - k * u) + Q * (k * z - W * D) + V * (W * u - Y * z));
  3668. p.y = H * (M * (Q * D - V * u) + L * (V * z - B * D) + I * (B * u - Q * z));
  3669. p.z = H * (M * (Y * V - k * Q) + L * (k * B - W * V) + I * (W * Q - Y * B));
  3670. return p
  3671. };
  3672. K.b2Math = function () {};
  3673. K.IsValid = function (p) {
  3674. if (p === undefined) p = 0;
  3675. return isFinite(p)
  3676. };
  3677. K.Dot = function (p, B) {
  3678. return p.x * B.x + p.y * B.y
  3679. };
  3680. K.CrossVV = function (p, B) {
  3681. return p.x * B.y - p.y * B.x
  3682. };
  3683. K.CrossVF = function (p, B) {
  3684. if (B === undefined) B = 0;
  3685. return new A(B * p.y, -B * p.x)
  3686. };
  3687. K.CrossFV = function (p, B) {
  3688. if (p === undefined) p = 0;
  3689. return new A(-p * B.y, p * B.x)
  3690. };
  3691. K.MulMV = function (p, B) {
  3692. return new A(p.col1.x * B.x + p.col2.x * B.y, p.col1.y * B.x + p.col2.y * B.y)
  3693. };
  3694. K.MulTMV = function (p, B) {
  3695. return new A(K.Dot(B, p.col1), K.Dot(B, p.col2))
  3696. };
  3697. K.MulX = function (p, B) {
  3698. var Q = K.MulMV(p.R, B);
  3699. Q.x += p.position.x;
  3700. Q.y += p.position.y;
  3701. return Q
  3702. };
  3703. K.MulXT = function (p, B) {
  3704. var Q = K.SubtractVV(B, p.position),
  3705. V = Q.x * p.R.col1.x + Q.y * p.R.col1.y;
  3706. Q.y = Q.x * p.R.col2.x + Q.y * p.R.col2.y;
  3707. Q.x = V;
  3708. return Q
  3709. };
  3710. K.AddVV = function (p, B) {
  3711. return new A(p.x + B.x, p.y + B.y)
  3712. };
  3713. K.SubtractVV = function (p, B) {
  3714. return new A(p.x - B.x, p.y - B.y)
  3715. };
  3716. K.Distance = function (p, B) {
  3717. var Q = p.x - B.x,
  3718. V = p.y - B.y;
  3719. return Math.sqrt(Q * Q + V * V)
  3720. };
  3721. K.DistanceSquared = function (p, B) {
  3722. var Q = p.x - B.x,
  3723. V = p.y - B.y;
  3724. return Q * Q + V * V
  3725. };
  3726. K.MulFV = function (p, B) {
  3727. if (p === undefined) p = 0;
  3728. return new A(p * B.x, p * B.y)
  3729. };
  3730. K.AddMM = function (p, B) {
  3731. return F.FromVV(K.AddVV(p.col1, B.col1), K.AddVV(p.col2, B.col2))
  3732. };
  3733. K.MulMM = function (p, B) {
  3734. return F.FromVV(K.MulMV(p,
  3735. B.col1), K.MulMV(p, B.col2))
  3736. };
  3737. K.MulTMM = function (p, B) {
  3738. var Q = new A(K.Dot(p.col1, B.col1), K.Dot(p.col2, B.col1)),
  3739. V = new A(K.Dot(p.col1, B.col2), K.Dot(p.col2, B.col2));
  3740. return F.FromVV(Q, V)
  3741. };
  3742. K.Abs = function (p) {
  3743. if (p === undefined) p = 0;
  3744. return p > 0 ? p : -p
  3745. };
  3746. K.AbsV = function (p) {
  3747. return new A(K.Abs(p.x), K.Abs(p.y))
  3748. };
  3749. K.AbsM = function (p) {
  3750. return F.FromVV(K.AbsV(p.col1), K.AbsV(p.col2))
  3751. };
  3752. K.Min = function (p, B) {
  3753. if (p === undefined) p = 0;
  3754. if (B === undefined) B = 0;
  3755. return p < B ? p : B
  3756. };
  3757. K.MinV = function (p, B) {
  3758. return new A(K.Min(p.x, B.x), K.Min(p.y, B.y))
  3759. };
  3760. K.Max = function (p, B) {
  3761. if (p === undefined) p = 0;
  3762. if (B === undefined) B = 0;
  3763. return p > B ? p : B
  3764. };
  3765. K.MaxV = function (p, B) {
  3766. return new A(K.Max(p.x, B.x), K.Max(p.y, B.y))
  3767. };
  3768. K.Clamp = function (p, B, Q) {
  3769. if (p === undefined) p = 0;
  3770. if (B === undefined) B = 0;
  3771. if (Q === undefined) Q = 0;
  3772. return p < B ? B : p > Q ? Q : p
  3773. };
  3774. K.ClampV = function (p, B, Q) {
  3775. return K.MaxV(B, K.MinV(p, Q))
  3776. };
  3777. K.Swap = function (p, B) {
  3778. var Q = p[0];
  3779. p[0] = B[0];
  3780. B[0] = Q
  3781. };
  3782. K.Random = function () {
  3783. return Math.random() * 2 - 1
  3784. };
  3785. K.RandomRange = function (p, B) {
  3786. if (p === undefined) p = 0;
  3787. if (B === undefined) B = 0;
  3788. var Q = Math.random();
  3789. return Q = (B - p) * Q + p
  3790. };
  3791. K.NextPowerOfTwo = function (p) {
  3792. if (p === undefined) p = 0;
  3793. p |= p >> 1 & 2147483647;
  3794. p |= p >> 2 & 1073741823;
  3795. p |= p >> 4 & 268435455;
  3796. p |= p >> 8 & 16777215;
  3797. p |= p >> 16 & 65535;
  3798. return p + 1
  3799. };
  3800. K.IsPowerOfTwo = function (p) {
  3801. if (p === undefined) p = 0;
  3802. return p > 0 && (p & p - 1) == 0
  3803. };
  3804. Box2D.postDefs.push(function () {
  3805. Box2D.Common.Math.b2Math.b2Vec2_zero = new A(0, 0);
  3806. Box2D.Common.Math.b2Math.b2Mat22_identity = F.FromVV(new A(1, 0), new A(0, 1));
  3807. Box2D.Common.Math.b2Math.b2Transform_identity = new w(K.b2Vec2_zero, K.b2Mat22_identity)
  3808. });
  3809. y.b2Sweep = function () {
  3810. this.localCenter = new A;
  3811. this.c0 = new A;
  3812. this.c = new A
  3813. };
  3814. y.prototype.Set = function (p) {
  3815. this.localCenter.SetV(p.localCenter);
  3816. this.c0.SetV(p.c0);
  3817. this.c.SetV(p.c);
  3818. this.a0 = p.a0;
  3819. this.a = p.a;
  3820. this.t0 = p.t0
  3821. };
  3822. y.prototype.Copy = function () {
  3823. var p = new y;
  3824. p.localCenter.SetV(this.localCenter);
  3825. p.c0.SetV(this.c0);
  3826. p.c.SetV(this.c);
  3827. p.a0 = this.a0;
  3828. p.a = this.a;
  3829. p.t0 = this.t0;
  3830. return p
  3831. };
  3832. y.prototype.GetTransform = function (p, B) {
  3833. if (B === undefined) B = 0;
  3834. p.position.x = (1 - B) * this.c0.x + B * this.c.x;
  3835. p.position.y = (1 - B) * this.c0.y + B * this.c.y;
  3836. p.R.Set((1 - B) * this.a0 + B * this.a);
  3837. var Q = p.R;
  3838. p.position.x -= Q.col1.x * this.localCenter.x + Q.col2.x * this.localCenter.y;
  3839. p.position.y -= Q.col1.y * this.localCenter.x + Q.col2.y * this.localCenter.y
  3840. };
  3841. y.prototype.Advance = function (p) {
  3842. if (p === undefined) p = 0;
  3843. if (this.t0 < p && 1 - this.t0 > Number.MIN_VALUE) {
  3844. var B = (p - this.t0) / (1 - this.t0);
  3845. this.c0.x = (1 - B) * this.c0.x + B * this.c.x;
  3846. this.c0.y = (1 - B) * this.c0.y + B * this.c.y;
  3847. this.a0 = (1 - B) * this.a0 + B * this.a;
  3848. this.t0 = p
  3849. }
  3850. };
  3851. w.b2Transform = function () {
  3852. this.position = new A;
  3853. this.R = new F
  3854. };
  3855. w.prototype.b2Transform = function (p, B) {
  3856. if (p === undefined) p = null;
  3857. if (B === undefined) B = null;
  3858. if (p) {
  3859. this.position.SetV(p);
  3860. this.R.SetM(B)
  3861. }
  3862. };
  3863. w.prototype.Initialize = function (p, B) {
  3864. this.position.SetV(p);
  3865. this.R.SetM(B)
  3866. };
  3867. w.prototype.SetIdentity = function () {
  3868. this.position.SetZero();
  3869. this.R.SetIdentity()
  3870. };
  3871. w.prototype.Set = function (p) {
  3872. this.position.SetV(p.position);
  3873. this.R.SetM(p.R)
  3874. };
  3875. w.prototype.GetAngle = function () {
  3876. return Math.atan2(this.R.col1.y, this.R.col1.x)
  3877. };
  3878. A.b2Vec2 = function () {};
  3879. A.prototype.b2Vec2 = function (p, B) {
  3880. if (p === undefined) p = 0;
  3881. if (B === undefined) B = 0;
  3882. this.x = p;
  3883. this.y = B
  3884. };
  3885. A.prototype.SetZero = function () {
  3886. this.y = this.x = 0
  3887. };
  3888. A.prototype.Set = function (p, B) {
  3889. if (p === undefined) p = 0;
  3890. if (B === undefined) B = 0;
  3891. this.x = p;
  3892. this.y = B
  3893. };
  3894. A.prototype.SetV = function (p) {
  3895. this.x = p.x;
  3896. this.y = p.y
  3897. };
  3898. A.prototype.GetNegative = function () {
  3899. return new A(-this.x, -this.y)
  3900. };
  3901. A.prototype.NegativeSelf = function () {
  3902. this.x = -this.x;
  3903. this.y = -this.y
  3904. };
  3905. A.Make = function (p, B) {
  3906. if (p === undefined) p = 0;
  3907. if (B === undefined) B = 0;
  3908. return new A(p, B)
  3909. };
  3910. A.prototype.Copy = function () {
  3911. return new A(this.x, this.y)
  3912. };
  3913. A.prototype.Add = function (p) {
  3914. this.x += p.x;
  3915. this.y += p.y
  3916. };
  3917. A.prototype.Subtract = function (p) {
  3918. this.x -= p.x;
  3919. this.y -= p.y
  3920. };
  3921. A.prototype.Multiply = function (p) {
  3922. if (p === undefined) p = 0;
  3923. this.x *= p;
  3924. this.y *= p
  3925. };
  3926. A.prototype.MulM = function (p) {
  3927. var B = this.x;
  3928. this.x = p.col1.x * B + p.col2.x * this.y;
  3929. this.y = p.col1.y * B + p.col2.y * this.y
  3930. };
  3931. A.prototype.MulTM = function (p) {
  3932. var B = K.Dot(this, p.col1);
  3933. this.y = K.Dot(this, p.col2);
  3934. this.x = B
  3935. };
  3936. A.prototype.CrossVF = function (p) {
  3937. if (p === undefined) p = 0;
  3938. var B = this.x;
  3939. this.x = p * this.y;
  3940. this.y = -p * B
  3941. };
  3942. A.prototype.CrossFV = function (p) {
  3943. if (p === undefined) p = 0;
  3944. var B = this.x;
  3945. this.x = -p * this.y;
  3946. this.y = p * B
  3947. };
  3948. A.prototype.MinV = function (p) {
  3949. this.x = this.x < p.x ? this.x : p.x;
  3950. this.y = this.y < p.y ? this.y : p.y
  3951. };
  3952. A.prototype.MaxV = function (p) {
  3953. this.x = this.x > p.x ? this.x : p.x;
  3954. this.y = this.y > p.y ? this.y : p.y
  3955. };
  3956. A.prototype.Abs = function () {
  3957. if (this.x < 0) this.x = -this.x;
  3958. if (this.y < 0) this.y = -this.y
  3959. };
  3960. A.prototype.Length = function () {
  3961. return Math.sqrt(this.x * this.x + this.y * this.y)
  3962. };
  3963. A.prototype.LengthSquared = function () {
  3964. return this.x * this.x + this.y * this.y
  3965. };
  3966. A.prototype.Normalize = function () {
  3967. var p = Math.sqrt(this.x * this.x + this.y * this.y);
  3968. if (p < Number.MIN_VALUE) return 0;
  3969. var B = 1 / p;
  3970. this.x *= B;
  3971. this.y *= B;
  3972. return p
  3973. };
  3974. A.prototype.IsValid = function () {
  3975. return K.IsValid(this.x) && K.IsValid(this.y)
  3976. };
  3977. U.b2Vec3 = function () {};
  3978. U.prototype.b2Vec3 = function (p, B, Q) {
  3979. if (p === undefined) p = 0;
  3980. if (B === undefined) B = 0;
  3981. if (Q === undefined) Q = 0;
  3982. this.x = p;
  3983. this.y = B;
  3984. this.z = Q
  3985. };
  3986. U.prototype.SetZero = function () {
  3987. this.x = this.y = this.z = 0
  3988. };
  3989. U.prototype.Set = function (p, B, Q) {
  3990. if (p === undefined) p = 0;
  3991. if (B === undefined) B = 0;
  3992. if (Q === undefined) Q = 0;
  3993. this.x = p;
  3994. this.y = B;
  3995. this.z = Q
  3996. };
  3997. U.prototype.SetV = function (p) {
  3998. this.x = p.x;
  3999. this.y = p.y;
  4000. this.z = p.z
  4001. };
  4002. U.prototype.GetNegative = function () {
  4003. return new U(-this.x, -this.y, -this.z)
  4004. };
  4005. U.prototype.NegativeSelf = function () {
  4006. this.x = -this.x;
  4007. this.y = -this.y;
  4008. this.z = -this.z
  4009. };
  4010. U.prototype.Copy = function () {
  4011. return new U(this.x, this.y, this.z)
  4012. };
  4013. U.prototype.Add = function (p) {
  4014. this.x += p.x;
  4015. this.y += p.y;
  4016. this.z += p.z
  4017. };
  4018. U.prototype.Subtract = function (p) {
  4019. this.x -= p.x;
  4020. this.y -= p.y;
  4021. this.z -= p.z
  4022. };
  4023. U.prototype.Multiply = function (p) {
  4024. if (p === undefined) p = 0;
  4025. this.x *= p;
  4026. this.y *= p;
  4027. this.z *= p
  4028. }
  4029. })();
  4030. (function () {
  4031. var F = Box2D.Common.Math.b2Math,
  4032. G = Box2D.Common.Math.b2Sweep,
  4033. K = Box2D.Common.Math.b2Transform,
  4034. y = Box2D.Common.Math.b2Vec2,
  4035. w = Box2D.Common.b2Color,
  4036. A = Box2D.Common.b2Settings,
  4037. U = Box2D.Collision.b2AABB,
  4038. p = Box2D.Collision.b2ContactPoint,
  4039. B = Box2D.Collision.b2DynamicTreeBroadPhase,
  4040. Q = Box2D.Collision.b2RayCastInput,
  4041. V = Box2D.Collision.b2RayCastOutput,
  4042. M = Box2D.Collision.Shapes.b2CircleShape,
  4043. L = Box2D.Collision.Shapes.b2EdgeShape,
  4044. I = Box2D.Collision.Shapes.b2MassData,
  4045. W = Box2D.Collision.Shapes.b2PolygonShape,
  4046. Y = Box2D.Collision.Shapes.b2Shape,
  4047. k = Box2D.Dynamics.b2Body,
  4048. z = Box2D.Dynamics.b2BodyDef,
  4049. u = Box2D.Dynamics.b2ContactFilter,
  4050. D = Box2D.Dynamics.b2ContactImpulse,
  4051. H = Box2D.Dynamics.b2ContactListener,
  4052. O = Box2D.Dynamics.b2ContactManager,
  4053. E = Box2D.Dynamics.b2DebugDraw,
  4054. R = Box2D.Dynamics.b2DestructionListener,
  4055. N = Box2D.Dynamics.b2FilterData,
  4056. S = Box2D.Dynamics.b2Fixture,
  4057. aa = Box2D.Dynamics.b2FixtureDef,
  4058. Z = Box2D.Dynamics.b2Island,
  4059. d = Box2D.Dynamics.b2TimeStep,
  4060. h = Box2D.Dynamics.b2World,
  4061. l = Box2D.Dynamics.Contacts.b2Contact,
  4062. j = Box2D.Dynamics.Contacts.b2ContactFactory,
  4063. o = Box2D.Dynamics.Contacts.b2ContactSolver,
  4064. q = Box2D.Dynamics.Joints.b2Joint,
  4065. n = Box2D.Dynamics.Joints.b2PulleyJoint;
  4066. k.b2Body = function () {
  4067. this.m_xf = new K;
  4068. this.m_sweep = new G;
  4069. this.m_linearVelocity = new y;
  4070. this.m_force = new y
  4071. };
  4072. k.prototype.connectEdges = function (a, c, g) {
  4073. if (g === undefined) g = 0;
  4074. var b = Math.atan2(c.GetDirectionVector().y, c.GetDirectionVector().x);
  4075. g = F.MulFV(Math.tan((b - g) * 0.5), c.GetDirectionVector());
  4076. g = F.SubtractVV(g, c.GetNormalVector());
  4077. g = F.MulFV(A.b2_toiSlop, g);
  4078. g = F.AddVV(g, c.GetVertex1());
  4079. var e = F.AddVV(a.GetDirectionVector(),
  4080. c.GetDirectionVector());
  4081. e.Normalize();
  4082. var f = F.Dot(a.GetDirectionVector(), c.GetNormalVector()) > 0;
  4083. a.SetNextEdge(c, g, e, f);
  4084. c.SetPrevEdge(a, g, e, f);
  4085. return b
  4086. };
  4087. k.prototype.CreateFixture = function (a) {
  4088. if (this.m_world.IsLocked() == true) return null;
  4089. var c = new S;
  4090. c.Create(this, this.m_xf, a);
  4091. this.m_flags & k.e_activeFlag && c.CreateProxy(this.m_world.m_contactManager.m_broadPhase, this.m_xf);
  4092. c.m_next = this.m_fixtureList;
  4093. this.m_fixtureList = c;
  4094. ++this.m_fixtureCount;
  4095. c.m_body = this;
  4096. c.m_density > 0 && this.ResetMassData();
  4097. this.m_world.m_flags |= h.e_newFixture;
  4098. return c
  4099. };
  4100. k.prototype.CreateFixture2 = function (a, c) {
  4101. if (c === undefined) c = 0;
  4102. var g = new aa;
  4103. g.shape = a;
  4104. g.density = c;
  4105. return this.CreateFixture(g)
  4106. };
  4107. k.prototype.DestroyFixture = function (a) {
  4108. if (this.m_world.IsLocked() != true) {
  4109. for (var c = this.m_fixtureList, g = null; c != null;) {
  4110. if (c == a) {
  4111. if (g) g.m_next = a.m_next;
  4112. else this.m_fixtureList = a.m_next;
  4113. break
  4114. }
  4115. g = c;
  4116. c = c.m_next
  4117. }
  4118. for (c = this.m_contactList; c;) {
  4119. g = c.contact;
  4120. c = c.next;
  4121. var b = g.GetFixtureA(),
  4122. e = g.GetFixtureB();
  4123. if (a == b || a == e) this.m_world.m_contactManager.Destroy(g)
  4124. }
  4125. this.m_flags &
  4126. k.e_activeFlag && a.DestroyProxy(this.m_world.m_contactManager.m_broadPhase);
  4127. a.Destroy();
  4128. a.m_body = null;
  4129. a.m_next = null;
  4130. --this.m_fixtureCount;
  4131. this.ResetMassData()
  4132. }
  4133. };
  4134. k.prototype.SetPositionAndAngle = function (a, c) {
  4135. if (c === undefined) c = 0;
  4136. var g;
  4137. if (this.m_world.IsLocked() != true) {
  4138. this.m_xf.R.Set(c);
  4139. this.m_xf.position.SetV(a);
  4140. g = this.m_xf.R;
  4141. var b = this.m_sweep.localCenter;
  4142. this.m_sweep.c.x = g.col1.x * b.x + g.col2.x * b.y;
  4143. this.m_sweep.c.y = g.col1.y * b.x + g.col2.y * b.y;
  4144. this.m_sweep.c.x += this.m_xf.position.x;
  4145. this.m_sweep.c.y += this.m_xf.position.y;
  4146. this.m_sweep.c0.SetV(this.m_sweep.c);
  4147. this.m_sweep.a0 = this.m_sweep.a = c;
  4148. b = this.m_world.m_contactManager.m_broadPhase;
  4149. for (g = this.m_fixtureList; g; g = g.m_next) g.Synchronize(b, this.m_xf, this.m_xf);
  4150. this.m_world.m_contactManager.FindNewContacts()
  4151. }
  4152. };
  4153. k.prototype.SetTransform = function (a) {
  4154. this.SetPositionAndAngle(a.position, a.GetAngle())
  4155. };
  4156. k.prototype.GetTransform = function () {
  4157. return this.m_xf
  4158. };
  4159. k.prototype.GetPosition = function () {
  4160. return this.m_xf.position
  4161. };
  4162. k.prototype.SetPosition = function (a) {
  4163. this.SetPositionAndAngle(a,
  4164. this.GetAngle())
  4165. };
  4166. k.prototype.GetAngle = function () {
  4167. return this.m_sweep.a
  4168. };
  4169. k.prototype.SetAngle = function (a) {
  4170. if (a === undefined) a = 0;
  4171. this.SetPositionAndAngle(this.GetPosition(), a)
  4172. };
  4173. k.prototype.GetWorldCenter = function () {
  4174. return this.m_sweep.c
  4175. };
  4176. k.prototype.GetLocalCenter = function () {
  4177. return this.m_sweep.localCenter
  4178. };
  4179. k.prototype.SetLinearVelocity = function (a) {
  4180. this.m_type != k.b2_staticBody && this.m_linearVelocity.SetV(a)
  4181. };
  4182. k.prototype.GetLinearVelocity = function () {
  4183. return this.m_linearVelocity
  4184. };
  4185. k.prototype.SetAngularVelocity = function (a) {
  4186. if (a === undefined) a = 0;
  4187. if (this.m_type != k.b2_staticBody) this.m_angularVelocity = a
  4188. };
  4189. k.prototype.GetAngularVelocity = function () {
  4190. return this.m_angularVelocity
  4191. };
  4192. k.prototype.GetDefinition = function () {
  4193. var a = new z;
  4194. a.type = this.GetType();
  4195. a.allowSleep = (this.m_flags & k.e_allowSleepFlag) == k.e_allowSleepFlag;
  4196. a.angle = this.GetAngle();
  4197. a.angularDamping = this.m_angularDamping;
  4198. a.angularVelocity = this.m_angularVelocity;
  4199. a.fixedRotation = (this.m_flags & k.e_fixedRotationFlag) == k.e_fixedRotationFlag;
  4200. a.bullet = (this.m_flags &
  4201. k.e_bulletFlag) == k.e_bulletFlag;
  4202. a.awake = (this.m_flags & k.e_awakeFlag) == k.e_awakeFlag;
  4203. a.linearDamping = this.m_linearDamping;
  4204. a.linearVelocity.SetV(this.GetLinearVelocity());
  4205. a.position = this.GetPosition();
  4206. a.userData = this.GetUserData();
  4207. return a
  4208. };
  4209. k.prototype.ApplyForce = function (a, c) {
  4210. if (this.m_type == k.b2_dynamicBody) {
  4211. this.IsAwake() == false && this.SetAwake(true);
  4212. this.m_force.x += a.x;
  4213. this.m_force.y += a.y;
  4214. this.m_torque += (c.x - this.m_sweep.c.x) * a.y - (c.y - this.m_sweep.c.y) * a.x
  4215. }
  4216. };
  4217. k.prototype.ApplyTorque = function (a) {
  4218. if (a === undefined) a = 0;
  4219. if (this.m_type == k.b2_dynamicBody) {
  4220. this.IsAwake() == false && this.SetAwake(true);
  4221. this.m_torque += a
  4222. }
  4223. };
  4224. k.prototype.ApplyImpulse = function (a, c) {
  4225. if (this.m_type == k.b2_dynamicBody) {
  4226. this.IsAwake() == false && this.SetAwake(true);
  4227. this.m_linearVelocity.x += this.m_invMass * a.x;
  4228. this.m_linearVelocity.y += this.m_invMass * a.y;
  4229. this.m_angularVelocity += this.m_invI * ((c.x - this.m_sweep.c.x) * a.y - (c.y - this.m_sweep.c.y) * a.x)
  4230. }
  4231. };
  4232. k.prototype.Split = function (a) {
  4233. for (var c = this.GetLinearVelocity().Copy(), g = this.GetAngularVelocity(),
  4234. b = this.GetWorldCenter(), e = this.m_world.CreateBody(this.GetDefinition()), f, m = this.m_fixtureList; m;)
  4235. if (a(m)) {
  4236. var r = m.m_next;
  4237. if (f) f.m_next = r;
  4238. else this.m_fixtureList = r;
  4239. this.m_fixtureCount--;
  4240. m.m_next = e.m_fixtureList;
  4241. e.m_fixtureList = m;
  4242. e.m_fixtureCount++;
  4243. m.m_body = e;
  4244. m = r
  4245. } else {
  4246. f = m;
  4247. m = m.m_next
  4248. }
  4249. this.ResetMassData();
  4250. e.ResetMassData();
  4251. f = this.GetWorldCenter();
  4252. a = e.GetWorldCenter();
  4253. f = F.AddVV(c, F.CrossFV(g, F.SubtractVV(f, b)));
  4254. c = F.AddVV(c, F.CrossFV(g, F.SubtractVV(a, b)));
  4255. this.SetLinearVelocity(f);
  4256. e.SetLinearVelocity(c);
  4257. this.SetAngularVelocity(g);
  4258. e.SetAngularVelocity(g);
  4259. this.SynchronizeFixtures();
  4260. e.SynchronizeFixtures();
  4261. return e
  4262. };
  4263. k.prototype.Merge = function (a) {
  4264. var c;
  4265. for (c = a.m_fixtureList; c;) {
  4266. var g = c.m_next;
  4267. a.m_fixtureCount--;
  4268. c.m_next = this.m_fixtureList;
  4269. this.m_fixtureList = c;
  4270. this.m_fixtureCount++;
  4271. c.m_body = e;
  4272. c = g
  4273. }
  4274. b.m_fixtureCount = 0;
  4275. var b = this,
  4276. e = a;
  4277. b.GetWorldCenter();
  4278. e.GetWorldCenter();
  4279. b.GetLinearVelocity().Copy();
  4280. e.GetLinearVelocity().Copy();
  4281. b.GetAngularVelocity();
  4282. e.GetAngularVelocity();
  4283. b.ResetMassData();
  4284. this.SynchronizeFixtures()
  4285. };
  4286. k.prototype.GetMass = function () {
  4287. return this.m_mass
  4288. };
  4289. k.prototype.GetInertia = function () {
  4290. return this.m_I
  4291. };
  4292. k.prototype.GetMassData = function (a) {
  4293. a.mass = this.m_mass;
  4294. a.I = this.m_I;
  4295. a.center.SetV(this.m_sweep.localCenter)
  4296. };
  4297. k.prototype.SetMassData = function (a) {
  4298. A.b2Assert(this.m_world.IsLocked() == false);
  4299. if (this.m_world.IsLocked() != true)
  4300. if (this.m_type == k.b2_dynamicBody) {
  4301. this.m_invI = this.m_I = this.m_invMass = 0;
  4302. this.m_mass = a.mass;
  4303. if (this.m_mass <= 0) this.m_mass = 1;
  4304. this.m_invMass = 1 / this.m_mass;
  4305. if (a.I > 0 && (this.m_flags & k.e_fixedRotationFlag) == 0) {
  4306. this.m_I = a.I - this.m_mass * (a.center.x * a.center.x + a.center.y * a.center.y);
  4307. this.m_invI = 1 / this.m_I
  4308. }
  4309. var c = this.m_sweep.c.Copy();
  4310. this.m_sweep.localCenter.SetV(a.center);
  4311. this.m_sweep.c0.SetV(F.MulX(this.m_xf, this.m_sweep.localCenter));
  4312. this.m_sweep.c.SetV(this.m_sweep.c0);
  4313. this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - c.y);
  4314. this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - c.x)
  4315. }
  4316. };
  4317. k.prototype.ResetMassData = function () {
  4318. this.m_invI = this.m_I = this.m_invMass = this.m_mass = 0;
  4319. this.m_sweep.localCenter.SetZero();
  4320. if (!(this.m_type == k.b2_staticBody || this.m_type == k.b2_kinematicBody)) {
  4321. for (var a = y.Make(0, 0), c = this.m_fixtureList; c; c = c.m_next)
  4322. if (c.m_density != 0) {
  4323. var g = c.GetMassData();
  4324. this.m_mass += g.mass;
  4325. a.x += g.center.x * g.mass;
  4326. a.y += g.center.y * g.mass;
  4327. this.m_I += g.I
  4328. }
  4329. if (this.m_mass > 0) {
  4330. this.m_invMass = 1 / this.m_mass;
  4331. a.x *= this.m_invMass;
  4332. a.y *= this.m_invMass
  4333. } else this.m_invMass = this.m_mass = 1; if (this.m_I > 0 && (this.m_flags & k.e_fixedRotationFlag) == 0) {
  4334. this.m_I -= this.m_mass * (a.x * a.x + a.y * a.y);
  4335. this.m_I *= this.m_inertiaScale;
  4336. A.b2Assert(this.m_I > 0);
  4337. this.m_invI = 1 / this.m_I
  4338. } else this.m_invI = this.m_I = 0;
  4339. c = this.m_sweep.c.Copy();
  4340. this.m_sweep.localCenter.SetV(a);
  4341. this.m_sweep.c0.SetV(F.MulX(this.m_xf, this.m_sweep.localCenter));
  4342. this.m_sweep.c.SetV(this.m_sweep.c0);
  4343. this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - c.y);
  4344. this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - c.x)
  4345. }
  4346. };
  4347. k.prototype.GetWorldPoint = function (a) {
  4348. var c = this.m_xf.R;
  4349. a = new y(c.col1.x * a.x + c.col2.x * a.y, c.col1.y * a.x + c.col2.y * a.y);
  4350. a.x += this.m_xf.position.x;
  4351. a.y += this.m_xf.position.y;
  4352. return a
  4353. };
  4354. k.prototype.GetWorldVector = function (a) {
  4355. return F.MulMV(this.m_xf.R, a)
  4356. };
  4357. k.prototype.GetLocalPoint = function (a) {
  4358. return F.MulXT(this.m_xf, a)
  4359. };
  4360. k.prototype.GetLocalVector = function (a) {
  4361. return F.MulTMV(this.m_xf.R, a)
  4362. };
  4363. k.prototype.GetLinearVelocityFromWorldPoint = function (a) {
  4364. return new y(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))
  4365. };
  4366. k.prototype.GetLinearVelocityFromLocalPoint = function (a) {
  4367. var c = this.m_xf.R;
  4368. a = new y(c.col1.x * a.x + c.col2.x * a.y, c.col1.y * a.x + c.col2.y * a.y);
  4369. a.x += this.m_xf.position.x;
  4370. a.y += this.m_xf.position.y;
  4371. return new y(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))
  4372. };
  4373. k.prototype.GetLinearDamping = function () {
  4374. return this.m_linearDamping
  4375. };
  4376. k.prototype.SetLinearDamping = function (a) {
  4377. if (a === undefined) a = 0;
  4378. this.m_linearDamping = a
  4379. };
  4380. k.prototype.GetAngularDamping = function () {
  4381. return this.m_angularDamping
  4382. };
  4383. k.prototype.SetAngularDamping = function (a) {
  4384. if (a === undefined) a = 0;
  4385. this.m_angularDamping = a
  4386. };
  4387. k.prototype.SetType = function (a) {
  4388. if (a === undefined) a = 0;
  4389. if (this.m_type != a) {
  4390. this.m_type = a;
  4391. this.ResetMassData();
  4392. if (this.m_type == k.b2_staticBody) {
  4393. this.m_linearVelocity.SetZero();
  4394. this.m_angularVelocity = 0
  4395. }
  4396. this.SetAwake(true);
  4397. this.m_force.SetZero();
  4398. this.m_torque = 0;
  4399. for (a = this.m_contactList; a; a = a.next) a.contact.FlagForFiltering()
  4400. }
  4401. };
  4402. k.prototype.GetType = function () {
  4403. return this.m_type
  4404. };
  4405. k.prototype.SetBullet = function (a) {
  4406. if (a) this.m_flags |= k.e_bulletFlag;
  4407. else this.m_flags &= ~k.e_bulletFlag
  4408. };
  4409. k.prototype.IsBullet = function () {
  4410. return (this.m_flags & k.e_bulletFlag) == k.e_bulletFlag
  4411. };
  4412. k.prototype.SetSleepingAllowed = function (a) {
  4413. if (a) this.m_flags |= k.e_allowSleepFlag;
  4414. else {
  4415. this.m_flags &= ~k.e_allowSleepFlag;
  4416. this.SetAwake(true)
  4417. }
  4418. };
  4419. k.prototype.SetAwake = function (a) {
  4420. if (a) {
  4421. this.m_flags |= k.e_awakeFlag;
  4422. this.m_sleepTime = 0
  4423. } else {
  4424. this.m_flags &= ~k.e_awakeFlag;
  4425. this.m_sleepTime = 0;
  4426. this.m_linearVelocity.SetZero();
  4427. this.m_angularVelocity = 0;
  4428. this.m_force.SetZero();
  4429. this.m_torque = 0
  4430. }
  4431. };
  4432. k.prototype.IsAwake = function () {
  4433. return (this.m_flags & k.e_awakeFlag) == k.e_awakeFlag
  4434. };
  4435. k.prototype.SetFixedRotation = function (a) {
  4436. if (a) this.m_flags |= k.e_fixedRotationFlag;
  4437. else this.m_flags &= ~k.e_fixedRotationFlag;
  4438. this.ResetMassData()
  4439. };
  4440. k.prototype.IsFixedRotation = function () {
  4441. return (this.m_flags & k.e_fixedRotationFlag) == k.e_fixedRotationFlag
  4442. };
  4443. k.prototype.SetActive = function (a) {
  4444. if (a != this.IsActive()) {
  4445. var c;
  4446. if (a) {
  4447. this.m_flags |= k.e_activeFlag;
  4448. a = this.m_world.m_contactManager.m_broadPhase;
  4449. for (c = this.m_fixtureList; c; c = c.m_next) c.CreateProxy(a, this.m_xf)
  4450. } else {
  4451. this.m_flags &= ~k.e_activeFlag;
  4452. a = this.m_world.m_contactManager.m_broadPhase;
  4453. for (c = this.m_fixtureList; c; c = c.m_next) c.DestroyProxy(a);
  4454. for (a = this.m_contactList; a;) {
  4455. c = a;
  4456. a = a.next;
  4457. this.m_world.m_contactManager.Destroy(c.contact)
  4458. }
  4459. this.m_contactList = null
  4460. }
  4461. }
  4462. };
  4463. k.prototype.IsActive = function () {
  4464. return (this.m_flags & k.e_activeFlag) == k.e_activeFlag
  4465. };
  4466. k.prototype.IsSleepingAllowed = function () {
  4467. return (this.m_flags & k.e_allowSleepFlag) == k.e_allowSleepFlag
  4468. };
  4469. k.prototype.GetFixtureList = function () {
  4470. return this.m_fixtureList
  4471. };
  4472. k.prototype.GetJointList = function () {
  4473. return this.m_jointList
  4474. };
  4475. k.prototype.GetControllerList = function () {
  4476. return this.m_controllerList
  4477. };
  4478. k.prototype.GetContactList = function () {
  4479. return this.m_contactList
  4480. };
  4481. k.prototype.GetNext = function () {
  4482. return this.m_next
  4483. };
  4484. k.prototype.GetUserData = function () {
  4485. return this.m_userData
  4486. };
  4487. k.prototype.SetUserData = function (a) {
  4488. this.m_userData = a
  4489. };
  4490. k.prototype.GetWorld = function () {
  4491. return this.m_world
  4492. };
  4493. k.prototype.b2Body = function (a, c) {
  4494. this.m_flags = 0;
  4495. if (a.bullet) this.m_flags |= k.e_bulletFlag;
  4496. if (a.fixedRotation) this.m_flags |= k.e_fixedRotationFlag;
  4497. if (a.allowSleep) this.m_flags |= k.e_allowSleepFlag;
  4498. if (a.awake) this.m_flags |= k.e_awakeFlag;
  4499. if (a.active) this.m_flags |= k.e_activeFlag;
  4500. this.m_world = c;
  4501. this.m_xf.position.SetV(a.position);
  4502. this.m_xf.R.Set(a.angle);
  4503. this.m_sweep.localCenter.SetZero();
  4504. this.m_sweep.t0 = 1;
  4505. this.m_sweep.a0 = this.m_sweep.a = a.angle;
  4506. var g = this.m_xf.R,
  4507. b = this.m_sweep.localCenter;
  4508. this.m_sweep.c.x = g.col1.x * b.x + g.col2.x * b.y;
  4509. this.m_sweep.c.y = g.col1.y * b.x + g.col2.y * b.y;
  4510. this.m_sweep.c.x += this.m_xf.position.x;
  4511. this.m_sweep.c.y += this.m_xf.position.y;
  4512. this.m_sweep.c0.SetV(this.m_sweep.c);
  4513. this.m_contactList = this.m_controllerList = this.m_jointList = null;
  4514. this.m_controllerCount = 0;
  4515. this.m_next = this.m_prev = null;
  4516. this.m_linearVelocity.SetV(a.linearVelocity);
  4517. this.m_angularVelocity = a.angularVelocity;
  4518. this.m_linearDamping = a.linearDamping;
  4519. this.m_angularDamping = a.angularDamping;
  4520. this.m_force.Set(0, 0);
  4521. this.m_sleepTime = this.m_torque = 0;
  4522. this.m_type = a.type;
  4523. if (this.m_type == k.b2_dynamicBody) this.m_invMass = this.m_mass = 1;
  4524. else this.m_invMass = this.m_mass = 0;
  4525. this.m_invI = this.m_I = 0;
  4526. this.m_inertiaScale = a.inertiaScale;
  4527. this.m_userData = a.userData;
  4528. this.m_fixtureList = null;
  4529. this.m_fixtureCount = 0
  4530. };
  4531. k.prototype.SynchronizeFixtures = function () {
  4532. var a = k.s_xf1;
  4533. a.R.Set(this.m_sweep.a0);
  4534. var c = a.R,
  4535. g = this.m_sweep.localCenter;
  4536. a.position.x = this.m_sweep.c0.x - (c.col1.x * g.x + c.col2.x * g.y);
  4537. a.position.y = this.m_sweep.c0.y - (c.col1.y * g.x + c.col2.y * g.y);
  4538. g = this.m_world.m_contactManager.m_broadPhase;
  4539. for (c = this.m_fixtureList; c; c = c.m_next) c.Synchronize(g, a, this.m_xf)
  4540. };
  4541. k.prototype.SynchronizeTransform = function () {
  4542. this.m_xf.R.Set(this.m_sweep.a);
  4543. var a = this.m_xf.R,
  4544. c = this.m_sweep.localCenter;
  4545. this.m_xf.position.x = this.m_sweep.c.x - (a.col1.x * c.x + a.col2.x * c.y);
  4546. this.m_xf.position.y = this.m_sweep.c.y - (a.col1.y * c.x + a.col2.y * c.y)
  4547. };
  4548. k.prototype.ShouldCollide = function (a) {
  4549. if (this.m_type != k.b2_dynamicBody && a.m_type != k.b2_dynamicBody) return false;
  4550. for (var c = this.m_jointList; c; c = c.next)
  4551. if (c.other == a)
  4552. if (c.joint.m_collideConnected == false) return false;
  4553. return true
  4554. };
  4555. k.prototype.Advance = function (a) {
  4556. if (a === undefined) a = 0;
  4557. this.m_sweep.Advance(a);
  4558. this.m_sweep.c.SetV(this.m_sweep.c0);
  4559. this.m_sweep.a = this.m_sweep.a0;
  4560. this.SynchronizeTransform()
  4561. };
  4562. Box2D.postDefs.push(function () {
  4563. Box2D.Dynamics.b2Body.s_xf1 = new K;
  4564. Box2D.Dynamics.b2Body.e_islandFlag = 1;
  4565. Box2D.Dynamics.b2Body.e_awakeFlag = 2;
  4566. Box2D.Dynamics.b2Body.e_allowSleepFlag = 4;
  4567. Box2D.Dynamics.b2Body.e_bulletFlag = 8;
  4568. Box2D.Dynamics.b2Body.e_fixedRotationFlag = 16;
  4569. Box2D.Dynamics.b2Body.e_activeFlag = 32;
  4570. Box2D.Dynamics.b2Body.b2_staticBody = 0;
  4571. Box2D.Dynamics.b2Body.b2_kinematicBody = 1;
  4572. Box2D.Dynamics.b2Body.b2_dynamicBody = 2
  4573. });
  4574. z.b2BodyDef = function () {
  4575. this.position = new y;
  4576. this.linearVelocity = new y
  4577. };
  4578. z.prototype.b2BodyDef = function () {
  4579. this.userData = null;
  4580. this.position.Set(0, 0);
  4581. this.angle = 0;
  4582. this.linearVelocity.Set(0, 0);
  4583. this.angularDamping = this.linearDamping = this.angularVelocity = 0;
  4584. this.awake = this.allowSleep = true;
  4585. this.bullet = this.fixedRotation = false;
  4586. this.type = k.b2_staticBody;
  4587. this.active = true;
  4588. this.inertiaScale = 1
  4589. };
  4590. u.b2ContactFilter = function () {};
  4591. u.prototype.ShouldCollide = function (a, c) {
  4592. var g = a.GetFilterData(),
  4593. b = c.GetFilterData();
  4594. if (g.groupIndex == b.groupIndex && g.groupIndex != 0) return g.groupIndex > 0;
  4595. return (g.maskBits & b.categoryBits) != 0 && (g.categoryBits & b.maskBits) != 0
  4596. };
  4597. u.prototype.RayCollide = function (a, c) {
  4598. if (!a) return true;
  4599. return this.ShouldCollide(a instanceof S ? a : null, c)
  4600. };
  4601. Box2D.postDefs.push(function () {
  4602. Box2D.Dynamics.b2ContactFilter.b2_defaultFilter = new u
  4603. });
  4604. D.b2ContactImpulse = function () {
  4605. this.normalImpulses = new Vector_a2j_Number(A.b2_maxManifoldPoints);
  4606. this.tangentImpulses = new Vector_a2j_Number(A.b2_maxManifoldPoints)
  4607. };
  4608. H.b2ContactListener = function () {};
  4609. H.prototype.BeginContact = function () {};
  4610. H.prototype.EndContact = function () {};
  4611. H.prototype.PreSolve = function () {};
  4612. H.prototype.PostSolve = function () {};
  4613. Box2D.postDefs.push(function () {
  4614. Box2D.Dynamics.b2ContactListener.b2_defaultListener = new H
  4615. });
  4616. O.b2ContactManager = function () {};
  4617. O.prototype.b2ContactManager = function () {
  4618. this.m_world = null;
  4619. this.m_contactCount = 0;
  4620. this.m_contactFilter = u.b2_defaultFilter;
  4621. this.m_contactListener = H.b2_defaultListener;
  4622. this.m_contactFactory = new j(this.m_allocator);
  4623. this.m_broadPhase = new B
  4624. };
  4625. O.prototype.AddPair = function (a, c) {
  4626. var g = a instanceof S ? a : null,
  4627. b = c instanceof S ? c : null,
  4628. e = g.GetBody(),
  4629. f = b.GetBody();
  4630. if (e != f) {
  4631. for (var m = f.GetContactList(); m;) {
  4632. if (m.other == e) {
  4633. var r = m.contact.GetFixtureA(),
  4634. s = m.contact.GetFixtureB();
  4635. if (r == g && s == b) return;
  4636. if (r == b && s == g) return
  4637. }
  4638. m = m.next
  4639. }
  4640. if (f.ShouldCollide(e) != false)
  4641. if (this.m_contactFilter.ShouldCollide(g, b) != false) {
  4642. m = this.m_contactFactory.Create(g, b);
  4643. g = m.GetFixtureA();
  4644. b = m.GetFixtureB();
  4645. e = g.m_body;
  4646. f = b.m_body;
  4647. m.m_prev = null;
  4648. m.m_next = this.m_world.m_contactList;
  4649. if (this.m_world.m_contactList != null) this.m_world.m_contactList.m_prev = m;
  4650. this.m_world.m_contactList = m;
  4651. m.m_nodeA.contact = m;
  4652. m.m_nodeA.other = f;
  4653. m.m_nodeA.prev = null;
  4654. m.m_nodeA.next = e.m_contactList;
  4655. if (e.m_contactList != null) e.m_contactList.prev = m.m_nodeA;
  4656. e.m_contactList = m.m_nodeA;
  4657. m.m_nodeB.contact = m;
  4658. m.m_nodeB.other = e;
  4659. m.m_nodeB.prev = null;
  4660. m.m_nodeB.next = f.m_contactList;
  4661. if (f.m_contactList != null) f.m_contactList.prev = m.m_nodeB;
  4662. f.m_contactList = m.m_nodeB;
  4663. ++this.m_world.m_contactCount
  4664. }
  4665. }
  4666. };
  4667. O.prototype.FindNewContacts = function () {
  4668. this.m_broadPhase.UpdatePairs(Box2D.generateCallback(this, this.AddPair))
  4669. };
  4670. O.prototype.Destroy = function (a) {
  4671. var c = a.GetFixtureA(),
  4672. g = a.GetFixtureB();
  4673. c = c.GetBody();
  4674. g = g.GetBody();
  4675. a.IsTouching() && this.m_contactListener.EndContact(a);
  4676. if (a.m_prev) a.m_prev.m_next = a.m_next;
  4677. if (a.m_next) a.m_next.m_prev = a.m_prev;
  4678. if (a == this.m_world.m_contactList) this.m_world.m_contactList = a.m_next;
  4679. if (a.m_nodeA.prev) a.m_nodeA.prev.next = a.m_nodeA.next;
  4680. if (a.m_nodeA.next) a.m_nodeA.next.prev = a.m_nodeA.prev;
  4681. if (a.m_nodeA == c.m_contactList) c.m_contactList = a.m_nodeA.next;
  4682. if (a.m_nodeB.prev) a.m_nodeB.prev.next = a.m_nodeB.next;
  4683. if (a.m_nodeB.next) a.m_nodeB.next.prev = a.m_nodeB.prev;
  4684. if (a.m_nodeB == g.m_contactList) g.m_contactList = a.m_nodeB.next;
  4685. this.m_contactFactory.Destroy(a);
  4686. --this.m_contactCount
  4687. };
  4688. O.prototype.Collide = function () {
  4689. for (var a = this.m_world.m_contactList; a;) {
  4690. var c = a.GetFixtureA(),
  4691. g = a.GetFixtureB(),
  4692. b = c.GetBody(),
  4693. e = g.GetBody();
  4694. if (b.IsAwake() == false && e.IsAwake() == false) a = a.GetNext();
  4695. else {
  4696. if (a.m_flags & l.e_filterFlag) {
  4697. if (e.ShouldCollide(b) == false) {
  4698. c = a;
  4699. a = c.GetNext();
  4700. this.Destroy(c);
  4701. continue
  4702. }
  4703. if (this.m_contactFilter.ShouldCollide(c, g) == false) {
  4704. c = a;
  4705. a = c.GetNext();
  4706. this.Destroy(c);
  4707. continue
  4708. }
  4709. a.m_flags &= ~l.e_filterFlag
  4710. }
  4711. if (this.m_broadPhase.TestOverlap(c.m_proxy, g.m_proxy) == false) {
  4712. c = a;
  4713. a = c.GetNext();
  4714. this.Destroy(c)
  4715. } else {
  4716. a.Update(this.m_contactListener);
  4717. a = a.GetNext()
  4718. }
  4719. }
  4720. }
  4721. };
  4722. Box2D.postDefs.push(function () {
  4723. Box2D.Dynamics.b2ContactManager.s_evalCP = new p
  4724. });
  4725. E.b2DebugDraw = function () {};
  4726. E.prototype.b2DebugDraw = function () {};
  4727. E.prototype.SetFlags = function () {};
  4728. E.prototype.GetFlags = function () {};
  4729. E.prototype.AppendFlags = function () {};
  4730. E.prototype.ClearFlags = function () {};
  4731. E.prototype.SetSprite = function () {};
  4732. E.prototype.GetSprite = function () {};
  4733. E.prototype.SetDrawScale = function () {};
  4734. E.prototype.GetDrawScale = function () {};
  4735. E.prototype.SetLineThickness = function () {};
  4736. E.prototype.GetLineThickness = function () {};
  4737. E.prototype.SetAlpha = function () {};
  4738. E.prototype.GetAlpha = function () {};
  4739. E.prototype.SetFillAlpha = function () {};
  4740. E.prototype.GetFillAlpha = function () {};
  4741. E.prototype.SetXFormScale = function () {};
  4742. E.prototype.GetXFormScale = function () {};
  4743. E.prototype.DrawPolygon = function () {};
  4744. E.prototype.DrawSolidPolygon = function () {};
  4745. E.prototype.DrawCircle = function () {};
  4746. E.prototype.DrawSolidCircle = function () {};
  4747. E.prototype.DrawSegment = function () {};
  4748. E.prototype.DrawTransform = function () {};
  4749. Box2D.postDefs.push(function () {
  4750. Box2D.Dynamics.b2DebugDraw.e_shapeBit = 1;
  4751. Box2D.Dynamics.b2DebugDraw.e_jointBit = 2;
  4752. Box2D.Dynamics.b2DebugDraw.e_aabbBit = 4;
  4753. Box2D.Dynamics.b2DebugDraw.e_pairBit = 8;
  4754. Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit = 16;
  4755. Box2D.Dynamics.b2DebugDraw.e_controllerBit = 32
  4756. });
  4757. R.b2DestructionListener = function () {};
  4758. R.prototype.SayGoodbyeJoint = function () {};
  4759. R.prototype.SayGoodbyeFixture = function () {};
  4760. N.b2FilterData = function () {
  4761. this.categoryBits = 1;
  4762. this.maskBits = 65535;
  4763. this.groupIndex = 0
  4764. };
  4765. N.prototype.Copy = function () {
  4766. var a = new N;
  4767. a.categoryBits = this.categoryBits;
  4768. a.maskBits = this.maskBits;
  4769. a.groupIndex = this.groupIndex;
  4770. return a
  4771. };
  4772. S.b2Fixture = function () {
  4773. this.m_filter = new N
  4774. };
  4775. S.prototype.GetType = function () {
  4776. return this.m_shape.GetType()
  4777. };
  4778. S.prototype.GetShape = function () {
  4779. return this.m_shape
  4780. };
  4781. S.prototype.SetSensor = function (a) {
  4782. if (this.m_isSensor != a) {
  4783. this.m_isSensor = a;
  4784. if (this.m_body != null) for (a = this.m_body.GetContactList(); a;) {
  4785. var c = a.contact,
  4786. g = c.GetFixtureA(),
  4787. b = c.GetFixtureB();
  4788. if (g == this || b == this) c.SetSensor(g.IsSensor() || b.IsSensor());
  4789. a = a.next
  4790. }
  4791. }
  4792. };
  4793. S.prototype.IsSensor = function () {
  4794. return this.m_isSensor
  4795. };
  4796. S.prototype.SetFilterData = function (a) {
  4797. this.m_filter = a.Copy();
  4798. if (!this.m_body) for (a = this.m_body.GetContactList(); a;) {
  4799. var c = a.contact,
  4800. g = c.GetFixtureA(),
  4801. b = c.GetFixtureB();
  4802. if (g == this || b == this) c.FlagForFiltering();
  4803. a = a.next
  4804. }
  4805. };
  4806. S.prototype.GetFilterData = function () {
  4807. return this.m_filter.Copy()
  4808. };
  4809. S.prototype.GetBody = function () {
  4810. return this.m_body
  4811. };
  4812. S.prototype.GetNext = function () {
  4813. return this.m_next
  4814. };
  4815. S.prototype.GetUserData = function () {
  4816. return this.m_userData
  4817. };
  4818. S.prototype.SetUserData = function (a) {
  4819. this.m_userData = a
  4820. };
  4821. S.prototype.TestPoint = function (a) {
  4822. return this.m_shape.TestPoint(this.m_body.GetTransform(),
  4823. a)
  4824. };
  4825. S.prototype.RayCast = function (a, c) {
  4826. return this.m_shape.RayCast(a, c, this.m_body.GetTransform())
  4827. };
  4828. S.prototype.GetMassData = function (a) {
  4829. if (a === undefined) a = null;
  4830. if (a == null) a = new I;
  4831. this.m_shape.ComputeMass(a, this.m_density);
  4832. return a
  4833. };
  4834. S.prototype.SetDensity = function (a) {
  4835. if (a === undefined) a = 0;
  4836. this.m_density = a
  4837. };
  4838. S.prototype.GetDensity = function () {
  4839. return this.m_density
  4840. };
  4841. S.prototype.GetFriction = function () {
  4842. return this.m_friction
  4843. };
  4844. S.prototype.SetFriction = function (a) {
  4845. if (a === undefined) a = 0;
  4846. this.m_friction = a
  4847. };
  4848. S.prototype.GetRestitution = function () {
  4849. return this.m_restitution
  4850. };
  4851. S.prototype.SetRestitution = function (a) {
  4852. if (a === undefined) a = 0;
  4853. this.m_restitution = a
  4854. };
  4855. S.prototype.GetAABB = function () {
  4856. return this.m_aabb
  4857. };
  4858. S.prototype.b2Fixture = function () {
  4859. this.m_aabb = new U;
  4860. this.m_shape = this.m_next = this.m_body = this.m_userData = null;
  4861. this.m_restitution = this.m_friction = this.m_density = 0
  4862. };
  4863. S.prototype.Create = function (a, c, g) {
  4864. this.m_userData = g.userData;
  4865. this.m_friction = g.friction;
  4866. this.m_restitution = g.restitution;
  4867. this.m_body = a;
  4868. this.m_next = null;
  4869. this.m_filter = g.filter.Copy();
  4870. this.m_isSensor = g.isSensor;
  4871. this.m_shape = g.shape.Copy();
  4872. this.m_density = g.density
  4873. };
  4874. S.prototype.Destroy = function () {
  4875. this.m_shape = null
  4876. };
  4877. S.prototype.CreateProxy = function (a, c) {
  4878. this.m_shape.ComputeAABB(this.m_aabb, c);
  4879. this.m_proxy = a.CreateProxy(this.m_aabb, this)
  4880. };
  4881. S.prototype.DestroyProxy = function (a) {
  4882. if (this.m_proxy != null) {
  4883. a.DestroyProxy(this.m_proxy);
  4884. this.m_proxy = null
  4885. }
  4886. };
  4887. S.prototype.Synchronize = function (a, c, g) {
  4888. if (this.m_proxy) {
  4889. var b = new U,
  4890. e = new U;
  4891. this.m_shape.ComputeAABB(b, c);
  4892. this.m_shape.ComputeAABB(e, g);
  4893. this.m_aabb.Combine(b, e);
  4894. c = F.SubtractVV(g.position, c.position);
  4895. a.MoveProxy(this.m_proxy, this.m_aabb, c)
  4896. }
  4897. };
  4898. aa.b2FixtureDef = function () {
  4899. this.filter = new N
  4900. };
  4901. aa.prototype.b2FixtureDef = function () {
  4902. this.userData = this.shape = null;
  4903. this.friction = 0.2;
  4904. this.density = this.restitution = 0;
  4905. this.filter.categoryBits = 1;
  4906. this.filter.maskBits = 65535;
  4907. this.filter.groupIndex = 0;
  4908. this.isSensor = false
  4909. };
  4910. Z.b2Island = function () {};
  4911. Z.prototype.b2Island = function () {
  4912. this.m_bodies = new Vector;
  4913. this.m_contacts = new Vector;
  4914. this.m_joints = new Vector
  4915. };
  4916. Z.prototype.Initialize = function (a, c, g, b, e, f) {
  4917. if (a === undefined) a = 0;
  4918. if (c === undefined) c = 0;
  4919. if (g === undefined) g = 0;
  4920. var m = 0;
  4921. this.m_bodyCapacity = a;
  4922. this.m_contactCapacity = c;
  4923. this.m_jointCapacity = g;
  4924. this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0;
  4925. this.m_allocator = b;
  4926. this.m_listener = e;
  4927. this.m_contactSolver = f;
  4928. for (m = this.m_bodies.length; m < a; m++) this.m_bodies[m] = null;
  4929. for (m = this.m_contacts.length; m < c; m++) this.m_contacts[m] = null;
  4930. for (m = this.m_joints.length; m < g; m++) this.m_joints[m] = null
  4931. };
  4932. Z.prototype.Clear = function () {
  4933. this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0
  4934. };
  4935. Z.prototype.Solve = function (a, c, g) {
  4936. var b = 0,
  4937. e = 0,
  4938. f;
  4939. for (b = 0; b < this.m_bodyCount; ++b) {
  4940. e = this.m_bodies[b];
  4941. if (e.GetType() == k.b2_dynamicBody) {
  4942. e.m_linearVelocity.x += a.dt * (c.x + e.m_invMass * e.m_force.x);
  4943. e.m_linearVelocity.y += a.dt * (c.y + e.m_invMass * e.m_force.y);
  4944. e.m_angularVelocity += a.dt * e.m_invI * e.m_torque;
  4945. e.m_linearVelocity.Multiply(F.Clamp(1 - a.dt * e.m_linearDamping, 0, 1));
  4946. e.m_angularVelocity *= F.Clamp(1 - a.dt * e.m_angularDamping, 0, 1)
  4947. }
  4948. }
  4949. this.m_contactSolver.Initialize(a, this.m_contacts,
  4950. this.m_contactCount, this.m_allocator);
  4951. c = this.m_contactSolver;
  4952. c.InitVelocityConstraints(a);
  4953. for (b = 0; b < this.m_jointCount; ++b) {
  4954. f = this.m_joints[b];
  4955. f.InitVelocityConstraints(a)
  4956. }
  4957. for (b = 0; b < a.velocityIterations; ++b) {
  4958. for (e = 0; e < this.m_jointCount; ++e) {
  4959. f = this.m_joints[e];
  4960. f.SolveVelocityConstraints(a)
  4961. }
  4962. c.SolveVelocityConstraints()
  4963. }
  4964. for (b = 0; b < this.m_jointCount; ++b) {
  4965. f = this.m_joints[b];
  4966. f.FinalizeVelocityConstraints()
  4967. }
  4968. c.FinalizeVelocityConstraints();
  4969. for (b = 0; b < this.m_bodyCount; ++b) {
  4970. e = this.m_bodies[b];
  4971. if (e.GetType() != k.b2_staticBody) {
  4972. var m = a.dt * e.m_linearVelocity.x,
  4973. r = a.dt * e.m_linearVelocity.y;
  4974. if (m * m + r * r > A.b2_maxTranslationSquared) {
  4975. e.m_linearVelocity.Normalize();
  4976. e.m_linearVelocity.x *= A.b2_maxTranslation * a.inv_dt;
  4977. e.m_linearVelocity.y *= A.b2_maxTranslation * a.inv_dt
  4978. }
  4979. m = a.dt * e.m_angularVelocity;
  4980. if (m * m > A.b2_maxRotationSquared) e.m_angularVelocity = e.m_angularVelocity < 0 ? -A.b2_maxRotation * a.inv_dt : A.b2_maxRotation * a.inv_dt;
  4981. e.m_sweep.c0.SetV(e.m_sweep.c);
  4982. e.m_sweep.a0 = e.m_sweep.a;
  4983. e.m_sweep.c.x += a.dt * e.m_linearVelocity.x;
  4984. e.m_sweep.c.y += a.dt * e.m_linearVelocity.y;
  4985. e.m_sweep.a += a.dt * e.m_angularVelocity;
  4986. e.SynchronizeTransform()
  4987. }
  4988. }
  4989. for (b = 0; b < a.positionIterations; ++b) {
  4990. m = c.SolvePositionConstraints(A.b2_contactBaumgarte);
  4991. r = true;
  4992. for (e = 0; e < this.m_jointCount; ++e) {
  4993. f = this.m_joints[e];
  4994. f = f.SolvePositionConstraints(A.b2_contactBaumgarte);
  4995. r = r && f
  4996. }
  4997. if (m && r) break
  4998. }
  4999. this.Report(c.m_constraints);
  5000. if (g) {
  5001. g = Number.MAX_VALUE;
  5002. c = A.b2_linearSleepTolerance * A.b2_linearSleepTolerance;
  5003. m = A.b2_angularSleepTolerance * A.b2_angularSleepTolerance;
  5004. for (b = 0; b < this.m_bodyCount; ++b) {
  5005. e = this.m_bodies[b];
  5006. if (e.GetType() != k.b2_staticBody) {
  5007. if ((e.m_flags & k.e_allowSleepFlag) == 0) g = e.m_sleepTime = 0;
  5008. if ((e.m_flags & k.e_allowSleepFlag) == 0 || e.m_angularVelocity * e.m_angularVelocity > m || F.Dot(e.m_linearVelocity, e.m_linearVelocity) > c) g = e.m_sleepTime = 0;
  5009. else {
  5010. e.m_sleepTime += a.dt;
  5011. g = F.Min(g, e.m_sleepTime)
  5012. }
  5013. }
  5014. }
  5015. if (g >= A.b2_timeToSleep)
  5016. for (b = 0; b < this.m_bodyCount; ++b) {
  5017. e = this.m_bodies[b];
  5018. e.SetAwake(false)
  5019. }
  5020. }
  5021. };
  5022. Z.prototype.SolveTOI = function (a) {
  5023. var c = 0,
  5024. g = 0;
  5025. this.m_contactSolver.Initialize(a, this.m_contacts, this.m_contactCount,
  5026. this.m_allocator);
  5027. var b = this.m_contactSolver;
  5028. for (c = 0; c < this.m_jointCount; ++c) this.m_joints[c].InitVelocityConstraints(a);
  5029. for (c = 0; c < a.velocityIterations; ++c) {
  5030. b.SolveVelocityConstraints();
  5031. for (g = 0; g < this.m_jointCount; ++g) this.m_joints[g].SolveVelocityConstraints(a)
  5032. }
  5033. for (c = 0; c < this.m_bodyCount; ++c) {
  5034. g = this.m_bodies[c];
  5035. if (g.GetType() != k.b2_staticBody) {
  5036. var e = a.dt * g.m_linearVelocity.x,
  5037. f = a.dt * g.m_linearVelocity.y;
  5038. if (e * e + f * f > A.b2_maxTranslationSquared) {
  5039. g.m_linearVelocity.Normalize();
  5040. g.m_linearVelocity.x *= A.b2_maxTranslation * a.inv_dt;
  5041. g.m_linearVelocity.y *= A.b2_maxTranslation * a.inv_dt
  5042. }
  5043. e = a.dt * g.m_angularVelocity;
  5044. if (e * e > A.b2_maxRotationSquared) g.m_angularVelocity = g.m_angularVelocity < 0 ? -A.b2_maxRotation * a.inv_dt : A.b2_maxRotation * a.inv_dt;
  5045. g.m_sweep.c0.SetV(g.m_sweep.c);
  5046. g.m_sweep.a0 = g.m_sweep.a;
  5047. g.m_sweep.c.x += a.dt * g.m_linearVelocity.x;
  5048. g.m_sweep.c.y += a.dt * g.m_linearVelocity.y;
  5049. g.m_sweep.a += a.dt * g.m_angularVelocity;
  5050. g.SynchronizeTransform()
  5051. }
  5052. }
  5053. for (c = 0; c < a.positionIterations; ++c) {
  5054. e = b.SolvePositionConstraints(0.75);
  5055. f = true;
  5056. for (g = 0; g <
  5057. this.m_jointCount; ++g) {
  5058. var m = this.m_joints[g].SolvePositionConstraints(A.b2_contactBaumgarte);
  5059. f = f && m
  5060. }
  5061. if (e && f) break
  5062. }
  5063. this.Report(b.m_constraints)
  5064. };
  5065. Z.prototype.Report = function (a) {
  5066. if (this.m_listener != null)
  5067. for (var c = 0; c < this.m_contactCount; ++c) {
  5068. for (var g = this.m_contacts[c], b = a[c], e = 0; e < b.pointCount; ++e) {
  5069. Z.s_impulse.normalImpulses[e] = b.points[e].normalImpulse;
  5070. Z.s_impulse.tangentImpulses[e] = b.points[e].tangentImpulse
  5071. }
  5072. this.m_listener.PostSolve(g, Z.s_impulse)
  5073. }
  5074. };
  5075. Z.prototype.AddBody = function (a) {
  5076. a.m_islandIndex = this.m_bodyCount;
  5077. this.m_bodies[this.m_bodyCount++] = a
  5078. };
  5079. Z.prototype.AddContact = function (a) {
  5080. this.m_contacts[this.m_contactCount++] = a
  5081. };
  5082. Z.prototype.AddJoint = function (a) {
  5083. this.m_joints[this.m_jointCount++] = a
  5084. };
  5085. Box2D.postDefs.push(function () {
  5086. Box2D.Dynamics.b2Island.s_impulse = new D
  5087. });
  5088. d.b2TimeStep = function () {};
  5089. d.prototype.Set = function (a) {
  5090. this.dt = a.dt;
  5091. this.inv_dt = a.inv_dt;
  5092. this.positionIterations = a.positionIterations;
  5093. this.velocityIterations = a.velocityIterations;
  5094. this.warmStarting = a.warmStarting
  5095. };
  5096. h.b2World = function () {
  5097. this.s_stack = new Vector;
  5098. this.m_contactManager = new O;
  5099. this.m_contactSolver = new o;
  5100. this.m_island = new Z
  5101. };
  5102. h.prototype.b2World = function (a, c) {
  5103. this.m_controllerList = this.m_jointList = this.m_contactList = this.m_bodyList = this.m_debugDraw = this.m_destructionListener = null;
  5104. this.m_controllerCount = this.m_jointCount = this.m_contactCount = this.m_bodyCount = 0;
  5105. h.m_warmStarting = true;
  5106. h.m_continuousPhysics = true;
  5107. this.m_allowSleep = c;
  5108. this.m_gravity = a;
  5109. this.m_inv_dt0 = 0;
  5110. this.m_contactManager.m_world = this;
  5111. this.m_groundBody = this.CreateBody(new z)
  5112. };
  5113. h.prototype.SetDestructionListener = function (a) {
  5114. this.m_destructionListener = a
  5115. };
  5116. h.prototype.SetContactFilter = function (a) {
  5117. this.m_contactManager.m_contactFilter = a
  5118. };
  5119. h.prototype.SetContactListener = function (a) {
  5120. this.m_contactManager.m_contactListener = a
  5121. };
  5122. h.prototype.SetDebugDraw = function (a) {
  5123. this.m_debugDraw = a
  5124. };
  5125. h.prototype.SetBroadPhase = function (a) {
  5126. var c = this.m_contactManager.m_broadPhase;
  5127. this.m_contactManager.m_broadPhase = a;
  5128. for (var g = this.m_bodyList; g; g = g.m_next)
  5129. for (var b = g.m_fixtureList; b; b = b.m_next) b.m_proxy = a.CreateProxy(c.GetFatAABB(b.m_proxy), b)
  5130. };
  5131. h.prototype.Validate = function () {
  5132. this.m_contactManager.m_broadPhase.Validate()
  5133. };
  5134. h.prototype.GetProxyCount = function () {
  5135. return this.m_contactManager.m_broadPhase.GetProxyCount()
  5136. };
  5137. h.prototype.CreateBody = function (a) {
  5138. if (this.IsLocked() == true) return null;
  5139. a = new k(a, this);
  5140. a.m_prev = null;
  5141. if (a.m_next = this.m_bodyList) this.m_bodyList.m_prev = a;
  5142. this.m_bodyList = a;
  5143. ++this.m_bodyCount;
  5144. return a
  5145. };
  5146. h.prototype.DestroyBody = function (a) {
  5147. if (this.IsLocked() != true) {
  5148. for (var c = a.m_jointList; c;) {
  5149. var g = c;
  5150. c = c.next;
  5151. this.m_destructionListener && this.m_destructionListener.SayGoodbyeJoint(g.joint);
  5152. this.DestroyJoint(g.joint)
  5153. }
  5154. for (c = a.m_controllerList; c;) {
  5155. g = c;
  5156. c = c.nextController;
  5157. g.controller.RemoveBody(a)
  5158. }
  5159. for (c = a.m_contactList; c;) {
  5160. g = c;
  5161. c = c.next;
  5162. this.m_contactManager.Destroy(g.contact)
  5163. }
  5164. a.m_contactList = null;
  5165. for (c = a.m_fixtureList; c;) {
  5166. g = c;
  5167. c = c.m_next;
  5168. this.m_destructionListener && this.m_destructionListener.SayGoodbyeFixture(g);
  5169. g.DestroyProxy(this.m_contactManager.m_broadPhase);
  5170. g.Destroy()
  5171. }
  5172. a.m_fixtureList = null;
  5173. a.m_fixtureCount = 0;
  5174. if (a.m_prev) a.m_prev.m_next = a.m_next;
  5175. if (a.m_next) a.m_next.m_prev = a.m_prev;
  5176. if (a == this.m_bodyList) this.m_bodyList = a.m_next;
  5177. --this.m_bodyCount
  5178. }
  5179. };
  5180. h.prototype.CreateJoint = function (a) {
  5181. var c = q.Create(a, null);
  5182. c.m_prev = null;
  5183. if (c.m_next = this.m_jointList) this.m_jointList.m_prev = c;
  5184. this.m_jointList = c;
  5185. ++this.m_jointCount;
  5186. c.m_edgeA.joint = c;
  5187. c.m_edgeA.other = c.m_bodyB;
  5188. c.m_edgeA.prev = null;
  5189. if (c.m_edgeA.next = c.m_bodyA.m_jointList) c.m_bodyA.m_jointList.prev = c.m_edgeA;
  5190. c.m_bodyA.m_jointList = c.m_edgeA;
  5191. c.m_edgeB.joint = c;
  5192. c.m_edgeB.other = c.m_bodyA;
  5193. c.m_edgeB.prev = null;
  5194. if (c.m_edgeB.next = c.m_bodyB.m_jointList) c.m_bodyB.m_jointList.prev = c.m_edgeB;
  5195. c.m_bodyB.m_jointList = c.m_edgeB;
  5196. var g = a.bodyA,
  5197. b = a.bodyB;
  5198. if (a.collideConnected == false)
  5199. for (a = b.GetContactList(); a;) {
  5200. a.other == g && a.contact.FlagForFiltering();
  5201. a = a.next
  5202. }
  5203. return c
  5204. };
  5205. h.prototype.DestroyJoint = function (a) {
  5206. var c = a.m_collideConnected;
  5207. if (a.m_prev) a.m_prev.m_next = a.m_next;
  5208. if (a.m_next) a.m_next.m_prev = a.m_prev;
  5209. if (a == this.m_jointList) this.m_jointList = a.m_next;
  5210. var g = a.m_bodyA,
  5211. b = a.m_bodyB;
  5212. g.SetAwake(true);
  5213. b.SetAwake(true);
  5214. if (a.m_edgeA.prev) a.m_edgeA.prev.next = a.m_edgeA.next;
  5215. if (a.m_edgeA.next) a.m_edgeA.next.prev = a.m_edgeA.prev;
  5216. if (a.m_edgeA == g.m_jointList) g.m_jointList = a.m_edgeA.next;
  5217. a.m_edgeA.prev = null;
  5218. a.m_edgeA.next = null;
  5219. if (a.m_edgeB.prev) a.m_edgeB.prev.next = a.m_edgeB.next;
  5220. if (a.m_edgeB.next) a.m_edgeB.next.prev = a.m_edgeB.prev;
  5221. if (a.m_edgeB == b.m_jointList) b.m_jointList = a.m_edgeB.next;
  5222. a.m_edgeB.prev = null;
  5223. a.m_edgeB.next = null;
  5224. q.Destroy(a, null);
  5225. --this.m_jointCount;
  5226. if (c == false)
  5227. for (a = b.GetContactList(); a;) {
  5228. a.other == g && a.contact.FlagForFiltering();
  5229. a = a.next
  5230. }
  5231. };
  5232. h.prototype.AddController = function (a) {
  5233. a.m_next = this.m_controllerList;
  5234. a.m_prev = null;
  5235. this.m_controllerList = a;
  5236. a.m_world = this;
  5237. this.m_controllerCount++;
  5238. return a
  5239. };
  5240. h.prototype.RemoveController = function (a) {
  5241. if (a.m_prev) a.m_prev.m_next = a.m_next;
  5242. if (a.m_next) a.m_next.m_prev = a.m_prev;
  5243. if (this.m_controllerList == a) this.m_controllerList = a.m_next;
  5244. this.m_controllerCount--
  5245. };
  5246. h.prototype.CreateController = function (a) {
  5247. if (a.m_world != this) throw Error("Controller can only be a member of one world");
  5248. a.m_next = this.m_controllerList;
  5249. a.m_prev = null;
  5250. if (this.m_controllerList) this.m_controllerList.m_prev = a;
  5251. this.m_controllerList = a;
  5252. ++this.m_controllerCount;
  5253. a.m_world = this;
  5254. return a
  5255. };
  5256. h.prototype.DestroyController = function (a) {
  5257. a.Clear();
  5258. if (a.m_next) a.m_next.m_prev = a.m_prev;
  5259. if (a.m_prev) a.m_prev.m_next = a.m_next;
  5260. if (a == this.m_controllerList) this.m_controllerList = a.m_next;
  5261. --this.m_controllerCount
  5262. };
  5263. h.prototype.SetWarmStarting = function (a) {
  5264. h.m_warmStarting = a
  5265. };
  5266. h.prototype.SetContinuousPhysics = function (a) {
  5267. h.m_continuousPhysics = a
  5268. };
  5269. h.prototype.GetBodyCount = function () {
  5270. return this.m_bodyCount
  5271. };
  5272. h.prototype.GetJointCount = function () {
  5273. return this.m_jointCount
  5274. };
  5275. h.prototype.GetContactCount = function () {
  5276. return this.m_contactCount
  5277. };
  5278. h.prototype.SetGravity = function (a) {
  5279. this.m_gravity = a
  5280. };
  5281. h.prototype.GetGravity = function () {
  5282. return this.m_gravity
  5283. };
  5284. h.prototype.GetGroundBody = function () {
  5285. return this.m_groundBody
  5286. };
  5287. h.prototype.Step = function (a, c, g) {
  5288. if (a === undefined) a = 0;
  5289. if (c === undefined) c = 0;
  5290. if (g === undefined) g = 0;
  5291. if (this.m_flags & h.e_newFixture) {
  5292. this.m_contactManager.FindNewContacts();
  5293. this.m_flags &= ~h.e_newFixture
  5294. }
  5295. this.m_flags |= h.e_locked;
  5296. var b = h.s_timestep2;
  5297. b.dt = a;
  5298. b.velocityIterations = c;
  5299. b.positionIterations = g;
  5300. b.inv_dt = a > 0 ? 1 / a : 0;
  5301. b.dtRatio = this.m_inv_dt0 * a;
  5302. b.warmStarting = h.m_warmStarting;
  5303. this.m_contactManager.Collide();
  5304. b.dt > 0 && this.Solve(b);
  5305. h.m_continuousPhysics && b.dt > 0 && this.SolveTOI(b);
  5306. if (b.dt > 0) this.m_inv_dt0 = b.inv_dt;
  5307. this.m_flags &= ~h.e_locked
  5308. };
  5309. h.prototype.ClearForces = function () {
  5310. for (var a = this.m_bodyList; a; a = a.m_next) {
  5311. a.m_force.SetZero();
  5312. a.m_torque = 0
  5313. }
  5314. };
  5315. h.prototype.DrawDebugData = function () {
  5316. if (this.m_debugDraw != null) {
  5317. this.m_debugDraw.m_sprite.graphics.clear();
  5318. var a = this.m_debugDraw.GetFlags(),
  5319. c, g, b;
  5320. new y;
  5321. new y;
  5322. new y;
  5323. var e;
  5324. new U;
  5325. new U;
  5326. e = [new y, new y, new y, new y];
  5327. var f = new w(0, 0, 0);
  5328. if (a & E.e_shapeBit)
  5329. for (c = this.m_bodyList; c; c = c.m_next) {
  5330. e = c.m_xf;
  5331. for (g = c.GetFixtureList(); g; g = g.m_next) {
  5332. b = g.GetShape();
  5333. if (c.IsActive() == false) f.Set(0.5, 0.5, 0.3);
  5334. else if (c.GetType() == k.b2_staticBody) f.Set(0.5, 0.9, 0.5);
  5335. else if (c.GetType() == k.b2_kinematicBody) f.Set(0.5, 0.5, 0.9);
  5336. else c.IsAwake() == false ?
  5337. f.Set(0.6, 0.6, 0.6) : f.Set(0.9, 0.7, 0.7);
  5338. this.DrawShape(b, e, f)
  5339. }
  5340. }
  5341. if (a & E.e_jointBit)
  5342. for (c = this.m_jointList; c; c = c.m_next) this.DrawJoint(c);
  5343. if (a & E.e_controllerBit)
  5344. for (c = this.m_controllerList; c; c = c.m_next) c.Draw(this.m_debugDraw);
  5345. if (a & E.e_pairBit) {
  5346. f.Set(0.3, 0.9, 0.9);
  5347. for (c = this.m_contactManager.m_contactList; c; c = c.GetNext()) {
  5348. b = c.GetFixtureA();
  5349. g = c.GetFixtureB();
  5350. b = b.GetAABB().GetCenter();
  5351. g = g.GetAABB().GetCenter();
  5352. this.m_debugDraw.DrawSegment(b, g, f)
  5353. }
  5354. }
  5355. if (a & E.e_aabbBit) {
  5356. b = this.m_contactManager.m_broadPhase;
  5357. e = [new y,
  5358. new y, new y, new y
  5359. ];
  5360. for (c = this.m_bodyList; c; c = c.GetNext())
  5361. if (c.IsActive() != false)
  5362. for (g = c.GetFixtureList(); g; g = g.GetNext()) {
  5363. var m = b.GetFatAABB(g.m_proxy);
  5364. e[0].Set(m.lowerBound.x, m.lowerBound.y);
  5365. e[1].Set(m.upperBound.x, m.lowerBound.y);
  5366. e[2].Set(m.upperBound.x, m.upperBound.y);
  5367. e[3].Set(m.lowerBound.x, m.upperBound.y);
  5368. this.m_debugDraw.DrawPolygon(e, 4, f)
  5369. }
  5370. }
  5371. if (a & E.e_centerOfMassBit)
  5372. for (c = this.m_bodyList; c; c = c.m_next) {
  5373. e = h.s_xf;
  5374. e.R = c.m_xf.R;
  5375. e.position = c.GetWorldCenter();
  5376. this.m_debugDraw.DrawTransform(e)
  5377. }
  5378. }
  5379. };
  5380. h.prototype.QueryAABB = function (a, c) {
  5381. var g = this.m_contactManager.m_broadPhase;
  5382. g.Query(function (b) {
  5383. return a(g.GetUserData(b))
  5384. }, c)
  5385. };
  5386. h.prototype.QueryShape = function (a, c, g) {
  5387. if (g === undefined) g = null;
  5388. if (g == null) {
  5389. g = new K;
  5390. g.SetIdentity()
  5391. }
  5392. var b = this.m_contactManager.m_broadPhase,
  5393. e = new U;
  5394. c.ComputeAABB(e, g);
  5395. b.Query(function (f) {
  5396. f = b.GetUserData(f) instanceof S ? b.GetUserData(f) : null;
  5397. if (Y.TestOverlap(c, g, f.GetShape(), f.GetBody().GetTransform())) return a(f);
  5398. return true
  5399. }, e)
  5400. };
  5401. h.prototype.QueryPoint = function (a, c) {
  5402. var g = this.m_contactManager.m_broadPhase,
  5403. b = new U;
  5404. b.lowerBound.Set(c.x - A.b2_linearSlop, c.y - A.b2_linearSlop);
  5405. b.upperBound.Set(c.x + A.b2_linearSlop, c.y + A.b2_linearSlop);
  5406. g.Query(function (e) {
  5407. e = g.GetUserData(e) instanceof S ? g.GetUserData(e) : null;
  5408. if (e.TestPoint(c)) return a(e);
  5409. return true
  5410. }, b)
  5411. };
  5412. h.prototype.RayCast = function (a, c, g) {
  5413. var b = this.m_contactManager.m_broadPhase,
  5414. e = new V,
  5415. f = new Q(c, g);
  5416. b.RayCast(function (m, r) {
  5417. var s = b.GetUserData(r);
  5418. s = s instanceof S ? s : null;
  5419. if (s.RayCast(e, m)) {
  5420. var v = e.fraction,
  5421. t = new y((1 - v) * c.x + v * g.x, (1 - v) * c.y + v * g.y);
  5422. return a(s,
  5423. t, e.normal, v)
  5424. }
  5425. return m.maxFraction
  5426. }, f)
  5427. };
  5428. h.prototype.RayCastOne = function (a, c) {
  5429. var g;
  5430. this.RayCast(function (b, e, f, m) {
  5431. if (m === undefined) m = 0;
  5432. g = b;
  5433. return m
  5434. }, a, c);
  5435. return g
  5436. };
  5437. h.prototype.RayCastAll = function (a, c) {
  5438. var g = new Vector;
  5439. this.RayCast(function (b) {
  5440. g[g.length] = b;
  5441. return 1
  5442. }, a, c);
  5443. return g
  5444. };
  5445. h.prototype.GetBodyList = function () {
  5446. return this.m_bodyList
  5447. };
  5448. h.prototype.GetJointList = function () {
  5449. return this.m_jointList
  5450. };
  5451. h.prototype.GetContactList = function () {
  5452. return this.m_contactList
  5453. };
  5454. h.prototype.IsLocked = function () {
  5455. return (this.m_flags &
  5456. h.e_locked) > 0
  5457. };
  5458. h.prototype.Solve = function (a) {
  5459. for (var c, g = this.m_controllerList; g; g = g.m_next) g.Step(a);
  5460. g = this.m_island;
  5461. g.Initialize(this.m_bodyCount, this.m_contactCount, this.m_jointCount, null, this.m_contactManager.m_contactListener, this.m_contactSolver);
  5462. for (c = this.m_bodyList; c; c = c.m_next) c.m_flags &= ~k.e_islandFlag;
  5463. for (var b = this.m_contactList; b; b = b.m_next) b.m_flags &= ~l.e_islandFlag;
  5464. for (b = this.m_jointList; b; b = b.m_next) b.m_islandFlag = false;
  5465. parseInt(this.m_bodyCount);
  5466. b = this.s_stack;
  5467. for (var e = this.m_bodyList; e; e = e.m_next)
  5468. if (!(e.m_flags & k.e_islandFlag))
  5469. if (!(e.IsAwake() == false || e.IsActive() == false))
  5470. if (e.GetType() != k.b2_staticBody) {
  5471. g.Clear();
  5472. var f = 0;
  5473. b[f++] = e;
  5474. for (e.m_flags |= k.e_islandFlag; f > 0;) {
  5475. c = b[--f];
  5476. g.AddBody(c);
  5477. c.IsAwake() == false && c.SetAwake(true);
  5478. if (c.GetType() != k.b2_staticBody) {
  5479. for (var m, r = c.m_contactList; r; r = r.next)
  5480. if (!(r.contact.m_flags & l.e_islandFlag))
  5481. if (!(r.contact.IsSensor() == true || r.contact.IsEnabled() == false || r.contact.IsTouching() == false)) {
  5482. g.AddContact(r.contact);
  5483. r.contact.m_flags |= l.e_islandFlag;
  5484. m = r.other;
  5485. if (!(m.m_flags & k.e_islandFlag)) {
  5486. b[f++] = m;
  5487. m.m_flags |= k.e_islandFlag
  5488. }
  5489. }
  5490. for (c = c.m_jointList; c; c = c.next)
  5491. if (c.joint.m_islandFlag != true) {
  5492. m = c.other;
  5493. if (m.IsActive() != false) {
  5494. g.AddJoint(c.joint);
  5495. c.joint.m_islandFlag = true;
  5496. if (!(m.m_flags & k.e_islandFlag)) {
  5497. b[f++] = m;
  5498. m.m_flags |= k.e_islandFlag
  5499. }
  5500. }
  5501. }
  5502. }
  5503. }
  5504. g.Solve(a, this.m_gravity, this.m_allowSleep);
  5505. for (f = 0; f < g.m_bodyCount; ++f) {
  5506. c = g.m_bodies[f];
  5507. if (c.GetType() == k.b2_staticBody) c.m_flags &= ~k.e_islandFlag
  5508. }
  5509. }
  5510. for (f = 0; f < b.length; ++f) {
  5511. if (!b[f]) break;
  5512. b[f] = null
  5513. }
  5514. for (c = this.m_bodyList; c; c = c.m_next) c.IsAwake() == false || c.IsActive() == false || c.GetType() != k.b2_staticBody && c.SynchronizeFixtures();
  5515. this.m_contactManager.FindNewContacts()
  5516. };
  5517. h.prototype.SolveTOI = function (a) {
  5518. var c, g, b, e = this.m_island;
  5519. e.Initialize(this.m_bodyCount, A.b2_maxTOIContactsPerIsland, A.b2_maxTOIJointsPerIsland, null, this.m_contactManager.m_contactListener, this.m_contactSolver);
  5520. var f = h.s_queue;
  5521. for (c = this.m_bodyList; c; c = c.m_next) {
  5522. c.m_flags &= ~k.e_islandFlag;
  5523. c.m_sweep.t0 = 0
  5524. }
  5525. for (b = this.m_contactList; b; b = b.m_next) b.m_flags &= ~(l.e_toiFlag |
  5526. l.e_islandFlag);
  5527. for (b = this.m_jointList; b; b = b.m_next) b.m_islandFlag = false;
  5528. for (;;) {
  5529. var m = null,
  5530. r = 1;
  5531. for (b = this.m_contactList; b; b = b.m_next)
  5532. if (!(b.IsSensor() == true || b.IsEnabled() == false || b.IsContinuous() == false)) {
  5533. c = 1;
  5534. if (b.m_flags & l.e_toiFlag) c = b.m_toi;
  5535. else {
  5536. c = b.m_fixtureA;
  5537. g = b.m_fixtureB;
  5538. c = c.m_body;
  5539. g = g.m_body;
  5540. if ((c.GetType() != k.b2_dynamicBody || c.IsAwake() == false) && (g.GetType() != k.b2_dynamicBody || g.IsAwake() == false)) continue;
  5541. var s = c.m_sweep.t0;
  5542. if (c.m_sweep.t0 < g.m_sweep.t0) {
  5543. s = g.m_sweep.t0;
  5544. c.m_sweep.Advance(s)
  5545. } else if (g.m_sweep.t0 <
  5546. c.m_sweep.t0) {
  5547. s = c.m_sweep.t0;
  5548. g.m_sweep.Advance(s)
  5549. }
  5550. c = b.ComputeTOI(c.m_sweep, g.m_sweep);
  5551. A.b2Assert(0 <= c && c <= 1);
  5552. if (c > 0 && c < 1) {
  5553. c = (1 - c) * s + c;
  5554. if (c > 1) c = 1
  5555. }
  5556. b.m_toi = c;
  5557. b.m_flags |= l.e_toiFlag
  5558. } if (Number.MIN_VALUE < c && c < r) {
  5559. m = b;
  5560. r = c
  5561. }
  5562. }
  5563. if (m == null || 1 - 100 * Number.MIN_VALUE < r) break;
  5564. c = m.m_fixtureA;
  5565. g = m.m_fixtureB;
  5566. c = c.m_body;
  5567. g = g.m_body;
  5568. h.s_backupA.Set(c.m_sweep);
  5569. h.s_backupB.Set(g.m_sweep);
  5570. c.Advance(r);
  5571. g.Advance(r);
  5572. m.Update(this.m_contactManager.m_contactListener);
  5573. m.m_flags &= ~l.e_toiFlag;
  5574. if (m.IsSensor() == true || m.IsEnabled() == false) {
  5575. c.m_sweep.Set(h.s_backupA);
  5576. g.m_sweep.Set(h.s_backupB);
  5577. c.SynchronizeTransform();
  5578. g.SynchronizeTransform()
  5579. } else if (m.IsTouching() != false) {
  5580. c = c;
  5581. if (c.GetType() != k.b2_dynamicBody) c = g;
  5582. e.Clear();
  5583. m = b = 0;
  5584. f[b + m++] = c;
  5585. for (c.m_flags |= k.e_islandFlag; m > 0;) {
  5586. c = f[b++];
  5587. --m;
  5588. e.AddBody(c);
  5589. c.IsAwake() == false && c.SetAwake(true);
  5590. if (c.GetType() == k.b2_dynamicBody) {
  5591. for (g = c.m_contactList; g; g = g.next) {
  5592. if (e.m_contactCount == e.m_contactCapacity) break;
  5593. if (!(g.contact.m_flags & l.e_islandFlag))
  5594. if (!(g.contact.IsSensor() == true || g.contact.IsEnabled() == false || g.contact.IsTouching() == false)) {
  5595. e.AddContact(g.contact);
  5596. g.contact.m_flags |= l.e_islandFlag;
  5597. s = g.other;
  5598. if (!(s.m_flags & k.e_islandFlag)) {
  5599. if (s.GetType() != k.b2_staticBody) {
  5600. s.Advance(r);
  5601. s.SetAwake(true)
  5602. }
  5603. f[b + m] = s;
  5604. ++m;
  5605. s.m_flags |= k.e_islandFlag
  5606. }
  5607. }
  5608. }
  5609. for (c = c.m_jointList; c; c = c.next)
  5610. if (e.m_jointCount != e.m_jointCapacity)
  5611. if (c.joint.m_islandFlag != true) {
  5612. s = c.other;
  5613. if (s.IsActive() != false) {
  5614. e.AddJoint(c.joint);
  5615. c.joint.m_islandFlag = true;
  5616. if (!(s.m_flags & k.e_islandFlag)) {
  5617. if (s.GetType() != k.b2_staticBody) {
  5618. s.Advance(r);
  5619. s.SetAwake(true)
  5620. }
  5621. f[b + m] = s;
  5622. ++m;
  5623. s.m_flags |= k.e_islandFlag
  5624. }
  5625. }
  5626. }
  5627. }
  5628. }
  5629. b = h.s_timestep;
  5630. b.warmStarting = false;
  5631. b.dt = (1 - r) * a.dt;
  5632. b.inv_dt = 1 / b.dt;
  5633. b.dtRatio = 0;
  5634. b.velocityIterations = a.velocityIterations;
  5635. b.positionIterations = a.positionIterations;
  5636. e.SolveTOI(b);
  5637. for (r = r = 0; r < e.m_bodyCount; ++r) {
  5638. c = e.m_bodies[r];
  5639. c.m_flags &= ~k.e_islandFlag;
  5640. if (c.IsAwake() != false)
  5641. if (c.GetType() == k.b2_dynamicBody) {
  5642. c.SynchronizeFixtures();
  5643. for (g = c.m_contactList; g; g = g.next) g.contact.m_flags &= ~l.e_toiFlag
  5644. }
  5645. }
  5646. for (r = 0; r < e.m_contactCount; ++r) {
  5647. b = e.m_contacts[r];
  5648. b.m_flags &= ~(l.e_toiFlag |
  5649. l.e_islandFlag)
  5650. }
  5651. for (r = 0; r < e.m_jointCount; ++r) {
  5652. b = e.m_joints[r];
  5653. b.m_islandFlag = false
  5654. }
  5655. this.m_contactManager.FindNewContacts()
  5656. }
  5657. }
  5658. };
  5659. h.prototype.DrawJoint = function (a) {
  5660. var c = a.GetBodyA(),
  5661. g = a.GetBodyB(),
  5662. b = c.m_xf.position,
  5663. e = g.m_xf.position,
  5664. f = a.GetAnchorA(),
  5665. m = a.GetAnchorB(),
  5666. r = h.s_jointColor;
  5667. switch (a.m_type) {
  5668. case q.e_distanceJoint:
  5669. this.m_debugDraw.DrawSegment(f, m, r);
  5670. break;
  5671. case q.e_pulleyJoint:
  5672. c = a instanceof n ? a : null;
  5673. a = c.GetGroundAnchorA();
  5674. c = c.GetGroundAnchorB();
  5675. this.m_debugDraw.DrawSegment(a, f, r);
  5676. this.m_debugDraw.DrawSegment(c,
  5677. m, r);
  5678. this.m_debugDraw.DrawSegment(a, c, r);
  5679. break;
  5680. case q.e_mouseJoint:
  5681. this.m_debugDraw.DrawSegment(f, m, r);
  5682. break;
  5683. default:
  5684. c != this.m_groundBody && this.m_debugDraw.DrawSegment(b, f, r);
  5685. this.m_debugDraw.DrawSegment(f, m, r);
  5686. g != this.m_groundBody && this.m_debugDraw.DrawSegment(e, m, r)
  5687. }
  5688. };
  5689. h.prototype.DrawShape = function (a, c, g) {
  5690. switch (a.m_type) {
  5691. case Y.e_circleShape:
  5692. var b = a instanceof M ? a : null;
  5693. this.m_debugDraw.DrawSolidCircle(F.MulX(c, b.m_p), b.m_radius, c.R.col1, g);
  5694. break;
  5695. case Y.e_polygonShape:
  5696. b = 0;
  5697. b = a instanceof W ? a : null;
  5698. a = parseInt(b.GetVertexCount());
  5699. var e = b.GetVertices(),
  5700. f = new Vector(a);
  5701. for (b = 0; b < a; ++b) f[b] = F.MulX(c, e[b]);
  5702. this.m_debugDraw.DrawSolidPolygon(f, a, g);
  5703. break;
  5704. case Y.e_edgeShape:
  5705. b = a instanceof L ? a : null;
  5706. this.m_debugDraw.DrawSegment(F.MulX(c, b.GetVertex1()), F.MulX(c, b.GetVertex2()), g)
  5707. }
  5708. };
  5709. Box2D.postDefs.push(function () {
  5710. Box2D.Dynamics.b2World.s_timestep2 = new d;
  5711. Box2D.Dynamics.b2World.s_xf = new K;
  5712. Box2D.Dynamics.b2World.s_backupA = new G;
  5713. Box2D.Dynamics.b2World.s_backupB = new G;
  5714. Box2D.Dynamics.b2World.s_timestep = new d;
  5715. Box2D.Dynamics.b2World.s_queue = new Vector;
  5716. Box2D.Dynamics.b2World.s_jointColor = new w(0.5, 0.8, 0.8);
  5717. Box2D.Dynamics.b2World.e_newFixture = 1;
  5718. Box2D.Dynamics.b2World.e_locked = 2
  5719. })
  5720. })();
  5721. (function () {
  5722. var F = Box2D.Collision.Shapes.b2CircleShape,
  5723. G = Box2D.Collision.Shapes.b2EdgeShape,
  5724. K = Box2D.Collision.Shapes.b2PolygonShape,
  5725. y = Box2D.Collision.Shapes.b2Shape,
  5726. w = Box2D.Dynamics.Contacts.b2CircleContact,
  5727. A = Box2D.Dynamics.Contacts.b2Contact,
  5728. U = Box2D.Dynamics.Contacts.b2ContactConstraint,
  5729. p = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,
  5730. B = Box2D.Dynamics.Contacts.b2ContactEdge,
  5731. Q = Box2D.Dynamics.Contacts.b2ContactFactory,
  5732. V = Box2D.Dynamics.Contacts.b2ContactRegister,
  5733. M = Box2D.Dynamics.Contacts.b2ContactResult,
  5734. L = Box2D.Dynamics.Contacts.b2ContactSolver,
  5735. I = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,
  5736. W = Box2D.Dynamics.Contacts.b2NullContact,
  5737. Y = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,
  5738. k = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,
  5739. z = Box2D.Dynamics.Contacts.b2PolygonContact,
  5740. u = Box2D.Dynamics.Contacts.b2PositionSolverManifold,
  5741. D = Box2D.Dynamics.b2Body,
  5742. H = Box2D.Dynamics.b2TimeStep,
  5743. O = Box2D.Common.b2Settings,
  5744. E = Box2D.Common.Math.b2Mat22,
  5745. R = Box2D.Common.Math.b2Math,
  5746. N = Box2D.Common.Math.b2Vec2,
  5747. S = Box2D.Collision.b2Collision,
  5748. aa = Box2D.Collision.b2ContactID,
  5749. Z = Box2D.Collision.b2Manifold,
  5750. d = Box2D.Collision.b2TimeOfImpact,
  5751. h = Box2D.Collision.b2TOIInput,
  5752. l = Box2D.Collision.b2WorldManifold;
  5753. Box2D.inherit(w, Box2D.Dynamics.Contacts.b2Contact);
  5754. w.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  5755. w.b2CircleContact = function () {
  5756. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  5757. };
  5758. w.Create = function () {
  5759. return new w
  5760. };
  5761. w.Destroy = function () {};
  5762. w.prototype.Reset = function (j, o) {
  5763. this.__super.Reset.call(this, j, o)
  5764. };
  5765. w.prototype.Evaluate = function () {
  5766. var j = this.m_fixtureA.GetBody(),
  5767. o = this.m_fixtureB.GetBody();
  5768. S.CollideCircles(this.m_manifold, this.m_fixtureA.GetShape() instanceof F ? this.m_fixtureA.GetShape() : null, j.m_xf, this.m_fixtureB.GetShape() instanceof F ? this.m_fixtureB.GetShape() : null, o.m_xf)
  5769. };
  5770. A.b2Contact = function () {
  5771. this.m_nodeA = new B;
  5772. this.m_nodeB = new B;
  5773. this.m_manifold = new Z;
  5774. this.m_oldManifold = new Z
  5775. };
  5776. A.prototype.GetManifold = function () {
  5777. return this.m_manifold
  5778. };
  5779. A.prototype.GetWorldManifold = function (j) {
  5780. var o = this.m_fixtureA.GetBody(),
  5781. q = this.m_fixtureB.GetBody(),
  5782. n = this.m_fixtureA.GetShape(),
  5783. a = this.m_fixtureB.GetShape();
  5784. j.Initialize(this.m_manifold, o.GetTransform(), n.m_radius, q.GetTransform(), a.m_radius)
  5785. };
  5786. A.prototype.IsTouching = function () {
  5787. return (this.m_flags & A.e_touchingFlag) == A.e_touchingFlag
  5788. };
  5789. A.prototype.IsContinuous = function () {
  5790. return (this.m_flags & A.e_continuousFlag) == A.e_continuousFlag
  5791. };
  5792. A.prototype.SetSensor = function (j) {
  5793. if (j) this.m_flags |= A.e_sensorFlag;
  5794. else this.m_flags &= ~A.e_sensorFlag
  5795. };
  5796. A.prototype.IsSensor = function () {
  5797. return (this.m_flags &
  5798. A.e_sensorFlag) == A.e_sensorFlag
  5799. };
  5800. A.prototype.SetEnabled = function (j) {
  5801. if (j) this.m_flags |= A.e_enabledFlag;
  5802. else this.m_flags &= ~A.e_enabledFlag
  5803. };
  5804. A.prototype.IsEnabled = function () {
  5805. return (this.m_flags & A.e_enabledFlag) == A.e_enabledFlag
  5806. };
  5807. A.prototype.GetNext = function () {
  5808. return this.m_next
  5809. };
  5810. A.prototype.GetFixtureA = function () {
  5811. return this.m_fixtureA
  5812. };
  5813. A.prototype.GetFixtureB = function () {
  5814. return this.m_fixtureB
  5815. };
  5816. A.prototype.FlagForFiltering = function () {
  5817. this.m_flags |= A.e_filterFlag
  5818. };
  5819. A.prototype.b2Contact = function () {};
  5820. A.prototype.Reset = function (j, o) {
  5821. if (j === undefined) j = null;
  5822. if (o === undefined) o = null;
  5823. this.m_flags = A.e_enabledFlag;
  5824. if (!j || !o) this.m_fixtureB = this.m_fixtureA = null;
  5825. else {
  5826. if (j.IsSensor() || o.IsSensor()) this.m_flags |= A.e_sensorFlag;
  5827. var q = j.GetBody(),
  5828. n = o.GetBody();
  5829. if (q.GetType() != D.b2_dynamicBody || q.IsBullet() || n.GetType() != D.b2_dynamicBody || n.IsBullet()) this.m_flags |= A.e_continuousFlag;
  5830. this.m_fixtureA = j;
  5831. this.m_fixtureB = o;
  5832. this.m_manifold.m_pointCount = 0;
  5833. this.m_next = this.m_prev = null;
  5834. this.m_nodeA.contact = null;
  5835. this.m_nodeA.prev = null;
  5836. this.m_nodeA.next = null;
  5837. this.m_nodeA.other = null;
  5838. this.m_nodeB.contact = null;
  5839. this.m_nodeB.prev = null;
  5840. this.m_nodeB.next = null;
  5841. this.m_nodeB.other = null
  5842. }
  5843. };
  5844. A.prototype.Update = function (j) {
  5845. var o = this.m_oldManifold;
  5846. this.m_oldManifold = this.m_manifold;
  5847. this.m_manifold = o;
  5848. this.m_flags |= A.e_enabledFlag;
  5849. var q = false;
  5850. o = (this.m_flags & A.e_touchingFlag) == A.e_touchingFlag;
  5851. var n = this.m_fixtureA.m_body,
  5852. a = this.m_fixtureB.m_body,
  5853. c = this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);
  5854. if (this.m_flags & A.e_sensorFlag) {
  5855. if (c) {
  5856. q = this.m_fixtureA.GetShape();
  5857. c = this.m_fixtureB.GetShape();
  5858. n = n.GetTransform();
  5859. a = a.GetTransform();
  5860. q = y.TestOverlap(q, n, c, a)
  5861. }
  5862. this.m_manifold.m_pointCount = 0
  5863. } else {
  5864. if (n.GetType() != D.b2_dynamicBody || n.IsBullet() || a.GetType() != D.b2_dynamicBody || a.IsBullet()) this.m_flags |= A.e_continuousFlag;
  5865. else this.m_flags &= ~A.e_continuousFlag; if (c) {
  5866. this.Evaluate();
  5867. q = this.m_manifold.m_pointCount > 0;
  5868. for (c = 0; c < this.m_manifold.m_pointCount; ++c) {
  5869. var g = this.m_manifold.m_points[c];
  5870. g.m_normalImpulse = 0;
  5871. g.m_tangentImpulse = 0;
  5872. for (var b = g.m_id, e = 0; e < this.m_oldManifold.m_pointCount; ++e) {
  5873. var f = this.m_oldManifold.m_points[e];
  5874. if (f.m_id.key == b.key) {
  5875. g.m_normalImpulse = f.m_normalImpulse;
  5876. g.m_tangentImpulse = f.m_tangentImpulse;
  5877. break
  5878. }
  5879. }
  5880. }
  5881. } else this.m_manifold.m_pointCount = 0; if (q != o) {
  5882. n.SetAwake(true);
  5883. a.SetAwake(true)
  5884. }
  5885. } if (q) this.m_flags |= A.e_touchingFlag;
  5886. else this.m_flags &= ~A.e_touchingFlag;
  5887. o == false && q == true && j.BeginContact(this);
  5888. o == true && q == false && j.EndContact(this);
  5889. (this.m_flags & A.e_sensorFlag) == 0 && j.PreSolve(this, this.m_oldManifold)
  5890. };
  5891. A.prototype.Evaluate = function () {};
  5892. A.prototype.ComputeTOI = function (j, o) {
  5893. A.s_input.proxyA.Set(this.m_fixtureA.GetShape());
  5894. A.s_input.proxyB.Set(this.m_fixtureB.GetShape());
  5895. A.s_input.sweepA = j;
  5896. A.s_input.sweepB = o;
  5897. A.s_input.tolerance = O.b2_linearSlop;
  5898. return d.TimeOfImpact(A.s_input)
  5899. };
  5900. Box2D.postDefs.push(function () {
  5901. Box2D.Dynamics.Contacts.b2Contact.e_sensorFlag = 1;
  5902. Box2D.Dynamics.Contacts.b2Contact.e_continuousFlag = 2;
  5903. Box2D.Dynamics.Contacts.b2Contact.e_islandFlag = 4;
  5904. Box2D.Dynamics.Contacts.b2Contact.e_toiFlag = 8;
  5905. Box2D.Dynamics.Contacts.b2Contact.e_touchingFlag = 16;
  5906. Box2D.Dynamics.Contacts.b2Contact.e_enabledFlag = 32;
  5907. Box2D.Dynamics.Contacts.b2Contact.e_filterFlag = 64;
  5908. Box2D.Dynamics.Contacts.b2Contact.s_input = new h
  5909. });
  5910. U.b2ContactConstraint = function () {
  5911. this.localPlaneNormal = new N;
  5912. this.localPoint = new N;
  5913. this.normal = new N;
  5914. this.normalMass = new E;
  5915. this.K = new E
  5916. };
  5917. U.prototype.b2ContactConstraint = function () {
  5918. this.points = new Vector(O.b2_maxManifoldPoints);
  5919. for (var j = 0; j < O.b2_maxManifoldPoints; j++) this.points[j] = new p
  5920. };
  5921. p.b2ContactConstraintPoint = function () {
  5922. this.localPoint = new N;
  5923. this.rA = new N;
  5924. this.rB = new N
  5925. };
  5926. B.b2ContactEdge = function () {};
  5927. Q.b2ContactFactory = function () {};
  5928. Q.prototype.b2ContactFactory = function (j) {
  5929. this.m_allocator = j;
  5930. this.InitializeRegisters()
  5931. };
  5932. Q.prototype.AddType = function (j, o, q, n) {
  5933. if (q === undefined) q = 0;
  5934. if (n === undefined) n = 0;
  5935. this.m_registers[q][n].createFcn = j;
  5936. this.m_registers[q][n].destroyFcn = o;
  5937. this.m_registers[q][n].primary = true;
  5938. if (q != n) {
  5939. this.m_registers[n][q].createFcn = j;
  5940. this.m_registers[n][q].destroyFcn = o;
  5941. this.m_registers[n][q].primary = false
  5942. }
  5943. };
  5944. Q.prototype.InitializeRegisters = function () {
  5945. this.m_registers = new Vector(y.e_shapeTypeCount);
  5946. for (var j = 0; j < y.e_shapeTypeCount; j++) {
  5947. this.m_registers[j] = new Vector(y.e_shapeTypeCount);
  5948. for (var o = 0; o < y.e_shapeTypeCount; o++) this.m_registers[j][o] = new V
  5949. }
  5950. this.AddType(w.Create, w.Destroy, y.e_circleShape, y.e_circleShape);
  5951. this.AddType(Y.Create, Y.Destroy, y.e_polygonShape, y.e_circleShape);
  5952. this.AddType(z.Create, z.Destroy, y.e_polygonShape, y.e_polygonShape);
  5953. this.AddType(I.Create, I.Destroy, y.e_edgeShape, y.e_circleShape);
  5954. this.AddType(k.Create, k.Destroy,
  5955. y.e_polygonShape, y.e_edgeShape)
  5956. };
  5957. Q.prototype.Create = function (j, o) {
  5958. var q = parseInt(j.GetType()),
  5959. n = parseInt(o.GetType());
  5960. q = this.m_registers[q][n];
  5961. if (q.pool) {
  5962. n = q.pool;
  5963. q.pool = n.m_next;
  5964. q.poolCount--;
  5965. n.Reset(j, o);
  5966. return n
  5967. }
  5968. n = q.createFcn;
  5969. if (n != null) {
  5970. if (q.primary) {
  5971. n = n(this.m_allocator);
  5972. n.Reset(j, o)
  5973. } else {
  5974. n = n(this.m_allocator);
  5975. n.Reset(o, j)
  5976. }
  5977. return n
  5978. } else return null
  5979. };
  5980. Q.prototype.Destroy = function (j) {
  5981. if (j.m_manifold.m_pointCount > 0) {
  5982. j.m_fixtureA.m_body.SetAwake(true);
  5983. j.m_fixtureB.m_body.SetAwake(true)
  5984. }
  5985. var o = parseInt(j.m_fixtureA.GetType()),
  5986. q = parseInt(j.m_fixtureB.GetType());
  5987. o = this.m_registers[o][q];
  5988. o.poolCount++;
  5989. j.m_next = o.pool;
  5990. o.pool = j;
  5991. o = o.destroyFcn;
  5992. o(j, this.m_allocator)
  5993. };
  5994. V.b2ContactRegister = function () {};
  5995. M.b2ContactResult = function () {
  5996. this.position = new N;
  5997. this.normal = new N;
  5998. this.id = new aa
  5999. };
  6000. L.b2ContactSolver = function () {
  6001. this.m_step = new H;
  6002. this.m_constraints = new Vector
  6003. };
  6004. L.prototype.b2ContactSolver = function () {};
  6005. L.prototype.Initialize = function (j, o, q, n) {
  6006. if (q === undefined) q = 0;
  6007. var a;
  6008. this.m_step.Set(j);
  6009. this.m_allocator = n;
  6010. j = 0;
  6011. for (this.m_constraintCount = q; this.m_constraints.length < this.m_constraintCount;) this.m_constraints[this.m_constraints.length] = new U;
  6012. for (j = 0; j < q; ++j) {
  6013. a = o[j];
  6014. n = a.m_fixtureA;
  6015. var c = a.m_fixtureB,
  6016. g = n.m_shape.m_radius,
  6017. b = c.m_shape.m_radius,
  6018. e = n.m_body,
  6019. f = c.m_body,
  6020. m = a.GetManifold(),
  6021. r = O.b2MixFriction(n.GetFriction(), c.GetFriction()),
  6022. s = O.b2MixRestitution(n.GetRestitution(), c.GetRestitution()),
  6023. v = e.m_linearVelocity.x,
  6024. t = e.m_linearVelocity.y,
  6025. x = f.m_linearVelocity.x,
  6026. C = f.m_linearVelocity.y,
  6027. J = e.m_angularVelocity,
  6028. T = f.m_angularVelocity;
  6029. O.b2Assert(m.m_pointCount > 0);
  6030. L.s_worldManifold.Initialize(m, e.m_xf, g, f.m_xf, b);
  6031. c = L.s_worldManifold.m_normal.x;
  6032. a = L.s_worldManifold.m_normal.y;
  6033. n = this.m_constraints[j];
  6034. n.bodyA = e;
  6035. n.bodyB = f;
  6036. n.manifold = m;
  6037. n.normal.x = c;
  6038. n.normal.y = a;
  6039. n.pointCount = m.m_pointCount;
  6040. n.friction = r;
  6041. n.restitution = s;
  6042. n.localPlaneNormal.x = m.m_localPlaneNormal.x;
  6043. n.localPlaneNormal.y = m.m_localPlaneNormal.y;
  6044. n.localPoint.x = m.m_localPoint.x;
  6045. n.localPoint.y = m.m_localPoint.y;
  6046. n.radius = g + b;
  6047. n.type = m.m_type;
  6048. for (g = 0; g < n.pointCount; ++g) {
  6049. r = m.m_points[g];
  6050. b = n.points[g];
  6051. b.normalImpulse = r.m_normalImpulse;
  6052. b.tangentImpulse = r.m_tangentImpulse;
  6053. b.localPoint.SetV(r.m_localPoint);
  6054. r = b.rA.x = L.s_worldManifold.m_points[g].x - e.m_sweep.c.x;
  6055. s = b.rA.y = L.s_worldManifold.m_points[g].y - e.m_sweep.c.y;
  6056. var P = b.rB.x = L.s_worldManifold.m_points[g].x - f.m_sweep.c.x,
  6057. X = b.rB.y = L.s_worldManifold.m_points[g].y - f.m_sweep.c.y,
  6058. $ = r * a - s * c,
  6059. ba = P * a - X * c;
  6060. $ *= $;
  6061. ba *= ba;
  6062. b.normalMass = 1 / (e.m_invMass + f.m_invMass + e.m_invI * $ + f.m_invI * ba);
  6063. var ca = e.m_mass * e.m_invMass + f.m_mass * f.m_invMass;
  6064. ca += e.m_mass * e.m_invI * $ + f.m_mass * f.m_invI * ba;
  6065. b.equalizedMass = 1 / ca;
  6066. ba = a;
  6067. ca = -c;
  6068. $ = r * ca - s * ba;
  6069. ba = P * ca - X * ba;
  6070. $ *= $;
  6071. ba *= ba;
  6072. b.tangentMass = 1 / (e.m_invMass + f.m_invMass + e.m_invI * $ + f.m_invI * ba);
  6073. b.velocityBias = 0;
  6074. r = n.normal.x * (x + -T * X - v - -J * s) + n.normal.y * (C + T * P - t - J * r);
  6075. if (r < -O.b2_velocityThreshold) b.velocityBias += -n.restitution * r
  6076. }
  6077. if (n.pointCount == 2) {
  6078. C = n.points[0];
  6079. x = n.points[1];
  6080. m = e.m_invMass;
  6081. e = e.m_invI;
  6082. v = f.m_invMass;
  6083. f = f.m_invI;
  6084. t = C.rA.x * a - C.rA.y * c;
  6085. C = C.rB.x * a - C.rB.y * c;
  6086. J = x.rA.x * a - x.rA.y * c;
  6087. x = x.rB.x * a - x.rB.y * c;
  6088. c = m + v + e * t * t + f * C * C;
  6089. a = m + v + e * J * J + f * x * x;
  6090. f = m + v + e * t * J + f * C * x;
  6091. if (c * c < 100 * (c * a - f * f)) {
  6092. n.K.col1.Set(c, f);
  6093. n.K.col2.Set(f, a);
  6094. n.K.GetInverse(n.normalMass)
  6095. } else n.pointCount = 1
  6096. }
  6097. }
  6098. };
  6099. L.prototype.InitVelocityConstraints = function (j) {
  6100. for (var o = 0; o < this.m_constraintCount; ++o) {
  6101. var q = this.m_constraints[o],
  6102. n = q.bodyA,
  6103. a = q.bodyB,
  6104. c = n.m_invMass,
  6105. g = n.m_invI,
  6106. b = a.m_invMass,
  6107. e = a.m_invI,
  6108. f = q.normal.x,
  6109. m = q.normal.y,
  6110. r = m,
  6111. s = -f,
  6112. v = 0,
  6113. t = 0;
  6114. if (j.warmStarting) {
  6115. t = q.pointCount;
  6116. for (v = 0; v < t; ++v) {
  6117. var x = q.points[v];
  6118. x.normalImpulse *= j.dtRatio;
  6119. x.tangentImpulse *= j.dtRatio;
  6120. var C = x.normalImpulse * f + x.tangentImpulse * r,
  6121. J = x.normalImpulse * m + x.tangentImpulse * s;
  6122. n.m_angularVelocity -= g * (x.rA.x * J - x.rA.y * C);
  6123. n.m_linearVelocity.x -= c * C;
  6124. n.m_linearVelocity.y -= c * J;
  6125. a.m_angularVelocity += e * (x.rB.x * J - x.rB.y * C);
  6126. a.m_linearVelocity.x += b * C;
  6127. a.m_linearVelocity.y += b * J
  6128. }
  6129. } else {
  6130. t = q.pointCount;
  6131. for (v = 0; v < t; ++v) {
  6132. n = q.points[v];
  6133. n.normalImpulse = 0;
  6134. n.tangentImpulse = 0
  6135. }
  6136. }
  6137. }
  6138. };
  6139. L.prototype.SolveVelocityConstraints = function () {
  6140. for (var j = 0, o, q = 0, n = 0, a = 0, c = n = n = q = q = 0, g = q = q = 0, b = q = a = 0, e = 0, f, m = 0; m < this.m_constraintCount; ++m) {
  6141. a = this.m_constraints[m];
  6142. var r = a.bodyA,
  6143. s = a.bodyB,
  6144. v = r.m_angularVelocity,
  6145. t = s.m_angularVelocity,
  6146. x = r.m_linearVelocity,
  6147. C = s.m_linearVelocity,
  6148. J = r.m_invMass,
  6149. T = r.m_invI,
  6150. P = s.m_invMass,
  6151. X = s.m_invI;
  6152. b = a.normal.x;
  6153. var $ = e = a.normal.y;
  6154. f = -b;
  6155. g = a.friction;
  6156. for (j = 0; j < a.pointCount; j++) {
  6157. o = a.points[j];
  6158. q = C.x - t * o.rB.y - x.x + v * o.rA.y;
  6159. n = C.y + t * o.rB.x - x.y - v * o.rA.x;
  6160. q = q * $ + n * f;
  6161. q = o.tangentMass * -q;
  6162. n = g * o.normalImpulse;
  6163. n = R.Clamp(o.tangentImpulse + q, -n, n);
  6164. q = n - o.tangentImpulse;
  6165. c = q * $;
  6166. q = q * f;
  6167. x.x -= J * c;
  6168. x.y -= J * q;
  6169. v -= T * (o.rA.x * q - o.rA.y * c);
  6170. C.x += P * c;
  6171. C.y += P * q;
  6172. t += X * (o.rB.x * q - o.rB.y * c);
  6173. o.tangentImpulse = n
  6174. }
  6175. parseInt(a.pointCount);
  6176. if (a.pointCount == 1) {
  6177. o = a.points[0];
  6178. q = C.x + -t * o.rB.y - x.x - -v * o.rA.y;
  6179. n = C.y + t * o.rB.x - x.y - v * o.rA.x;
  6180. a = q * b + n * e;
  6181. q = -o.normalMass * (a - o.velocityBias);
  6182. n = o.normalImpulse + q;
  6183. n = n > 0 ? n : 0;
  6184. q = n - o.normalImpulse;
  6185. c = q * b;
  6186. q = q * e;
  6187. x.x -= J * c;
  6188. x.y -= J * q;
  6189. v -= T * (o.rA.x * q - o.rA.y * c);
  6190. C.x += P * c;
  6191. C.y += P * q;
  6192. t += X * (o.rB.x * q - o.rB.y * c);
  6193. o.normalImpulse = n
  6194. } else {
  6195. o = a.points[0];
  6196. j = a.points[1];
  6197. q = o.normalImpulse;
  6198. g = j.normalImpulse;
  6199. var ba = (C.x - t * o.rB.y - x.x + v * o.rA.y) * b + (C.y + t * o.rB.x - x.y - v * o.rA.x) * e,
  6200. ca = (C.x - t * j.rB.y - x.x + v * j.rA.y) * b + (C.y + t * j.rB.x - x.y - v * j.rA.x) * e;
  6201. n = ba - o.velocityBias;
  6202. c = ca - j.velocityBias;
  6203. f = a.K;
  6204. n -= f.col1.x * q + f.col2.x * g;
  6205. for (c -= f.col1.y * q + f.col2.y * g;;) {
  6206. f = a.normalMass;
  6207. $ = -(f.col1.x * n + f.col2.x * c);
  6208. f = -(f.col1.y * n + f.col2.y * c);
  6209. if ($ >= 0 && f >= 0) {
  6210. q = $ - q;
  6211. g = f - g;
  6212. a = q * b;
  6213. q = q * e;
  6214. b = g * b;
  6215. e = g * e;
  6216. x.x -= J * (a + b);
  6217. x.y -= J * (q + e);
  6218. v -= T * (o.rA.x * q - o.rA.y * a + j.rA.x * e - j.rA.y * b);
  6219. C.x += P * (a + b);
  6220. C.y += P * (q + e);
  6221. t += X * (o.rB.x * q - o.rB.y * a + j.rB.x * e - j.rB.y * b);
  6222. o.normalImpulse = $;
  6223. j.normalImpulse = f;
  6224. break
  6225. }
  6226. $ = -o.normalMass * n;
  6227. f = 0;
  6228. ca = a.K.col1.y * $ + c;
  6229. if ($ >= 0 && ca >= 0) {
  6230. q = $ - q;
  6231. g = f - g;
  6232. a = q * b;
  6233. q = q * e;
  6234. b = g * b;
  6235. e = g * e;
  6236. x.x -= J * (a + b);
  6237. x.y -= J * (q + e);
  6238. v -= T * (o.rA.x * q - o.rA.y * a + j.rA.x * e - j.rA.y * b);
  6239. C.x += P * (a + b);
  6240. C.y += P * (q + e);
  6241. t += X * (o.rB.x * q - o.rB.y * a + j.rB.x * e - j.rB.y * b);
  6242. o.normalImpulse = $;
  6243. j.normalImpulse = f;
  6244. break
  6245. }
  6246. $ = 0;
  6247. f = -j.normalMass * c;
  6248. ba = a.K.col2.x * f + n;
  6249. if (f >= 0 && ba >= 0) {
  6250. q = $ - q;
  6251. g = f - g;
  6252. a = q * b;
  6253. q = q * e;
  6254. b = g * b;
  6255. e = g * e;
  6256. x.x -= J * (a + b);
  6257. x.y -= J * (q + e);
  6258. v -= T * (o.rA.x * q - o.rA.y * a + j.rA.x * e - j.rA.y * b);
  6259. C.x += P * (a + b);
  6260. C.y += P * (q + e);
  6261. t += X * (o.rB.x * q - o.rB.y * a + j.rB.x * e - j.rB.y * b);
  6262. o.normalImpulse = $;
  6263. j.normalImpulse = f;
  6264. break
  6265. }
  6266. f = $ = 0;
  6267. ba = n;
  6268. ca = c;
  6269. if (ba >= 0 && ca >= 0) {
  6270. q = $ - q;
  6271. g = f - g;
  6272. a = q * b;
  6273. q = q * e;
  6274. b = g * b;
  6275. e = g * e;
  6276. x.x -= J * (a + b);
  6277. x.y -= J * (q + e);
  6278. v -= T * (o.rA.x * q - o.rA.y * a + j.rA.x * e - j.rA.y * b);
  6279. C.x += P * (a + b);
  6280. C.y += P * (q + e);
  6281. t += X * (o.rB.x * q - o.rB.y * a + j.rB.x * e - j.rB.y * b);
  6282. o.normalImpulse = $;
  6283. j.normalImpulse = f;
  6284. break
  6285. }
  6286. break
  6287. }
  6288. }
  6289. r.m_angularVelocity = v;
  6290. s.m_angularVelocity = t
  6291. }
  6292. };
  6293. L.prototype.FinalizeVelocityConstraints = function () {
  6294. for (var j = 0; j < this.m_constraintCount; ++j) for (var o = this.m_constraints[j], q = o.manifold, n = 0; n < o.pointCount; ++n) {
  6295. var a = q.m_points[n],
  6296. c = o.points[n];
  6297. a.m_normalImpulse = c.normalImpulse;
  6298. a.m_tangentImpulse = c.tangentImpulse
  6299. }
  6300. };
  6301. L.prototype.SolvePositionConstraints = function (j) {
  6302. if (j === undefined) j = 0;
  6303. for (var o = 0, q = 0; q < this.m_constraintCount; q++) {
  6304. var n = this.m_constraints[q],
  6305. a = n.bodyA,
  6306. c = n.bodyB,
  6307. g = a.m_mass * a.m_invMass,
  6308. b = a.m_mass * a.m_invI,
  6309. e = c.m_mass * c.m_invMass,
  6310. f = c.m_mass * c.m_invI;
  6311. L.s_psm.Initialize(n);
  6312. for (var m = L.s_psm.m_normal, r = 0; r < n.pointCount; r++) {
  6313. var s = n.points[r],
  6314. v = L.s_psm.m_points[r],
  6315. t = L.s_psm.m_separations[r],
  6316. x = v.x - a.m_sweep.c.x,
  6317. C = v.y - a.m_sweep.c.y,
  6318. J = v.x - c.m_sweep.c.x;
  6319. v = v.y - c.m_sweep.c.y;
  6320. o = o < t ? o : t;
  6321. t = R.Clamp(j * (t + O.b2_linearSlop), -O.b2_maxLinearCorrection, 0);
  6322. t = -s.equalizedMass * t;
  6323. s = t * m.x;
  6324. t = t * m.y;
  6325. a.m_sweep.c.x -= g * s;
  6326. a.m_sweep.c.y -= g * t;
  6327. a.m_sweep.a -= b * (x * t - C * s);
  6328. a.SynchronizeTransform();
  6329. c.m_sweep.c.x += e * s;
  6330. c.m_sweep.c.y += e * t;
  6331. c.m_sweep.a += f * (J * t - v * s);
  6332. c.SynchronizeTransform()
  6333. }
  6334. }
  6335. return o > -1.5 * O.b2_linearSlop
  6336. };
  6337. Box2D.postDefs.push(function () {
  6338. Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold = new l;
  6339. Box2D.Dynamics.Contacts.b2ContactSolver.s_psm = new u
  6340. });
  6341. Box2D.inherit(I, Box2D.Dynamics.Contacts.b2Contact);
  6342. I.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  6343. I.b2EdgeAndCircleContact = function () {
  6344. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  6345. };
  6346. I.Create = function () {
  6347. return new I
  6348. };
  6349. I.Destroy = function () {};
  6350. I.prototype.Reset = function (j, o) {
  6351. this.__super.Reset.call(this, j, o)
  6352. };
  6353. I.prototype.Evaluate = function () {
  6354. var j = this.m_fixtureA.GetBody(),
  6355. o = this.m_fixtureB.GetBody();
  6356. this.b2CollideEdgeAndCircle(this.m_manifold, this.m_fixtureA.GetShape() instanceof G ? this.m_fixtureA.GetShape() : null, j.m_xf,
  6357. this.m_fixtureB.GetShape() instanceof F ? this.m_fixtureB.GetShape() : null, o.m_xf)
  6358. };
  6359. I.prototype.b2CollideEdgeAndCircle = function () {};
  6360. Box2D.inherit(W, Box2D.Dynamics.Contacts.b2Contact);
  6361. W.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  6362. W.b2NullContact = function () {
  6363. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  6364. };
  6365. W.prototype.b2NullContact = function () {
  6366. this.__super.b2Contact.call(this)
  6367. };
  6368. W.prototype.Evaluate = function () {};
  6369. Box2D.inherit(Y, Box2D.Dynamics.Contacts.b2Contact);
  6370. Y.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  6371. Y.b2PolyAndCircleContact = function () {
  6372. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  6373. };
  6374. Y.Create = function () {
  6375. return new Y
  6376. };
  6377. Y.Destroy = function () {};
  6378. Y.prototype.Reset = function (j, o) {
  6379. this.__super.Reset.call(this, j, o);
  6380. O.b2Assert(j.GetType() == y.e_polygonShape);
  6381. O.b2Assert(o.GetType() == y.e_circleShape)
  6382. };
  6383. Y.prototype.Evaluate = function () {
  6384. var j = this.m_fixtureA.m_body,
  6385. o = this.m_fixtureB.m_body;
  6386. S.CollidePolygonAndCircle(this.m_manifold, this.m_fixtureA.GetShape() instanceof K ? this.m_fixtureA.GetShape() : null, j.m_xf, this.m_fixtureB.GetShape() instanceof F ? this.m_fixtureB.GetShape() : null, o.m_xf)
  6387. };
  6388. Box2D.inherit(k, Box2D.Dynamics.Contacts.b2Contact);
  6389. k.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  6390. k.b2PolyAndEdgeContact = function () {
  6391. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  6392. };
  6393. k.Create = function () {
  6394. return new k
  6395. };
  6396. k.Destroy = function () {};
  6397. k.prototype.Reset = function (j, o) {
  6398. this.__super.Reset.call(this, j, o);
  6399. O.b2Assert(j.GetType() == y.e_polygonShape);
  6400. O.b2Assert(o.GetType() == y.e_edgeShape)
  6401. };
  6402. k.prototype.Evaluate = function () {
  6403. var j = this.m_fixtureA.GetBody(),
  6404. o = this.m_fixtureB.GetBody();
  6405. this.b2CollidePolyAndEdge(this.m_manifold, this.m_fixtureA.GetShape() instanceof K ? this.m_fixtureA.GetShape() : null, j.m_xf, this.m_fixtureB.GetShape() instanceof G ? this.m_fixtureB.GetShape() : null, o.m_xf)
  6406. };
  6407. k.prototype.b2CollidePolyAndEdge = function () {};
  6408. Box2D.inherit(z, Box2D.Dynamics.Contacts.b2Contact);
  6409. z.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;
  6410. z.b2PolygonContact = function () {
  6411. Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments)
  6412. };
  6413. z.Create = function () {
  6414. return new z
  6415. };
  6416. z.Destroy = function () {};
  6417. z.prototype.Reset = function (j, o) {
  6418. this.__super.Reset.call(this, j, o)
  6419. };
  6420. z.prototype.Evaluate = function () {
  6421. var j = this.m_fixtureA.GetBody(),
  6422. o = this.m_fixtureB.GetBody();
  6423. S.CollidePolygons(this.m_manifold, this.m_fixtureA.GetShape() instanceof K ? this.m_fixtureA.GetShape() : null, j.m_xf, this.m_fixtureB.GetShape() instanceof K ? this.m_fixtureB.GetShape() : null, o.m_xf)
  6424. };
  6425. u.b2PositionSolverManifold = function () {};
  6426. u.prototype.b2PositionSolverManifold = function () {
  6427. this.m_normal = new N;
  6428. this.m_separations = new Vector_a2j_Number(O.b2_maxManifoldPoints);
  6429. this.m_points = new Vector(O.b2_maxManifoldPoints);
  6430. for (var j = 0; j < O.b2_maxManifoldPoints; j++) this.m_points[j] = new N
  6431. };
  6432. u.prototype.Initialize = function (j) {
  6433. O.b2Assert(j.pointCount > 0);
  6434. var o = 0,
  6435. q = 0,
  6436. n = 0,
  6437. a, c = 0,
  6438. g = 0;
  6439. switch (j.type) {
  6440. case Z.e_circles:
  6441. a = j.bodyA.m_xf.R;
  6442. n = j.localPoint;
  6443. o = j.bodyA.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6444. q = j.bodyA.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6445. a = j.bodyB.m_xf.R;
  6446. n = j.points[0].localPoint;
  6447. c = j.bodyB.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6448. a = j.bodyB.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6449. n = c - o;
  6450. g = a - q;
  6451. var b = n * n + g * g;
  6452. if (b > Number.MIN_VALUE * Number.MIN_VALUE) {
  6453. b = Math.sqrt(b);
  6454. this.m_normal.x = n / b;
  6455. this.m_normal.y = g / b
  6456. } else {
  6457. this.m_normal.x = 1;
  6458. this.m_normal.y = 0
  6459. }
  6460. this.m_points[0].x = 0.5 * (o + c);
  6461. this.m_points[0].y = 0.5 * (q + a);
  6462. this.m_separations[0] = n * this.m_normal.x + g * this.m_normal.y - j.radius;
  6463. break;
  6464. case Z.e_faceA:
  6465. a = j.bodyA.m_xf.R;
  6466. n = j.localPlaneNormal;
  6467. this.m_normal.x = a.col1.x * n.x + a.col2.x * n.y;
  6468. this.m_normal.y = a.col1.y * n.x + a.col2.y * n.y;
  6469. a = j.bodyA.m_xf.R;
  6470. n = j.localPoint;
  6471. c = j.bodyA.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6472. g = j.bodyA.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6473. a = j.bodyB.m_xf.R;
  6474. for (o = 0; o < j.pointCount; ++o) {
  6475. n = j.points[o].localPoint;
  6476. q = j.bodyB.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6477. n = j.bodyB.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6478. this.m_separations[o] = (q - c) * this.m_normal.x + (n - g) * this.m_normal.y - j.radius;
  6479. this.m_points[o].x = q;
  6480. this.m_points[o].y = n
  6481. }
  6482. break;
  6483. case Z.e_faceB:
  6484. a = j.bodyB.m_xf.R;
  6485. n = j.localPlaneNormal;
  6486. this.m_normal.x = a.col1.x * n.x + a.col2.x * n.y;
  6487. this.m_normal.y = a.col1.y * n.x + a.col2.y * n.y;
  6488. a = j.bodyB.m_xf.R;
  6489. n = j.localPoint;
  6490. c = j.bodyB.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6491. g = j.bodyB.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6492. a = j.bodyA.m_xf.R;
  6493. for (o = 0; o < j.pointCount; ++o) {
  6494. n = j.points[o].localPoint;
  6495. q = j.bodyA.m_xf.position.x + (a.col1.x * n.x + a.col2.x * n.y);
  6496. n = j.bodyA.m_xf.position.y + (a.col1.y * n.x + a.col2.y * n.y);
  6497. this.m_separations[o] = (q - c) * this.m_normal.x + (n - g) * this.m_normal.y - j.radius;
  6498. this.m_points[o].Set(q, n)
  6499. }
  6500. this.m_normal.x *= -1;
  6501. this.m_normal.y *= -1
  6502. }
  6503. };
  6504. Box2D.postDefs.push(function () {
  6505. Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointA = new N;
  6506. Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointB = new N
  6507. })
  6508. })();
  6509. (function () {
  6510. var F = Box2D.Common.Math.b2Mat22,
  6511. G = Box2D.Common.Math.b2Math,
  6512. K = Box2D.Common.Math.b2Vec2,
  6513. y = Box2D.Common.b2Color,
  6514. w = Box2D.Dynamics.Controllers.b2BuoyancyController,
  6515. A = Box2D.Dynamics.Controllers.b2ConstantAccelController,
  6516. U = Box2D.Dynamics.Controllers.b2ConstantForceController,
  6517. p = Box2D.Dynamics.Controllers.b2Controller,
  6518. B = Box2D.Dynamics.Controllers.b2ControllerEdge,
  6519. Q = Box2D.Dynamics.Controllers.b2GravityController,
  6520. V = Box2D.Dynamics.Controllers.b2TensorDampingController;
  6521. Box2D.inherit(w, Box2D.Dynamics.Controllers.b2Controller);
  6522. w.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  6523. w.b2BuoyancyController = function () {
  6524. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  6525. this.normal = new K(0, -1);
  6526. this.density = this.offset = 0;
  6527. this.velocity = new K(0, 0);
  6528. this.linearDrag = 2;
  6529. this.angularDrag = 1;
  6530. this.useDensity = false;
  6531. this.useWorldGravity = true;
  6532. this.gravity = null
  6533. };
  6534. w.prototype.Step = function () {
  6535. if (this.m_bodyList) {
  6536. if (this.useWorldGravity) this.gravity = this.GetWorld().GetGravity().Copy();
  6537. for (var M = this.m_bodyList; M; M = M.nextBody) {
  6538. var L = M.body;
  6539. if (L.IsAwake() != false) {
  6540. for (var I = new K, W = new K, Y = 0, k = 0, z = L.GetFixtureList(); z; z = z.GetNext()) {
  6541. var u = new K,
  6542. D = z.GetShape().ComputeSubmergedArea(this.normal, this.offset, L.GetTransform(), u);
  6543. Y += D;
  6544. I.x += D * u.x;
  6545. I.y += D * u.y;
  6546. var H = 0;
  6547. H = 1;
  6548. k += D * H;
  6549. W.x += D * u.x * H;
  6550. W.y += D * u.y * H
  6551. }
  6552. I.x /= Y;
  6553. I.y /= Y;
  6554. W.x /= k;
  6555. W.y /= k;
  6556. if (!(Y < Number.MIN_VALUE)) {
  6557. k = this.gravity.GetNegative();
  6558. k.Multiply(this.density * Y);
  6559. L.ApplyForce(k, W);
  6560. W = L.GetLinearVelocityFromWorldPoint(I);
  6561. W.Subtract(this.velocity);
  6562. W.Multiply(-this.linearDrag * Y);
  6563. L.ApplyForce(W, I);
  6564. L.ApplyTorque(-L.GetInertia() / L.GetMass() * Y * L.GetAngularVelocity() * this.angularDrag)
  6565. }
  6566. }
  6567. }
  6568. }
  6569. };
  6570. w.prototype.Draw = function (M) {
  6571. var L = new K,
  6572. I = new K;
  6573. L.x = this.normal.x * this.offset + this.normal.y * 1E3;
  6574. L.y = this.normal.y * this.offset - this.normal.x * 1E3;
  6575. I.x = this.normal.x * this.offset - this.normal.y * 1E3;
  6576. I.y = this.normal.y * this.offset + this.normal.x * 1E3;
  6577. var W = new y(0, 0, 1);
  6578. M.DrawSegment(L, I, W)
  6579. };
  6580. Box2D.inherit(A, Box2D.Dynamics.Controllers.b2Controller);
  6581. A.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  6582. A.b2ConstantAccelController = function () {
  6583. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  6584. this.A = new K(0, 0)
  6585. };
  6586. A.prototype.Step = function (M) {
  6587. M = new K(this.A.x * M.dt, this.A.y * M.dt);
  6588. for (var L = this.m_bodyList; L; L = L.nextBody) {
  6589. var I = L.body;
  6590. I.IsAwake() && I.SetLinearVelocity(new K(I.GetLinearVelocity().x + M.x, I.GetLinearVelocity().y + M.y))
  6591. }
  6592. };
  6593. Box2D.inherit(U, Box2D.Dynamics.Controllers.b2Controller);
  6594. U.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  6595. U.b2ConstantForceController = function () {
  6596. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  6597. this.F = new K(0, 0)
  6598. };
  6599. U.prototype.Step = function () {
  6600. for (var M = this.m_bodyList; M; M = M.nextBody) {
  6601. var L = M.body;
  6602. L.IsAwake() && L.ApplyForce(this.F, L.GetWorldCenter())
  6603. }
  6604. };
  6605. p.b2Controller = function () {};
  6606. p.prototype.Step = function () {};
  6607. p.prototype.Draw = function () {};
  6608. p.prototype.AddBody = function (M) {
  6609. var L = new B;
  6610. L.controller = this;
  6611. L.body = M;
  6612. L.nextBody = this.m_bodyList;
  6613. L.prevBody = null;
  6614. this.m_bodyList = L;
  6615. if (L.nextBody) L.nextBody.prevBody = L;
  6616. this.m_bodyCount++;
  6617. L.nextController = M.m_controllerList;
  6618. L.prevController = null;
  6619. M.m_controllerList = L;
  6620. if (L.nextController) L.nextController.prevController = L;
  6621. M.m_controllerCount++
  6622. };
  6623. p.prototype.RemoveBody = function (M) {
  6624. for (var L = M.m_controllerList; L && L.controller != this;) L = L.nextController;
  6625. if (L.prevBody) L.prevBody.nextBody = L.nextBody;
  6626. if (L.nextBody) L.nextBody.prevBody = L.prevBody;
  6627. if (L.nextController) L.nextController.prevController = L.prevController;
  6628. if (L.prevController) L.prevController.nextController = L.nextController;
  6629. if (this.m_bodyList == L) this.m_bodyList = L.nextBody;
  6630. if (M.m_controllerList == L) M.m_controllerList = L.nextController;
  6631. M.m_controllerCount--;
  6632. this.m_bodyCount--
  6633. };
  6634. p.prototype.Clear = function () {
  6635. for (; this.m_bodyList;) this.RemoveBody(this.m_bodyList.body)
  6636. };
  6637. p.prototype.GetNext = function () {
  6638. return this.m_next
  6639. };
  6640. p.prototype.GetWorld = function () {
  6641. return this.m_world
  6642. };
  6643. p.prototype.GetBodyList = function () {
  6644. return this.m_bodyList
  6645. };
  6646. B.b2ControllerEdge = function () {};
  6647. Box2D.inherit(Q, Box2D.Dynamics.Controllers.b2Controller);
  6648. Q.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  6649. Q.b2GravityController = function () {
  6650. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  6651. this.G = 1;
  6652. this.invSqr = true
  6653. };
  6654. Q.prototype.Step = function () {
  6655. var M = null,
  6656. L = null,
  6657. I = null,
  6658. W = 0,
  6659. Y = null,
  6660. k = null,
  6661. z = null,
  6662. u = 0,
  6663. D = 0,
  6664. H = 0;
  6665. u = null;
  6666. if (this.invSqr) for (M = this.m_bodyList; M; M = M.nextBody) {
  6667. L = M.body;
  6668. I = L.GetWorldCenter();
  6669. W = L.GetMass();
  6670. for (Y = this.m_bodyList; Y != M; Y = Y.nextBody) {
  6671. k = Y.body;
  6672. z = k.GetWorldCenter();
  6673. u = z.x - I.x;
  6674. D = z.y - I.y;
  6675. H = u * u + D * D;
  6676. if (!(H < Number.MIN_VALUE)) {
  6677. u = new K(u, D);
  6678. u.Multiply(this.G / H / Math.sqrt(H) * W * k.GetMass());
  6679. L.IsAwake() && L.ApplyForce(u, I);
  6680. u.Multiply(-1);
  6681. k.IsAwake() && k.ApplyForce(u, z)
  6682. }
  6683. }
  6684. } else
  6685. for (M = this.m_bodyList; M; M = M.nextBody) {
  6686. L = M.body;
  6687. I = L.GetWorldCenter();
  6688. W = L.GetMass();
  6689. for (Y = this.m_bodyList; Y != M; Y = Y.nextBody) {
  6690. k = Y.body;
  6691. z = k.GetWorldCenter();
  6692. u = z.x - I.x;
  6693. D = z.y - I.y;
  6694. H = u * u + D * D;
  6695. if (!(H < Number.MIN_VALUE)) {
  6696. u = new K(u, D);
  6697. u.Multiply(this.G / H * W * k.GetMass());
  6698. L.IsAwake() && L.ApplyForce(u, I);
  6699. u.Multiply(-1);
  6700. k.IsAwake() && k.ApplyForce(u, z)
  6701. }
  6702. }
  6703. }
  6704. };
  6705. Box2D.inherit(V, Box2D.Dynamics.Controllers.b2Controller);
  6706. V.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;
  6707. V.b2TensorDampingController = function () {
  6708. Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);
  6709. this.T = new F;
  6710. this.maxTimestep = 0
  6711. };
  6712. V.prototype.SetAxisAligned = function (M, L) {
  6713. if (M === undefined) M = 0;
  6714. if (L === undefined) L = 0;
  6715. this.T.col1.x = -M;
  6716. this.T.col1.y = 0;
  6717. this.T.col2.x = 0;
  6718. this.T.col2.y = -L;
  6719. this.maxTimestep = M > 0 || L > 0 ? 1 / Math.max(M, L) : 0
  6720. };
  6721. V.prototype.Step = function (M) {
  6722. M = M.dt;
  6723. if (!(M <= Number.MIN_VALUE)) {
  6724. if (M > this.maxTimestep && this.maxTimestep > 0) M = this.maxTimestep;
  6725. for (var L = this.m_bodyList; L; L = L.nextBody) {
  6726. var I = L.body;
  6727. if (I.IsAwake()) {
  6728. var W = I.GetWorldVector(G.MulMV(this.T, I.GetLocalVector(I.GetLinearVelocity())));
  6729. I.SetLinearVelocity(new K(I.GetLinearVelocity().x + W.x * M, I.GetLinearVelocity().y + W.y * M))
  6730. }
  6731. }
  6732. }
  6733. }
  6734. })();
  6735. (function () {
  6736. var F = Box2D.Common.b2Settings,
  6737. G = Box2D.Common.Math.b2Mat22,
  6738. K = Box2D.Common.Math.b2Mat33,
  6739. y = Box2D.Common.Math.b2Math,
  6740. w = Box2D.Common.Math.b2Vec2,
  6741. A = Box2D.Common.Math.b2Vec3,
  6742. U = Box2D.Dynamics.Joints.b2DistanceJoint,
  6743. p = Box2D.Dynamics.Joints.b2DistanceJointDef,
  6744. B = Box2D.Dynamics.Joints.b2FrictionJoint,
  6745. Q = Box2D.Dynamics.Joints.b2FrictionJointDef,
  6746. V = Box2D.Dynamics.Joints.b2GearJoint,
  6747. M = Box2D.Dynamics.Joints.b2GearJointDef,
  6748. L = Box2D.Dynamics.Joints.b2Jacobian,
  6749. I = Box2D.Dynamics.Joints.b2Joint,
  6750. W = Box2D.Dynamics.Joints.b2JointDef,
  6751. Y = Box2D.Dynamics.Joints.b2JointEdge,
  6752. k = Box2D.Dynamics.Joints.b2LineJoint,
  6753. z = Box2D.Dynamics.Joints.b2LineJointDef,
  6754. u = Box2D.Dynamics.Joints.b2MouseJoint,
  6755. D = Box2D.Dynamics.Joints.b2MouseJointDef,
  6756. H = Box2D.Dynamics.Joints.b2PrismaticJoint,
  6757. O = Box2D.Dynamics.Joints.b2PrismaticJointDef,
  6758. E = Box2D.Dynamics.Joints.b2PulleyJoint,
  6759. R = Box2D.Dynamics.Joints.b2PulleyJointDef,
  6760. N = Box2D.Dynamics.Joints.b2RevoluteJoint,
  6761. S = Box2D.Dynamics.Joints.b2RevoluteJointDef,
  6762. aa = Box2D.Dynamics.Joints.b2WeldJoint,
  6763. Z = Box2D.Dynamics.Joints.b2WeldJointDef;
  6764. Box2D.inherit(U, Box2D.Dynamics.Joints.b2Joint);
  6765. U.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6766. U.b2DistanceJoint = function () {
  6767. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6768. this.m_localAnchor1 = new w;
  6769. this.m_localAnchor2 = new w;
  6770. this.m_u = new w
  6771. };
  6772. U.prototype.GetAnchorA = function () {
  6773. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  6774. };
  6775. U.prototype.GetAnchorB = function () {
  6776. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  6777. };
  6778. U.prototype.GetReactionForce = function (d) {
  6779. if (d === undefined) d = 0;
  6780. return new w(d * this.m_impulse * this.m_u.x, d * this.m_impulse * this.m_u.y)
  6781. };
  6782. U.prototype.GetReactionTorque = function () {
  6783. return 0
  6784. };
  6785. U.prototype.GetLength = function () {
  6786. return this.m_length
  6787. };
  6788. U.prototype.SetLength = function (d) {
  6789. if (d === undefined) d = 0;
  6790. this.m_length = d
  6791. };
  6792. U.prototype.GetFrequency = function () {
  6793. return this.m_frequencyHz
  6794. };
  6795. U.prototype.SetFrequency = function (d) {
  6796. if (d === undefined) d = 0;
  6797. this.m_frequencyHz = d
  6798. };
  6799. U.prototype.GetDampingRatio = function () {
  6800. return this.m_dampingRatio
  6801. };
  6802. U.prototype.SetDampingRatio = function (d) {
  6803. if (d === undefined) d = 0;
  6804. this.m_dampingRatio = d
  6805. };
  6806. U.prototype.b2DistanceJoint = function (d) {
  6807. this.__super.b2Joint.call(this, d);
  6808. this.m_localAnchor1.SetV(d.localAnchorA);
  6809. this.m_localAnchor2.SetV(d.localAnchorB);
  6810. this.m_length = d.length;
  6811. this.m_frequencyHz = d.frequencyHz;
  6812. this.m_dampingRatio = d.dampingRatio;
  6813. this.m_bias = this.m_gamma = this.m_impulse = 0
  6814. };
  6815. U.prototype.InitVelocityConstraints = function (d) {
  6816. var h, l = 0,
  6817. j = this.m_bodyA,
  6818. o = this.m_bodyB;
  6819. h = j.m_xf.R;
  6820. var q = this.m_localAnchor1.x - j.m_sweep.localCenter.x,
  6821. n = this.m_localAnchor1.y - j.m_sweep.localCenter.y;
  6822. l = h.col1.x * q + h.col2.x * n;
  6823. n = h.col1.y * q + h.col2.y * n;
  6824. q = l;
  6825. h = o.m_xf.R;
  6826. var a = this.m_localAnchor2.x - o.m_sweep.localCenter.x,
  6827. c = this.m_localAnchor2.y - o.m_sweep.localCenter.y;
  6828. l = h.col1.x * a + h.col2.x * c;
  6829. c = h.col1.y * a + h.col2.y * c;
  6830. a = l;
  6831. this.m_u.x = o.m_sweep.c.x + a - j.m_sweep.c.x - q;
  6832. this.m_u.y = o.m_sweep.c.y + c - j.m_sweep.c.y - n;
  6833. l = Math.sqrt(this.m_u.x * this.m_u.x + this.m_u.y * this.m_u.y);
  6834. l > F.b2_linearSlop ? this.m_u.Multiply(1 / l) : this.m_u.SetZero();
  6835. h = q * this.m_u.y - n * this.m_u.x;
  6836. var g = a * this.m_u.y - c * this.m_u.x;
  6837. h = j.m_invMass + j.m_invI * h * h + o.m_invMass + o.m_invI * g * g;
  6838. this.m_mass = h != 0 ? 1 / h : 0;
  6839. if (this.m_frequencyHz > 0) {
  6840. l = l - this.m_length;
  6841. g = 2 * Math.PI * this.m_frequencyHz;
  6842. var b = this.m_mass * g * g;
  6843. this.m_gamma = d.dt * (2 * this.m_mass * this.m_dampingRatio * g + d.dt * b);
  6844. this.m_gamma = this.m_gamma != 0 ? 1 / this.m_gamma : 0;
  6845. this.m_bias = l * d.dt * b * this.m_gamma;
  6846. this.m_mass = h + this.m_gamma;
  6847. this.m_mass = this.m_mass != 0 ? 1 / this.m_mass : 0
  6848. }
  6849. if (d.warmStarting) {
  6850. this.m_impulse *= d.dtRatio;
  6851. d = this.m_impulse * this.m_u.x;
  6852. h = this.m_impulse * this.m_u.y;
  6853. j.m_linearVelocity.x -= j.m_invMass * d;
  6854. j.m_linearVelocity.y -= j.m_invMass * h;
  6855. j.m_angularVelocity -= j.m_invI * (q * h - n * d);
  6856. o.m_linearVelocity.x += o.m_invMass * d;
  6857. o.m_linearVelocity.y += o.m_invMass * h;
  6858. o.m_angularVelocity += o.m_invI * (a * h - c * d)
  6859. } else this.m_impulse = 0
  6860. };
  6861. U.prototype.SolveVelocityConstraints = function () {
  6862. var d, h = this.m_bodyA,
  6863. l = this.m_bodyB;
  6864. d = h.m_xf.R;
  6865. var j = this.m_localAnchor1.x - h.m_sweep.localCenter.x,
  6866. o = this.m_localAnchor1.y - h.m_sweep.localCenter.y,
  6867. q = d.col1.x * j + d.col2.x * o;
  6868. o = d.col1.y * j + d.col2.y * o;
  6869. j = q;
  6870. d = l.m_xf.R;
  6871. var n = this.m_localAnchor2.x - l.m_sweep.localCenter.x,
  6872. a = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  6873. q = d.col1.x * n + d.col2.x * a;
  6874. a = d.col1.y * n + d.col2.y * a;
  6875. n = q;
  6876. q = -this.m_mass * (this.m_u.x * (l.m_linearVelocity.x + -l.m_angularVelocity * a - (h.m_linearVelocity.x + -h.m_angularVelocity * o)) + this.m_u.y * (l.m_linearVelocity.y + l.m_angularVelocity * n - (h.m_linearVelocity.y + h.m_angularVelocity * j)) + this.m_bias + this.m_gamma * this.m_impulse);
  6877. this.m_impulse += q;
  6878. d = q * this.m_u.x;
  6879. q = q * this.m_u.y;
  6880. h.m_linearVelocity.x -= h.m_invMass * d;
  6881. h.m_linearVelocity.y -= h.m_invMass * q;
  6882. h.m_angularVelocity -= h.m_invI * (j * q - o * d);
  6883. l.m_linearVelocity.x += l.m_invMass * d;
  6884. l.m_linearVelocity.y += l.m_invMass * q;
  6885. l.m_angularVelocity += l.m_invI * (n * q - a * d)
  6886. };
  6887. U.prototype.SolvePositionConstraints = function () {
  6888. var d;
  6889. if (this.m_frequencyHz > 0) return true;
  6890. var h = this.m_bodyA,
  6891. l = this.m_bodyB;
  6892. d = h.m_xf.R;
  6893. var j = this.m_localAnchor1.x - h.m_sweep.localCenter.x,
  6894. o = this.m_localAnchor1.y - h.m_sweep.localCenter.y,
  6895. q = d.col1.x * j + d.col2.x * o;
  6896. o = d.col1.y * j + d.col2.y * o;
  6897. j = q;
  6898. d = l.m_xf.R;
  6899. var n = this.m_localAnchor2.x - l.m_sweep.localCenter.x,
  6900. a = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  6901. q = d.col1.x * n + d.col2.x * a;
  6902. a = d.col1.y * n + d.col2.y * a;
  6903. n = q;
  6904. q = l.m_sweep.c.x + n - h.m_sweep.c.x - j;
  6905. var c = l.m_sweep.c.y + a - h.m_sweep.c.y - o;
  6906. d = Math.sqrt(q * q + c * c);
  6907. q /= d;
  6908. c /= d;
  6909. d = d - this.m_length;
  6910. d = y.Clamp(d, -F.b2_maxLinearCorrection, F.b2_maxLinearCorrection);
  6911. var g = -this.m_mass * d;
  6912. this.m_u.Set(q, c);
  6913. q = g * this.m_u.x;
  6914. c = g * this.m_u.y;
  6915. h.m_sweep.c.x -= h.m_invMass * q;
  6916. h.m_sweep.c.y -= h.m_invMass * c;
  6917. h.m_sweep.a -= h.m_invI * (j * c - o * q);
  6918. l.m_sweep.c.x += l.m_invMass * q;
  6919. l.m_sweep.c.y += l.m_invMass * c;
  6920. l.m_sweep.a += l.m_invI * (n * c - a * q);
  6921. h.SynchronizeTransform();
  6922. l.SynchronizeTransform();
  6923. return y.Abs(d) < F.b2_linearSlop
  6924. };
  6925. Box2D.inherit(p, Box2D.Dynamics.Joints.b2JointDef);
  6926. p.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  6927. p.b2DistanceJointDef = function () {
  6928. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  6929. this.localAnchorA = new w;
  6930. this.localAnchorB = new w
  6931. };
  6932. p.prototype.b2DistanceJointDef = function () {
  6933. this.__super.b2JointDef.call(this);
  6934. this.type = I.e_distanceJoint;
  6935. this.length = 1;
  6936. this.dampingRatio = this.frequencyHz = 0
  6937. };
  6938. p.prototype.Initialize = function (d, h, l, j) {
  6939. this.bodyA = d;
  6940. this.bodyB = h;
  6941. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(l));
  6942. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(j));
  6943. d = j.x - l.x;
  6944. l = j.y - l.y;
  6945. this.length = Math.sqrt(d * d + l * l);
  6946. this.dampingRatio = this.frequencyHz = 0
  6947. };
  6948. Box2D.inherit(B, Box2D.Dynamics.Joints.b2Joint);
  6949. B.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  6950. B.b2FrictionJoint = function () {
  6951. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  6952. this.m_localAnchorA = new w;
  6953. this.m_localAnchorB = new w;
  6954. this.m_linearMass = new G;
  6955. this.m_linearImpulse = new w
  6956. };
  6957. B.prototype.GetAnchorA = function () {
  6958. return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)
  6959. };
  6960. B.prototype.GetAnchorB = function () {
  6961. return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)
  6962. };
  6963. B.prototype.GetReactionForce = function (d) {
  6964. if (d === undefined) d = 0;
  6965. return new w(d * this.m_linearImpulse.x, d * this.m_linearImpulse.y)
  6966. };
  6967. B.prototype.GetReactionTorque = function (d) {
  6968. if (d === undefined) d = 0;
  6969. return d * this.m_angularImpulse
  6970. };
  6971. B.prototype.SetMaxForce = function (d) {
  6972. if (d === undefined) d = 0;
  6973. this.m_maxForce = d
  6974. };
  6975. B.prototype.GetMaxForce = function () {
  6976. return this.m_maxForce
  6977. };
  6978. B.prototype.SetMaxTorque = function (d) {
  6979. if (d === undefined) d = 0;
  6980. this.m_maxTorque = d
  6981. };
  6982. B.prototype.GetMaxTorque = function () {
  6983. return this.m_maxTorque
  6984. };
  6985. B.prototype.b2FrictionJoint = function (d) {
  6986. this.__super.b2Joint.call(this, d);
  6987. this.m_localAnchorA.SetV(d.localAnchorA);
  6988. this.m_localAnchorB.SetV(d.localAnchorB);
  6989. this.m_linearMass.SetZero();
  6990. this.m_angularMass = 0;
  6991. this.m_linearImpulse.SetZero();
  6992. this.m_angularImpulse = 0;
  6993. this.m_maxForce = d.maxForce;
  6994. this.m_maxTorque = d.maxTorque
  6995. };
  6996. B.prototype.InitVelocityConstraints = function (d) {
  6997. var h, l = 0,
  6998. j = this.m_bodyA,
  6999. o = this.m_bodyB;
  7000. h = j.m_xf.R;
  7001. var q = this.m_localAnchorA.x - j.m_sweep.localCenter.x,
  7002. n = this.m_localAnchorA.y - j.m_sweep.localCenter.y;
  7003. l = h.col1.x * q + h.col2.x * n;
  7004. n = h.col1.y * q + h.col2.y * n;
  7005. q = l;
  7006. h = o.m_xf.R;
  7007. var a = this.m_localAnchorB.x - o.m_sweep.localCenter.x,
  7008. c = this.m_localAnchorB.y - o.m_sweep.localCenter.y;
  7009. l = h.col1.x * a + h.col2.x * c;
  7010. c = h.col1.y * a + h.col2.y * c;
  7011. a = l;
  7012. h = j.m_invMass;
  7013. l = o.m_invMass;
  7014. var g = j.m_invI,
  7015. b = o.m_invI,
  7016. e = new G;
  7017. e.col1.x = h + l;
  7018. e.col2.x = 0;
  7019. e.col1.y = 0;
  7020. e.col2.y = h + l;
  7021. e.col1.x += g * n * n;
  7022. e.col2.x += -g * q * n;
  7023. e.col1.y += -g * q * n;
  7024. e.col2.y += g * q * q;
  7025. e.col1.x += b * c * c;
  7026. e.col2.x += -b * a * c;
  7027. e.col1.y += -b * a * c;
  7028. e.col2.y += b * a * a;
  7029. e.GetInverse(this.m_linearMass);
  7030. this.m_angularMass = g + b;
  7031. if (this.m_angularMass > 0) this.m_angularMass = 1 / this.m_angularMass;
  7032. if (d.warmStarting) {
  7033. this.m_linearImpulse.x *= d.dtRatio;
  7034. this.m_linearImpulse.y *= d.dtRatio;
  7035. this.m_angularImpulse *= d.dtRatio;
  7036. d = this.m_linearImpulse;
  7037. j.m_linearVelocity.x -= h * d.x;
  7038. j.m_linearVelocity.y -= h * d.y;
  7039. j.m_angularVelocity -= g * (q * d.y - n * d.x + this.m_angularImpulse);
  7040. o.m_linearVelocity.x += l * d.x;
  7041. o.m_linearVelocity.y += l * d.y;
  7042. o.m_angularVelocity += b * (a * d.y - c * d.x + this.m_angularImpulse)
  7043. } else {
  7044. this.m_linearImpulse.SetZero();
  7045. this.m_angularImpulse = 0
  7046. }
  7047. };
  7048. B.prototype.SolveVelocityConstraints = function (d) {
  7049. var h, l = 0,
  7050. j = this.m_bodyA,
  7051. o = this.m_bodyB,
  7052. q = j.m_linearVelocity,
  7053. n = j.m_angularVelocity,
  7054. a = o.m_linearVelocity,
  7055. c = o.m_angularVelocity,
  7056. g = j.m_invMass,
  7057. b = o.m_invMass,
  7058. e = j.m_invI,
  7059. f = o.m_invI;
  7060. h = j.m_xf.R;
  7061. var m = this.m_localAnchorA.x - j.m_sweep.localCenter.x,
  7062. r = this.m_localAnchorA.y - j.m_sweep.localCenter.y;
  7063. l = h.col1.x * m + h.col2.x * r;
  7064. r = h.col1.y * m + h.col2.y * r;
  7065. m = l;
  7066. h = o.m_xf.R;
  7067. var s = this.m_localAnchorB.x - o.m_sweep.localCenter.x,
  7068. v = this.m_localAnchorB.y - o.m_sweep.localCenter.y;
  7069. l = h.col1.x * s + h.col2.x * v;
  7070. v = h.col1.y * s + h.col2.y * v;
  7071. s = l;
  7072. h = 0;
  7073. l = -this.m_angularMass * (c - n);
  7074. var t = this.m_angularImpulse;
  7075. h = d.dt * this.m_maxTorque;
  7076. this.m_angularImpulse = y.Clamp(this.m_angularImpulse + l, -h, h);
  7077. l = this.m_angularImpulse - t;
  7078. n -= e * l;
  7079. c += f * l;
  7080. h = y.MulMV(this.m_linearMass,
  7081. new w(-(a.x - c * v - q.x + n * r), -(a.y + c * s - q.y - n * m)));
  7082. l = this.m_linearImpulse.Copy();
  7083. this.m_linearImpulse.Add(h);
  7084. h = d.dt * this.m_maxForce;
  7085. if (this.m_linearImpulse.LengthSquared() > h * h) {
  7086. this.m_linearImpulse.Normalize();
  7087. this.m_linearImpulse.Multiply(h)
  7088. }
  7089. h = y.SubtractVV(this.m_linearImpulse, l);
  7090. q.x -= g * h.x;
  7091. q.y -= g * h.y;
  7092. n -= e * (m * h.y - r * h.x);
  7093. a.x += b * h.x;
  7094. a.y += b * h.y;
  7095. c += f * (s * h.y - v * h.x);
  7096. j.m_angularVelocity = n;
  7097. o.m_angularVelocity = c
  7098. };
  7099. B.prototype.SolvePositionConstraints = function () {
  7100. return true
  7101. };
  7102. Box2D.inherit(Q, Box2D.Dynamics.Joints.b2JointDef);
  7103. Q.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7104. Q.b2FrictionJointDef = function () {
  7105. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  7106. this.localAnchorA = new w;
  7107. this.localAnchorB = new w
  7108. };
  7109. Q.prototype.b2FrictionJointDef = function () {
  7110. this.__super.b2JointDef.call(this);
  7111. this.type = I.e_frictionJoint;
  7112. this.maxTorque = this.maxForce = 0
  7113. };
  7114. Q.prototype.Initialize = function (d, h, l) {
  7115. this.bodyA = d;
  7116. this.bodyB = h;
  7117. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(l));
  7118. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(l))
  7119. };
  7120. Box2D.inherit(V, Box2D.Dynamics.Joints.b2Joint);
  7121. V.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7122. V.b2GearJoint = function () {
  7123. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7124. this.m_groundAnchor1 = new w;
  7125. this.m_groundAnchor2 = new w;
  7126. this.m_localAnchor1 = new w;
  7127. this.m_localAnchor2 = new w;
  7128. this.m_J = new L
  7129. };
  7130. V.prototype.GetAnchorA = function () {
  7131. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  7132. };
  7133. V.prototype.GetAnchorB = function () {
  7134. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  7135. };
  7136. V.prototype.GetReactionForce = function (d) {
  7137. if (d === undefined) d = 0;
  7138. return new w(d * this.m_impulse * this.m_J.linearB.x, d * this.m_impulse * this.m_J.linearB.y)
  7139. };
  7140. V.prototype.GetReactionTorque = function (d) {
  7141. if (d === undefined) d = 0;
  7142. var h = this.m_bodyB.m_xf.R,
  7143. l = this.m_localAnchor1.x - this.m_bodyB.m_sweep.localCenter.x,
  7144. j = this.m_localAnchor1.y - this.m_bodyB.m_sweep.localCenter.y,
  7145. o = h.col1.x * l + h.col2.x * j;
  7146. j = h.col1.y * l + h.col2.y * j;
  7147. l = o;
  7148. return d * (this.m_impulse * this.m_J.angularB - l * this.m_impulse * this.m_J.linearB.y + j * this.m_impulse * this.m_J.linearB.x)
  7149. };
  7150. V.prototype.GetRatio = function () {
  7151. return this.m_ratio
  7152. };
  7153. V.prototype.SetRatio = function (d) {
  7154. if (d === undefined) d = 0;
  7155. this.m_ratio = d
  7156. };
  7157. V.prototype.b2GearJoint = function (d) {
  7158. this.__super.b2Joint.call(this, d);
  7159. var h = parseInt(d.joint1.m_type),
  7160. l = parseInt(d.joint2.m_type);
  7161. this.m_prismatic2 = this.m_revolute2 = this.m_prismatic1 = this.m_revolute1 = null;
  7162. var j = 0,
  7163. o = 0;
  7164. this.m_ground1 = d.joint1.GetBodyA();
  7165. this.m_bodyA = d.joint1.GetBodyB();
  7166. if (h == I.e_revoluteJoint) {
  7167. this.m_revolute1 = d.joint1 instanceof N ? d.joint1 : null;
  7168. this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1);
  7169. this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2);
  7170. j = this.m_revolute1.GetJointAngle()
  7171. } else {
  7172. this.m_prismatic1 = d.joint1 instanceof H ? d.joint1 : null;
  7173. this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1);
  7174. this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2);
  7175. j = this.m_prismatic1.GetJointTranslation()
  7176. }
  7177. this.m_ground2 = d.joint2.GetBodyA();
  7178. this.m_bodyB = d.joint2.GetBodyB();
  7179. if (l == I.e_revoluteJoint) {
  7180. this.m_revolute2 = d.joint2 instanceof N ? d.joint2 : null;
  7181. this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1);
  7182. this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2);
  7183. o = this.m_revolute2.GetJointAngle()
  7184. } else {
  7185. this.m_prismatic2 = d.joint2 instanceof H ? d.joint2 : null;
  7186. this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1);
  7187. this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2);
  7188. o = this.m_prismatic2.GetJointTranslation()
  7189. }
  7190. this.m_ratio = d.ratio;
  7191. this.m_constant = j + this.m_ratio * o;
  7192. this.m_impulse = 0
  7193. };
  7194. V.prototype.InitVelocityConstraints = function (d) {
  7195. var h = this.m_ground1,
  7196. l = this.m_ground2,
  7197. j = this.m_bodyA,
  7198. o = this.m_bodyB,
  7199. q = 0,
  7200. n = 0,
  7201. a = 0,
  7202. c = 0,
  7203. g = a = 0,
  7204. b = 0;
  7205. this.m_J.SetZero();
  7206. if (this.m_revolute1) {
  7207. this.m_J.angularA = -1;
  7208. b += j.m_invI
  7209. } else {
  7210. h = h.m_xf.R;
  7211. n = this.m_prismatic1.m_localXAxis1;
  7212. q = h.col1.x * n.x + h.col2.x * n.y;
  7213. n = h.col1.y * n.x + h.col2.y * n.y;
  7214. h = j.m_xf.R;
  7215. a = this.m_localAnchor1.x - j.m_sweep.localCenter.x;
  7216. c = this.m_localAnchor1.y - j.m_sweep.localCenter.y;
  7217. g = h.col1.x * a + h.col2.x * c;
  7218. c = h.col1.y * a + h.col2.y * c;
  7219. a = g;
  7220. a = a * n - c * q;
  7221. this.m_J.linearA.Set(-q, -n);
  7222. this.m_J.angularA = -a;
  7223. b += j.m_invMass + j.m_invI * a * a
  7224. } if (this.m_revolute2) {
  7225. this.m_J.angularB = -this.m_ratio;
  7226. b += this.m_ratio * this.m_ratio * o.m_invI
  7227. } else {
  7228. h = l.m_xf.R;
  7229. n = this.m_prismatic2.m_localXAxis1;
  7230. q = h.col1.x * n.x + h.col2.x * n.y;
  7231. n = h.col1.y * n.x + h.col2.y * n.y;
  7232. h = o.m_xf.R;
  7233. a = this.m_localAnchor2.x - o.m_sweep.localCenter.x;
  7234. c = this.m_localAnchor2.y - o.m_sweep.localCenter.y;
  7235. g = h.col1.x * a + h.col2.x * c;
  7236. c = h.col1.y * a + h.col2.y * c;
  7237. a = g;
  7238. a = a * n - c * q;
  7239. this.m_J.linearB.Set(-this.m_ratio * q, -this.m_ratio * n);
  7240. this.m_J.angularB = -this.m_ratio * a;
  7241. b += this.m_ratio * this.m_ratio * (o.m_invMass + o.m_invI * a * a)
  7242. }
  7243. this.m_mass = b > 0 ? 1 / b : 0;
  7244. if (d.warmStarting) {
  7245. j.m_linearVelocity.x += j.m_invMass * this.m_impulse * this.m_J.linearA.x;
  7246. j.m_linearVelocity.y += j.m_invMass * this.m_impulse * this.m_J.linearA.y;
  7247. j.m_angularVelocity += j.m_invI * this.m_impulse * this.m_J.angularA;
  7248. o.m_linearVelocity.x += o.m_invMass * this.m_impulse * this.m_J.linearB.x;
  7249. o.m_linearVelocity.y += o.m_invMass * this.m_impulse * this.m_J.linearB.y;
  7250. o.m_angularVelocity += o.m_invI * this.m_impulse * this.m_J.angularB
  7251. } else this.m_impulse = 0
  7252. };
  7253. V.prototype.SolveVelocityConstraints = function () {
  7254. var d = this.m_bodyA,
  7255. h = this.m_bodyB,
  7256. l = -this.m_mass * this.m_J.Compute(d.m_linearVelocity,
  7257. d.m_angularVelocity, h.m_linearVelocity, h.m_angularVelocity);
  7258. this.m_impulse += l;
  7259. d.m_linearVelocity.x += d.m_invMass * l * this.m_J.linearA.x;
  7260. d.m_linearVelocity.y += d.m_invMass * l * this.m_J.linearA.y;
  7261. d.m_angularVelocity += d.m_invI * l * this.m_J.angularA;
  7262. h.m_linearVelocity.x += h.m_invMass * l * this.m_J.linearB.x;
  7263. h.m_linearVelocity.y += h.m_invMass * l * this.m_J.linearB.y;
  7264. h.m_angularVelocity += h.m_invI * l * this.m_J.angularB
  7265. };
  7266. V.prototype.SolvePositionConstraints = function () {
  7267. var d = this.m_bodyA,
  7268. h = this.m_bodyB,
  7269. l = 0,
  7270. j = 0;
  7271. l = this.m_revolute1 ?
  7272. this.m_revolute1.GetJointAngle() : this.m_prismatic1.GetJointTranslation();
  7273. j = this.m_revolute2 ? this.m_revolute2.GetJointAngle() : this.m_prismatic2.GetJointTranslation();
  7274. l = -this.m_mass * (this.m_constant - (l + this.m_ratio * j));
  7275. d.m_sweep.c.x += d.m_invMass * l * this.m_J.linearA.x;
  7276. d.m_sweep.c.y += d.m_invMass * l * this.m_J.linearA.y;
  7277. d.m_sweep.a += d.m_invI * l * this.m_J.angularA;
  7278. h.m_sweep.c.x += h.m_invMass * l * this.m_J.linearB.x;
  7279. h.m_sweep.c.y += h.m_invMass * l * this.m_J.linearB.y;
  7280. h.m_sweep.a += h.m_invI * l * this.m_J.angularB;
  7281. d.SynchronizeTransform();
  7282. h.SynchronizeTransform();
  7283. return 0 < F.b2_linearSlop
  7284. };
  7285. Box2D.inherit(M, Box2D.Dynamics.Joints.b2JointDef);
  7286. M.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7287. M.b2GearJointDef = function () {
  7288. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments)
  7289. };
  7290. M.prototype.b2GearJointDef = function () {
  7291. this.__super.b2JointDef.call(this);
  7292. this.type = I.e_gearJoint;
  7293. this.joint2 = this.joint1 = null;
  7294. this.ratio = 1
  7295. };
  7296. L.b2Jacobian = function () {
  7297. this.linearA = new w;
  7298. this.linearB = new w
  7299. };
  7300. L.prototype.SetZero = function () {
  7301. this.linearA.SetZero();
  7302. this.angularA = 0;
  7303. this.linearB.SetZero();
  7304. this.angularB = 0
  7305. };
  7306. L.prototype.Set = function (d, h, l, j) {
  7307. if (h === undefined) h = 0;
  7308. if (j === undefined) j = 0;
  7309. this.linearA.SetV(d);
  7310. this.angularA = h;
  7311. this.linearB.SetV(l);
  7312. this.angularB = j
  7313. };
  7314. L.prototype.Compute = function (d, h, l, j) {
  7315. if (h === undefined) h = 0;
  7316. if (j === undefined) j = 0;
  7317. return this.linearA.x * d.x + this.linearA.y * d.y + this.angularA * h + (this.linearB.x * l.x + this.linearB.y * l.y) + this.angularB * j
  7318. };
  7319. I.b2Joint = function () {
  7320. this.m_edgeA = new Y;
  7321. this.m_edgeB = new Y;
  7322. this.m_localCenterA = new w;
  7323. this.m_localCenterB = new w
  7324. };
  7325. I.prototype.GetType = function () {
  7326. return this.m_type
  7327. };
  7328. I.prototype.GetAnchorA = function () {
  7329. return null
  7330. };
  7331. I.prototype.GetAnchorB = function () {
  7332. return null
  7333. };
  7334. I.prototype.GetReactionForce = function () {
  7335. return null
  7336. };
  7337. I.prototype.GetReactionTorque = function () {
  7338. return 0
  7339. };
  7340. I.prototype.GetBodyA = function () {
  7341. return this.m_bodyA
  7342. };
  7343. I.prototype.GetBodyB = function () {
  7344. return this.m_bodyB
  7345. };
  7346. I.prototype.GetNext = function () {
  7347. return this.m_next
  7348. };
  7349. I.prototype.GetUserData = function () {
  7350. return this.m_userData
  7351. };
  7352. I.prototype.SetUserData = function (d) {
  7353. this.m_userData = d
  7354. };
  7355. I.prototype.IsActive = function () {
  7356. return this.m_bodyA.IsActive() && this.m_bodyB.IsActive()
  7357. };
  7358. I.Create = function (d) {
  7359. var h = null;
  7360. switch (d.type) {
  7361. case I.e_distanceJoint:
  7362. h = new U(d instanceof p ? d : null);
  7363. break;
  7364. case I.e_mouseJoint:
  7365. h = new u(d instanceof D ? d : null);
  7366. break;
  7367. case I.e_prismaticJoint:
  7368. h = new H(d instanceof O ? d : null);
  7369. break;
  7370. case I.e_revoluteJoint:
  7371. h = new N(d instanceof S ? d : null);
  7372. break;
  7373. case I.e_pulleyJoint:
  7374. h = new E(d instanceof R ? d : null);
  7375. break;
  7376. case I.e_gearJoint:
  7377. h = new V(d instanceof M ? d : null);
  7378. break;
  7379. case I.e_lineJoint:
  7380. h = new k(d instanceof z ? d : null);
  7381. break;
  7382. case I.e_weldJoint:
  7383. h = new aa(d instanceof Z ? d : null);
  7384. break;
  7385. case I.e_frictionJoint:
  7386. h = new B(d instanceof Q ? d : null)
  7387. }
  7388. return h
  7389. };
  7390. I.Destroy = function () {};
  7391. I.prototype.b2Joint = function (d) {
  7392. F.b2Assert(d.bodyA != d.bodyB);
  7393. this.m_type = d.type;
  7394. this.m_next = this.m_prev = null;
  7395. this.m_bodyA = d.bodyA;
  7396. this.m_bodyB = d.bodyB;
  7397. this.m_collideConnected = d.collideConnected;
  7398. this.m_islandFlag = false;
  7399. this.m_userData = d.userData
  7400. };
  7401. I.prototype.InitVelocityConstraints = function () {};
  7402. I.prototype.SolveVelocityConstraints = function () {};
  7403. I.prototype.FinalizeVelocityConstraints = function () {};
  7404. I.prototype.SolvePositionConstraints = function () {
  7405. return false
  7406. };
  7407. Box2D.postDefs.push(function () {
  7408. Box2D.Dynamics.Joints.b2Joint.e_unknownJoint = 0;
  7409. Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint = 1;
  7410. Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint = 2;
  7411. Box2D.Dynamics.Joints.b2Joint.e_distanceJoint = 3;
  7412. Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint = 4;
  7413. Box2D.Dynamics.Joints.b2Joint.e_mouseJoint = 5;
  7414. Box2D.Dynamics.Joints.b2Joint.e_gearJoint = 6;
  7415. Box2D.Dynamics.Joints.b2Joint.e_lineJoint = 7;
  7416. Box2D.Dynamics.Joints.b2Joint.e_weldJoint = 8;
  7417. Box2D.Dynamics.Joints.b2Joint.e_frictionJoint = 9;
  7418. Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit = 0;
  7419. Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit = 1;
  7420. Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit = 2;
  7421. Box2D.Dynamics.Joints.b2Joint.e_equalLimits = 3
  7422. });
  7423. W.b2JointDef = function () {};
  7424. W.prototype.b2JointDef = function () {
  7425. this.type = I.e_unknownJoint;
  7426. this.bodyB = this.bodyA = this.userData = null;
  7427. this.collideConnected = false
  7428. };
  7429. Y.b2JointEdge = function () {};
  7430. Box2D.inherit(k, Box2D.Dynamics.Joints.b2Joint);
  7431. k.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7432. k.b2LineJoint = function () {
  7433. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7434. this.m_localAnchor1 = new w;
  7435. this.m_localAnchor2 = new w;
  7436. this.m_localXAxis1 = new w;
  7437. this.m_localYAxis1 = new w;
  7438. this.m_axis = new w;
  7439. this.m_perp = new w;
  7440. this.m_K = new G;
  7441. this.m_impulse = new w
  7442. };
  7443. k.prototype.GetAnchorA = function () {
  7444. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  7445. };
  7446. k.prototype.GetAnchorB = function () {
  7447. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  7448. };
  7449. k.prototype.GetReactionForce = function (d) {
  7450. if (d === undefined) d = 0;
  7451. return new w(d * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x), d * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y))
  7452. };
  7453. k.prototype.GetReactionTorque = function (d) {
  7454. if (d === undefined) d = 0;
  7455. return d * this.m_impulse.y
  7456. };
  7457. k.prototype.GetJointTranslation = function () {
  7458. var d = this.m_bodyA,
  7459. h = this.m_bodyB,
  7460. l = d.GetWorldPoint(this.m_localAnchor1),
  7461. j = h.GetWorldPoint(this.m_localAnchor2);
  7462. h = j.x - l.x;
  7463. l = j.y - l.y;
  7464. d = d.GetWorldVector(this.m_localXAxis1);
  7465. return d.x * h + d.y * l
  7466. };
  7467. k.prototype.GetJointSpeed = function () {
  7468. var d = this.m_bodyA,
  7469. h = this.m_bodyB,
  7470. l;
  7471. l = d.m_xf.R;
  7472. var j = this.m_localAnchor1.x - d.m_sweep.localCenter.x,
  7473. o = this.m_localAnchor1.y - d.m_sweep.localCenter.y,
  7474. q = l.col1.x * j + l.col2.x * o;
  7475. o = l.col1.y * j + l.col2.y * o;
  7476. j = q;
  7477. l = h.m_xf.R;
  7478. var n = this.m_localAnchor2.x - h.m_sweep.localCenter.x,
  7479. a = this.m_localAnchor2.y - h.m_sweep.localCenter.y;
  7480. q = l.col1.x * n + l.col2.x * a;
  7481. a = l.col1.y * n + l.col2.y * a;
  7482. n = q;
  7483. l = h.m_sweep.c.x + n - (d.m_sweep.c.x + j);
  7484. q = h.m_sweep.c.y + a - (d.m_sweep.c.y + o);
  7485. var c = d.GetWorldVector(this.m_localXAxis1),
  7486. g = d.m_linearVelocity,
  7487. b = h.m_linearVelocity;
  7488. d = d.m_angularVelocity;
  7489. h = h.m_angularVelocity;
  7490. return l * -d * c.y + q * d * c.x + (c.x * (b.x + -h * a - g.x - -d * o) + c.y * (b.y + h * n - g.y - d * j))
  7491. };
  7492. k.prototype.IsLimitEnabled = function () {
  7493. return this.m_enableLimit
  7494. };
  7495. k.prototype.EnableLimit = function (d) {
  7496. this.m_bodyA.SetAwake(true);
  7497. this.m_bodyB.SetAwake(true);
  7498. this.m_enableLimit = d
  7499. };
  7500. k.prototype.GetLowerLimit = function () {
  7501. return this.m_lowerTranslation
  7502. };
  7503. k.prototype.GetUpperLimit = function () {
  7504. return this.m_upperTranslation
  7505. };
  7506. k.prototype.SetLimits = function (d,
  7507. h) {
  7508. if (d === undefined) d = 0;
  7509. if (h === undefined) h = 0;
  7510. this.m_bodyA.SetAwake(true);
  7511. this.m_bodyB.SetAwake(true);
  7512. this.m_lowerTranslation = d;
  7513. this.m_upperTranslation = h
  7514. };
  7515. k.prototype.IsMotorEnabled = function () {
  7516. return this.m_enableMotor
  7517. };
  7518. k.prototype.EnableMotor = function (d) {
  7519. this.m_bodyA.SetAwake(true);
  7520. this.m_bodyB.SetAwake(true);
  7521. this.m_enableMotor = d
  7522. };
  7523. k.prototype.SetMotorSpeed = function (d) {
  7524. if (d === undefined) d = 0;
  7525. this.m_bodyA.SetAwake(true);
  7526. this.m_bodyB.SetAwake(true);
  7527. this.m_motorSpeed = d
  7528. };
  7529. k.prototype.GetMotorSpeed = function () {
  7530. return this.m_motorSpeed
  7531. };
  7532. k.prototype.SetMaxMotorForce = function (d) {
  7533. if (d === undefined) d = 0;
  7534. this.m_bodyA.SetAwake(true);
  7535. this.m_bodyB.SetAwake(true);
  7536. this.m_maxMotorForce = d
  7537. };
  7538. k.prototype.GetMaxMotorForce = function () {
  7539. return this.m_maxMotorForce
  7540. };
  7541. k.prototype.GetMotorForce = function () {
  7542. return this.m_motorImpulse
  7543. };
  7544. k.prototype.b2LineJoint = function (d) {
  7545. this.__super.b2Joint.call(this, d);
  7546. this.m_localAnchor1.SetV(d.localAnchorA);
  7547. this.m_localAnchor2.SetV(d.localAnchorB);
  7548. this.m_localXAxis1.SetV(d.localAxisA);
  7549. this.m_localYAxis1.x = -this.m_localXAxis1.y;
  7550. this.m_localYAxis1.y = this.m_localXAxis1.x;
  7551. this.m_impulse.SetZero();
  7552. this.m_motorImpulse = this.m_motorMass = 0;
  7553. this.m_lowerTranslation = d.lowerTranslation;
  7554. this.m_upperTranslation = d.upperTranslation;
  7555. this.m_maxMotorForce = d.maxMotorForce;
  7556. this.m_motorSpeed = d.motorSpeed;
  7557. this.m_enableLimit = d.enableLimit;
  7558. this.m_enableMotor = d.enableMotor;
  7559. this.m_limitState = I.e_inactiveLimit;
  7560. this.m_axis.SetZero();
  7561. this.m_perp.SetZero()
  7562. };
  7563. k.prototype.InitVelocityConstraints = function (d) {
  7564. var h = this.m_bodyA,
  7565. l = this.m_bodyB,
  7566. j, o = 0;
  7567. this.m_localCenterA.SetV(h.GetLocalCenter());
  7568. this.m_localCenterB.SetV(l.GetLocalCenter());
  7569. var q = h.GetTransform();
  7570. l.GetTransform();
  7571. j = h.m_xf.R;
  7572. var n = this.m_localAnchor1.x - this.m_localCenterA.x,
  7573. a = this.m_localAnchor1.y - this.m_localCenterA.y;
  7574. o = j.col1.x * n + j.col2.x * a;
  7575. a = j.col1.y * n + j.col2.y * a;
  7576. n = o;
  7577. j = l.m_xf.R;
  7578. var c = this.m_localAnchor2.x - this.m_localCenterB.x,
  7579. g = this.m_localAnchor2.y - this.m_localCenterB.y;
  7580. o = j.col1.x * c + j.col2.x * g;
  7581. g = j.col1.y * c + j.col2.y * g;
  7582. c = o;
  7583. j = l.m_sweep.c.x + c - h.m_sweep.c.x - n;
  7584. o = l.m_sweep.c.y + g - h.m_sweep.c.y - a;
  7585. this.m_invMassA = h.m_invMass;
  7586. this.m_invMassB = l.m_invMass;
  7587. this.m_invIA = h.m_invI;
  7588. this.m_invIB = l.m_invI;
  7589. this.m_axis.SetV(y.MulMV(q.R, this.m_localXAxis1));
  7590. this.m_a1 = (j + n) * this.m_axis.y - (o + a) * this.m_axis.x;
  7591. this.m_a2 = c * this.m_axis.y - g * this.m_axis.x;
  7592. 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;
  7593. this.m_motorMass = this.m_motorMass > Number.MIN_VALUE ? 1 / this.m_motorMass : 0;
  7594. this.m_perp.SetV(y.MulMV(q.R, this.m_localYAxis1));
  7595. this.m_s1 = (j + n) * this.m_perp.y - (o + a) * this.m_perp.x;
  7596. this.m_s2 = c * this.m_perp.y - g * this.m_perp.x;
  7597. q = this.m_invMassA;
  7598. n = this.m_invMassB;
  7599. a = this.m_invIA;
  7600. c = this.m_invIB;
  7601. this.m_K.col1.x = q + n + a * this.m_s1 * this.m_s1 + c * this.m_s2 * this.m_s2;
  7602. this.m_K.col1.y = a * this.m_s1 * this.m_a1 + c * this.m_s2 * this.m_a2;
  7603. this.m_K.col2.x = this.m_K.col1.y;
  7604. this.m_K.col2.y = q + n + a * this.m_a1 * this.m_a1 + c * this.m_a2 * this.m_a2;
  7605. if (this.m_enableLimit) {
  7606. j = this.m_axis.x * j + this.m_axis.y * o;
  7607. if (y.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * F.b2_linearSlop) this.m_limitState = I.e_equalLimits;
  7608. else if (j <= this.m_lowerTranslation) {
  7609. if (this.m_limitState != I.e_atLowerLimit) {
  7610. this.m_limitState = I.e_atLowerLimit;
  7611. this.m_impulse.y = 0
  7612. }
  7613. } else if (j >= this.m_upperTranslation) {
  7614. if (this.m_limitState != I.e_atUpperLimit) {
  7615. this.m_limitState = I.e_atUpperLimit;
  7616. this.m_impulse.y = 0
  7617. }
  7618. } else {
  7619. this.m_limitState = I.e_inactiveLimit;
  7620. this.m_impulse.y = 0
  7621. }
  7622. } else this.m_limitState = I.e_inactiveLimit; if (this.m_enableMotor == false) this.m_motorImpulse = 0;
  7623. if (d.warmStarting) {
  7624. this.m_impulse.x *= d.dtRatio;
  7625. this.m_impulse.y *= d.dtRatio;
  7626. this.m_motorImpulse *= d.dtRatio;
  7627. d = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x;
  7628. j = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y;
  7629. o = this.m_impulse.x * this.m_s1 + (this.m_motorImpulse + this.m_impulse.y) * this.m_a1;
  7630. q = this.m_impulse.x * this.m_s2 + (this.m_motorImpulse + this.m_impulse.y) * this.m_a2;
  7631. h.m_linearVelocity.x -= this.m_invMassA * d;
  7632. h.m_linearVelocity.y -= this.m_invMassA * j;
  7633. h.m_angularVelocity -= this.m_invIA * o;
  7634. l.m_linearVelocity.x += this.m_invMassB * d;
  7635. l.m_linearVelocity.y += this.m_invMassB * j;
  7636. l.m_angularVelocity += this.m_invIB * q
  7637. } else {
  7638. this.m_impulse.SetZero();
  7639. this.m_motorImpulse = 0
  7640. }
  7641. };
  7642. k.prototype.SolveVelocityConstraints = function (d) {
  7643. var h = this.m_bodyA,
  7644. l = this.m_bodyB,
  7645. j = h.m_linearVelocity,
  7646. o = h.m_angularVelocity,
  7647. q = l.m_linearVelocity,
  7648. n = l.m_angularVelocity,
  7649. a = 0,
  7650. c = 0,
  7651. g = 0,
  7652. b = 0;
  7653. if (this.m_enableMotor && this.m_limitState != I.e_equalLimits) {
  7654. b = this.m_motorMass * (this.m_motorSpeed - (this.m_axis.x * (q.x - j.x) + this.m_axis.y * (q.y - j.y) + this.m_a2 * n - this.m_a1 * o));
  7655. a = this.m_motorImpulse;
  7656. c = d.dt * this.m_maxMotorForce;
  7657. this.m_motorImpulse = y.Clamp(this.m_motorImpulse + b, -c, c);
  7658. b = this.m_motorImpulse - a;
  7659. a = b * this.m_axis.x;
  7660. c = b * this.m_axis.y;
  7661. g = b * this.m_a1;
  7662. b = b * this.m_a2;
  7663. j.x -= this.m_invMassA * a;
  7664. j.y -= this.m_invMassA * c;
  7665. o -= this.m_invIA * g;
  7666. q.x += this.m_invMassB * a;
  7667. q.y += this.m_invMassB * c;
  7668. n += this.m_invIB * b
  7669. }
  7670. c = this.m_perp.x * (q.x - j.x) + this.m_perp.y * (q.y - j.y) + this.m_s2 * n - this.m_s1 * o;
  7671. if (this.m_enableLimit && this.m_limitState != I.e_inactiveLimit) {
  7672. g = this.m_axis.x * (q.x - j.x) + this.m_axis.y * (q.y - j.y) + this.m_a2 * n - this.m_a1 * o;
  7673. a = this.m_impulse.Copy();
  7674. d = this.m_K.Solve(new w, -c, -g);
  7675. this.m_impulse.Add(d);
  7676. if (this.m_limitState == I.e_atLowerLimit) this.m_impulse.y = y.Max(this.m_impulse.y, 0);
  7677. else if (this.m_limitState == I.e_atUpperLimit) this.m_impulse.y = y.Min(this.m_impulse.y, 0);
  7678. c = -c - (this.m_impulse.y - a.y) * this.m_K.col2.x;
  7679. g = 0;
  7680. g = this.m_K.col1.x != 0 ? c / this.m_K.col1.x + a.x : a.x;
  7681. this.m_impulse.x = g;
  7682. d.x = this.m_impulse.x - a.x;
  7683. d.y = this.m_impulse.y - a.y;
  7684. a = d.x * this.m_perp.x + d.y * this.m_axis.x;
  7685. c = d.x * this.m_perp.y + d.y * this.m_axis.y;
  7686. g = d.x * this.m_s1 + d.y * this.m_a1;
  7687. b = d.x * this.m_s2 + d.y * this.m_a2
  7688. } else {
  7689. d = 0;
  7690. d = this.m_K.col1.x != 0 ? -c / this.m_K.col1.x : 0;
  7691. this.m_impulse.x += d;
  7692. a = d * this.m_perp.x;
  7693. c = d * this.m_perp.y;
  7694. g = d * this.m_s1;
  7695. b = d * this.m_s2
  7696. }
  7697. j.x -= this.m_invMassA * a;
  7698. j.y -= this.m_invMassA * c;
  7699. o -= this.m_invIA * g;
  7700. q.x += this.m_invMassB * a;
  7701. q.y += this.m_invMassB * c;
  7702. n += this.m_invIB * b;
  7703. h.m_linearVelocity.SetV(j);
  7704. h.m_angularVelocity = o;
  7705. l.m_linearVelocity.SetV(q);
  7706. l.m_angularVelocity = n
  7707. };
  7708. k.prototype.SolvePositionConstraints = function () {
  7709. var d = this.m_bodyA,
  7710. h = this.m_bodyB,
  7711. l = d.m_sweep.c,
  7712. j = d.m_sweep.a,
  7713. o = h.m_sweep.c,
  7714. q = h.m_sweep.a,
  7715. n, a = 0,
  7716. c = 0,
  7717. g = 0,
  7718. b = 0,
  7719. e = n = 0,
  7720. f = 0;
  7721. c = false;
  7722. var m = 0,
  7723. r = G.FromAngle(j);
  7724. g = G.FromAngle(q);
  7725. n = r;
  7726. f = this.m_localAnchor1.x - this.m_localCenterA.x;
  7727. var s = this.m_localAnchor1.y - this.m_localCenterA.y;
  7728. a = n.col1.x * f + n.col2.x * s;
  7729. s = n.col1.y * f + n.col2.y * s;
  7730. f = a;
  7731. n = g;
  7732. g = this.m_localAnchor2.x - this.m_localCenterB.x;
  7733. b = this.m_localAnchor2.y - this.m_localCenterB.y;
  7734. a = n.col1.x * g + n.col2.x * b;
  7735. b = n.col1.y * g + n.col2.y * b;
  7736. g = a;
  7737. n = o.x + g - l.x - f;
  7738. a = o.y + b - l.y - s;
  7739. if (this.m_enableLimit) {
  7740. this.m_axis = y.MulMV(r, this.m_localXAxis1);
  7741. this.m_a1 = (n + f) * this.m_axis.y - (a + s) * this.m_axis.x;
  7742. this.m_a2 = g * this.m_axis.y - b * this.m_axis.x;
  7743. var v = this.m_axis.x * n + this.m_axis.y * a;
  7744. if (y.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * F.b2_linearSlop) {
  7745. m = y.Clamp(v, -F.b2_maxLinearCorrection, F.b2_maxLinearCorrection);
  7746. e = y.Abs(v);
  7747. c = true
  7748. } else if (v <= this.m_lowerTranslation) {
  7749. m = y.Clamp(v - this.m_lowerTranslation + F.b2_linearSlop, -F.b2_maxLinearCorrection, 0);
  7750. e = this.m_lowerTranslation - v;
  7751. c = true
  7752. } else if (v >= this.m_upperTranslation) {
  7753. m = y.Clamp(v - this.m_upperTranslation + F.b2_linearSlop, 0, F.b2_maxLinearCorrection);
  7754. e = v - this.m_upperTranslation;
  7755. c = true
  7756. }
  7757. }
  7758. this.m_perp = y.MulMV(r, this.m_localYAxis1);
  7759. this.m_s1 = (n + f) * this.m_perp.y - (a + s) * this.m_perp.x;
  7760. this.m_s2 = g * this.m_perp.y - b * this.m_perp.x;
  7761. r = new w;
  7762. s = this.m_perp.x * n + this.m_perp.y * a;
  7763. e = y.Max(e, y.Abs(s));
  7764. f = 0;
  7765. if (c) {
  7766. c = this.m_invMassA;
  7767. g = this.m_invMassB;
  7768. b = this.m_invIA;
  7769. n = this.m_invIB;
  7770. this.m_K.col1.x = c + g + b * this.m_s1 * this.m_s1 + n * this.m_s2 * this.m_s2;
  7771. this.m_K.col1.y = b * this.m_s1 * this.m_a1 + n * this.m_s2 * this.m_a2;
  7772. this.m_K.col2.x = this.m_K.col1.y;
  7773. this.m_K.col2.y = c + g + b * this.m_a1 * this.m_a1 + n * this.m_a2 * this.m_a2;
  7774. this.m_K.Solve(r, -s, -m)
  7775. } else {
  7776. c = this.m_invMassA;
  7777. g = this.m_invMassB;
  7778. b = this.m_invIA;
  7779. n = this.m_invIB;
  7780. m = c + g + b * this.m_s1 * this.m_s1 + n * this.m_s2 * this.m_s2;
  7781. c = 0;
  7782. c = m != 0 ? -s / m : 0;
  7783. r.x = c;
  7784. r.y = 0
  7785. }
  7786. m = r.x * this.m_perp.x + r.y * this.m_axis.x;
  7787. c = r.x * this.m_perp.y + r.y * this.m_axis.y;
  7788. s = r.x * this.m_s1 + r.y * this.m_a1;
  7789. r = r.x * this.m_s2 + r.y * this.m_a2;
  7790. l.x -= this.m_invMassA * m;
  7791. l.y -= this.m_invMassA * c;
  7792. j -= this.m_invIA * s;
  7793. o.x += this.m_invMassB * m;
  7794. o.y += this.m_invMassB * c;
  7795. q += this.m_invIB * r;
  7796. d.m_sweep.a = j;
  7797. h.m_sweep.a = q;
  7798. d.SynchronizeTransform();
  7799. h.SynchronizeTransform();
  7800. return e <= F.b2_linearSlop && f <= F.b2_angularSlop
  7801. };
  7802. Box2D.inherit(z, Box2D.Dynamics.Joints.b2JointDef);
  7803. z.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7804. z.b2LineJointDef = function () {
  7805. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  7806. this.localAnchorA = new w;
  7807. this.localAnchorB = new w;
  7808. this.localAxisA = new w
  7809. };
  7810. z.prototype.b2LineJointDef = function () {
  7811. this.__super.b2JointDef.call(this);
  7812. this.type = I.e_lineJoint;
  7813. this.localAxisA.Set(1, 0);
  7814. this.enableLimit = false;
  7815. this.upperTranslation = this.lowerTranslation = 0;
  7816. this.enableMotor = false;
  7817. this.motorSpeed = this.maxMotorForce = 0
  7818. };
  7819. z.prototype.Initialize = function (d, h, l, j) {
  7820. this.bodyA = d;
  7821. this.bodyB = h;
  7822. this.localAnchorA = this.bodyA.GetLocalPoint(l);
  7823. this.localAnchorB = this.bodyB.GetLocalPoint(l);
  7824. this.localAxisA = this.bodyA.GetLocalVector(j)
  7825. };
  7826. Box2D.inherit(u, Box2D.Dynamics.Joints.b2Joint);
  7827. u.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7828. u.b2MouseJoint = function () {
  7829. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7830. this.K = new G;
  7831. this.K1 = new G;
  7832. this.K2 = new G;
  7833. this.m_localAnchor = new w;
  7834. this.m_target = new w;
  7835. this.m_impulse = new w;
  7836. this.m_mass = new G;
  7837. this.m_C = new w
  7838. };
  7839. u.prototype.GetAnchorA = function () {
  7840. return this.m_target
  7841. };
  7842. u.prototype.GetAnchorB = function () {
  7843. return this.m_bodyB.GetWorldPoint(this.m_localAnchor)
  7844. };
  7845. u.prototype.GetReactionForce = function (d) {
  7846. if (d === undefined) d = 0;
  7847. return new w(d * this.m_impulse.x, d * this.m_impulse.y)
  7848. };
  7849. u.prototype.GetReactionTorque = function () {
  7850. return 0
  7851. };
  7852. u.prototype.GetTarget = function () {
  7853. return this.m_target
  7854. };
  7855. u.prototype.SetTarget = function (d) {
  7856. this.m_bodyB.IsAwake() == false && this.m_bodyB.SetAwake(true);
  7857. this.m_target = d
  7858. };
  7859. u.prototype.GetMaxForce = function () {
  7860. return this.m_maxForce
  7861. };
  7862. u.prototype.SetMaxForce = function (d) {
  7863. if (d === undefined) d = 0;
  7864. this.m_maxForce = d
  7865. };
  7866. u.prototype.GetFrequency = function () {
  7867. return this.m_frequencyHz
  7868. };
  7869. u.prototype.SetFrequency = function (d) {
  7870. if (d === undefined) d = 0;
  7871. this.m_frequencyHz = d
  7872. };
  7873. u.prototype.GetDampingRatio = function () {
  7874. return this.m_dampingRatio
  7875. };
  7876. u.prototype.SetDampingRatio = function (d) {
  7877. if (d === undefined) d = 0;
  7878. this.m_dampingRatio = d
  7879. };
  7880. u.prototype.b2MouseJoint = function (d) {
  7881. this.__super.b2Joint.call(this, d);
  7882. this.m_target.SetV(d.target);
  7883. var h = this.m_target.x - this.m_bodyB.m_xf.position.x,
  7884. l = this.m_target.y - this.m_bodyB.m_xf.position.y,
  7885. j = this.m_bodyB.m_xf.R;
  7886. this.m_localAnchor.x = h * j.col1.x + l * j.col1.y;
  7887. this.m_localAnchor.y = h * j.col2.x + l * j.col2.y;
  7888. this.m_maxForce = d.maxForce;
  7889. this.m_impulse.SetZero();
  7890. this.m_frequencyHz = d.frequencyHz;
  7891. this.m_dampingRatio = d.dampingRatio;
  7892. this.m_gamma = this.m_beta = 0
  7893. };
  7894. u.prototype.InitVelocityConstraints = function (d) {
  7895. var h = this.m_bodyB,
  7896. l = h.GetMass(),
  7897. j = 2 * Math.PI * this.m_frequencyHz,
  7898. o = l * j * j;
  7899. this.m_gamma = d.dt * (2 * l * this.m_dampingRatio * j + d.dt * o);
  7900. this.m_gamma = this.m_gamma != 0 ? 1 / this.m_gamma : 0;
  7901. this.m_beta = d.dt * o * this.m_gamma;
  7902. o = h.m_xf.R;
  7903. l = this.m_localAnchor.x - h.m_sweep.localCenter.x;
  7904. j = this.m_localAnchor.y - h.m_sweep.localCenter.y;
  7905. var q = o.col1.x * l + o.col2.x * j;
  7906. j = o.col1.y * l + o.col2.y * j;
  7907. l = q;
  7908. o = h.m_invMass;
  7909. q = h.m_invI;
  7910. this.K1.col1.x = o;
  7911. this.K1.col2.x = 0;
  7912. this.K1.col1.y = 0;
  7913. this.K1.col2.y = o;
  7914. this.K2.col1.x = q * j * j;
  7915. this.K2.col2.x = -q * l * j;
  7916. this.K2.col1.y = -q * l * j;
  7917. this.K2.col2.y = q * l * l;
  7918. this.K.SetM(this.K1);
  7919. this.K.AddM(this.K2);
  7920. this.K.col1.x += this.m_gamma;
  7921. this.K.col2.y += this.m_gamma;
  7922. this.K.GetInverse(this.m_mass);
  7923. this.m_C.x = h.m_sweep.c.x + l - this.m_target.x;
  7924. this.m_C.y = h.m_sweep.c.y + j - this.m_target.y;
  7925. h.m_angularVelocity *= 0.98;
  7926. this.m_impulse.x *= d.dtRatio;
  7927. this.m_impulse.y *= d.dtRatio;
  7928. h.m_linearVelocity.x += o * this.m_impulse.x;
  7929. h.m_linearVelocity.y += o * this.m_impulse.y;
  7930. h.m_angularVelocity += q * (l * this.m_impulse.y - j * this.m_impulse.x)
  7931. };
  7932. u.prototype.SolveVelocityConstraints = function (d) {
  7933. var h = this.m_bodyB,
  7934. l, j = 0,
  7935. o = 0;
  7936. l = h.m_xf.R;
  7937. var q = this.m_localAnchor.x - h.m_sweep.localCenter.x,
  7938. n = this.m_localAnchor.y - h.m_sweep.localCenter.y;
  7939. j = l.col1.x * q + l.col2.x * n;
  7940. n = l.col1.y * q + l.col2.y * n;
  7941. q = j;
  7942. j = h.m_linearVelocity.x + -h.m_angularVelocity * n;
  7943. var a = h.m_linearVelocity.y + h.m_angularVelocity * q;
  7944. l = this.m_mass;
  7945. j = j + this.m_beta * this.m_C.x + this.m_gamma * this.m_impulse.x;
  7946. o = a + this.m_beta * this.m_C.y + this.m_gamma * this.m_impulse.y;
  7947. a = -(l.col1.x * j + l.col2.x * o);
  7948. o = -(l.col1.y * j + l.col2.y * o);
  7949. l = this.m_impulse.x;
  7950. j = this.m_impulse.y;
  7951. this.m_impulse.x += a;
  7952. this.m_impulse.y += o;
  7953. d = d.dt * this.m_maxForce;
  7954. this.m_impulse.LengthSquared() > d * d && this.m_impulse.Multiply(d / this.m_impulse.Length());
  7955. a = this.m_impulse.x - l;
  7956. o = this.m_impulse.y - j;
  7957. h.m_linearVelocity.x += h.m_invMass * a;
  7958. h.m_linearVelocity.y += h.m_invMass * o;
  7959. h.m_angularVelocity += h.m_invI * (q * o - n * a)
  7960. };
  7961. u.prototype.SolvePositionConstraints = function () {
  7962. return true
  7963. };
  7964. Box2D.inherit(D, Box2D.Dynamics.Joints.b2JointDef);
  7965. D.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  7966. D.b2MouseJointDef = function () {
  7967. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
  7968. arguments);
  7969. this.target = new w
  7970. };
  7971. D.prototype.b2MouseJointDef = function () {
  7972. this.__super.b2JointDef.call(this);
  7973. this.type = I.e_mouseJoint;
  7974. this.maxForce = 0;
  7975. this.frequencyHz = 5;
  7976. this.dampingRatio = 0.7
  7977. };
  7978. Box2D.inherit(H, Box2D.Dynamics.Joints.b2Joint);
  7979. H.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  7980. H.b2PrismaticJoint = function () {
  7981. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  7982. this.m_localAnchor1 = new w;
  7983. this.m_localAnchor2 = new w;
  7984. this.m_localXAxis1 = new w;
  7985. this.m_localYAxis1 = new w;
  7986. this.m_axis = new w;
  7987. this.m_perp = new w;
  7988. this.m_K = new K;
  7989. this.m_impulse = new A
  7990. };
  7991. H.prototype.GetAnchorA = function () {
  7992. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  7993. };
  7994. H.prototype.GetAnchorB = function () {
  7995. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  7996. };
  7997. H.prototype.GetReactionForce = function (d) {
  7998. if (d === undefined) d = 0;
  7999. return new w(d * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x), d * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y))
  8000. };
  8001. H.prototype.GetReactionTorque = function (d) {
  8002. if (d === undefined) d = 0;
  8003. return d * this.m_impulse.y
  8004. };
  8005. H.prototype.GetJointTranslation = function () {
  8006. var d = this.m_bodyA,
  8007. h = this.m_bodyB,
  8008. l = d.GetWorldPoint(this.m_localAnchor1),
  8009. j = h.GetWorldPoint(this.m_localAnchor2);
  8010. h = j.x - l.x;
  8011. l = j.y - l.y;
  8012. d = d.GetWorldVector(this.m_localXAxis1);
  8013. return d.x * h + d.y * l
  8014. };
  8015. H.prototype.GetJointSpeed = function () {
  8016. var d = this.m_bodyA,
  8017. h = this.m_bodyB,
  8018. l;
  8019. l = d.m_xf.R;
  8020. var j = this.m_localAnchor1.x - d.m_sweep.localCenter.x,
  8021. o = this.m_localAnchor1.y - d.m_sweep.localCenter.y,
  8022. q = l.col1.x * j + l.col2.x * o;
  8023. o = l.col1.y * j + l.col2.y * o;
  8024. j = q;
  8025. l = h.m_xf.R;
  8026. var n = this.m_localAnchor2.x - h.m_sweep.localCenter.x,
  8027. a = this.m_localAnchor2.y - h.m_sweep.localCenter.y;
  8028. q = l.col1.x * n + l.col2.x * a;
  8029. a = l.col1.y * n + l.col2.y * a;
  8030. n = q;
  8031. l = h.m_sweep.c.x + n - (d.m_sweep.c.x + j);
  8032. q = h.m_sweep.c.y + a - (d.m_sweep.c.y + o);
  8033. var c = d.GetWorldVector(this.m_localXAxis1),
  8034. g = d.m_linearVelocity,
  8035. b = h.m_linearVelocity;
  8036. d = d.m_angularVelocity;
  8037. h = h.m_angularVelocity;
  8038. return l * -d * c.y + q * d * c.x + (c.x * (b.x + -h * a - g.x - -d * o) + c.y * (b.y + h * n - g.y - d * j))
  8039. };
  8040. H.prototype.IsLimitEnabled = function () {
  8041. return this.m_enableLimit
  8042. };
  8043. H.prototype.EnableLimit = function (d) {
  8044. this.m_bodyA.SetAwake(true);
  8045. this.m_bodyB.SetAwake(true);
  8046. this.m_enableLimit = d
  8047. };
  8048. H.prototype.GetLowerLimit = function () {
  8049. return this.m_lowerTranslation
  8050. };
  8051. H.prototype.GetUpperLimit = function () {
  8052. return this.m_upperTranslation
  8053. };
  8054. H.prototype.SetLimits = function (d, h) {
  8055. if (d === undefined) d = 0;
  8056. if (h === undefined) h = 0;
  8057. this.m_bodyA.SetAwake(true);
  8058. this.m_bodyB.SetAwake(true);
  8059. this.m_lowerTranslation = d;
  8060. this.m_upperTranslation = h
  8061. };
  8062. H.prototype.IsMotorEnabled = function () {
  8063. return this.m_enableMotor
  8064. };
  8065. H.prototype.EnableMotor = function (d) {
  8066. this.m_bodyA.SetAwake(true);
  8067. this.m_bodyB.SetAwake(true);
  8068. this.m_enableMotor = d
  8069. };
  8070. H.prototype.SetMotorSpeed = function (d) {
  8071. if (d === undefined) d = 0;
  8072. this.m_bodyA.SetAwake(true);
  8073. this.m_bodyB.SetAwake(true);
  8074. this.m_motorSpeed = d
  8075. };
  8076. H.prototype.GetMotorSpeed = function () {
  8077. return this.m_motorSpeed
  8078. };
  8079. H.prototype.SetMaxMotorForce = function (d) {
  8080. if (d === undefined) d = 0;
  8081. this.m_bodyA.SetAwake(true);
  8082. this.m_bodyB.SetAwake(true);
  8083. this.m_maxMotorForce = d
  8084. };
  8085. H.prototype.GetMotorForce = function () {
  8086. return this.m_motorImpulse
  8087. };
  8088. H.prototype.b2PrismaticJoint = function (d) {
  8089. this.__super.b2Joint.call(this, d);
  8090. this.m_localAnchor1.SetV(d.localAnchorA);
  8091. this.m_localAnchor2.SetV(d.localAnchorB);
  8092. this.m_localXAxis1.SetV(d.localAxisA);
  8093. this.m_localYAxis1.x = -this.m_localXAxis1.y;
  8094. this.m_localYAxis1.y = this.m_localXAxis1.x;
  8095. this.m_refAngle = d.referenceAngle;
  8096. this.m_impulse.SetZero();
  8097. this.m_motorImpulse = this.m_motorMass = 0;
  8098. this.m_lowerTranslation = d.lowerTranslation;
  8099. this.m_upperTranslation = d.upperTranslation;
  8100. this.m_maxMotorForce = d.maxMotorForce;
  8101. this.m_motorSpeed = d.motorSpeed;
  8102. this.m_enableLimit = d.enableLimit;
  8103. this.m_enableMotor = d.enableMotor;
  8104. this.m_limitState = I.e_inactiveLimit;
  8105. this.m_axis.SetZero();
  8106. this.m_perp.SetZero()
  8107. };
  8108. H.prototype.InitVelocityConstraints = function (d) {
  8109. var h = this.m_bodyA,
  8110. l = this.m_bodyB,
  8111. j, o = 0;
  8112. this.m_localCenterA.SetV(h.GetLocalCenter());
  8113. this.m_localCenterB.SetV(l.GetLocalCenter());
  8114. var q = h.GetTransform();
  8115. l.GetTransform();
  8116. j = h.m_xf.R;
  8117. var n = this.m_localAnchor1.x - this.m_localCenterA.x,
  8118. a = this.m_localAnchor1.y - this.m_localCenterA.y;
  8119. o = j.col1.x * n + j.col2.x * a;
  8120. a = j.col1.y * n + j.col2.y * a;
  8121. n = o;
  8122. j = l.m_xf.R;
  8123. var c = this.m_localAnchor2.x - this.m_localCenterB.x,
  8124. g = this.m_localAnchor2.y - this.m_localCenterB.y;
  8125. o = j.col1.x * c + j.col2.x * g;
  8126. g = j.col1.y * c + j.col2.y * g;
  8127. c = o;
  8128. j = l.m_sweep.c.x + c - h.m_sweep.c.x - n;
  8129. o = l.m_sweep.c.y + g - h.m_sweep.c.y - a;
  8130. this.m_invMassA = h.m_invMass;
  8131. this.m_invMassB = l.m_invMass;
  8132. this.m_invIA = h.m_invI;
  8133. this.m_invIB = l.m_invI;
  8134. this.m_axis.SetV(y.MulMV(q.R, this.m_localXAxis1));
  8135. this.m_a1 = (j + n) * this.m_axis.y - (o + a) * this.m_axis.x;
  8136. this.m_a2 = c * this.m_axis.y - g * this.m_axis.x;
  8137. 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;
  8138. if (this.m_motorMass > Number.MIN_VALUE) this.m_motorMass = 1 / this.m_motorMass;
  8139. this.m_perp.SetV(y.MulMV(q.R, this.m_localYAxis1));
  8140. this.m_s1 = (j + n) * this.m_perp.y - (o + a) * this.m_perp.x;
  8141. this.m_s2 = c * this.m_perp.y - g * this.m_perp.x;
  8142. q = this.m_invMassA;
  8143. n = this.m_invMassB;
  8144. a = this.m_invIA;
  8145. c = this.m_invIB;
  8146. this.m_K.col1.x = q + n + a * this.m_s1 * this.m_s1 + c * this.m_s2 * this.m_s2;
  8147. this.m_K.col1.y = a * this.m_s1 + c * this.m_s2;
  8148. this.m_K.col1.z = a * this.m_s1 * this.m_a1 + c * this.m_s2 * this.m_a2;
  8149. this.m_K.col2.x = this.m_K.col1.y;
  8150. this.m_K.col2.y = a + c;
  8151. this.m_K.col2.z = a * this.m_a1 + c * this.m_a2;
  8152. this.m_K.col3.x = this.m_K.col1.z;
  8153. this.m_K.col3.y = this.m_K.col2.z;
  8154. this.m_K.col3.z = q + n + a * this.m_a1 * this.m_a1 + c * this.m_a2 * this.m_a2;
  8155. if (this.m_enableLimit) {
  8156. j = this.m_axis.x * j + this.m_axis.y * o;
  8157. if (y.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * F.b2_linearSlop) this.m_limitState = I.e_equalLimits;
  8158. else if (j <= this.m_lowerTranslation) {
  8159. if (this.m_limitState != I.e_atLowerLimit) {
  8160. this.m_limitState = I.e_atLowerLimit;
  8161. this.m_impulse.z = 0
  8162. }
  8163. } else if (j >= this.m_upperTranslation) {
  8164. if (this.m_limitState != I.e_atUpperLimit) {
  8165. this.m_limitState = I.e_atUpperLimit;
  8166. this.m_impulse.z = 0
  8167. }
  8168. } else {
  8169. this.m_limitState = I.e_inactiveLimit;
  8170. this.m_impulse.z = 0
  8171. }
  8172. } else this.m_limitState = I.e_inactiveLimit; if (this.m_enableMotor == false) this.m_motorImpulse = 0;
  8173. if (d.warmStarting) {
  8174. this.m_impulse.x *= d.dtRatio;
  8175. this.m_impulse.y *= d.dtRatio;
  8176. this.m_motorImpulse *= d.dtRatio;
  8177. d = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x;
  8178. j = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y;
  8179. o = this.m_impulse.x * this.m_s1 + this.m_impulse.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_a1;
  8180. q = this.m_impulse.x * this.m_s2 + this.m_impulse.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_a2;
  8181. h.m_linearVelocity.x -= this.m_invMassA * d;
  8182. h.m_linearVelocity.y -= this.m_invMassA * j;
  8183. h.m_angularVelocity -= this.m_invIA * o;
  8184. l.m_linearVelocity.x += this.m_invMassB * d;
  8185. l.m_linearVelocity.y += this.m_invMassB * j;
  8186. l.m_angularVelocity += this.m_invIB * q
  8187. } else {
  8188. this.m_impulse.SetZero();
  8189. this.m_motorImpulse = 0
  8190. }
  8191. };
  8192. H.prototype.SolveVelocityConstraints = function (d) {
  8193. var h = this.m_bodyA,
  8194. l = this.m_bodyB,
  8195. j = h.m_linearVelocity,
  8196. o = h.m_angularVelocity,
  8197. q = l.m_linearVelocity,
  8198. n = l.m_angularVelocity,
  8199. a = 0,
  8200. c = 0,
  8201. g = 0,
  8202. b = 0;
  8203. if (this.m_enableMotor && this.m_limitState != I.e_equalLimits) {
  8204. b = this.m_motorMass * (this.m_motorSpeed - (this.m_axis.x * (q.x - j.x) + this.m_axis.y * (q.y - j.y) + this.m_a2 * n - this.m_a1 * o));
  8205. a = this.m_motorImpulse;
  8206. d = d.dt * this.m_maxMotorForce;
  8207. this.m_motorImpulse = y.Clamp(this.m_motorImpulse + b, -d, d);
  8208. b = this.m_motorImpulse - a;
  8209. a = b * this.m_axis.x;
  8210. c = b * this.m_axis.y;
  8211. g = b * this.m_a1;
  8212. b = b * this.m_a2;
  8213. j.x -= this.m_invMassA * a;
  8214. j.y -= this.m_invMassA * c;
  8215. o -= this.m_invIA * g;
  8216. q.x += this.m_invMassB * a;
  8217. q.y += this.m_invMassB * c;
  8218. n += this.m_invIB * b
  8219. }
  8220. g = this.m_perp.x * (q.x - j.x) + this.m_perp.y * (q.y - j.y) + this.m_s2 * n - this.m_s1 * o;
  8221. c = n - o;
  8222. if (this.m_enableLimit && this.m_limitState != I.e_inactiveLimit) {
  8223. d = this.m_axis.x * (q.x - j.x) + this.m_axis.y * (q.y - j.y) + this.m_a2 * n - this.m_a1 * o;
  8224. a = this.m_impulse.Copy();
  8225. d = this.m_K.Solve33(new A, -g, -c, -d);
  8226. this.m_impulse.Add(d);
  8227. if (this.m_limitState == I.e_atLowerLimit) this.m_impulse.z = y.Max(this.m_impulse.z, 0);
  8228. else if (this.m_limitState == I.e_atUpperLimit) this.m_impulse.z = y.Min(this.m_impulse.z, 0);
  8229. g = -g - (this.m_impulse.z - a.z) * this.m_K.col3.x;
  8230. c = -c - (this.m_impulse.z - a.z) * this.m_K.col3.y;
  8231. c = this.m_K.Solve22(new w, g, c);
  8232. c.x += a.x;
  8233. c.y += a.y;
  8234. this.m_impulse.x = c.x;
  8235. this.m_impulse.y = c.y;
  8236. d.x = this.m_impulse.x - a.x;
  8237. d.y = this.m_impulse.y - a.y;
  8238. d.z = this.m_impulse.z - a.z;
  8239. a = d.x * this.m_perp.x + d.z * this.m_axis.x;
  8240. c = d.x * this.m_perp.y + d.z * this.m_axis.y;
  8241. g = d.x * this.m_s1 + d.y + d.z * this.m_a1;
  8242. b = d.x * this.m_s2 + d.y + d.z * this.m_a2
  8243. } else {
  8244. d = this.m_K.Solve22(new w, -g, -c);
  8245. this.m_impulse.x += d.x;
  8246. this.m_impulse.y += d.y;
  8247. a = d.x * this.m_perp.x;
  8248. c = d.x * this.m_perp.y;
  8249. g = d.x * this.m_s1 + d.y;
  8250. b = d.x * this.m_s2 + d.y
  8251. }
  8252. j.x -= this.m_invMassA * a;
  8253. j.y -= this.m_invMassA * c;
  8254. o -= this.m_invIA * g;
  8255. q.x += this.m_invMassB * a;
  8256. q.y += this.m_invMassB * c;
  8257. n += this.m_invIB * b;
  8258. h.m_linearVelocity.SetV(j);
  8259. h.m_angularVelocity = o;
  8260. l.m_linearVelocity.SetV(q);
  8261. l.m_angularVelocity = n
  8262. };
  8263. H.prototype.SolvePositionConstraints = function () {
  8264. var d = this.m_bodyA,
  8265. h = this.m_bodyB,
  8266. l = d.m_sweep.c,
  8267. j = d.m_sweep.a,
  8268. o = h.m_sweep.c,
  8269. q = h.m_sweep.a,
  8270. n, a = 0,
  8271. c = 0,
  8272. g = 0,
  8273. b = a = n = 0,
  8274. e = 0;
  8275. c = false;
  8276. var f = 0,
  8277. m = G.FromAngle(j),
  8278. r = G.FromAngle(q);
  8279. n = m;
  8280. e = this.m_localAnchor1.x - this.m_localCenterA.x;
  8281. var s = this.m_localAnchor1.y - this.m_localCenterA.y;
  8282. a = n.col1.x * e + n.col2.x * s;
  8283. s = n.col1.y * e + n.col2.y * s;
  8284. e = a;
  8285. n = r;
  8286. r = this.m_localAnchor2.x - this.m_localCenterB.x;
  8287. g = this.m_localAnchor2.y - this.m_localCenterB.y;
  8288. a = n.col1.x * r + n.col2.x * g;
  8289. g = n.col1.y * r + n.col2.y * g;
  8290. r = a;
  8291. n = o.x + r - l.x - e;
  8292. a = o.y + g - l.y - s;
  8293. if (this.m_enableLimit) {
  8294. this.m_axis = y.MulMV(m, this.m_localXAxis1);
  8295. this.m_a1 = (n + e) * this.m_axis.y - (a + s) * this.m_axis.x;
  8296. this.m_a2 = r * this.m_axis.y - g * this.m_axis.x;
  8297. var v = this.m_axis.x * n + this.m_axis.y * a;
  8298. if (y.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2 * F.b2_linearSlop) {
  8299. f = y.Clamp(v, -F.b2_maxLinearCorrection, F.b2_maxLinearCorrection);
  8300. b = y.Abs(v);
  8301. c = true
  8302. } else if (v <= this.m_lowerTranslation) {
  8303. f = y.Clamp(v - this.m_lowerTranslation + F.b2_linearSlop, -F.b2_maxLinearCorrection, 0);
  8304. b = this.m_lowerTranslation - v;
  8305. c = true
  8306. } else if (v >= this.m_upperTranslation) {
  8307. f = y.Clamp(v - this.m_upperTranslation + F.b2_linearSlop, 0, F.b2_maxLinearCorrection);
  8308. b = v - this.m_upperTranslation;
  8309. c = true
  8310. }
  8311. }
  8312. this.m_perp = y.MulMV(m, this.m_localYAxis1);
  8313. this.m_s1 = (n + e) * this.m_perp.y - (a + s) * this.m_perp.x;
  8314. this.m_s2 = r * this.m_perp.y - g * this.m_perp.x;
  8315. m = new A;
  8316. s = this.m_perp.x * n + this.m_perp.y * a;
  8317. r = q - j - this.m_refAngle;
  8318. b = y.Max(b, y.Abs(s));
  8319. e = y.Abs(r);
  8320. if (c) {
  8321. c = this.m_invMassA;
  8322. g = this.m_invMassB;
  8323. n = this.m_invIA;
  8324. a = this.m_invIB;
  8325. this.m_K.col1.x = c + g + n * this.m_s1 * this.m_s1 + a * this.m_s2 * this.m_s2;
  8326. this.m_K.col1.y = n * this.m_s1 + a * this.m_s2;
  8327. this.m_K.col1.z = n * this.m_s1 * this.m_a1 + a * this.m_s2 * this.m_a2;
  8328. this.m_K.col2.x = this.m_K.col1.y;
  8329. this.m_K.col2.y = n + a;
  8330. this.m_K.col2.z = n * this.m_a1 + a * this.m_a2;
  8331. this.m_K.col3.x = this.m_K.col1.z;
  8332. this.m_K.col3.y = this.m_K.col2.z;
  8333. this.m_K.col3.z = c + g + n * this.m_a1 * this.m_a1 + a * this.m_a2 * this.m_a2;
  8334. this.m_K.Solve33(m, -s, -r, -f)
  8335. } else {
  8336. c = this.m_invMassA;
  8337. g = this.m_invMassB;
  8338. n = this.m_invIA;
  8339. a = this.m_invIB;
  8340. f = n * this.m_s1 + a * this.m_s2;
  8341. v = n + a;
  8342. this.m_K.col1.Set(c + g + n * this.m_s1 * this.m_s1 + a * this.m_s2 * this.m_s2, f, 0);
  8343. this.m_K.col2.Set(f,
  8344. v, 0);
  8345. f = this.m_K.Solve22(new w, -s, -r);
  8346. m.x = f.x;
  8347. m.y = f.y;
  8348. m.z = 0
  8349. }
  8350. f = m.x * this.m_perp.x + m.z * this.m_axis.x;
  8351. c = m.x * this.m_perp.y + m.z * this.m_axis.y;
  8352. s = m.x * this.m_s1 + m.y + m.z * this.m_a1;
  8353. m = m.x * this.m_s2 + m.y + m.z * this.m_a2;
  8354. l.x -= this.m_invMassA * f;
  8355. l.y -= this.m_invMassA * c;
  8356. j -= this.m_invIA * s;
  8357. o.x += this.m_invMassB * f;
  8358. o.y += this.m_invMassB * c;
  8359. q += this.m_invIB * m;
  8360. d.m_sweep.a = j;
  8361. h.m_sweep.a = q;
  8362. d.SynchronizeTransform();
  8363. h.SynchronizeTransform();
  8364. return b <= F.b2_linearSlop && e <= F.b2_angularSlop
  8365. };
  8366. Box2D.inherit(O, Box2D.Dynamics.Joints.b2JointDef);
  8367. O.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  8368. O.b2PrismaticJointDef = function () {
  8369. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  8370. this.localAnchorA = new w;
  8371. this.localAnchorB = new w;
  8372. this.localAxisA = new w
  8373. };
  8374. O.prototype.b2PrismaticJointDef = function () {
  8375. this.__super.b2JointDef.call(this);
  8376. this.type = I.e_prismaticJoint;
  8377. this.localAxisA.Set(1, 0);
  8378. this.referenceAngle = 0;
  8379. this.enableLimit = false;
  8380. this.upperTranslation = this.lowerTranslation = 0;
  8381. this.enableMotor = false;
  8382. this.motorSpeed = this.maxMotorForce = 0
  8383. };
  8384. O.prototype.Initialize = function (d, h, l, j) {
  8385. this.bodyA = d;
  8386. this.bodyB = h;
  8387. this.localAnchorA = this.bodyA.GetLocalPoint(l);
  8388. this.localAnchorB = this.bodyB.GetLocalPoint(l);
  8389. this.localAxisA = this.bodyA.GetLocalVector(j);
  8390. this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle()
  8391. };
  8392. Box2D.inherit(E, Box2D.Dynamics.Joints.b2Joint);
  8393. E.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  8394. E.b2PulleyJoint = function () {
  8395. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  8396. this.m_groundAnchor1 = new w;
  8397. this.m_groundAnchor2 = new w;
  8398. this.m_localAnchor1 = new w;
  8399. this.m_localAnchor2 = new w;
  8400. this.m_u1 = new w;
  8401. this.m_u2 = new w
  8402. };
  8403. E.prototype.GetAnchorA = function () {
  8404. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  8405. };
  8406. E.prototype.GetAnchorB = function () {
  8407. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  8408. };
  8409. E.prototype.GetReactionForce = function (d) {
  8410. if (d === undefined) d = 0;
  8411. return new w(d * this.m_impulse * this.m_u2.x, d * this.m_impulse * this.m_u2.y)
  8412. };
  8413. E.prototype.GetReactionTorque = function () {
  8414. return 0
  8415. };
  8416. E.prototype.GetGroundAnchorA = function () {
  8417. var d = this.m_ground.m_xf.position.Copy();
  8418. d.Add(this.m_groundAnchor1);
  8419. return d
  8420. };
  8421. E.prototype.GetGroundAnchorB = function () {
  8422. var d = this.m_ground.m_xf.position.Copy();
  8423. d.Add(this.m_groundAnchor2);
  8424. return d
  8425. };
  8426. E.prototype.GetLength1 = function () {
  8427. var d = this.m_bodyA.GetWorldPoint(this.m_localAnchor1),
  8428. h = d.x - (this.m_ground.m_xf.position.x + this.m_groundAnchor1.x);
  8429. d = d.y - (this.m_ground.m_xf.position.y + this.m_groundAnchor1.y);
  8430. return Math.sqrt(h * h + d * d)
  8431. };
  8432. E.prototype.GetLength2 = function () {
  8433. var d = this.m_bodyB.GetWorldPoint(this.m_localAnchor2),
  8434. h = d.x - (this.m_ground.m_xf.position.x + this.m_groundAnchor2.x);
  8435. d = d.y - (this.m_ground.m_xf.position.y + this.m_groundAnchor2.y);
  8436. return Math.sqrt(h * h + d * d)
  8437. };
  8438. E.prototype.GetRatio = function () {
  8439. return this.m_ratio
  8440. };
  8441. E.prototype.b2PulleyJoint = function (d) {
  8442. this.__super.b2Joint.call(this, d);
  8443. this.m_ground = this.m_bodyA.m_world.m_groundBody;
  8444. this.m_groundAnchor1.x = d.groundAnchorA.x - this.m_ground.m_xf.position.x;
  8445. this.m_groundAnchor1.y = d.groundAnchorA.y - this.m_ground.m_xf.position.y;
  8446. this.m_groundAnchor2.x = d.groundAnchorB.x - this.m_ground.m_xf.position.x;
  8447. this.m_groundAnchor2.y = d.groundAnchorB.y - this.m_ground.m_xf.position.y;
  8448. this.m_localAnchor1.SetV(d.localAnchorA);
  8449. this.m_localAnchor2.SetV(d.localAnchorB);
  8450. this.m_ratio = d.ratio;
  8451. this.m_constant = d.lengthA + this.m_ratio * d.lengthB;
  8452. this.m_maxLength1 = y.Min(d.maxLengthA, this.m_constant - this.m_ratio * E.b2_minPulleyLength);
  8453. this.m_maxLength2 = y.Min(d.maxLengthB, (this.m_constant - E.b2_minPulleyLength) / this.m_ratio);
  8454. this.m_limitImpulse2 = this.m_limitImpulse1 = this.m_impulse = 0
  8455. };
  8456. E.prototype.InitVelocityConstraints = function (d) {
  8457. var h = this.m_bodyA,
  8458. l = this.m_bodyB,
  8459. j;
  8460. j = h.m_xf.R;
  8461. var o = this.m_localAnchor1.x - h.m_sweep.localCenter.x,
  8462. q = this.m_localAnchor1.y - h.m_sweep.localCenter.y,
  8463. n = j.col1.x * o + j.col2.x * q;
  8464. q = j.col1.y * o + j.col2.y * q;
  8465. o = n;
  8466. j = l.m_xf.R;
  8467. var a = this.m_localAnchor2.x - l.m_sweep.localCenter.x,
  8468. c = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  8469. n = j.col1.x * a + j.col2.x * c;
  8470. c = j.col1.y * a + j.col2.y * c;
  8471. a = n;
  8472. j = l.m_sweep.c.x + a;
  8473. n = l.m_sweep.c.y + c;
  8474. var g = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x,
  8475. b = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;
  8476. this.m_u1.Set(h.m_sweep.c.x + o - (this.m_ground.m_xf.position.x + this.m_groundAnchor1.x), h.m_sweep.c.y + q - (this.m_ground.m_xf.position.y + this.m_groundAnchor1.y));
  8477. this.m_u2.Set(j - g, n - b);
  8478. j = this.m_u1.Length();
  8479. n = this.m_u2.Length();
  8480. j > F.b2_linearSlop ? this.m_u1.Multiply(1 / j) : this.m_u1.SetZero();
  8481. n > F.b2_linearSlop ? this.m_u2.Multiply(1 / n) : this.m_u2.SetZero();
  8482. if (this.m_constant - j - this.m_ratio * n > 0) {
  8483. this.m_state = I.e_inactiveLimit;
  8484. this.m_impulse = 0
  8485. } else this.m_state = I.e_atUpperLimit; if (j < this.m_maxLength1) {
  8486. this.m_limitState1 = I.e_inactiveLimit;
  8487. this.m_limitImpulse1 = 0
  8488. } else this.m_limitState1 = I.e_atUpperLimit; if (n < this.m_maxLength2) {
  8489. this.m_limitState2 = I.e_inactiveLimit;
  8490. this.m_limitImpulse2 = 0
  8491. } else this.m_limitState2 = I.e_atUpperLimit;
  8492. j = o * this.m_u1.y - q * this.m_u1.x;
  8493. n = a * this.m_u2.y - c * this.m_u2.x;
  8494. this.m_limitMass1 = h.m_invMass + h.m_invI * j * j;
  8495. this.m_limitMass2 = l.m_invMass + l.m_invI * n * n;
  8496. this.m_pulleyMass = this.m_limitMass1 + this.m_ratio * this.m_ratio * this.m_limitMass2;
  8497. this.m_limitMass1 = 1 / this.m_limitMass1;
  8498. this.m_limitMass2 = 1 / this.m_limitMass2;
  8499. this.m_pulleyMass = 1 / this.m_pulleyMass;
  8500. if (d.warmStarting) {
  8501. this.m_impulse *= d.dtRatio;
  8502. this.m_limitImpulse1 *= d.dtRatio;
  8503. this.m_limitImpulse2 *= d.dtRatio;
  8504. d = (-this.m_impulse - this.m_limitImpulse1) * this.m_u1.x;
  8505. j = (-this.m_impulse - this.m_limitImpulse1) * this.m_u1.y;
  8506. n = (-this.m_ratio * this.m_impulse - this.m_limitImpulse2) * this.m_u2.x;
  8507. g = (-this.m_ratio * this.m_impulse - this.m_limitImpulse2) * this.m_u2.y;
  8508. h.m_linearVelocity.x += h.m_invMass * d;
  8509. h.m_linearVelocity.y += h.m_invMass * j;
  8510. h.m_angularVelocity += h.m_invI * (o * j - q * d);
  8511. l.m_linearVelocity.x += l.m_invMass * n;
  8512. l.m_linearVelocity.y += l.m_invMass * g;
  8513. l.m_angularVelocity += l.m_invI * (a * g - c * n)
  8514. } else this.m_limitImpulse2 = this.m_limitImpulse1 = this.m_impulse = 0
  8515. };
  8516. E.prototype.SolveVelocityConstraints = function () {
  8517. var d = this.m_bodyA,
  8518. h = this.m_bodyB,
  8519. l;
  8520. l = d.m_xf.R;
  8521. var j = this.m_localAnchor1.x - d.m_sweep.localCenter.x,
  8522. o = this.m_localAnchor1.y - d.m_sweep.localCenter.y,
  8523. q = l.col1.x * j + l.col2.x * o;
  8524. o = l.col1.y * j + l.col2.y * o;
  8525. j = q;
  8526. l = h.m_xf.R;
  8527. var n = this.m_localAnchor2.x - h.m_sweep.localCenter.x,
  8528. a = this.m_localAnchor2.y - h.m_sweep.localCenter.y;
  8529. q = l.col1.x * n + l.col2.x * a;
  8530. a = l.col1.y * n + l.col2.y * a;
  8531. n = q;
  8532. var c = q = l = 0,
  8533. g = 0;
  8534. l = g = l = g = c = q = l = 0;
  8535. if (this.m_state == I.e_atUpperLimit) {
  8536. l = d.m_linearVelocity.x + -d.m_angularVelocity * o;
  8537. q = d.m_linearVelocity.y + d.m_angularVelocity * j;
  8538. c = h.m_linearVelocity.x + -h.m_angularVelocity * a;
  8539. g = h.m_linearVelocity.y + h.m_angularVelocity * n;
  8540. l = -(this.m_u1.x * l + this.m_u1.y * q) - this.m_ratio * (this.m_u2.x * c + this.m_u2.y * g);
  8541. g = this.m_pulleyMass * -l;
  8542. l = this.m_impulse;
  8543. this.m_impulse = y.Max(0, this.m_impulse + g);
  8544. g = this.m_impulse - l;
  8545. l = -g * this.m_u1.x;
  8546. q = -g * this.m_u1.y;
  8547. c = -this.m_ratio * g * this.m_u2.x;
  8548. g = -this.m_ratio * g * this.m_u2.y;
  8549. d.m_linearVelocity.x += d.m_invMass * l;
  8550. d.m_linearVelocity.y += d.m_invMass * q;
  8551. d.m_angularVelocity += d.m_invI * (j * q - o * l);
  8552. h.m_linearVelocity.x += h.m_invMass * c;
  8553. h.m_linearVelocity.y += h.m_invMass * g;
  8554. h.m_angularVelocity += h.m_invI * (n * g - a * c)
  8555. }
  8556. if (this.m_limitState1 == I.e_atUpperLimit) {
  8557. l = d.m_linearVelocity.x + -d.m_angularVelocity * o;
  8558. q = d.m_linearVelocity.y + d.m_angularVelocity * j;
  8559. l = -(this.m_u1.x * l + this.m_u1.y * q);
  8560. g = -this.m_limitMass1 * l;
  8561. l = this.m_limitImpulse1;
  8562. this.m_limitImpulse1 = y.Max(0, this.m_limitImpulse1 + g);
  8563. g = this.m_limitImpulse1 - l;
  8564. l = -g * this.m_u1.x;
  8565. q = -g * this.m_u1.y;
  8566. d.m_linearVelocity.x += d.m_invMass * l;
  8567. d.m_linearVelocity.y += d.m_invMass * q;
  8568. d.m_angularVelocity += d.m_invI * (j * q - o * l)
  8569. }
  8570. if (this.m_limitState2 == I.e_atUpperLimit) {
  8571. c = h.m_linearVelocity.x + -h.m_angularVelocity * a;
  8572. g = h.m_linearVelocity.y + h.m_angularVelocity * n;
  8573. l = -(this.m_u2.x * c + this.m_u2.y * g);
  8574. g = -this.m_limitMass2 * l;
  8575. l = this.m_limitImpulse2;
  8576. this.m_limitImpulse2 = y.Max(0, this.m_limitImpulse2 + g);
  8577. g = this.m_limitImpulse2 - l;
  8578. c = -g * this.m_u2.x;
  8579. g = -g * this.m_u2.y;
  8580. h.m_linearVelocity.x += h.m_invMass * c;
  8581. h.m_linearVelocity.y += h.m_invMass * g;
  8582. h.m_angularVelocity += h.m_invI * (n * g - a * c)
  8583. }
  8584. };
  8585. E.prototype.SolvePositionConstraints = function () {
  8586. var d = this.m_bodyA,
  8587. h = this.m_bodyB,
  8588. l, j = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x,
  8589. o = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y,
  8590. q = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x,
  8591. n = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y,
  8592. a = 0,
  8593. c = 0,
  8594. g = 0,
  8595. b = 0,
  8596. e = l = 0,
  8597. f = 0,
  8598. m = 0,
  8599. r = e = m = l = e = l = 0;
  8600. if (this.m_state == I.e_atUpperLimit) {
  8601. l = d.m_xf.R;
  8602. a = this.m_localAnchor1.x - d.m_sweep.localCenter.x;
  8603. c = this.m_localAnchor1.y - d.m_sweep.localCenter.y;
  8604. e = l.col1.x * a + l.col2.x * c;
  8605. c = l.col1.y * a + l.col2.y * c;
  8606. a = e;
  8607. l = h.m_xf.R;
  8608. g = this.m_localAnchor2.x - h.m_sweep.localCenter.x;
  8609. b = this.m_localAnchor2.y - h.m_sweep.localCenter.y;
  8610. e = l.col1.x * g + l.col2.x * b;
  8611. b = l.col1.y * g + l.col2.y * b;
  8612. g = e;
  8613. l = d.m_sweep.c.x + a;
  8614. e = d.m_sweep.c.y + c;
  8615. f = h.m_sweep.c.x + g;
  8616. m = h.m_sweep.c.y + b;
  8617. this.m_u1.Set(l - j, e - o);
  8618. this.m_u2.Set(f - q, m - n);
  8619. l = this.m_u1.Length();
  8620. e = this.m_u2.Length();
  8621. l > F.b2_linearSlop ? this.m_u1.Multiply(1 / l) : this.m_u1.SetZero();
  8622. e > F.b2_linearSlop ? this.m_u2.Multiply(1 / e) : this.m_u2.SetZero();
  8623. l = this.m_constant - l - this.m_ratio * e;
  8624. r = y.Max(r, -l);
  8625. l = y.Clamp(l + F.b2_linearSlop, -F.b2_maxLinearCorrection, 0);
  8626. m = -this.m_pulleyMass * l;
  8627. l = -m * this.m_u1.x;
  8628. e = -m * this.m_u1.y;
  8629. f = -this.m_ratio * m * this.m_u2.x;
  8630. m = -this.m_ratio * m * this.m_u2.y;
  8631. d.m_sweep.c.x += d.m_invMass * l;
  8632. d.m_sweep.c.y += d.m_invMass * e;
  8633. d.m_sweep.a += d.m_invI * (a * e - c * l);
  8634. h.m_sweep.c.x += h.m_invMass * f;
  8635. h.m_sweep.c.y += h.m_invMass * m;
  8636. h.m_sweep.a += h.m_invI * (g * m - b * f);
  8637. d.SynchronizeTransform();
  8638. h.SynchronizeTransform()
  8639. }
  8640. if (this.m_limitState1 == I.e_atUpperLimit) {
  8641. l = d.m_xf.R;
  8642. a = this.m_localAnchor1.x - d.m_sweep.localCenter.x;
  8643. c = this.m_localAnchor1.y - d.m_sweep.localCenter.y;
  8644. e = l.col1.x * a + l.col2.x * c;
  8645. c = l.col1.y * a + l.col2.y * c;
  8646. a = e;
  8647. l = d.m_sweep.c.x + a;
  8648. e = d.m_sweep.c.y + c;
  8649. this.m_u1.Set(l - j, e - o);
  8650. l = this.m_u1.Length();
  8651. if (l > F.b2_linearSlop) {
  8652. this.m_u1.x *= 1 / l;
  8653. this.m_u1.y *= 1 / l
  8654. } else this.m_u1.SetZero();
  8655. l = this.m_maxLength1 - l;
  8656. r = y.Max(r, -l);
  8657. l = y.Clamp(l + F.b2_linearSlop, -F.b2_maxLinearCorrection, 0);
  8658. m = -this.m_limitMass1 * l;
  8659. l = -m * this.m_u1.x;
  8660. e = -m * this.m_u1.y;
  8661. d.m_sweep.c.x += d.m_invMass * l;
  8662. d.m_sweep.c.y += d.m_invMass * e;
  8663. d.m_sweep.a += d.m_invI * (a * e - c * l);
  8664. d.SynchronizeTransform()
  8665. }
  8666. if (this.m_limitState2 == I.e_atUpperLimit) {
  8667. l = h.m_xf.R;
  8668. g = this.m_localAnchor2.x - h.m_sweep.localCenter.x;
  8669. b = this.m_localAnchor2.y - h.m_sweep.localCenter.y;
  8670. e = l.col1.x * g + l.col2.x * b;
  8671. b = l.col1.y * g + l.col2.y * b;
  8672. g = e;
  8673. f = h.m_sweep.c.x + g;
  8674. m = h.m_sweep.c.y + b;
  8675. this.m_u2.Set(f - q, m - n);
  8676. e = this.m_u2.Length();
  8677. if (e > F.b2_linearSlop) {
  8678. this.m_u2.x *= 1 / e;
  8679. this.m_u2.y *= 1 / e
  8680. } else this.m_u2.SetZero();
  8681. l = this.m_maxLength2 - e;
  8682. r = y.Max(r, -l);
  8683. l = y.Clamp(l + F.b2_linearSlop, -F.b2_maxLinearCorrection, 0);
  8684. m = -this.m_limitMass2 * l;
  8685. f = -m * this.m_u2.x;
  8686. m = -m * this.m_u2.y;
  8687. h.m_sweep.c.x += h.m_invMass * f;
  8688. h.m_sweep.c.y += h.m_invMass * m;
  8689. h.m_sweep.a += h.m_invI * (g * m - b * f);
  8690. h.SynchronizeTransform()
  8691. }
  8692. return r < F.b2_linearSlop
  8693. };
  8694. Box2D.postDefs.push(function () {
  8695. Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength = 2
  8696. });
  8697. Box2D.inherit(R, Box2D.Dynamics.Joints.b2JointDef);
  8698. R.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  8699. R.b2PulleyJointDef = function () {
  8700. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  8701. this.groundAnchorA = new w;
  8702. this.groundAnchorB = new w;
  8703. this.localAnchorA = new w;
  8704. this.localAnchorB = new w
  8705. };
  8706. R.prototype.b2PulleyJointDef = function () {
  8707. this.__super.b2JointDef.call(this);
  8708. this.type = I.e_pulleyJoint;
  8709. this.groundAnchorA.Set(-1, 1);
  8710. this.groundAnchorB.Set(1, 1);
  8711. this.localAnchorA.Set(-1, 0);
  8712. this.localAnchorB.Set(1, 0);
  8713. this.maxLengthB = this.lengthB = this.maxLengthA = this.lengthA = 0;
  8714. this.ratio = 1;
  8715. this.collideConnected = true
  8716. };
  8717. R.prototype.Initialize = function (d, h, l, j, o, q, n) {
  8718. if (n === undefined) n = 0;
  8719. this.bodyA = d;
  8720. this.bodyB = h;
  8721. this.groundAnchorA.SetV(l);
  8722. this.groundAnchorB.SetV(j);
  8723. this.localAnchorA = this.bodyA.GetLocalPoint(o);
  8724. this.localAnchorB = this.bodyB.GetLocalPoint(q);
  8725. d = o.x - l.x;
  8726. l = o.y - l.y;
  8727. this.lengthA = Math.sqrt(d * d + l * l);
  8728. l = q.x - j.x;
  8729. j = q.y - j.y;
  8730. this.lengthB = Math.sqrt(l * l + j * j);
  8731. this.ratio = n;
  8732. n = this.lengthA + this.ratio * this.lengthB;
  8733. this.maxLengthA = n - this.ratio * E.b2_minPulleyLength;
  8734. this.maxLengthB = (n - E.b2_minPulleyLength) / this.ratio
  8735. };
  8736. Box2D.inherit(N, Box2D.Dynamics.Joints.b2Joint);
  8737. N.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  8738. N.b2RevoluteJoint = function () {
  8739. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  8740. this.K = new G;
  8741. this.K1 = new G;
  8742. this.K2 = new G;
  8743. this.K3 = new G;
  8744. this.impulse3 = new A;
  8745. this.impulse2 = new w;
  8746. this.reduced = new w;
  8747. this.m_localAnchor1 = new w;
  8748. this.m_localAnchor2 = new w;
  8749. this.m_impulse = new A;
  8750. this.m_mass = new K
  8751. };
  8752. N.prototype.GetAnchorA = function () {
  8753. return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)
  8754. };
  8755. N.prototype.GetAnchorB = function () {
  8756. return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)
  8757. };
  8758. N.prototype.GetReactionForce = function (d) {
  8759. if (d === undefined) d = 0;
  8760. return new w(d * this.m_impulse.x, d * this.m_impulse.y)
  8761. };
  8762. N.prototype.GetReactionTorque = function (d) {
  8763. if (d === undefined) d = 0;
  8764. return d * this.m_impulse.z
  8765. };
  8766. N.prototype.GetJointAngle = function () {
  8767. return this.m_bodyB.m_sweep.a - this.m_bodyA.m_sweep.a - this.m_referenceAngle
  8768. };
  8769. N.prototype.GetJointSpeed = function () {
  8770. return this.m_bodyB.m_angularVelocity - this.m_bodyA.m_angularVelocity
  8771. };
  8772. N.prototype.IsLimitEnabled = function () {
  8773. return this.m_enableLimit
  8774. };
  8775. N.prototype.EnableLimit = function (d) {
  8776. this.m_enableLimit = d
  8777. };
  8778. N.prototype.GetLowerLimit = function () {
  8779. return this.m_lowerAngle
  8780. };
  8781. N.prototype.GetUpperLimit = function () {
  8782. return this.m_upperAngle
  8783. };
  8784. N.prototype.SetLimits = function (d, h) {
  8785. if (d === undefined) d = 0;
  8786. if (h === undefined) h = 0;
  8787. this.m_lowerAngle = d;
  8788. this.m_upperAngle = h
  8789. };
  8790. N.prototype.IsMotorEnabled = function () {
  8791. this.m_bodyA.SetAwake(true);
  8792. this.m_bodyB.SetAwake(true);
  8793. return this.m_enableMotor
  8794. };
  8795. N.prototype.EnableMotor = function (d) {
  8796. this.m_enableMotor = d
  8797. };
  8798. N.prototype.SetMotorSpeed = function (d) {
  8799. if (d === undefined) d = 0;
  8800. this.m_bodyA.SetAwake(true);
  8801. this.m_bodyB.SetAwake(true);
  8802. this.m_motorSpeed = d
  8803. };
  8804. N.prototype.GetMotorSpeed = function () {
  8805. return this.m_motorSpeed
  8806. };
  8807. N.prototype.SetMaxMotorTorque = function (d) {
  8808. if (d === undefined) d = 0;
  8809. this.m_maxMotorTorque = d
  8810. };
  8811. N.prototype.GetMotorTorque = function () {
  8812. return this.m_maxMotorTorque
  8813. };
  8814. N.prototype.b2RevoluteJoint = function (d) {
  8815. this.__super.b2Joint.call(this, d);
  8816. this.m_localAnchor1.SetV(d.localAnchorA);
  8817. this.m_localAnchor2.SetV(d.localAnchorB);
  8818. this.m_referenceAngle = d.referenceAngle;
  8819. this.m_impulse.SetZero();
  8820. this.m_motorImpulse = 0;
  8821. this.m_lowerAngle = d.lowerAngle;
  8822. this.m_upperAngle = d.upperAngle;
  8823. this.m_maxMotorTorque = d.maxMotorTorque;
  8824. this.m_motorSpeed = d.motorSpeed;
  8825. this.m_enableLimit = d.enableLimit;
  8826. this.m_enableMotor = d.enableMotor;
  8827. this.m_limitState = I.e_inactiveLimit
  8828. };
  8829. N.prototype.InitVelocityConstraints = function (d) {
  8830. var h = this.m_bodyA,
  8831. l = this.m_bodyB,
  8832. j, o = 0;
  8833. j = h.m_xf.R;
  8834. var q = this.m_localAnchor1.x - h.m_sweep.localCenter.x,
  8835. n = this.m_localAnchor1.y - h.m_sweep.localCenter.y;
  8836. o = j.col1.x * q + j.col2.x * n;
  8837. n = j.col1.y * q + j.col2.y * n;
  8838. q = o;
  8839. j = l.m_xf.R;
  8840. var a = this.m_localAnchor2.x - l.m_sweep.localCenter.x,
  8841. c = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  8842. o = j.col1.x * a + j.col2.x * c;
  8843. c = j.col1.y * a + j.col2.y * c;
  8844. a = o;
  8845. j = h.m_invMass;
  8846. o = l.m_invMass;
  8847. var g = h.m_invI,
  8848. b = l.m_invI;
  8849. this.m_mass.col1.x = j + o + n * n * g + c * c * b;
  8850. this.m_mass.col2.x = -n * q * g - c * a * b;
  8851. this.m_mass.col3.x = -n * g - c * b;
  8852. this.m_mass.col1.y = this.m_mass.col2.x;
  8853. this.m_mass.col2.y = j + o + q * q * g + a * a * b;
  8854. this.m_mass.col3.y = q * g + a * b;
  8855. this.m_mass.col1.z = this.m_mass.col3.x;
  8856. this.m_mass.col2.z = this.m_mass.col3.y;
  8857. this.m_mass.col3.z = g + b;
  8858. this.m_motorMass = 1 / (g + b);
  8859. if (this.m_enableMotor == false) this.m_motorImpulse = 0;
  8860. if (this.m_enableLimit) {
  8861. var e = l.m_sweep.a - h.m_sweep.a - this.m_referenceAngle;
  8862. if (y.Abs(this.m_upperAngle - this.m_lowerAngle) < 2 * F.b2_angularSlop) this.m_limitState = I.e_equalLimits;
  8863. else if (e <= this.m_lowerAngle) {
  8864. if (this.m_limitState != I.e_atLowerLimit) this.m_impulse.z = 0;
  8865. this.m_limitState = I.e_atLowerLimit
  8866. } else if (e >= this.m_upperAngle) {
  8867. if (this.m_limitState != I.e_atUpperLimit) this.m_impulse.z = 0;
  8868. this.m_limitState = I.e_atUpperLimit
  8869. } else {
  8870. this.m_limitState = I.e_inactiveLimit;
  8871. this.m_impulse.z = 0
  8872. }
  8873. } else this.m_limitState = I.e_inactiveLimit; if (d.warmStarting) {
  8874. this.m_impulse.x *= d.dtRatio;
  8875. this.m_impulse.y *= d.dtRatio;
  8876. this.m_motorImpulse *= d.dtRatio;
  8877. d = this.m_impulse.x;
  8878. e = this.m_impulse.y;
  8879. h.m_linearVelocity.x -= j * d;
  8880. h.m_linearVelocity.y -= j * e;
  8881. h.m_angularVelocity -= g * (q * e - n * d + this.m_motorImpulse + this.m_impulse.z);
  8882. l.m_linearVelocity.x += o * d;
  8883. l.m_linearVelocity.y += o * e;
  8884. l.m_angularVelocity += b * (a * e - c * d + this.m_motorImpulse + this.m_impulse.z)
  8885. } else {
  8886. this.m_impulse.SetZero();
  8887. this.m_motorImpulse = 0
  8888. }
  8889. };
  8890. N.prototype.SolveVelocityConstraints = function (d) {
  8891. var h = this.m_bodyA,
  8892. l = this.m_bodyB,
  8893. j = 0,
  8894. o = j = 0,
  8895. q = 0,
  8896. n = 0,
  8897. a = 0,
  8898. c = h.m_linearVelocity,
  8899. g = h.m_angularVelocity,
  8900. b = l.m_linearVelocity,
  8901. e = l.m_angularVelocity,
  8902. f = h.m_invMass,
  8903. m = l.m_invMass,
  8904. r = h.m_invI,
  8905. s = l.m_invI;
  8906. if (this.m_enableMotor && this.m_limitState != I.e_equalLimits) {
  8907. o = this.m_motorMass * -(e - g - this.m_motorSpeed);
  8908. q = this.m_motorImpulse;
  8909. n = d.dt * this.m_maxMotorTorque;
  8910. this.m_motorImpulse = y.Clamp(this.m_motorImpulse + o, -n, n);
  8911. o = this.m_motorImpulse - q;
  8912. g -= r * o;
  8913. e += s * o
  8914. }
  8915. if (this.m_enableLimit && this.m_limitState != I.e_inactiveLimit) {
  8916. d = h.m_xf.R;
  8917. o = this.m_localAnchor1.x - h.m_sweep.localCenter.x;
  8918. q = this.m_localAnchor1.y - h.m_sweep.localCenter.y;
  8919. j = d.col1.x * o + d.col2.x * q;
  8920. q = d.col1.y * o + d.col2.y * q;
  8921. o = j;
  8922. d = l.m_xf.R;
  8923. n = this.m_localAnchor2.x - l.m_sweep.localCenter.x;
  8924. a = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  8925. j = d.col1.x * n + d.col2.x * a;
  8926. a = d.col1.y * n + d.col2.y * a;
  8927. n = j;
  8928. d = b.x + -e * a - c.x - -g * q;
  8929. var v = b.y + e * n - c.y - g * o;
  8930. this.m_mass.Solve33(this.impulse3, -d, -v, -(e - g));
  8931. if (this.m_limitState == I.e_equalLimits) this.m_impulse.Add(this.impulse3);
  8932. else if (this.m_limitState == I.e_atLowerLimit) {
  8933. j = this.m_impulse.z + this.impulse3.z;
  8934. if (j < 0) {
  8935. this.m_mass.Solve22(this.reduced, -d, -v);
  8936. this.impulse3.x = this.reduced.x;
  8937. this.impulse3.y = this.reduced.y;
  8938. this.impulse3.z = -this.m_impulse.z;
  8939. this.m_impulse.x += this.reduced.x;
  8940. this.m_impulse.y += this.reduced.y;
  8941. this.m_impulse.z = 0
  8942. }
  8943. } else if (this.m_limitState == I.e_atUpperLimit) {
  8944. j = this.m_impulse.z + this.impulse3.z;
  8945. if (j > 0) {
  8946. this.m_mass.Solve22(this.reduced, -d, -v);
  8947. this.impulse3.x = this.reduced.x;
  8948. this.impulse3.y = this.reduced.y;
  8949. this.impulse3.z = -this.m_impulse.z;
  8950. this.m_impulse.x += this.reduced.x;
  8951. this.m_impulse.y += this.reduced.y;
  8952. this.m_impulse.z = 0
  8953. }
  8954. }
  8955. c.x -= f * this.impulse3.x;
  8956. c.y -= f * this.impulse3.y;
  8957. g -= r * (o * this.impulse3.y - q * this.impulse3.x + this.impulse3.z);
  8958. b.x += m * this.impulse3.x;
  8959. b.y += m * this.impulse3.y;
  8960. e += s * (n * this.impulse3.y - a * this.impulse3.x + this.impulse3.z)
  8961. } else {
  8962. d = h.m_xf.R;
  8963. o = this.m_localAnchor1.x - h.m_sweep.localCenter.x;
  8964. q = this.m_localAnchor1.y - h.m_sweep.localCenter.y;
  8965. j = d.col1.x * o + d.col2.x * q;
  8966. q = d.col1.y * o + d.col2.y * q;
  8967. o = j;
  8968. d = l.m_xf.R;
  8969. n = this.m_localAnchor2.x - l.m_sweep.localCenter.x;
  8970. a = this.m_localAnchor2.y - l.m_sweep.localCenter.y;
  8971. j = d.col1.x * n + d.col2.x * a;
  8972. a = d.col1.y * n + d.col2.y * a;
  8973. n = j;
  8974. this.m_mass.Solve22(this.impulse2, -(b.x + -e * a - c.x - -g * q), -(b.y + e * n - c.y - g * o));
  8975. this.m_impulse.x += this.impulse2.x;
  8976. this.m_impulse.y += this.impulse2.y;
  8977. c.x -= f * this.impulse2.x;
  8978. c.y -= f * this.impulse2.y;
  8979. g -= r * (o * this.impulse2.y - q * this.impulse2.x);
  8980. b.x += m * this.impulse2.x;
  8981. b.y += m * this.impulse2.y;
  8982. e += s * (n * this.impulse2.y - a * this.impulse2.x)
  8983. }
  8984. h.m_linearVelocity.SetV(c);
  8985. h.m_angularVelocity = g;
  8986. l.m_linearVelocity.SetV(b);
  8987. l.m_angularVelocity = e
  8988. };
  8989. N.prototype.SolvePositionConstraints = function () {
  8990. var d = 0,
  8991. h, l = this.m_bodyA,
  8992. j = this.m_bodyB,
  8993. o = 0,
  8994. q = h = 0,
  8995. n = 0,
  8996. a = 0;
  8997. if (this.m_enableLimit && this.m_limitState != I.e_inactiveLimit) {
  8998. d = j.m_sweep.a - l.m_sweep.a - this.m_referenceAngle;
  8999. var c = 0;
  9000. if (this.m_limitState == I.e_equalLimits) {
  9001. d = y.Clamp(d - this.m_lowerAngle, -F.b2_maxAngularCorrection, F.b2_maxAngularCorrection);
  9002. c = -this.m_motorMass * d;
  9003. o = y.Abs(d)
  9004. } else if (this.m_limitState == I.e_atLowerLimit) {
  9005. d = d - this.m_lowerAngle;
  9006. o = -d;
  9007. d = y.Clamp(d + F.b2_angularSlop, -F.b2_maxAngularCorrection, 0);
  9008. c = -this.m_motorMass * d
  9009. } else if (this.m_limitState == I.e_atUpperLimit) {
  9010. o = d = d - this.m_upperAngle;
  9011. d = y.Clamp(d - F.b2_angularSlop, 0, F.b2_maxAngularCorrection);
  9012. c = -this.m_motorMass * d
  9013. }
  9014. l.m_sweep.a -= l.m_invI * c;
  9015. j.m_sweep.a += j.m_invI * c;
  9016. l.SynchronizeTransform();
  9017. j.SynchronizeTransform()
  9018. }
  9019. h = l.m_xf.R;
  9020. c = this.m_localAnchor1.x - l.m_sweep.localCenter.x;
  9021. d = this.m_localAnchor1.y - l.m_sweep.localCenter.y;
  9022. q = h.col1.x * c + h.col2.x * d;
  9023. d = h.col1.y * c + h.col2.y * d;
  9024. c = q;
  9025. h = j.m_xf.R;
  9026. var g = this.m_localAnchor2.x - j.m_sweep.localCenter.x,
  9027. b = this.m_localAnchor2.y - j.m_sweep.localCenter.y;
  9028. q = h.col1.x * g + h.col2.x * b;
  9029. b = h.col1.y * g + h.col2.y * b;
  9030. g = q;
  9031. n = j.m_sweep.c.x + g - l.m_sweep.c.x - c;
  9032. a = j.m_sweep.c.y + b - l.m_sweep.c.y - d;
  9033. var e = n * n + a * a;
  9034. h = Math.sqrt(e);
  9035. q = l.m_invMass;
  9036. var f = j.m_invMass,
  9037. m = l.m_invI,
  9038. r = j.m_invI,
  9039. s = 10 * F.b2_linearSlop;
  9040. if (e > s * s) {
  9041. e = 1 / (q + f);
  9042. n = e * -n;
  9043. a = e * -a;
  9044. l.m_sweep.c.x -= 0.5 * q * n;
  9045. l.m_sweep.c.y -= 0.5 * q * a;
  9046. j.m_sweep.c.x += 0.5 * f * n;
  9047. j.m_sweep.c.y += 0.5 * f * a;
  9048. n = j.m_sweep.c.x + g - l.m_sweep.c.x - c;
  9049. a = j.m_sweep.c.y + b - l.m_sweep.c.y - d
  9050. }
  9051. this.K1.col1.x = q + f;
  9052. this.K1.col2.x = 0;
  9053. this.K1.col1.y = 0;
  9054. this.K1.col2.y = q + f;
  9055. this.K2.col1.x = m * d * d;
  9056. this.K2.col2.x = -m * c * d;
  9057. this.K2.col1.y = -m * c * d;
  9058. this.K2.col2.y = m * c * c;
  9059. this.K3.col1.x = r * b * b;
  9060. this.K3.col2.x = -r * g * b;
  9061. this.K3.col1.y = -r * g * b;
  9062. this.K3.col2.y = r * g * g;
  9063. this.K.SetM(this.K1);
  9064. this.K.AddM(this.K2);
  9065. this.K.AddM(this.K3);
  9066. this.K.Solve(N.tImpulse, -n, -a);
  9067. n = N.tImpulse.x;
  9068. a = N.tImpulse.y;
  9069. l.m_sweep.c.x -= l.m_invMass * n;
  9070. l.m_sweep.c.y -= l.m_invMass * a;
  9071. l.m_sweep.a -= l.m_invI * (c * a - d * n);
  9072. j.m_sweep.c.x += j.m_invMass * n;
  9073. j.m_sweep.c.y += j.m_invMass * a;
  9074. j.m_sweep.a += j.m_invI * (g * a - b * n);
  9075. l.SynchronizeTransform();
  9076. j.SynchronizeTransform();
  9077. return h <= F.b2_linearSlop && o <= F.b2_angularSlop
  9078. };
  9079. Box2D.postDefs.push(function () {
  9080. Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse = new w
  9081. });
  9082. Box2D.inherit(S, Box2D.Dynamics.Joints.b2JointDef);
  9083. S.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  9084. S.b2RevoluteJointDef = function () {
  9085. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  9086. this.localAnchorA = new w;
  9087. this.localAnchorB = new w
  9088. };
  9089. S.prototype.b2RevoluteJointDef = function () {
  9090. this.__super.b2JointDef.call(this);
  9091. this.type = I.e_revoluteJoint;
  9092. this.localAnchorA.Set(0, 0);
  9093. this.localAnchorB.Set(0, 0);
  9094. this.motorSpeed = this.maxMotorTorque = this.upperAngle = this.lowerAngle = this.referenceAngle = 0;
  9095. this.enableMotor = this.enableLimit = false
  9096. };
  9097. S.prototype.Initialize = function (d, h, l) {
  9098. this.bodyA = d;
  9099. this.bodyB = h;
  9100. this.localAnchorA = this.bodyA.GetLocalPoint(l);
  9101. this.localAnchorB = this.bodyB.GetLocalPoint(l);
  9102. this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle()
  9103. };
  9104. Box2D.inherit(aa, Box2D.Dynamics.Joints.b2Joint);
  9105. aa.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;
  9106. aa.b2WeldJoint = function () {
  9107. Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);
  9108. this.m_localAnchorA = new w;
  9109. this.m_localAnchorB = new w;
  9110. this.m_impulse = new A;
  9111. this.m_mass = new K
  9112. };
  9113. aa.prototype.GetAnchorA = function () {
  9114. return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)
  9115. };
  9116. aa.prototype.GetAnchorB = function () {
  9117. return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)
  9118. };
  9119. aa.prototype.GetReactionForce = function (d) {
  9120. if (d === undefined) d = 0;
  9121. return new w(d * this.m_impulse.x, d * this.m_impulse.y)
  9122. };
  9123. aa.prototype.GetReactionTorque = function (d) {
  9124. if (d === undefined) d = 0;
  9125. return d * this.m_impulse.z
  9126. };
  9127. aa.prototype.b2WeldJoint = function (d) {
  9128. this.__super.b2Joint.call(this, d);
  9129. this.m_localAnchorA.SetV(d.localAnchorA);
  9130. this.m_localAnchorB.SetV(d.localAnchorB);
  9131. this.m_referenceAngle = d.referenceAngle;
  9132. this.m_impulse.SetZero();
  9133. this.m_mass = new K
  9134. };
  9135. aa.prototype.InitVelocityConstraints = function (d) {
  9136. var h, l = 0,
  9137. j = this.m_bodyA,
  9138. o = this.m_bodyB;
  9139. h = j.m_xf.R;
  9140. var q = this.m_localAnchorA.x - j.m_sweep.localCenter.x,
  9141. n = this.m_localAnchorA.y - j.m_sweep.localCenter.y;
  9142. l = h.col1.x * q + h.col2.x * n;
  9143. n = h.col1.y * q + h.col2.y * n;
  9144. q = l;
  9145. h = o.m_xf.R;
  9146. var a = this.m_localAnchorB.x - o.m_sweep.localCenter.x,
  9147. c = this.m_localAnchorB.y - o.m_sweep.localCenter.y;
  9148. l = h.col1.x * a + h.col2.x * c;
  9149. c = h.col1.y * a + h.col2.y * c;
  9150. a = l;
  9151. h = j.m_invMass;
  9152. l = o.m_invMass;
  9153. var g = j.m_invI,
  9154. b = o.m_invI;
  9155. this.m_mass.col1.x = h + l + n * n * g + c * c * b;
  9156. this.m_mass.col2.x = -n * q * g - c * a * b;
  9157. this.m_mass.col3.x = -n * g - c * b;
  9158. this.m_mass.col1.y = this.m_mass.col2.x;
  9159. this.m_mass.col2.y = h + l + q * q * g + a * a * b;
  9160. this.m_mass.col3.y = q * g + a * b;
  9161. this.m_mass.col1.z = this.m_mass.col3.x;
  9162. this.m_mass.col2.z = this.m_mass.col3.y;
  9163. this.m_mass.col3.z = g + b;
  9164. if (d.warmStarting) {
  9165. this.m_impulse.x *= d.dtRatio;
  9166. this.m_impulse.y *= d.dtRatio;
  9167. this.m_impulse.z *= d.dtRatio;
  9168. j.m_linearVelocity.x -= h * this.m_impulse.x;
  9169. j.m_linearVelocity.y -= h * this.m_impulse.y;
  9170. j.m_angularVelocity -= g * (q * this.m_impulse.y - n * this.m_impulse.x + this.m_impulse.z);
  9171. o.m_linearVelocity.x += l * this.m_impulse.x;
  9172. o.m_linearVelocity.y += l * this.m_impulse.y;
  9173. o.m_angularVelocity += b * (a * this.m_impulse.y - c * this.m_impulse.x + this.m_impulse.z)
  9174. } else this.m_impulse.SetZero()
  9175. };
  9176. aa.prototype.SolveVelocityConstraints = function () {
  9177. var d, h = 0,
  9178. l = this.m_bodyA,
  9179. j = this.m_bodyB,
  9180. o = l.m_linearVelocity,
  9181. q = l.m_angularVelocity,
  9182. n = j.m_linearVelocity,
  9183. a = j.m_angularVelocity,
  9184. c = l.m_invMass,
  9185. g = j.m_invMass,
  9186. b = l.m_invI,
  9187. e = j.m_invI;
  9188. d = l.m_xf.R;
  9189. var f = this.m_localAnchorA.x - l.m_sweep.localCenter.x,
  9190. m = this.m_localAnchorA.y - l.m_sweep.localCenter.y;
  9191. h = d.col1.x * f + d.col2.x * m;
  9192. m = d.col1.y * f + d.col2.y * m;
  9193. f = h;
  9194. d = j.m_xf.R;
  9195. var r = this.m_localAnchorB.x - j.m_sweep.localCenter.x,
  9196. s = this.m_localAnchorB.y - j.m_sweep.localCenter.y;
  9197. h = d.col1.x * r + d.col2.x * s;
  9198. s = d.col1.y * r + d.col2.y * s;
  9199. r = h;
  9200. d = n.x - a * s - o.x + q * m;
  9201. h = n.y + a * r - o.y - q * f;
  9202. var v = a - q,
  9203. t = new A;
  9204. this.m_mass.Solve33(t, -d, -h, -v);
  9205. this.m_impulse.Add(t);
  9206. o.x -= c * t.x;
  9207. o.y -= c * t.y;
  9208. q -= b * (f * t.y - m * t.x + t.z);
  9209. n.x += g * t.x;
  9210. n.y += g * t.y;
  9211. a += e * (r * t.y - s * t.x + t.z);
  9212. l.m_angularVelocity = q;
  9213. j.m_angularVelocity = a
  9214. };
  9215. aa.prototype.SolvePositionConstraints = function () {
  9216. var d, h = 0,
  9217. l = this.m_bodyA,
  9218. j = this.m_bodyB;
  9219. d = l.m_xf.R;
  9220. var o = this.m_localAnchorA.x - l.m_sweep.localCenter.x,
  9221. q = this.m_localAnchorA.y - l.m_sweep.localCenter.y;
  9222. h = d.col1.x * o + d.col2.x * q;
  9223. q = d.col1.y * o + d.col2.y * q;
  9224. o = h;
  9225. d = j.m_xf.R;
  9226. var n = this.m_localAnchorB.x - j.m_sweep.localCenter.x,
  9227. a = this.m_localAnchorB.y - j.m_sweep.localCenter.y;
  9228. h = d.col1.x * n + d.col2.x * a;
  9229. a = d.col1.y * n + d.col2.y * a;
  9230. n = h;
  9231. d = l.m_invMass;
  9232. h = j.m_invMass;
  9233. var c = l.m_invI,
  9234. g = j.m_invI,
  9235. b = j.m_sweep.c.x + n - l.m_sweep.c.x - o,
  9236. e = j.m_sweep.c.y + a - l.m_sweep.c.y - q,
  9237. f = j.m_sweep.a - l.m_sweep.a - this.m_referenceAngle,
  9238. m = 10 * F.b2_linearSlop,
  9239. r = Math.sqrt(b * b + e * e),
  9240. s = y.Abs(f);
  9241. if (r > m) {
  9242. c *= 1;
  9243. g *= 1
  9244. }
  9245. this.m_mass.col1.x = d + h + q * q * c + a * a * g;
  9246. this.m_mass.col2.x = -q * o * c - a * n * g;
  9247. this.m_mass.col3.x = -q * c - a * g;
  9248. this.m_mass.col1.y = this.m_mass.col2.x;
  9249. this.m_mass.col2.y = d + h + o * o * c + n * n * g;
  9250. this.m_mass.col3.y = o * c + n * g;
  9251. this.m_mass.col1.z = this.m_mass.col3.x;
  9252. this.m_mass.col2.z = this.m_mass.col3.y;
  9253. this.m_mass.col3.z = c + g;
  9254. m = new A;
  9255. this.m_mass.Solve33(m, -b, -e, -f);
  9256. l.m_sweep.c.x -= d * m.x;
  9257. l.m_sweep.c.y -= d * m.y;
  9258. l.m_sweep.a -= c * (o * m.y - q * m.x + m.z);
  9259. j.m_sweep.c.x += h * m.x;
  9260. j.m_sweep.c.y += h * m.y;
  9261. j.m_sweep.a += g * (n * m.y - a * m.x + m.z);
  9262. l.SynchronizeTransform();
  9263. j.SynchronizeTransform();
  9264. return r <= F.b2_linearSlop && s <= F.b2_angularSlop
  9265. };
  9266. Box2D.inherit(Z, Box2D.Dynamics.Joints.b2JointDef);
  9267. Z.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;
  9268. Z.b2WeldJointDef = function () {
  9269. Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);
  9270. this.localAnchorA = new w;
  9271. this.localAnchorB = new w
  9272. };
  9273. Z.prototype.b2WeldJointDef = function () {
  9274. this.__super.b2JointDef.call(this);
  9275. this.type = I.e_weldJoint;
  9276. this.referenceAngle = 0
  9277. };
  9278. Z.prototype.Initialize = function (d, h, l) {
  9279. this.bodyA = d;
  9280. this.bodyB = h;
  9281. this.localAnchorA.SetV(this.bodyA.GetLocalPoint(l));
  9282. this.localAnchorB.SetV(this.bodyB.GetLocalPoint(l));
  9283. this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle()
  9284. }
  9285. })();
  9286. (function () {
  9287. var F = Box2D.Dynamics.b2DebugDraw;
  9288. F.b2DebugDraw = function () {
  9289. this.m_xformScale = this.m_fillAlpha = this.m_alpha = this.m_lineThickness = this.m_drawScale = 1;
  9290. var G = this;
  9291. this.m_sprite = {
  9292. graphics: {
  9293. clear: function () {
  9294. G.m_ctx.clearRect(0, 0, G.m_ctx.canvas.width, G.m_ctx.canvas.height)
  9295. }
  9296. }
  9297. }
  9298. };
  9299. F.prototype._color = function (G, K) {
  9300. return "rgba(" + ((G & 16711680) >> 16) + "," + ((G & 65280) >> 8) + "," + (G & 255) + "," + K + ")"
  9301. };
  9302. F.prototype.b2DebugDraw = function () {
  9303. this.m_drawFlags = 0
  9304. };
  9305. F.prototype.SetFlags = function (G) {
  9306. if (G === undefined) G = 0;
  9307. this.m_drawFlags = G
  9308. };
  9309. F.prototype.GetFlags = function () {
  9310. return this.m_drawFlags
  9311. };
  9312. F.prototype.AppendFlags = function (G) {
  9313. if (G === undefined) G = 0;
  9314. this.m_drawFlags |= G
  9315. };
  9316. F.prototype.ClearFlags = function (G) {
  9317. if (G === undefined) G = 0;
  9318. this.m_drawFlags &= ~G
  9319. };
  9320. F.prototype.SetSprite = function (G) {
  9321. this.m_ctx = G
  9322. };
  9323. F.prototype.GetSprite = function () {
  9324. return this.m_ctx
  9325. };
  9326. F.prototype.SetDrawScale = function (G) {
  9327. if (G === undefined) G = 0;
  9328. this.m_drawScale = G
  9329. };
  9330. F.prototype.GetDrawScale = function () {
  9331. return this.m_drawScale
  9332. };
  9333. F.prototype.SetLineThickness = function (G) {
  9334. if (G === undefined) G = 0;
  9335. this.m_lineThickness = G;
  9336. this.m_ctx.strokeWidth = G
  9337. };
  9338. F.prototype.GetLineThickness = function () {
  9339. return this.m_lineThickness
  9340. };
  9341. F.prototype.SetAlpha = function (G) {
  9342. if (G === undefined) G = 0;
  9343. this.m_alpha = G
  9344. };
  9345. F.prototype.GetAlpha = function () {
  9346. return this.m_alpha
  9347. };
  9348. F.prototype.SetFillAlpha = function (G) {
  9349. if (G === undefined) G = 0;
  9350. this.m_fillAlpha = G
  9351. };
  9352. F.prototype.GetFillAlpha = function () {
  9353. return this.m_fillAlpha
  9354. };
  9355. F.prototype.SetXFormScale = function (G) {
  9356. if (G === undefined) G = 0;
  9357. this.m_xformScale = G
  9358. };
  9359. F.prototype.GetXFormScale = function () {
  9360. return this.m_xformScale
  9361. };
  9362. F.prototype.DrawPolygon = function (G, K, y) {
  9363. if (K) {
  9364. var w = this.m_ctx,
  9365. A = this.m_drawScale;
  9366. w.beginPath();
  9367. w.strokeStyle = this._color(y.color, this.m_alpha);
  9368. w.moveTo(G[0].x * A, G[0].y * A);
  9369. for (y = 1; y < K; y++) w.lineTo(G[y].x * A, G[y].y * A);
  9370. w.lineTo(G[0].x * A, G[0].y * A);
  9371. w.closePath();
  9372. w.stroke()
  9373. }
  9374. };
  9375. F.prototype.DrawSolidPolygon = function (G, K, y) {
  9376. if (K) {
  9377. var w = this.m_ctx,
  9378. A = this.m_drawScale;
  9379. w.beginPath();
  9380. w.strokeStyle = this._color(y.color, this.m_alpha);
  9381. w.fillStyle = this._color(y.color, this.m_fillAlpha);
  9382. w.moveTo(G[0].x * A, G[0].y * A);
  9383. for (y = 1; y < K; y++) w.lineTo(G[y].x * A, G[y].y * A);
  9384. w.lineTo(G[0].x * A, G[0].y * A);
  9385. w.closePath();
  9386. w.fill();
  9387. w.stroke()
  9388. }
  9389. };
  9390. F.prototype.DrawCircle = function (G, K, y) {
  9391. if (K) {
  9392. var w = this.m_ctx,
  9393. A = this.m_drawScale;
  9394. w.beginPath();
  9395. w.strokeStyle = this._color(y.color, this.m_alpha);
  9396. w.arc(G.x * A, G.y * A, K * A, 0, Math.PI * 2, true);
  9397. w.closePath();
  9398. w.stroke()
  9399. }
  9400. };
  9401. F.prototype.DrawSolidCircle = function (G, K, y, w) {
  9402. if (K) {
  9403. var A = this.m_ctx,
  9404. U = this.m_drawScale,
  9405. p = G.x * U,
  9406. B = G.y * U;
  9407. A.moveTo(0, 0);
  9408. A.beginPath();
  9409. A.strokeStyle = this._color(w.color, this.m_alpha);
  9410. A.fillStyle = this._color(w.color, this.m_fillAlpha);
  9411. A.arc(p, B, K * U, 0, Math.PI * 2, true);
  9412. A.moveTo(p, B);
  9413. A.lineTo((G.x + y.x * K) * U, (G.y + y.y * K) * U);
  9414. A.closePath();
  9415. A.fill();
  9416. A.stroke()
  9417. }
  9418. };
  9419. F.prototype.DrawSegment = function (G, K, y) {
  9420. var w = this.m_ctx,
  9421. A = this.m_drawScale;
  9422. w.strokeStyle = this._color(y.color, this.m_alpha);
  9423. w.beginPath();
  9424. w.moveTo(G.x * A, G.y * A);
  9425. w.lineTo(K.x * A, K.y * A);
  9426. w.closePath();
  9427. w.stroke()
  9428. };
  9429. F.prototype.DrawTransform = function (G) {
  9430. var K = this.m_ctx,
  9431. y = this.m_drawScale;
  9432. K.beginPath();
  9433. K.strokeStyle = this._color(16711680, this.m_alpha);
  9434. K.moveTo(G.position.x * y, G.position.y * y);
  9435. K.lineTo((G.position.x + this.m_xformScale * G.R.col1.x) * y, (G.position.y + this.m_xformScale * G.R.col1.y) * y);
  9436. K.strokeStyle = this._color(65280, this.m_alpha);
  9437. K.moveTo(G.position.x * y, G.position.y * y);
  9438. K.lineTo((G.position.x + this.m_xformScale * G.R.col2.x) * y, (G.position.y + this.m_xformScale * G.R.col2.y) * y);
  9439. K.closePath();
  9440. K.stroke()
  9441. }
  9442. })();
  9443. var i;
  9444. for (i = 0; i < Box2D.postDefs.length; ++i) Box2D.postDefs[i]();
  9445. delete Box2D.postDefs;
  9446. // Copyright 2013 the V8 project authors. All rights reserved.
  9447. // This program is free software; you can redistribute it and/or modify
  9448. // it under the terms of the GNU General Public License as published by
  9449. // the Free Software Foundation; either version 2 of the License, or
  9450. // (at your option) any later version.
  9451. //
  9452. // This program is distributed in the hope that it will be useful,
  9453. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9454. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9455. // GNU General Public License for more details.
  9456. //
  9457. // You should have received a copy of the GNU General Public License
  9458. // along with this program; if not, write to the Free Software
  9459. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9460. function MakeNewWorld () {
  9461. var Vec2 = Box2D.Common.Math.b2Vec2,
  9462. BodyDef = Box2D.Dynamics.b2BodyDef,
  9463. Body = Box2D.Dynamics.b2Body,
  9464. FixtureDef = Box2D.Dynamics.b2FixtureDef,
  9465. Fixture = Box2D.Dynamics.b2Fixture,
  9466. World = Box2D.Dynamics.b2World,
  9467. MassData = Box2D.Collision.Shapes.b2MassData,
  9468. PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
  9469. CircleShape = Box2D.Collision.Shapes.b2CircleShape;
  9470. var gravity = new Vec2(0, -10);
  9471. var world = new World(gravity, true);
  9472. var shape = new PolygonShape();
  9473. shape.SetAsEdge(new Vec2(-40.0, 0), new Vec2(40.0, 0));
  9474. var fd = new FixtureDef();
  9475. fd.density = 0.0;
  9476. fd.shape = shape;
  9477. var bd = new BodyDef();
  9478. var ground = world.CreateBody(bd);
  9479. ground.CreateFixture(fd);
  9480. var a = .5;
  9481. var shape = new PolygonShape();
  9482. shape.SetAsBox(a, a);
  9483. var x = new Vec2(-7.0, 0.75);
  9484. var y = new Vec2();
  9485. var deltaX = new Vec2(0.5625, 1);
  9486. var deltaY = new Vec2(1.125, 0.0);
  9487. for (var i = 0; i < 10; ++i) {
  9488. y.Set(x.x, x.y);
  9489. for (var j = 0; j < 5; ++j) {
  9490. var fd = new FixtureDef();
  9491. fd.density = 5.0;
  9492. fd.shape = shape;
  9493. var bd = new BodyDef();
  9494. bd.type = Body.b2_dynamicBody;
  9495. bd.position.Set(y.x, y.y);
  9496. var body = world.CreateBody(bd);
  9497. body.CreateFixture(fd);
  9498. y.Add(deltaY);
  9499. }
  9500. x.Add(deltaX);
  9501. }
  9502. return world;
  9503. }
  9504. var world = null;
  9505. var Box2DBenchmark = new BenchmarkSuite('Box2D', [5432788],
  9506. [new Benchmark('Box2D',
  9507. false,
  9508. false,
  9509. 60,
  9510. runBox2D,
  9511. setupBox2D,
  9512. tearDownBox2D,
  9513. null,
  9514. 8)]);
  9515. function runBox2D() {
  9516. var world = MakeNewWorld();
  9517. for (var i = 0; i < 20; i++) {
  9518. world.Step(1 / 60, 10, 3);
  9519. }
  9520. }
  9521. function setupBox2D() {
  9522. }
  9523. function tearDownBox2D() {
  9524. world = null;
  9525. Box2D = null;
  9526. }
  9527. ////////////////////////////////////////////////////////////////////////////////
  9528. // Runner
  9529. ////////////////////////////////////////////////////////////////////////////////
  9530. var success = true;
  9531. function NotifyStart(name) {
  9532. }
  9533. function NotifyError(name, error) {
  9534. WScript.Echo(name + " : ERROR : " +error.stack);
  9535. success = false;
  9536. }
  9537. function NotifyResult(name, score) {
  9538. if (success) {
  9539. WScript.Echo("### SCORE:", score);
  9540. }
  9541. }
  9542. function NotifyScore(score) {
  9543. }
  9544. BenchmarkSuite.RunSuites({
  9545. NotifyStart : NotifyStart,
  9546. NotifyError : NotifyError,
  9547. NotifyResult : NotifyResult,
  9548. NotifyScore : NotifyScore
  9549. });