glue.cpp 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341
  1. /*
  2. Copyright (c) 2008-2022 Bruce A Henderson
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include <blitz.h>
  20. #include "Box2D.h"
  21. class MaxDebugDraw;
  22. class MaxContactFilter;
  23. class MaxContactListener;
  24. class MaxBoundaryListener;
  25. class MaxDestructionListener;
  26. class Maxb2EdgeChainDef;
  27. enum b2ControllerType
  28. {
  29. e_buoyancyController,
  30. e_constantAccelController,
  31. e_tensorDampingController,
  32. e_gravityController,
  33. e_constantForceController
  34. };
  35. #ifdef BMX_NG
  36. #define CB_PREF(func) func
  37. #else
  38. #define CB_PREF(func) _##func
  39. #endif
  40. extern "C" {
  41. typedef struct Maxb2Vec2 {
  42. float32 x, y;
  43. } Maxb2Vec2;
  44. typedef struct Maxb2AABB {
  45. Maxb2Vec2 lowerBound;
  46. Maxb2Vec2 upperBound;
  47. } Maxb2AABB;
  48. typedef struct Maxb2Mat22 {
  49. Maxb2Vec2 col1;
  50. Maxb2Vec2 col2;
  51. } Maxb2Mat22;
  52. typedef struct Maxb2XForm {
  53. Maxb2Vec2 position;
  54. Maxb2Mat22 R;
  55. } Maxb2XForm;
  56. typedef struct Maxb2ContactPoint {
  57. b2Shape* shape1;
  58. b2Shape* shape2;
  59. Maxb2Vec2 position;
  60. Maxb2Vec2 velocity;
  61. Maxb2Vec2 normal;
  62. float32 separation;
  63. float32 friction;
  64. float32 restitution;
  65. unsigned int id;
  66. } Maxb2ContactPoint;
  67. typedef struct Maxb2ContactResult {
  68. b2Shape* shape1;
  69. b2Shape* shape2;
  70. Maxb2Vec2 position;
  71. Maxb2Vec2 normal;
  72. float32 normalImpulse;
  73. float32 tangentImpulse;
  74. unsigned int id;
  75. } Maxb2ContactResult;
  76. typedef struct Maxb2Segment {
  77. Maxb2Vec2 p1;
  78. Maxb2Vec2 p2;
  79. } Maxb2Segment;
  80. typedef struct Maxb2FilterData
  81. {
  82. uint16 categoryBits;
  83. uint16 maskBits;
  84. int groupIndex;
  85. } Maxb2FilterData;
  86. void bmx_Maxb2AABBtob2AABB(Maxb2AABB * m, b2AABB * b) {
  87. b->lowerBound = b2Vec2(m->lowerBound.x, m->lowerBound.y);
  88. b->upperBound = b2Vec2(m->upperBound.x, m->upperBound.y);
  89. }
  90. void bmx_Maxb2XFormtob2XForm(Maxb2XForm * xf, b2XForm * f) {
  91. b2Vec2 p(xf->position.x, xf->position.y);
  92. b2Mat22 mat(b2Vec2(xf->R.col1.x, xf->R.col1.y), b2Vec2(xf->R.col2.x, xf->R.col2.y));
  93. f->position = p;
  94. f->R = mat;
  95. }
  96. BBArray * CB_PREF(physics_box2d_b2Vec2__newVecArray)(int count);
  97. void CB_PREF(physics_box2d_b2World__setShape)(BBArray * shapes, int index, b2Shape * shape);
  98. void CB_PREF(physics_box2d_b2DebugDraw__DrawPolygon)(BBObject * maxHandle, BBArray * array, int r, int g, int b);
  99. void CB_PREF(physics_box2d_b2DebugDraw__DrawSolidPolygon)(BBObject * maxHandle, BBArray * array, int r, int g, int b);
  100. void CB_PREF(physics_box2d_b2DebugDraw__DrawSegment)(BBObject * maxHandle, Maxb2Vec2 p1, Maxb2Vec2 p2, int r, int g, int b);
  101. void CB_PREF(physics_box2d_b2DebugDraw__DrawSolidCircle)(BBObject * maxHandle, Maxb2Vec2 center, float32 radius, Maxb2Vec2 axis, int r, int g, int b);
  102. BBObject * CB_PREF(physics_box2d_b2World__createJoint)(b2JointType type);
  103. int CB_PREF(physics_box2d_b2ContactFilter__ShouldCollide)(BBObject * maxHandle, b2Shape * shape1, b2Shape * shape2);
  104. void CB_PREF(physics_box2d_b2ContactListener__Add)(BBObject * maxHandle, Maxb2ContactPoint point);
  105. void CB_PREF(physics_box2d_b2ContactListener__Persist)(BBObject * maxHandle, Maxb2ContactPoint point);
  106. void CB_PREF(physics_box2d_b2ContactListener__Remove)(BBObject * maxHandle, Maxb2ContactPoint point);
  107. void CB_PREF(physics_box2d_b2ContactListener__Result)(BBObject * maxHandle, Maxb2ContactResult result);
  108. void CB_PREF(physics_box2d_b2BoundaryListener__Violation)(BBObject * maxHandle, b2Body * body);
  109. BBObject * CB_PREF(physics_box2d_b2World___createController)(b2ControllerType type);
  110. void CB_PREF(physics_box2d_b2DestructionListener__SayGoodbyeJoint)(BBObject * maxHandle, b2Joint * joint);
  111. void CB_PREF(physics_box2d_b2DestructionListener__SayGoodbyeShape)(BBObject * maxHandle, b2Shape * shape);
  112. BBObject * CB_PREF(physics_box2d_b2Body__createShape)(b2ShapeType type);
  113. int bmx_b2abb_isvalid(Maxb2AABB * aabb);
  114. Maxb2Vec2 bmx_b2vec2_create(float32 x, float32 y);
  115. void bmx_b2vec2_delete(b2Vec2 * vec);
  116. float32 bmx_b2vec2_getx(Maxb2Vec2 * vec);
  117. float32 bmx_b2vec2_gety(Maxb2Vec2 * vec);
  118. void bmx_b2vec2_add(Maxb2Vec2 * vec, Maxb2Vec2 * other);
  119. void bmx_b2vec2_copy(Maxb2Vec2 * vec, Maxb2Vec2 * other);
  120. void bmx_b2vec2_set(Maxb2Vec2 * vec, float32 x, float32 y);
  121. Maxb2Vec2 bmx_b2vec2_subtract(Maxb2Vec2 * vec, Maxb2Vec2 * other);
  122. float32 bmx_b2vec2_length(Maxb2Vec2 * vec);
  123. void bmx_b2vec2_multiply(Maxb2Vec2 * vec, float32 value);
  124. Maxb2Vec2 bmx_b2vec2_plus(Maxb2Vec2 * vec, Maxb2Vec2 * other);
  125. float32 bmx_b2vec2_normalize(Maxb2Vec2 * vec);
  126. float32 bmx_b2vec2_lengthsquared(Maxb2Vec2 * vec);
  127. BBArray * bmx_b2vec2_getvertexarray(const b2Vec2* vertices, int32 vertexCount);
  128. void bmx_b2vec2_setx(Maxb2Vec2 * vec, float32 x);
  129. void bmx_b2vec2_sety(Maxb2Vec2 * vec, float32 y);
  130. b2Body * bmx_b2world_createbody(b2World * world, b2BodyDef * def, BBObject * body);
  131. void bmx_b2world_destroybody(b2World * world, b2Body * body);
  132. b2Body * bmx_b2world_getgroundbody(b2World * world);
  133. void bmx_b2world_setwarmstarting(b2World * world, int flag);
  134. void bmx_b2world_setcontinuousphysics(b2World * world, int flag);
  135. void bmx_b2world_validate(b2World * world);
  136. void bmx_b2world_setdebugDraw(b2World * world, b2DebugDraw * debugDraw);
  137. b2Joint * bmx_b2world_createjoint(b2World * world, b2JointDef * def);
  138. void bmx_b2world_destroyjoint(b2World * world, b2Joint * joint);
  139. b2Body * bmx_b2world_getbodylist(b2World * world);
  140. b2Joint * bmx_b2world_getjointlist(b2World * world);
  141. void bmx_b2world_setfilter(b2World * world, b2ContactFilter * filter);
  142. void bmx_b2world_setcontactlistener(b2World * world, b2ContactListener * listener);
  143. void bmx_b2world_setboundarylistener(b2World * world, b2BoundaryListener * listener);
  144. void bmx_b2world_setgravity(b2World * world, Maxb2Vec2 * gravity);
  145. int32 bmx_b2world_getproxycount(b2World * world);
  146. int32 bmx_b2world_getpaircount(b2World * world);
  147. int32 bmx_b2world_getbodycount(b2World * world);
  148. int32 bmx_b2world_getjointcount(b2World * world);
  149. int32 bmx_b2world_query(b2World * world, Maxb2AABB * aabb, BBArray * shapes);
  150. void bmx_b2world_free(b2World * world);
  151. void bmx_b2world_setdestructionlistener(b2World * world, b2DestructionListener * listener);
  152. void bmx_b2world_refilter(b2World * world, b2Shape * shape);
  153. int32 bmx_b2world_raycast(b2World * world, Maxb2Segment * segment, BBArray * shapes, int solidShapes);
  154. b2Shape * bmx_b2world_raycastone(b2World * world, Maxb2Segment * segment, float32 * lambda, Maxb2Vec2 * normal, int solidShapes);
  155. int bmx_b2world_inrange(b2World * world, Maxb2AABB * aabb);
  156. b2Controller * bmx_b2world_createcontroller(b2World * world, b2ControllerDef * def, b2ControllerType type);
  157. void bmx_b2world_destroycontroller(b2World * world, b2Controller * controller);
  158. b2BodyDef * bmx_b2bodydef_create();
  159. void bmx_b2bodydef_delete(b2BodyDef * def);
  160. void bmx_b2bodydef_setposition(b2BodyDef * def, Maxb2Vec2 * position);
  161. void bmx_b2bodydef_setpositionxy(b2BodyDef * def, float32 x, float32 y);
  162. void bmx_b2bodydef_setangle(b2BodyDef * def, float32 angle);
  163. void bmx_b2bodydef_setmassdata(b2BodyDef * def, b2MassData * data);
  164. int bmx_b2bodydef_issleeping(b2BodyDef * def);
  165. void bmx_b2bodydef_setissleeping(b2BodyDef * def, int sleeping);
  166. void bmx_b2bodydef_setfixedrotation(b2BodyDef * def, int fixed);
  167. int bmx_b2bodydef_getfixedrotation(b2BodyDef * def);
  168. void bmx_b2bodydef_setisbullet(b2BodyDef * def, int bullet);
  169. void bmx_b2bodydef_setlineardamping(b2BodyDef * def, float32 damping);
  170. float32 bmx_b2bodydef_getlineardamping(b2BodyDef * def);
  171. void bmx_b2bodydef_setangulardamping(b2BodyDef * def, float32 damping);
  172. float32 bmx_b2bodydef_getangulardamping(b2BodyDef * def);
  173. void bmx_b2bodydef_setallowsleep(b2BodyDef * def, int allow);
  174. int bmx_b2bodydef_getallowsleep(b2BodyDef * def);
  175. Maxb2Vec2 bmx_b2bodydef_getposition(b2BodyDef * def);
  176. float32 bmx_b2bodydef_getangle(b2BodyDef * def);
  177. int bmx_b2bodydef_isbullet(b2BodyDef * def);
  178. b2MassData * bmx_b2bodydef_getmassdata(b2BodyDef * def);
  179. b2World * bmx_b2world_create(Maxb2AABB * worldAABB, Maxb2Vec2 * gravity, int doSleep);
  180. void bmx_b2world_dostep(b2World * world, float32 timeStep, int velocityIterations, int positionIterations);
  181. void bmx_b2shapedef_setfriction(b2ShapeDef * def, float32 friction);
  182. void bmx_b2shapedef_setrestitution(b2ShapeDef * def, float32 restitution);
  183. void bmx_b2shapedef_setdensity(b2ShapeDef * def, float32 density);
  184. void bmx_b2shapedef_setfilter(b2ShapeDef * def, Maxb2FilterData filterData);
  185. Maxb2FilterData bmx_b2shapedef_getfilter(b2ShapeDef * def);
  186. void bmx_b2shapedef_setissensor(b2ShapeDef * def, int sensor);
  187. int bmx_b2shapedef_issensor(b2ShapeDef * def);
  188. float32 bmx_b2shapedef_getfriction(b2ShapeDef * def);
  189. float32 bmx_b2shapedef_getrestitution(b2ShapeDef * def);
  190. float32 bmx_b2shapedef_getdensity(b2ShapeDef * def);
  191. void bmx_b2shapedef_setfilter_groupindex(b2ShapeDef * def, int groupIndex);
  192. void bmx_b2shapedef_setfilter_categorybits(b2ShapeDef * def, BBSHORT categoryBits);
  193. void bmx_b2shapedef_setfilter_maskbits(b2ShapeDef * def, BBSHORT maskBits);
  194. b2PolygonDef * bmx_b2polygondef_create();
  195. void bmx_b2polygondef_setasbox(b2PolygonDef * def, float32 hx, float32 hy);
  196. void bmx_b2polygondef_delete(b2PolygonDef * def);
  197. void bmx_b2polygondef_setasorientedbox(b2PolygonDef * def, float32 hx, float32 hy, b2Vec2 * center, float32 angle);
  198. void bmx_b2polygondef_setvertices(b2PolygonDef * def, BBArray * vertices);
  199. b2Shape * bmx_b2body_createshape(b2Body * body, b2ShapeDef * def);
  200. void bmx_b2body_destroyshape(b2Body * body, b2Shape * shape);
  201. void bmx_b2body_setmassfromshapes(b2Body * body);
  202. Maxb2Vec2 bmx_b2body_getposition(b2Body * body);
  203. float32 bmx_b2body_getangle(b2Body * body);
  204. BBObject * bmx_b2body_getmaxbody(b2Body * body);
  205. void bmx_b2body_setmaxbody(b2Body * body, BBObject * obj);
  206. b2Body * bmx_b2body_getnext(b2Body * body);
  207. b2Shape * bmx_b2body_getshapelist(b2Body * body);
  208. int bmx_b2body_isstatic(b2Body * body);
  209. int bmx_b2body_isdynamic(b2Body * body);
  210. int bmx_b2body_isfrozen(b2Body * body);
  211. int bmx_b2body_issleeping(b2Body * body);
  212. void bmx_b2body_allowsleeping(b2Body * body, int flag);
  213. void bmx_b2body_wakeup(b2Body * body);
  214. void bmx_b2body_puttosleep(b2Body * body);
  215. int bmx_b2body_isbullet(b2Body * body);
  216. void bmx_b2body_setbullet(b2Body * body, int flag);
  217. Maxb2Vec2 bmx_b2body_getworldcenter(b2Body * body);
  218. Maxb2Vec2 bmx_b2body_getlocalcenter(b2Body * body);
  219. void bmx_b2body_setlinearvelocity(b2Body * body, Maxb2Vec2 * v);
  220. Maxb2Vec2 bmx_b2body_getlinearvelocity(b2Body * body);
  221. void bmx_b2body_setangularvelocity(b2Body * body, float32 omega);
  222. float32 bmx_b2body_getangularvelocity(b2Body * body);
  223. void bmx_b2body_applyforce(b2Body * body, Maxb2Vec2 * force, Maxb2Vec2 * point);
  224. void bmx_b2body_applytorque(b2Body * body, float32 torque);
  225. void bmx_b2body_applyimpulse(b2Body * body, Maxb2Vec2 * impulse, Maxb2Vec2 * point);
  226. float32 bmx_b2body_getmass(b2Body * body);
  227. float32 bmx_b2body_getinertia(b2Body * body);
  228. Maxb2Vec2 bmx_b2body_getworldpoint(b2Body * body, Maxb2Vec2 * localPoint);
  229. Maxb2Vec2 bmx_b2body_getworldvector(b2Body * body, Maxb2Vec2 * localVector);
  230. Maxb2Vec2 bmx_b2body_getlocalpoint(b2Body * body, Maxb2Vec2 * worldPoint);
  231. Maxb2Vec2 bmx_b2body_getlocalvector(b2Body * body, Maxb2Vec2 * worldVector);
  232. b2JointEdge * bmx_b2body_getjointlist(b2Body * body);
  233. Maxb2XForm bmx_b2body_getxform(b2Body * body);
  234. int bmx_b2body_setxform(b2Body * body, Maxb2Vec2 * position, float32 angle);
  235. b2World * bmx_b2body_getworld(b2Body * body);
  236. void bmx_b2body_setmass(b2Body * body, b2MassData * massData);
  237. MaxDebugDraw * bmx_b2debugdraw_create(BBObject * handle);
  238. void bmx_b2debugdraw_setflags(MaxDebugDraw * dbg, uint32 flags);
  239. uint32 bmx_b2debugdraw_getflags(MaxDebugDraw * dbg);
  240. void bmx_b2debugdraw_appendflags(MaxDebugDraw * dbg, uint32 flags);
  241. void bmx_b2debugdraw_clearflags(MaxDebugDraw * dbg, uint32 flags);
  242. b2CircleDef * bmx_b2circledef_create();
  243. void bmx_b2circledef_setradius(b2CircleDef * def, float32 radius);
  244. void bmx_b2circledef_setlocalposition(b2CircleDef * def, Maxb2Vec2 * pos);
  245. void bmx_b2circledef_delete(b2CircleDef * def);
  246. float32 bmx_b2circledef_getradius(b2CircleDef * def);
  247. Maxb2Vec2 bmx_b2circledef_getlocalposition(b2CircleDef * def);
  248. int bmx_b2shape_issensor(b2Shape * shape);
  249. b2Body * bmx_b2shape_getbody(b2Shape * shape);
  250. BBObject * bmx_b2shape_getmaxshape(b2Shape * shape);
  251. void bmx_b2shape_setmaxshape(b2Shape * shape, BBObject * obj);
  252. b2Shape * bmx_b2shape_getnext(b2Shape * shape);
  253. int bmx_b2shape_testpoint(b2Shape * shape, Maxb2XForm * xf, Maxb2Vec2 * p);
  254. float32 bmx_b2shape_getsweepradius(b2Shape * shape);
  255. float32 bmx_b2shape_getfriction(b2Shape * shape);
  256. float32 bmx_b2shape_getrestitution(b2Shape * shape);
  257. void bmx_b2shape_computeaabb(b2Shape * shape, Maxb2AABB * aabb, Maxb2XForm * xf);
  258. void bmx_b2shape_computesweptaabb(b2Shape * shape, Maxb2AABB * aabb, Maxb2XForm * xf1, Maxb2XForm * xf2);
  259. void bmx_b2shape_computemass(b2Shape * shape, b2MassData * data);
  260. Maxb2FilterData bmx_b2shape_getfilterdata(b2Shape * shape);
  261. void bmx_b2shape_setfilterdata(b2Shape * shape, Maxb2FilterData data);
  262. void bmx_b2shape_setfriction(b2Shape * shape, float32 friction);
  263. void bmx_b2shape_setrestitution(b2Shape * shape, float32 restitution);
  264. float32 bmx_b2shape_getdensity(b2Shape * shape);
  265. void bmx_b2shape_setdensity(b2Shape * shape, float32 density);
  266. b2RevoluteJointDef * bmx_b2revolutejointdef_create();
  267. void bmx_b2revolutejointdef_initialize(b2RevoluteJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor);
  268. void bmx_b2revolutejointdef_delete(b2RevoluteJointDef * def);
  269. int bmx_b2revolutejointdef_islimitenabled(b2RevoluteJointDef * def);
  270. void bmx_b2revolutejointdef_enablelimit(b2RevoluteJointDef * def, int limit);
  271. float32 bmx_b2revolutejointdef_getlowerangle(b2RevoluteJointDef * def);
  272. void bmx_b2revolutejointdef_setlowerangle(b2RevoluteJointDef * def, float32 angle);
  273. float32 bmx_b2revolutejointdef_getupperangle(b2RevoluteJointDef * def);
  274. void bmx_b2revolutejointdef_setupperangle(b2RevoluteJointDef * def, float32 angle);
  275. int bmx_b2revolutejointdef_ismotorenabled(b2RevoluteJointDef * def);
  276. void bmx_b2revolutejointdef_enablemotor(b2RevoluteJointDef * def, int value);
  277. float32 bmx_b2revolutejointdef_getmotorspeed(b2RevoluteJointDef * def);
  278. void bmx_b2revolutejointdef_setmotorspeed(b2RevoluteJointDef * def, float32 speed);
  279. float32 bmx_b2revolutejointdef_getmaxmotortorque(b2RevoluteJointDef * def);
  280. void bmx_b2revolutejointdef_setmaxmotortorque(b2RevoluteJointDef * def, float32 torque);
  281. Maxb2Vec2 bmx_b2revolutejointdef_getlocalanchor1(b2RevoluteJointDef * def);
  282. void bmx_b2revolutejointdef_setlocalanchor1(b2RevoluteJointDef * def, Maxb2Vec2 *anchor);
  283. Maxb2Vec2 bmx_b2revolutejointdef_getlocalanchor2(b2RevoluteJointDef * def);
  284. void bmx_b2revolutejointdef_setlocalanchor2(b2RevoluteJointDef * def, Maxb2Vec2 *anchor);
  285. float32 bmx_b2revolutejointdef_getreferenceangle(b2RevoluteJointDef * def);
  286. void bmx_b2revolutejointdef_setreferenceangle(b2RevoluteJointDef * def, float32 angle);
  287. BBObject * bmx_b2joint_getmaxjoint(b2Joint * joint);
  288. b2Body * bmx_b2joint_getbody1(b2Joint * joint);
  289. b2Body * bmx_b2joint_getbody2(b2Joint * joint);
  290. b2Joint * bmx_b2joint_getnext(b2Joint * joint);
  291. b2MassData * bmx_b2massdata_new();
  292. void bmx_b2massdata_delete(b2MassData * data);
  293. void bmx_b2massdata_setmass(b2MassData * data, float32 mass);
  294. void bmx_b2massdata_setcenter(b2MassData * data, Maxb2Vec2 * center);
  295. void bmx_b2massdata_seti(b2MassData * data, float32 i);
  296. b2Body * bmx_b2jointedge_getother(b2JointEdge * joint);
  297. b2Joint * bmx_b2jointedge_getjoint(b2JointEdge * joint);
  298. b2JointEdge * bmx_b2jointedge_getprev(b2JointEdge * joint);
  299. b2JointEdge * bmx_b2jointedge_getnext(b2JointEdge * joint);
  300. MaxContactFilter * bmx_b2contactfilter_new(BBObject * handle);
  301. void bmx_b2contactfilter_delete(MaxContactFilter * filter);
  302. MaxContactListener * bmx_b2contactlistener_new(BBObject * handle);
  303. void bmx_b2contactlistener_delete(MaxContactListener * filter);
  304. MaxBoundaryListener * bmx_b2boundarylistener_new(BBObject * handle);
  305. void bmx_b2boundarylistener_delete(MaxBoundaryListener * filter);
  306. void bmx_b2jointdef_setcollideconnected(b2JointDef * def, int collideConnected);
  307. int bmx_b2jointdef_getcollideconnected(b2JointDef * def);
  308. void bmx_b2jointdef_setbody1(b2JointDef * def, b2Body * body);
  309. b2Body * bmx_b2jointdef_getbody1(b2JointDef * def);
  310. void bmx_b2jointdef_setbody2(b2JointDef * def, b2Body * body);
  311. b2Body * bmx_b2jointdef_getbody2(b2JointDef * def);
  312. b2DistanceJointDef * bmx_b2distancejointdef_new();
  313. void bmx_b2distancejointdef_setlocalanchor1(b2DistanceJointDef * def, Maxb2Vec2 * anchor);
  314. Maxb2Vec2 bmx_b2distancejointdef_getlocalanchor1(b2DistanceJointDef * def);
  315. void bmx_b2distancejointdef_setlocalanchor2(b2DistanceJointDef * def, Maxb2Vec2 * anchor);
  316. Maxb2Vec2 bmx_b2distancejointdef_getlocalanchor2(b2DistanceJointDef * def);
  317. void bmx_b2distancejointdef_setlength(b2DistanceJointDef * def, float32 length);
  318. float32 bmx_b2distancejointdef_getlength(b2DistanceJointDef * def);
  319. void bmx_b2distancejointdef_delete(b2DistanceJointDef * def);
  320. void bmx_b2distancejointdef_setfrequencyhz(b2DistanceJointDef * def, float32 freq);
  321. void bmx_b2distancejointdef_setdampingratio(b2DistanceJointDef * def, float32 ratio);
  322. void bmx_b2distancejointdef_initialize(b2DistanceJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor1, Maxb2Vec2 * anchor2);
  323. b2PrismaticJointDef * bmx_b2prismaticjointdef_create();
  324. void bmx_b2prismaticjointdef_enablelimit(b2PrismaticJointDef * def, int value);
  325. int bmx_b2prismaticjointdef_islimitenabled(b2PrismaticJointDef * def);
  326. void bmx_b2prismaticjointdef_setlowertranslation(b2PrismaticJointDef * def, float32 translation);
  327. float32 bmx_b2prismaticjointdef_getlowertranslation(b2PrismaticJointDef * def);
  328. void bmx_b2prismaticjointdef_setuppertranslation(b2PrismaticJointDef * def, float32 translation);
  329. float32 bmx_b2prismaticjointdef_getuppertranslation(b2PrismaticJointDef * def);
  330. void bmx_b2prismaticjointdef_enablemotor(b2PrismaticJointDef * def, int value);
  331. int bmx_b2prismaticjointdef_ismotorenabled(b2PrismaticJointDef * def);
  332. void bmx_b2prismaticjointdef_setmaxmotorforce(b2PrismaticJointDef * def, float32 force);
  333. float32 bmx_b2prismaticjointdef_getmaxmotorforce(b2PrismaticJointDef * def);
  334. void bmx_b2prismaticjointdef_setmotorspeed(b2PrismaticJointDef * def, float32 speed);
  335. float32 bmx_b2prismaticjointdef_getmotorspeed(b2PrismaticJointDef * def);
  336. void bmx_b2prismaticjointdef_delete(b2PrismaticJointDef * def);
  337. void bmx_b2prismaticjointdef_initialize(b2PrismaticJointDef * def, b2Body * body1, b2Body * body2,
  338. Maxb2Vec2 * anchor, Maxb2Vec2 * axis);
  339. void bmx_b2prismaticjointdef_setlocalanchor1(b2PrismaticJointDef * def, Maxb2Vec2 * anchor);
  340. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalanchor1(b2PrismaticJointDef * def);
  341. void bmx_b2prismaticjointdef_setlocalanchor2(b2PrismaticJointDef * def, Maxb2Vec2 * anchor);
  342. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalanchor2(b2PrismaticJointDef * def);
  343. void bmx_b2prismaticjointdef_setlocalaxis1(b2PrismaticJointDef * def, Maxb2Vec2 * axis);
  344. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalaxis1(b2PrismaticJointDef * def);
  345. void bmx_b2prismaticjointdef_setreferenceangle(b2PrismaticJointDef * def, float32 angle);
  346. float32 bmx_b2prismaticjointdef_getreferenceangle(b2PrismaticJointDef * def);
  347. float32 bmx_b2revolutejoint_getlowerlimit(b2RevoluteJoint * joint);
  348. float32 bmx_b2revolutejoint_getupperlimit(b2RevoluteJoint * joint);
  349. void bmx_b2revolutejoint_setlimits(b2RevoluteJoint * joint, float32 lowerLimit, float32 upperLimit);
  350. int bmx_b2revolutejoint_ismotorenabled(b2RevoluteJoint * joint);
  351. void bmx_b2revolutejoint_enablemotor(b2RevoluteJoint * joint, int flag);
  352. void bmx_b2revolutejoint_setmotorspeed(b2RevoluteJoint * joint, float32 speed);
  353. float32 bmx_b2revolutejoint_getmotorspeed(b2RevoluteJoint * joint);
  354. void bmx_b2revolutejoint_setmaxmotortorque(b2RevoluteJoint * joint, float32 torque);
  355. float32 bmx_b2revolutejoint_getmotortorque(b2RevoluteJoint * joint);
  356. int bmx_b2revolutejoint_islimitenabled(b2RevoluteJoint * joint);
  357. void bmx_b2revolutejoint_enablelimit(b2RevoluteJoint * joint, int flag);
  358. Maxb2Vec2 bmx_b2revolutejoint_getanchor1(b2RevoluteJoint * joint);
  359. Maxb2Vec2 bmx_b2revolutejoint_getanchor2(b2RevoluteJoint * joint);
  360. Maxb2Vec2 bmx_b2revolutejoint_getreactionforce(b2RevoluteJoint * joint, float32 inv_dt);
  361. float32 bmx_b2revolutejoint_getreactiontorque(b2RevoluteJoint * joint, float32 inv_dt);
  362. float32 bmx_b2revolutejoint_getjointangle(b2RevoluteJoint * joint);
  363. float32 bmx_b2revolutejoint_getjointspeed(b2RevoluteJoint * joint);
  364. float32 bmx_b2prismaticjoint_getjointspeed(b2PrismaticJoint * joint);
  365. int bmx_b2prismaticjoint_islimitenabled(b2PrismaticJoint * joint);
  366. void bmx_b2prismaticjoint_enablelimit(b2PrismaticJoint * joint, int flag);
  367. float32 bmx_b2prismaticjoint_getlowerlimit(b2PrismaticJoint * joint);
  368. float32 bmx_b2prismaticjoint_getupperlimit(b2PrismaticJoint * joint);
  369. void bmx_b2prismaticjoint_setlimits(b2PrismaticJoint * joint, float32 lowerLimit, float32 upperLimit);
  370. int bmx_b2prismaticjoint_ismotorenabled(b2PrismaticJoint * joint);
  371. void bmx_b2prismaticjoint_enablemotor(b2PrismaticJoint * joint, int flag);
  372. void bmx_b2prismaticjoint_setmotorspeed(b2PrismaticJoint * joint, float32 speed);
  373. float32 bmx_b2prismaticjoint_getmotorspeed(b2PrismaticJoint * joint);
  374. void bmx_b2prismaticjoint_setmaxmotorforce(b2PrismaticJoint * joint, float32 force);
  375. float32 bmx_b2prismaticjoint_getmotorforce(b2PrismaticJoint * joint);
  376. Maxb2Vec2 bmx_b2prismaticjoint_getanchor1(b2PrismaticJoint * joint);
  377. Maxb2Vec2 bmx_b2prismaticjoint_getanchor2(b2PrismaticJoint * joint);
  378. Maxb2Vec2 bmx_b2prismaticjoint_getreactionforce(b2PrismaticJoint * joint, float32 inv_dt);
  379. float32 bmx_b2prismaticjoint_getreactiontorque(b2PrismaticJoint * joint, float32 inv_dt);
  380. float32 bmx_b2prismaticjoint_getjointtranslation(b2PrismaticJoint * joint);
  381. Maxb2Vec2 bmx_b2cross(Maxb2Vec2 * a, float32 s);
  382. Maxb2Vec2 bmx_b2crossf(float32 s, Maxb2Vec2 * a);
  383. Maxb2Vec2 bmx_b2mul(Maxb2Mat22 * A, Maxb2Vec2 * v);
  384. Maxb2Vec2 bmx_b2mult(Maxb2Mat22 * A, Maxb2Vec2 * v);
  385. Maxb2Vec2 bmx_b2mulf(Maxb2XForm * T, Maxb2Vec2 * v);
  386. Maxb2Vec2 bmx_b2multf(Maxb2XForm * T, Maxb2Vec2 * v);
  387. float32 bmx_b2dot(Maxb2Vec2 * a, Maxb2Vec2 * b);
  388. void bmx_b2mat22_setangle(Maxb2Mat22 * mat, float32 angle);
  389. float32 bmx_b2mat22_getangle(Maxb2Mat22 * mat);
  390. void bmx_b2mat22_createangle(Maxb2Mat22 * mat, float32 angle);
  391. Maxb2Mat22 bmx_b2mat22_getinverse(Maxb2Mat22 * mat);
  392. b2Shape * bmx_b2contact_getshape1(b2Contact * contact);
  393. b2Shape * bmx_b2contact_getshape2(b2Contact * contact);
  394. b2Contact * bmx_b2contact_getnext(b2Contact * contact);
  395. int bmx_b2contact_issolid(b2Contact * contact);
  396. int32 bmx_b2contact_getmanifoldcount(b2Contact * contact);
  397. b2GearJointDef * bmx_b2gearjointdef_new();
  398. void bmx_b2gearjointdef_setjoint1(b2GearJointDef * def, b2Joint * joint);
  399. void bmx_b2gearjointdef_setjoint2(b2GearJointDef * def, b2Joint * joint);
  400. void bmx_b2gearjointdef_setratio(b2GearJointDef * def, float32 ratio);
  401. void bmx_b2gearjointdef_delete(b2GearJointDef * def);
  402. Maxb2Vec2 bmx_b2gearjoint_getanchor1(b2GearJoint * joint);
  403. Maxb2Vec2 bmx_b2gearjoint_getanchor2(b2GearJoint * joint);
  404. Maxb2Vec2 bmx_b2gearjoint_getreactionforce(b2GearJoint * joint, float32 inv_dt);
  405. float32 bmx_b2gearjoint_getreactiontorque(b2GearJoint * joint, float32 inv_dt);
  406. float32 bmx_b2gearjoint_getratio(b2GearJoint * joint);
  407. Maxb2Vec2 bmx_b2mousejoint_getanchor1(b2MouseJoint * joint);
  408. Maxb2Vec2 bmx_b2mousejoint_getanchor2(b2MouseJoint * joint);
  409. Maxb2Vec2 bmx_b2mousejoint_getreactionforce(b2MouseJoint * joint, float32 inv_dt);
  410. float32 bmx_b2mousejoint_getreactiontorque(b2MouseJoint * joint, float32 inv_dt);
  411. void bmx_b2mousejoint_settarget(b2MouseJoint * joint, Maxb2Vec2 * target);
  412. Maxb2Vec2 bmx_b2mousejoint_gettarget(b2MouseJoint * joint);
  413. Maxb2Vec2 bmx_b2mousejoint_getlocalanchor(b2MouseJoint * joint);
  414. Maxb2Vec2 bmx_b2pulleyjoint_getanchor1(b2PulleyJoint * joint);
  415. Maxb2Vec2 bmx_b2pulleyjoint_getanchor2(b2PulleyJoint * joint);
  416. Maxb2Vec2 bmx_b2pulleyjoint_getreactionforce(b2PulleyJoint * joint, float32 inv_dt);
  417. float32 bmx_b2pulleyjoint_getreactiontorque(b2PulleyJoint * joint, float32 inv_dt);
  418. Maxb2Vec2 bmx_b2pulleyjoint_getgroundanchor1(b2PulleyJoint * joint);
  419. Maxb2Vec2 bmx_b2pulleyjoint_getgroundanchor2(b2PulleyJoint * joint);
  420. float32 bmx_b2pulleyjoint_getlength1(b2PulleyJoint * joint);
  421. float32 bmx_b2pulleyjoint_getlength2(b2PulleyJoint * joint);
  422. float32 bmx_b2pulleyjoint_getratio(b2PulleyJoint * joint);
  423. Maxb2Vec2 bmx_b2distancejoint_getanchor1(b2DistanceJoint * joint);
  424. Maxb2Vec2 bmx_b2distancejoint_getanchor2(b2DistanceJoint * joint);
  425. Maxb2Vec2 bmx_b2distancejoint_getreactionforce(b2DistanceJoint * joint, float32 inv_dt);
  426. float32 bmx_b2distancejoint_getreactiontorque(b2DistanceJoint * joint, float32 inv_dt);
  427. b2MouseJointDef * bmx_b2mousejointdef_new();
  428. void bmx_b2mousejointdef_settarget(b2MouseJointDef * def, Maxb2Vec2 * target);
  429. Maxb2Vec2 bmx_b2mousejointdef_gettarget(b2MouseJointDef * def);
  430. void bmx_b2mousejointdef_setmaxforce(b2MouseJointDef * def, float32 maxForce);
  431. float32 bmx_b2mousejointdef_getmaxforce(b2MouseJointDef * def);
  432. void bmx_b2mousejointdef_setfrequencyhz(b2MouseJointDef * def, float32 frequency);
  433. float32 bmx_b2mousejointdef_getfrequencyhz(b2MouseJointDef * def);
  434. void bmx_b2mousejointdef_setdampingration(b2MouseJointDef * def, float32 ratio);
  435. float32 bmx_b2mousejointdef_getdampingratio(b2MouseJointDef * def);
  436. void bmx_b2mousejointdef_delete(b2MouseJointDef * def);
  437. b2PulleyJointDef * bmx_b2pulleyjointdef_create();
  438. void bmx_b2pulleyjointdef_initialize(b2PulleyJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * groundAnchor1,
  439. Maxb2Vec2 * groundAnchor2, Maxb2Vec2 * anchor1, Maxb2Vec2 * anchor2, float32 ratio);
  440. void bmx_b2pulleyjointdef_setgroundanchor1(b2PulleyJointDef * def, Maxb2Vec2 * anchor);
  441. Maxb2Vec2 bmx_b2pulleyjointdef_getgroundanchor1(b2PulleyJointDef * def);
  442. void bmx_b2pulleyjointdef_setgroundanchor2(b2PulleyJointDef * def, Maxb2Vec2 * anchor);
  443. Maxb2Vec2 bmx_b2pulleyjointdef_getgroundanchor2(b2PulleyJointDef * def);
  444. void bmx_b2pulleyjointdef_setlocalanchor1(b2PulleyJointDef * def, Maxb2Vec2 * anchor);
  445. Maxb2Vec2 bmx_b2pulleyjointdef_getlocalanchor1(b2PulleyJointDef * def);
  446. void bmx_b2pulleyjointdef_setlocalanchor2(b2PulleyJointDef * def, Maxb2Vec2 * anchor);
  447. Maxb2Vec2 bmx_b2pulleyjointdef_getlocalanchor2(b2PulleyJointDef * def);
  448. void bmx_b2pulleyjointdef_setlength1(b2PulleyJointDef * def, float32 length);
  449. float32 bmx_b2pulleyjointdef_getlength1(b2PulleyJointDef * def);
  450. void bmx_b2pulleyjointdef_setmaxlength1(b2PulleyJointDef * def, float32 maxLength);
  451. float32 bmx_b2pulleyjointdef_getmaxlength1(b2PulleyJointDef * def);
  452. void bmx_b2pulleyjointdef_setlength2(b2PulleyJointDef * def, float32 length);
  453. float32 bmx_b2pulleyjointdef_getlength2(b2PulleyJointDef * def);
  454. void bmx_b2pulleyjointdef_setmaxlength2(b2PulleyJointDef * def, float32 maxLength);
  455. float32 bmx_b2pulleyjointdef_getmaxlength2(b2PulleyJointDef * def);
  456. void bmx_b2pulleyjointdef_setratio(b2PulleyJointDef * def, float32 ratio);
  457. float32 bmx_b2pulleyjointdef_getratio(b2PulleyJointDef * def);
  458. void bmx_b2pulleyjointdef_delete(b2PulleyJointDef * def);
  459. MaxDestructionListener * bmx_b2destructionlistener_new(BBObject * handle);
  460. void bmx_b2destructionlistener_delete(MaxDestructionListener * listener);
  461. Maxb2Mat22 bmx_b2obb_getrotationmatrix(b2OBB * obb);
  462. Maxb2Vec2 bmx_b2obb_getcenter(b2OBB * obb);
  463. Maxb2Vec2 bmx_b2obb_getextents(b2OBB * obb);
  464. void bmx_b2obb_delete(b2OBB * obb);
  465. BBArray * bmx_b2polygonshape_getvertices(b2PolygonShape * shape);
  466. BBArray * bmx_b2polygonshape_getcorevertices(b2PolygonShape * shape);
  467. BBArray * bmx_b2polygonshape_getnormals(b2PolygonShape * shape);
  468. const b2OBB * bmx_b2polygonshape_getobb(b2PolygonShape * shape);
  469. Maxb2Vec2 bmx_b2polygonshape_getcentroid(b2PolygonShape * shape);
  470. int bmx_b2polygonshape_getvertexcount(b2PolygonShape * shape);
  471. Maxb2Vec2 bmx_b2polygonshape_getfirstvertex(b2PolygonShape * shape, Maxb2XForm * xf);
  472. Maxb2Vec2 bmx_b2polygonshape_centroid(b2PolygonShape * shape, Maxb2XForm * xf);
  473. Maxb2Vec2 bmx_b2polygonshape_support(b2PolygonShape * shape, Maxb2XForm * xf, Maxb2Vec2 * d);
  474. int bmx_b2shape_testsegment(b2Shape * shape, Maxb2XForm * xf, float * lambda, Maxb2Vec2 * normal, Maxb2Segment * segment, float maxLambda);
  475. Maxb2Vec2 bmx_b2circleshape_getlocalposition(b2CircleShape * shape);
  476. float32 bmx_b2circleshape_getradius(b2CircleShape * shape);
  477. b2LineJointDef * bmx_b2linejointdef_create();
  478. void bmx_b2linejointdef_initialize(b2LineJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor, Maxb2Vec2 * axis);
  479. void bmx_b2linejointdef_setlocalanchor1(b2LineJointDef * def, Maxb2Vec2 * anchor);
  480. Maxb2Vec2 bmx_b2linejointdef_getlocalanchor1(b2LineJointDef * def);
  481. void bmx_b2linejointdef_setlocalanchor2(b2LineJointDef * def, Maxb2Vec2 * anchor);
  482. Maxb2Vec2 bmx_b2linejointdef_getlocalanchor2(b2LineJointDef * def);
  483. void bmx_b2linejointdef_setlocalaxis1(b2LineJointDef * def, Maxb2Vec2 * axis);
  484. Maxb2Vec2 bmx_b2linejointdef_getlocalaxis1(b2LineJointDef * def);
  485. void bmx_b2linejointdef_enablelimit(b2LineJointDef * def, int limit);
  486. int bmx_b2linejointdef_getlimit(b2LineJointDef * def);
  487. void bmx_b2linejointdef_setlowertranslation(b2LineJointDef * def, float32 translation);
  488. float32 bmx_b2linejointdef_getlowertranslation(b2LineJointDef * def);
  489. void bmx_b2linejointdef_setuppertranslation(b2LineJointDef * def, float32 translation);
  490. float32 bmx_b2linejointdef_getuppertranslation(b2LineJointDef * def);
  491. void bmx_b2linejointdef_enablemotor(b2LineJointDef * def, int enable);
  492. int bmx_b2linejointdef_ismotorenabled(b2LineJointDef * def);
  493. void bmx_b2linejointdef_setmaxmotorforce(b2LineJointDef * def, float32 maxForce);
  494. float32 bmx_b2linejointdef_getmaxmotorforce(b2LineJointDef * def);
  495. void bmx_b2linejointdef_setmotorspeed(b2LineJointDef * def, float32 speed);
  496. float32 bmx_b2linejointdef_getmotorspeed(b2LineJointDef * def);
  497. void bmx_b2linejointdef_delete(b2LineJointDef * def);
  498. Maxb2Vec2 bmx_b2linejoint_getanchor1(b2LineJoint * joint);
  499. Maxb2Vec2 bmx_b2linejoint_getanchor2(b2LineJoint * joint);
  500. Maxb2Vec2 bmx_b2linejoint_getreactionforce(b2LineJoint * joint, float32 inv_dt);
  501. float32 bmx_b2linejoint_getreactiontorque(b2LineJoint * joint, float32 inv_dt);
  502. float32 bmx_b2linejoint_getjointtranslation(b2LineJoint * joint);
  503. float32 bmx_b2linejoint_getjointspeed(b2LineJoint * joint);
  504. int bmx_b2linejoint_islimitenabled(b2LineJoint * joint);
  505. void bmx_b2linejoint_enablelimit(b2LineJoint * joint, int flag);
  506. float32 bmx_b2linejoint_getlowerlimit(b2LineJoint * joint);
  507. float32 bmx_b2linejoint_getupperlimit(b2LineJoint * joint);
  508. void bmx_b2linejoint_setlimits(b2LineJoint * joint, float32 _lower, float32 _upper);
  509. int bmx_b2linejoint_ismotorenabled(b2LineJoint * joint);
  510. void bmx_b2linejoint_enablemotor(b2LineJoint * joint, int flag);
  511. void bmx_b2linejoint_setmotorspeed(b2LineJoint * joint, float32 speed);
  512. float32 bmx_b2linejoint_getmotorspeed(b2LineJoint * joint);
  513. void bmx_b2linejoint_setmaxmotorforce(b2LineJoint * joint, float32 force);
  514. float32 bmx_b2linejoint_getmotorforce(b2LineJoint * joint);
  515. Maxb2EdgeChainDef * bmx_b2edgechaindef_create();
  516. b2EdgeChainDef * bmx_b2edgechaindef_getdef(Maxb2EdgeChainDef * def);
  517. int bmx_b2edgechaindef_isaloop(Maxb2EdgeChainDef * def);
  518. void bmx_b2edgechaindef_setisaloop(Maxb2EdgeChainDef * def, int value);
  519. void bmx_b2edgechaindef_delete(Maxb2EdgeChainDef * def);
  520. void bmx_b2edgechaindef_setvertices(Maxb2EdgeChainDef * def, BBArray * vertices);
  521. float32 bmx_b2edgeshape_getlength(b2EdgeShape * shape);
  522. Maxb2Vec2 bmx_b2edgeshape_getvertex1(b2EdgeShape * shape);
  523. Maxb2Vec2 bmx_b2edgeshape_getvertex2(b2EdgeShape * shape);
  524. Maxb2Vec2 bmx_b2edgeshape_getcorevertex1(b2EdgeShape * shape);
  525. Maxb2Vec2 bmx_b2edgeshape_getcorevertex2(b2EdgeShape * shape);
  526. Maxb2Vec2 bmx_b2edgeshape_getnormalvector(b2EdgeShape * shape);
  527. Maxb2Vec2 bmx_b2edgeshape_getdirectionvector(b2EdgeShape * shape);
  528. Maxb2Vec2 bmx_b2edgeshape_getcorner1vector(b2EdgeShape * shape);
  529. Maxb2Vec2 bmx_b2edgeshape_getcorner2vector(b2EdgeShape * shape);
  530. int bmx_b2edgeshape_corner1isconvex(b2EdgeShape * shape);
  531. int bmx_b2edgeshape_corner2isconvex(b2EdgeShape * shape);
  532. Maxb2Vec2 bmx_b2edgeshape_getfirstvertex(b2EdgeShape * shape, Maxb2XForm * xf);
  533. Maxb2Vec2 bmx_b2edgeshape_support(b2EdgeShape * shape, Maxb2XForm * xf, Maxb2Vec2 * d);
  534. b2EdgeShape * bmx_b2edgeshape_getnextedge(b2EdgeShape * shape);
  535. b2EdgeShape * bmx_b2edgeshape_getprevedge(b2EdgeShape * shape);
  536. b2BuoyancyControllerDef * bmx_b2buoyancycontrollerdef_create();
  537. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getnormal(b2BuoyancyControllerDef * def);
  538. void bmx_b2buoyancycontrollerdef_setnormal(b2BuoyancyControllerDef * def, Maxb2Vec2 * normal);
  539. float32 bmx_b2buoyancycontrollerdef_getoffset(b2BuoyancyControllerDef * def);
  540. void bmx_b2buoyancycontrollerdef_setoffset(b2BuoyancyControllerDef * def, float32 offset);
  541. float32 bmx_b2buoyancycontrollerdef_getdensity(b2BuoyancyControllerDef * def);
  542. void bmx_b2buoyancycontrollerdef_setdensity(b2BuoyancyControllerDef * def, float32 density);
  543. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getvelocity(b2BuoyancyControllerDef * def);
  544. void bmx_b2buoyancycontrollerdef_setvelocity(b2BuoyancyControllerDef * def, Maxb2Vec2 * velocity);
  545. float32 bmx_b2buoyancycontrollerdef_getlineardrag(b2BuoyancyControllerDef * def);
  546. void bmx_b2buoyancycontrollerdef_setlineardrag(b2BuoyancyControllerDef * def, float32 drag);
  547. float32 bmx_b2buoyancycontrollerdef_getangulardrag(b2BuoyancyControllerDef * def);
  548. void bmx_b2buoyancycontrollerdef_setangulardrag(b2BuoyancyControllerDef * def, float32 drag);
  549. int bmx_b2buoyancycontrollerdef_usesdensity(b2BuoyancyControllerDef * def);
  550. void bmx_b2buoyancycontrollerdef_setusesdensity(b2BuoyancyControllerDef * def, int value);
  551. int bmx_b2buoyancycontrollerdef_usesworldgravity(b2BuoyancyControllerDef * def);
  552. void bmx_b2buoyancycontrollerdef_setusesworldgravity(b2BuoyancyControllerDef * def, int value);
  553. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getgravity(b2BuoyancyControllerDef * def);
  554. void bmx_b2buoyancycontrollerdef_setgravity(b2BuoyancyControllerDef * def, Maxb2Vec2 * gravity);
  555. void bmx_b2buoyancycontrollerdef_delete(b2BuoyancyControllerDef * def);
  556. Maxb2Vec2 bmx_b2buoyancycontroller_getnormal(b2BuoyancyController * c);
  557. void bmx_b2buoyancycontroller_setnormal(b2BuoyancyController * c, Maxb2Vec2 * normal);
  558. float32 bmx_b2buoyancycontroller_getoffset(b2BuoyancyController * c);
  559. void bmx_b2buoyancycontroller_setoffset(b2BuoyancyController * c, float32 offset);
  560. float32 bmx_b2buoyancycontroller_getdensity(b2BuoyancyController * c);
  561. void bmx_b2buoyancycontroller_setdensity(b2BuoyancyController * c, float32 density);
  562. Maxb2Vec2 bmx_b2buoyancycontroller_getvelocity(b2BuoyancyController * c);
  563. void bmx_b2buoyancycontroller_setvelocity(b2BuoyancyController * c, Maxb2Vec2 * velocity);
  564. float32 bmx_b2buoyancycontroller_getlineardrag(b2BuoyancyController * c);
  565. void bmx_b2buoyancycontroller_setlineardrag(b2BuoyancyController * c, float32 drag);
  566. float32 bmx_b2buoyancycontroller_getangulardrag(b2BuoyancyController * c);
  567. void bmx_b2buoyancycontroller_setangulardrag(b2BuoyancyController * c, float32 drag);
  568. int bmx_b2buoyancycontroller_usesdensity(b2BuoyancyController * c);
  569. void bmx_b2buoyancycontroller_setusesdensity(b2BuoyancyController * c, int value);
  570. int bmx_b2buoyancycontroller_usesworldgravity(b2BuoyancyController * c);
  571. void bmx_b2buoyancycontroller_setusesworldgravity(b2BuoyancyController * c, int value);
  572. Maxb2Vec2 bmx_b2buoyancycontroller_getgravity(b2BuoyancyController * c);
  573. void bmx_b2buoyancycontroller_setgravity(b2BuoyancyController * c, Maxb2Vec2 * gravity);
  574. b2TensorDampingControllerDef * bmx_b2tensordampingcontrollerdef_create();
  575. void bmx_b2tensordampingcontrollerdef_delete(b2TensorDampingControllerDef * def);
  576. Maxb2Mat22 bmx_b2tensordampingcontrollerdef_gettensor(b2TensorDampingControllerDef * def);
  577. void bmx_b2tensordampingcontrollerdef_settensor(b2TensorDampingControllerDef * def, Maxb2Mat22 * tensor);
  578. float32 bmx_b2tensordampingcontrollerdef_getmaxtimestep(b2TensorDampingControllerDef * def);
  579. void bmx_b2tensordampingcontrollerdef_setmaxtimestep(b2TensorDampingControllerDef * def, float32 timestep);
  580. void bmx_b2tensordampingcontrollerdef_setaxisaligned(b2TensorDampingControllerDef * def, float32 xDamping, float32 yDamping);
  581. Maxb2Mat22 bmx_b2tensordampingcontroller_gettensor(b2TensorDampingController * c);
  582. void bmx_b2tensordampingcontroller_settensor(b2TensorDampingController * c, Maxb2Mat22 * tensor);
  583. float32 bmx_b2tensordampingcontroller_getmaxtimestep(b2TensorDampingController * c);
  584. void bmx_b2tensordampingcontroller_setmaxtimestep(b2TensorDampingController * c, float32 timestep);
  585. b2GravityControllerDef * bmx_b2gravitycontrollerdef_create();
  586. void bmx_b2gravitycontrollerdef_delete(b2GravityControllerDef * def);
  587. float32 bmx_b2gravitycontrollerdef_getforce(b2GravityControllerDef * def);
  588. void bmx_b2gravitycontrollerdef_setforce(b2GravityControllerDef * def, float32 force);
  589. int bmx_b2gravitycontrollerdef_isinvsqr(b2GravityControllerDef * def);
  590. void bmx_b2gravitycontrollerdef_setisinvsqr(b2GravityControllerDef * def, int value);
  591. float32 bmx_b2gravitycontroller_getforce(b2GravityController * c);
  592. void bmx_b2gravitycontroller_setforce(b2GravityController * c, float32 force);
  593. int bmx_b2gravitycontroller_isinvsqr(b2GravityController * c);
  594. void bmx_b2gravitycontroller_setisinvsqr(b2GravityController * c, int value);
  595. b2ConstantForceControllerDef * bmx_b2constantforcecontrollerdef_create();
  596. void bmx_b2constantforcecontrollerdef_delete(b2ConstantForceControllerDef * def);
  597. Maxb2Vec2 bmx_b2constantforcecontrollerdef_getforce(b2ConstantForceControllerDef * def);
  598. void bmx_b2constantforcecontrollerdef_setforce(b2ConstantForceControllerDef * def, Maxb2Vec2 * force);
  599. Maxb2Vec2 bmx_b2constantforcecontroller_getforce(b2ConstantForceController * c);
  600. void bmx_b2constantforcecontroller_setforce(b2ConstantForceController * c, Maxb2Vec2 * force);
  601. b2ConstantAccelControllerDef * bmx_b2constantaccelcontrollerdef_create();
  602. Maxb2Vec2 bmx_b2constantaccelcontrollerdef_getforce(b2ConstantAccelControllerDef * def);
  603. void bmx_b2constantaccelcontrollerdef_setforce(b2ConstantAccelControllerDef * def, Maxb2Vec2 * force);
  604. void bmx_b2constantaccelcontrollerdef_delete(b2ConstantAccelControllerDef * def);
  605. Maxb2Vec2 bmx_b2constantaccelcontroller_getforce(b2ConstantAccelController * c);
  606. void bmx_b2constantaccelcontroller_setforce(b2ConstantAccelController * c, Maxb2Vec2 * force);
  607. b2Controller * bmx_b2controlleredge_getcontroller(b2ControllerEdge * edge);
  608. b2Body * bmx_b2controlleredge_getbody(b2ControllerEdge * edge);
  609. b2ControllerEdge * bmx_b2controlleredge_getprevbody(b2ControllerEdge * edge);
  610. b2ControllerEdge * bmx_b2controlleredge_getnextbody(b2ControllerEdge * edge);
  611. b2ControllerEdge * bmx_b2controlleredge_getprevcontroller(b2ControllerEdge * edge);
  612. b2ControllerEdge * bmx_b2controlleredge_getnextcontroller(b2ControllerEdge * edge);
  613. BBObject * bmx_b2controller_getmaxcontroller(b2Controller * c);
  614. void bmx_b2controller_addbody(b2Controller * c, b2Body * body);
  615. void bmx_b2controller_removebody(b2Controller * c, b2Body * body);
  616. void bmx_b2controller_clear(b2Controller * c);
  617. b2Controller * bmx_b2controller_getnext(b2Controller * c);
  618. b2World * bmx_b2controller_getworld(b2Controller * c);
  619. b2ControllerEdge * bmx_b2controller_getbodylist(b2Controller * c);
  620. }
  621. // *****************************************************
  622. class Maxb2EdgeChainDef
  623. {
  624. public:
  625. Maxb2EdgeChainDef()
  626. {
  627. def = new b2EdgeChainDef;
  628. vertices = NULL;
  629. }
  630. ~Maxb2EdgeChainDef()
  631. {
  632. delete def;
  633. if (vertices) {
  634. delete [] vertices;
  635. }
  636. }
  637. void initVertices(int size) {
  638. if (vertices) {
  639. delete [] vertices;
  640. def->vertices = NULL;
  641. }
  642. vertices = new b2Vec2[size];
  643. def->vertexCount = size;
  644. def->vertices = vertices;
  645. }
  646. b2EdgeChainDef * def;
  647. b2Vec2 * vertices;
  648. };
  649. // *****************************************************
  650. int bmx_b2abb_isvalid(Maxb2AABB * aabb) {
  651. b2AABB b;
  652. bmx_Maxb2AABBtob2AABB(aabb, &b);
  653. return b.IsValid();
  654. }
  655. // *****************************************************
  656. float32 bmx_b2vec2_length(Maxb2Vec2 * vec) {
  657. b2Vec2 v(vec->x, vec->y);
  658. return v.Length();
  659. }
  660. float32 bmx_b2vec2_normalize(Maxb2Vec2 * vec) {
  661. b2Vec2 v(vec->x, vec->y);
  662. return v.Normalize();
  663. }
  664. float32 bmx_b2vec2_lengthsquared(Maxb2Vec2 * vec) {
  665. b2Vec2 v(vec->x, vec->y);
  666. return v.LengthSquared();
  667. }
  668. BBArray * bmx_b2vec2_getvertexarray(const b2Vec2* vertices, int32 vertexCount) {
  669. BBArray * array = CB_PREF(physics_box2d_b2Vec2__newVecArray)(vertexCount);
  670. const b2Vec2* vp = vertices;
  671. Maxb2Vec2* mv=(Maxb2Vec2*)BBARRAYDATA( array,array->dims );
  672. for( int i=0;i<vertexCount;++i ){
  673. mv->x = vp->x;
  674. mv->y = vp->y;
  675. mv++;
  676. vp++;
  677. }
  678. return array;
  679. }
  680. // *****************************************************
  681. b2Body * bmx_b2world_createbody(b2World * world, b2BodyDef * def, BBObject * body) {
  682. def->userData = body;
  683. BBRETAIN(body);
  684. return world->CreateBody(def);
  685. }
  686. void bmx_b2world_destroybody(b2World * world, b2Body * body) {
  687. void * data = body->GetUserData();
  688. if (data && data != &bbNullObject) {
  689. BBRELEASE((BBObject*)data);
  690. }
  691. world->DestroyBody(body);
  692. }
  693. b2Body * bmx_b2world_getgroundbody(b2World * world) {
  694. return world->GetGroundBody();
  695. }
  696. void bmx_b2world_setwarmstarting(b2World * world, int flag) {
  697. world->SetWarmStarting(flag);
  698. }
  699. void bmx_b2world_setcontinuousphysics(b2World * world, int flag) {
  700. world->SetContinuousPhysics(flag);
  701. }
  702. void bmx_b2world_validate(b2World * world) {
  703. world->Validate();
  704. }
  705. void bmx_b2world_setdebugDraw(b2World * world, b2DebugDraw * debugDraw) {
  706. world->SetDebugDraw(debugDraw);
  707. }
  708. b2Joint * bmx_b2world_createjoint(b2World * world, b2JointDef * def) {
  709. BBObject * joint = CB_PREF(physics_box2d_b2World__createJoint)(def->type);
  710. def->userData = joint;
  711. BBRETAIN(joint);
  712. return world->CreateJoint(def);
  713. }
  714. void bmx_b2world_destroyjoint(b2World * world, b2Joint * joint) {
  715. void * data = joint->GetUserData();
  716. if (data && data != &bbNullObject) {
  717. BBRELEASE((BBObject*)data);
  718. }
  719. world->DestroyJoint(joint);
  720. }
  721. b2Body * bmx_b2world_getbodylist(b2World * world) {
  722. return world->GetBodyList();
  723. }
  724. b2Joint * bmx_b2world_getjointlist(b2World * world) {
  725. return world->GetJointList();
  726. }
  727. void bmx_b2world_setfilter(b2World * world, b2ContactFilter * filter) {
  728. world->SetContactFilter(filter);
  729. }
  730. void bmx_b2world_setcontactlistener(b2World * world, b2ContactListener * listener) {
  731. world->SetContactListener(listener);
  732. }
  733. void bmx_b2world_setboundarylistener(b2World * world, b2BoundaryListener * listener) {
  734. world->SetBoundaryListener(listener);
  735. }
  736. void bmx_b2world_setgravity(b2World * world, Maxb2Vec2 * gravity) {
  737. world->SetGravity(b2Vec2(gravity->x, gravity->y));
  738. }
  739. int32 bmx_b2world_getproxycount(b2World * world) {
  740. return world->GetProxyCount();
  741. }
  742. int32 bmx_b2world_getpaircount(b2World * world) {
  743. return world->GetPairCount();
  744. }
  745. int32 bmx_b2world_getbodycount(b2World * world) {
  746. return world->GetBodyCount();
  747. }
  748. int32 bmx_b2world_getjointcount(b2World * world) {
  749. return world->GetJointCount();
  750. }
  751. int32 bmx_b2world_query(b2World * world, Maxb2AABB * aabb, BBArray * shapes) {
  752. int32 n = shapes->scales[0];
  753. b2Shape* _shapes[n];
  754. b2AABB b;
  755. bmx_Maxb2AABBtob2AABB(aabb, &b);
  756. int32 ret = world->Query(b, _shapes, n);
  757. int32 count = (ret < n) ? ret : n;
  758. for (int i = 0; i < count; i++) {
  759. CB_PREF(physics_box2d_b2World__setShape)(shapes, i, _shapes[i]);
  760. }
  761. return count;
  762. }
  763. void bmx_b2world_free(b2World * world) {
  764. delete world;
  765. }
  766. void bmx_b2world_setdestructionlistener(b2World * world, b2DestructionListener * listener) {
  767. world->SetDestructionListener(listener);
  768. }
  769. void bmx_b2world_refilter(b2World * world, b2Shape * shape) {
  770. world->Refilter(shape);
  771. }
  772. int32 bmx_b2world_raycast(b2World * world, Maxb2Segment * segment, BBArray * shapes, int solidShapes) {
  773. int32 n = shapes->scales[0];
  774. b2Shape* _shapes[n];
  775. b2Segment s;
  776. s.p1 = b2Vec2(segment->p1.x, segment->p1.y);
  777. s.p2 = b2Vec2(segment->p2.x, segment->p2.y);
  778. int32 ret = world->Raycast(s, _shapes, n, solidShapes, NULL);
  779. int32 count = (ret < n) ? ret : n;
  780. for (int i = 0; i < count; i++) {
  781. CB_PREF(physics_box2d_b2World__setShape)(shapes, i, _shapes[i]);
  782. }
  783. return ret;
  784. }
  785. b2Shape * bmx_b2world_raycastone(b2World * world, Maxb2Segment * segment, float32 * lambda, Maxb2Vec2 * normal, int solidShapes) {
  786. b2Vec2 norm;
  787. b2Segment s;
  788. s.p1 = b2Vec2(segment->p1.x, segment->p1.y);
  789. s.p2 = b2Vec2(segment->p2.x, segment->p2.y);
  790. b2Shape * shape = world->RaycastOne(s, lambda, &norm, solidShapes, NULL);
  791. normal->x = norm.x;
  792. normal->y = norm.y;
  793. return shape;
  794. }
  795. int bmx_b2world_inrange(b2World * world, Maxb2AABB * aabb) {
  796. b2AABB b;
  797. bmx_Maxb2AABBtob2AABB(aabb, &b);
  798. return world->InRange(b);
  799. }
  800. b2Controller * bmx_b2world_createcontroller(b2World * world, b2ControllerDef * def, b2ControllerType type) {
  801. BBObject * bbController = CB_PREF(physics_box2d_b2World___createController)(type);
  802. BBRETAIN(bbController);
  803. b2Controller * controller = world->CreateController(def);
  804. controller->SetUserData((void*)bbController);
  805. return controller;
  806. }
  807. void bmx_b2world_destroycontroller(b2World * world, b2Controller * controller) {
  808. void * data = controller->GetUserData();
  809. if (data && data != &bbNullObject) {
  810. BBRELEASE((BBObject*)data);
  811. }
  812. world->DestroyController(controller);
  813. }
  814. // *****************************************************
  815. b2BodyDef * bmx_b2bodydef_create() {
  816. return new b2BodyDef;
  817. }
  818. void bmx_b2bodydef_delete(b2BodyDef * def) {
  819. delete def;
  820. }
  821. void bmx_b2bodydef_setposition(b2BodyDef * def, Maxb2Vec2 * position) {
  822. b2Vec2 p(position->x, position->y);
  823. def->position = p;
  824. }
  825. void bmx_b2bodydef_setangle(b2BodyDef * def, float32 angle) {
  826. def->angle = angle * 0.0174533f;
  827. }
  828. void bmx_b2bodydef_setmassdata(b2BodyDef * def, b2MassData * data) {
  829. def->massData = *data;
  830. }
  831. int bmx_b2bodydef_issleeping(b2BodyDef * def) {
  832. return def->isSleeping;
  833. }
  834. void bmx_b2bodydef_setissleeping(b2BodyDef * def, int sleeping) {
  835. def->isSleeping = sleeping;
  836. }
  837. void bmx_b2bodydef_setfixedrotation(b2BodyDef * def, int fixed) {
  838. def->fixedRotation = fixed;
  839. }
  840. int bmx_b2bodydef_getfixedrotation(b2BodyDef * def) {
  841. return def->fixedRotation;
  842. }
  843. void bmx_b2bodydef_setisbullet(b2BodyDef * def, int bullet) {
  844. def->isBullet = bullet;
  845. }
  846. void bmx_b2bodydef_setlineardamping(b2BodyDef * def, float32 damping) {
  847. def->linearDamping = damping;
  848. }
  849. float32 bmx_b2bodydef_getlineardamping(b2BodyDef * def) {
  850. return def->linearDamping;
  851. }
  852. void bmx_b2bodydef_setangulardamping(b2BodyDef * def, float32 damping) {
  853. def->angularDamping = damping;
  854. }
  855. float32 bmx_b2bodydef_getangulardamping(b2BodyDef * def) {
  856. return def->angularDamping;
  857. }
  858. void bmx_b2bodydef_setallowsleep(b2BodyDef * def, int allow) {
  859. def->allowSleep = allow;
  860. }
  861. int bmx_b2bodydef_getallowsleep(b2BodyDef * def) {
  862. return def->allowSleep;
  863. }
  864. Maxb2Vec2 bmx_b2bodydef_getposition(b2BodyDef * def) {
  865. return {def->position.x, def->position.y};
  866. }
  867. void bmx_b2bodydef_setpositionxy(b2BodyDef * def, float32 x, float32 y) {
  868. def->position = b2Vec2(x, y);
  869. }
  870. float32 bmx_b2bodydef_getangle(b2BodyDef * def) {
  871. return def->angle * 57.2957795f;
  872. }
  873. int bmx_b2bodydef_isbullet(b2BodyDef * def) {
  874. return def->isBullet;
  875. }
  876. b2MassData * bmx_b2bodydef_getmassdata(b2BodyDef * def) {
  877. return &def->massData;
  878. }
  879. // *****************************************************
  880. b2World * bmx_b2world_create(Maxb2AABB * worldAABB, Maxb2Vec2 * gravity, int doSleep) {
  881. b2AABB b;
  882. bmx_Maxb2AABBtob2AABB( worldAABB, &b);
  883. return new b2World(b, b2Vec2(gravity->x, gravity->y), doSleep);
  884. }
  885. void bmx_b2world_dostep(b2World * world, float32 timeStep, int velocityIterations, int positionIterations) {
  886. world->Step(timeStep, velocityIterations, positionIterations);
  887. }
  888. // *****************************************************
  889. void bmx_b2shapedef_setfriction(b2ShapeDef * def, float32 friction) {
  890. def->friction = friction;
  891. }
  892. void bmx_b2shapedef_setrestitution(b2ShapeDef * def, float32 restitution) {
  893. def->restitution = restitution;
  894. }
  895. void bmx_b2shapedef_setdensity(b2ShapeDef * def, float32 density) {
  896. def->density = density;
  897. }
  898. void bmx_b2shapedef_setfilter(b2ShapeDef * def, Maxb2FilterData filterData) {
  899. def->filter.categoryBits = filterData.categoryBits;
  900. def->filter.groupIndex = filterData.groupIndex;
  901. def->filter.maskBits = filterData.maskBits;
  902. }
  903. Maxb2FilterData bmx_b2shapedef_getfilter(b2ShapeDef * def) {
  904. Maxb2FilterData data = {def->filter.categoryBits, def->filter.maskBits, def->filter.groupIndex};
  905. return data;
  906. }
  907. void bmx_b2shapedef_setissensor(b2ShapeDef * def, int sensor) {
  908. def->isSensor = sensor;
  909. }
  910. int bmx_b2shapedef_issensor(b2ShapeDef * def) {
  911. return def->isSensor;
  912. }
  913. float32 bmx_b2shapedef_getfriction(b2ShapeDef * def) {
  914. return def->friction;
  915. }
  916. float32 bmx_b2shapedef_getrestitution(b2ShapeDef * def) {
  917. return def->restitution;
  918. }
  919. float32 bmx_b2shapedef_getdensity(b2ShapeDef * def) {
  920. return def->density;
  921. }
  922. void bmx_b2shapedef_setfilter_groupindex(b2ShapeDef * def, int groupIndex) {
  923. def->filter.groupIndex = (int16)groupIndex;
  924. }
  925. void bmx_b2shapedef_setfilter_categorybits(b2ShapeDef * def, BBSHORT categoryBits) {
  926. def->filter.categoryBits = categoryBits;
  927. }
  928. void bmx_b2shapedef_setfilter_maskbits(b2ShapeDef * def, BBSHORT maskBits) {
  929. def->filter.maskBits = maskBits;
  930. }
  931. // *****************************************************
  932. b2PolygonDef * bmx_b2polygondef_create() {
  933. return new b2PolygonDef;
  934. }
  935. void bmx_b2polygondef_setasbox(b2PolygonDef * def, float32 hx, float32 hy) {
  936. def->SetAsBox(hx, hy);
  937. }
  938. void bmx_b2polygondef_delete(b2PolygonDef * def) {
  939. delete def;
  940. }
  941. void bmx_b2polygondef_setasorientedbox(b2PolygonDef * def, float32 hx, float32 hy, b2Vec2 * center, float32 angle) {
  942. def->SetAsBox(hx, hy, *center, angle * 0.0174533f);
  943. }
  944. void bmx_b2polygondef_setvertices(b2PolygonDef * def, BBArray * vertices) {
  945. int n = vertices->scales[0];
  946. def->vertexCount = n;
  947. Maxb2Vec2* mv=(Maxb2Vec2*)BBARRAYDATA( vertices,vertices->dims );
  948. b2Vec2* vp = def->vertices;
  949. for (int i = 0; i < n; i++) {
  950. vp->x = mv->x;
  951. vp->y = mv->y;
  952. vp++;
  953. mv++;
  954. }
  955. }
  956. // *****************************************************
  957. b2Shape * bmx_b2body_createshape(b2Body * body, b2ShapeDef * def) {
  958. BBObject * shape = CB_PREF(physics_box2d_b2Body__createShape)(def->type);
  959. def->userData = shape;
  960. BBRETAIN(shape);
  961. b2Shape * theShape = body->CreateShape(def);
  962. // if we are edges... we need to add lots of shapes (one per edge)
  963. if (def->type == e_edgeShape) {
  964. b2EdgeShape * edge = ((b2EdgeShape*)theShape)->GetNextEdge();
  965. while ((edge != theShape) && (edge != NULL)) {
  966. shape = CB_PREF(physics_box2d_b2Body__createShape)(def->type);
  967. edge->SetUserData(shape);
  968. BBRETAIN(shape);
  969. edge = edge->GetNextEdge();
  970. }
  971. }
  972. return theShape;
  973. }
  974. void bmx_b2body_destroyshape(b2Body * body, b2Shape * shape) {
  975. void * data = shape->GetUserData();
  976. if (data && data != &bbNullObject) {
  977. BBRELEASE((BBObject*)data);
  978. }
  979. body->DestroyShape(shape);
  980. }
  981. void bmx_b2body_setmassfromshapes(b2Body * body) {
  982. body->SetMassFromShapes();
  983. }
  984. Maxb2Vec2 bmx_b2body_getposition(b2Body * body) {
  985. b2Vec2 p = body->GetPosition();
  986. return {p.x, p.y};
  987. }
  988. float32 bmx_b2body_getangle(b2Body * body) {
  989. return body->GetAngle() * 57.2957795f;
  990. }
  991. BBObject * bmx_b2body_getmaxbody(b2Body * body) {
  992. void * obj = body->GetUserData();
  993. if (obj) {
  994. return (BBObject *)obj;
  995. }
  996. return &bbNullObject;
  997. }
  998. void bmx_b2body_setmaxbody(b2Body * body, BBObject * obj) {
  999. body->SetUserData(obj);
  1000. BBRETAIN(obj);
  1001. }
  1002. b2Body * bmx_b2body_getnext(b2Body * body) {
  1003. return body->GetNext();
  1004. }
  1005. b2Shape * bmx_b2body_getshapelist(b2Body * body) {
  1006. return body->GetShapeList();
  1007. }
  1008. int bmx_b2body_isstatic(b2Body * body) {
  1009. return body->IsStatic();
  1010. }
  1011. int bmx_b2body_isdynamic(b2Body * body) {
  1012. return body->IsDynamic();
  1013. }
  1014. int bmx_b2body_isfrozen(b2Body * body) {
  1015. return body->IsFrozen();
  1016. }
  1017. int bmx_b2body_issleeping(b2Body * body) {
  1018. return body->IsSleeping();
  1019. }
  1020. void bmx_b2body_allowsleeping(b2Body * body, int flag) {
  1021. body->AllowSleeping(flag);
  1022. }
  1023. void bmx_b2body_wakeup(b2Body * body) {
  1024. body->WakeUp();
  1025. }
  1026. void bmx_b2body_puttosleep(b2Body * body) {
  1027. body->PutToSleep();
  1028. }
  1029. int bmx_b2body_isbullet(b2Body * body) {
  1030. return body->IsBullet();
  1031. }
  1032. void bmx_b2body_setbullet(b2Body * body, int flag) {
  1033. body->SetBullet(flag);
  1034. }
  1035. Maxb2Vec2 bmx_b2body_getworldcenter(b2Body * body) {
  1036. b2Vec2 c = body->GetWorldCenter();
  1037. return {c.x, c.y};
  1038. }
  1039. Maxb2Vec2 bmx_b2body_getlocalcenter(b2Body * body) {
  1040. b2Vec2 c = body->GetLocalCenter();
  1041. return {c.x, c.y};
  1042. }
  1043. void bmx_b2body_setlinearvelocity(b2Body * body, Maxb2Vec2 * v) {
  1044. b2Vec2 b(v->x, v->y);
  1045. body->SetLinearVelocity(b);
  1046. }
  1047. Maxb2Vec2 bmx_b2body_getlinearvelocity(b2Body * body) {
  1048. b2Vec2 b = body->GetLinearVelocity();
  1049. return {b.x, b.y};
  1050. }
  1051. void bmx_b2body_setangularvelocity(b2Body * body, float32 omega) {
  1052. body->SetAngularVelocity(omega * 0.0174533f);
  1053. }
  1054. float32 bmx_b2body_getangularvelocity(b2Body * body) {
  1055. return body->GetAngularVelocity() * 57.2957795f;
  1056. }
  1057. void bmx_b2body_applyforce(b2Body * body, Maxb2Vec2 * force, Maxb2Vec2 * point) {
  1058. b2Vec2 f(force->x, force->y);
  1059. b2Vec2 p(point->x, point->y);
  1060. body->ApplyForce(f, p);
  1061. }
  1062. void bmx_b2body_applytorque(b2Body * body, float32 torque) {
  1063. body->ApplyTorque(torque);
  1064. }
  1065. void bmx_b2body_applyimpulse(b2Body * body, Maxb2Vec2 * impulse, Maxb2Vec2 * point) {
  1066. b2Vec2 i(impulse->x, impulse->y);
  1067. b2Vec2 p(point->x, point->y);
  1068. body->ApplyImpulse(i, p);
  1069. }
  1070. float32 bmx_b2body_getmass(b2Body * body) {
  1071. return body->GetMass();
  1072. }
  1073. float32 bmx_b2body_getinertia(b2Body * body) {
  1074. return body->GetInertia();
  1075. }
  1076. Maxb2Vec2 bmx_b2body_getworldpoint(b2Body * body, Maxb2Vec2 * localPoint) {
  1077. b2Vec2 p(localPoint->x, localPoint->y);
  1078. b2Vec2 wp = body->GetWorldPoint(p);
  1079. return {wp.x, wp.y};
  1080. }
  1081. Maxb2Vec2 bmx_b2body_getworldvector(b2Body * body, Maxb2Vec2 * localVector) {
  1082. b2Vec2 v(localVector->x, localVector->y);
  1083. b2Vec2 wv = body->GetWorldVector(v);
  1084. return {wv.x, wv.y};
  1085. }
  1086. Maxb2Vec2 bmx_b2body_getlocalpoint(b2Body * body, Maxb2Vec2 * worldPoint) {
  1087. b2Vec2 p(worldPoint->x, worldPoint->y);
  1088. b2Vec2 lp = body->GetLocalPoint(p);
  1089. return {lp.x, lp.y};
  1090. }
  1091. Maxb2Vec2 bmx_b2body_getlocalvector(b2Body * body, Maxb2Vec2 * worldVector) {
  1092. b2Vec2 v(worldVector->x, worldVector->y);
  1093. b2Vec2 lv = body->GetLocalVector(v);
  1094. return {lv.x, lv.y};
  1095. }
  1096. b2JointEdge * bmx_b2body_getjointlist(b2Body * body) {
  1097. return body->GetJointList();
  1098. }
  1099. Maxb2XForm bmx_b2body_getxform(b2Body * body) {
  1100. b2XForm f(body->GetXForm());
  1101. Maxb2XForm mf = { {f.position.x, f.position.y}, { {f.R.col1.x, f.R.col1.y}, {f.R.col2.x, f.R.col2.y} } };
  1102. return mf;
  1103. }
  1104. int bmx_b2body_setxform(b2Body * body, Maxb2Vec2 * position, float32 angle) {
  1105. b2Vec2 p(position->x, position->y);
  1106. return body->SetXForm(p, angle * 0.0174533f);
  1107. }
  1108. b2World * bmx_b2body_getworld(b2Body * body) {
  1109. return body->GetWorld();
  1110. }
  1111. void bmx_b2body_setmass(b2Body * body, b2MassData * massData) {
  1112. body->SetMass(massData);
  1113. }
  1114. // *****************************************************
  1115. class MaxDebugDraw : public b2DebugDraw
  1116. {
  1117. public:
  1118. MaxDebugDraw(BBObject * handle)
  1119. : maxHandle(handle)
  1120. {
  1121. }
  1122. ~MaxDebugDraw() {}
  1123. void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) {
  1124. BBArray * array = bmx_b2vec2_getvertexarray(vertices, vertexCount);
  1125. CB_PREF(physics_box2d_b2DebugDraw__DrawPolygon)(maxHandle, array,
  1126. static_cast<int>(color.r * 255.0f),
  1127. static_cast<int>(color.g * 255.0f),
  1128. static_cast<int>(color.b * 255.0f));
  1129. }
  1130. void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) {
  1131. BBArray * array = bmx_b2vec2_getvertexarray(vertices, vertexCount);
  1132. CB_PREF(physics_box2d_b2DebugDraw__DrawSolidPolygon)(maxHandle, array,
  1133. static_cast<int>(color.r * 255.0f),
  1134. static_cast<int>(color.g * 255.0f),
  1135. static_cast<int>(color.b * 255.0f));
  1136. }
  1137. void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) {
  1138. }
  1139. void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) {
  1140. Maxb2Vec2 c = {center.x, center.y};
  1141. Maxb2Vec2 a = {axis.x, axis.y};
  1142. CB_PREF(physics_box2d_b2DebugDraw__DrawSolidCircle)(maxHandle, c, radius, a,
  1143. static_cast<int>(color.r * 255.0f),
  1144. static_cast<int>(color.g * 255.0f),
  1145. static_cast<int>(color.b * 255.0f));
  1146. }
  1147. void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) {
  1148. Maxb2Vec2 v1 = {p1.x, p1.y};
  1149. Maxb2Vec2 v2 = {p2.x, p2.y};
  1150. CB_PREF(physics_box2d_b2DebugDraw__DrawSegment)(maxHandle, v1, v2,
  1151. static_cast<int>(color.r * 255.0f),
  1152. static_cast<int>(color.g * 255.0f),
  1153. static_cast<int>(color.b * 255.0f));
  1154. }
  1155. void DrawXForm(const b2XForm& xf) {
  1156. }
  1157. void SetFlags(uint32 flags) {
  1158. b2DebugDraw::m_drawFlags = flags;
  1159. }
  1160. private:
  1161. BBObject * maxHandle;
  1162. };
  1163. MaxDebugDraw * bmx_b2debugdraw_create(BBObject * handle) {
  1164. return new MaxDebugDraw(handle);
  1165. }
  1166. void bmx_b2debugdraw_setflags(MaxDebugDraw * dbg, uint32 flags) {
  1167. dbg->SetFlags(flags);
  1168. }
  1169. uint32 bmx_b2debugdraw_getflags(MaxDebugDraw * dbg) {
  1170. return dbg->GetFlags();
  1171. }
  1172. void bmx_b2debugdraw_appendflags(MaxDebugDraw * dbg, uint32 flags) {
  1173. dbg->AppendFlags(flags);
  1174. }
  1175. void bmx_b2debugdraw_clearflags(MaxDebugDraw * dbg, uint32 flags) {
  1176. dbg->ClearFlags(flags);
  1177. }
  1178. // *****************************************************
  1179. b2CircleDef * bmx_b2circledef_create() {
  1180. return new b2CircleDef;
  1181. }
  1182. void bmx_b2circledef_setradius(b2CircleDef * def, float32 radius) {
  1183. def->radius = radius;
  1184. }
  1185. void bmx_b2circledef_setlocalposition(b2CircleDef * def, Maxb2Vec2 * pos) {
  1186. b2Vec2 p(pos->x, pos->y);
  1187. def->localPosition = p;
  1188. }
  1189. void bmx_b2circledef_delete(b2CircleDef * def) {
  1190. delete def;
  1191. }
  1192. float32 bmx_b2circledef_getradius(b2CircleDef * def) {
  1193. return def->radius;
  1194. }
  1195. Maxb2Vec2 bmx_b2circledef_getlocalposition(b2CircleDef * def) {
  1196. return {def->localPosition.x, def->localPosition.y};
  1197. }
  1198. // *****************************************************
  1199. int bmx_b2shape_issensor(b2Shape * shape) {
  1200. return shape->IsSensor();
  1201. }
  1202. b2Body * bmx_b2shape_getbody(b2Shape * shape) {
  1203. return shape->GetBody();
  1204. }
  1205. BBObject * bmx_b2shape_getmaxshape(b2Shape * shape) {
  1206. void * obj = shape->GetUserData();
  1207. if (obj) {
  1208. return (BBObject *)obj;
  1209. }
  1210. return &bbNullObject;
  1211. }
  1212. void bmx_b2shape_setmaxshape(b2Shape * shape, BBObject * obj) {
  1213. shape->SetUserData(obj);
  1214. BBRETAIN(obj);
  1215. }
  1216. b2Shape * bmx_b2shape_getnext(b2Shape * shape) {
  1217. return shape->GetNext();
  1218. }
  1219. int bmx_b2shape_testpoint(b2Shape * shape, Maxb2XForm * xf, Maxb2Vec2 * p) {
  1220. b2XForm f;
  1221. bmx_Maxb2XFormtob2XForm(xf, &f);
  1222. b2Vec2 bp(p->x, p->y);
  1223. return shape->TestPoint(f, bp);
  1224. }
  1225. float32 bmx_b2shape_getsweepradius(b2Shape * shape) {
  1226. return shape->GetSweepRadius();
  1227. }
  1228. float32 bmx_b2shape_getfriction(b2Shape * shape) {
  1229. return shape->GetFriction();
  1230. }
  1231. float32 bmx_b2shape_getrestitution(b2Shape * shape) {
  1232. return shape->GetRestitution();
  1233. }
  1234. void bmx_b2shape_computeaabb(b2Shape * shape, Maxb2AABB * aabb, Maxb2XForm * xf) {
  1235. b2XForm f;
  1236. bmx_Maxb2XFormtob2XForm(xf, &f);
  1237. b2AABB ab;
  1238. shape->ComputeAABB(&ab, f);
  1239. aabb->lowerBound.x = ab.lowerBound.x;
  1240. aabb->lowerBound.y = ab.lowerBound.y;
  1241. aabb->upperBound.x = ab.upperBound.x;
  1242. aabb->upperBound.y = ab.upperBound.y;
  1243. }
  1244. void bmx_b2shape_computesweptaabb(b2Shape * shape, Maxb2AABB * aabb, Maxb2XForm * xf1, Maxb2XForm * xf2) {
  1245. b2XForm f1;
  1246. b2XForm f2;
  1247. bmx_Maxb2XFormtob2XForm(xf1, &f1);
  1248. bmx_Maxb2XFormtob2XForm(xf2, &f2);
  1249. b2AABB ab;
  1250. shape->ComputeSweptAABB(&ab, f1, f2);
  1251. aabb->lowerBound.x = ab.lowerBound.x;
  1252. aabb->lowerBound.y = ab.lowerBound.y;
  1253. aabb->upperBound.x = ab.upperBound.x;
  1254. aabb->upperBound.y = ab.upperBound.y;
  1255. }
  1256. void bmx_b2shape_computemass(b2Shape * shape, b2MassData * data) {
  1257. shape->ComputeMass(data);
  1258. }
  1259. Maxb2FilterData bmx_b2shape_getfilterdata(b2Shape * shape) {
  1260. b2FilterData filter = shape->GetFilterData();
  1261. Maxb2FilterData data = {filter.categoryBits, filter.maskBits, filter.groupIndex};
  1262. return data;
  1263. }
  1264. void bmx_b2shape_setfilterdata(b2Shape * shape, Maxb2FilterData data) {
  1265. b2FilterData filter;
  1266. filter.categoryBits = data.categoryBits;
  1267. filter.maskBits = data.maskBits;
  1268. filter.groupIndex = data.groupIndex;
  1269. shape->SetFilterData(filter);
  1270. }
  1271. void bmx_b2shape_setfriction(b2Shape * shape, float32 friction) {
  1272. shape->SetFriction(friction);
  1273. }
  1274. void bmx_b2shape_setrestitution(b2Shape * shape, float32 restitution) {
  1275. shape->SetRestitution(restitution);
  1276. }
  1277. float32 bmx_b2shape_getdensity(b2Shape * shape) {
  1278. return shape->GetDensity();
  1279. }
  1280. void bmx_b2shape_setdensity(b2Shape * shape, float32 density) {
  1281. shape->SetDensity(density);
  1282. }
  1283. int bmx_b2shape_testsegment(b2Shape * shape, Maxb2XForm * xf, float * lambda, Maxb2Vec2 * normal, Maxb2Segment * segment, float maxLambda) {
  1284. b2XForm f;
  1285. bmx_Maxb2XFormtob2XForm(xf, &f);
  1286. b2Vec2 n(normal->x, normal->y);
  1287. b2Segment s;
  1288. s.p1 = b2Vec2(segment->p1.x, segment->p1.y);
  1289. s.p2 = b2Vec2(segment->p2.x, segment->p2.y);
  1290. int result = shape->TestSegment(f, lambda, &n, s, maxLambda);
  1291. normal->x = n.x;
  1292. normal->y = n.y;
  1293. return result;
  1294. }
  1295. // *****************************************************
  1296. b2RevoluteJointDef * bmx_b2revolutejointdef_create() {
  1297. return new b2RevoluteJointDef;
  1298. }
  1299. void bmx_b2revolutejointdef_initialize(b2RevoluteJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor) {
  1300. def->Initialize(body1, body2, b2Vec2(anchor->x, anchor->y));
  1301. }
  1302. void bmx_b2revolutejointdef_delete(b2RevoluteJointDef * def) {
  1303. delete def;
  1304. }
  1305. int bmx_b2revolutejointdef_islimitenabled(b2RevoluteJointDef * def) {
  1306. return def->enableLimit;
  1307. }
  1308. void bmx_b2revolutejointdef_enablelimit(b2RevoluteJointDef * def, int limit) {
  1309. def->enableLimit = limit;
  1310. }
  1311. float32 bmx_b2revolutejointdef_getlowerangle(b2RevoluteJointDef * def) {
  1312. return def->lowerAngle * 57.2957795f;
  1313. }
  1314. void bmx_b2revolutejointdef_setlowerangle(b2RevoluteJointDef * def, float32 angle) {
  1315. def->lowerAngle = angle * 0.0174533f;
  1316. }
  1317. float32 bmx_b2revolutejointdef_getupperangle(b2RevoluteJointDef * def) {
  1318. return def->upperAngle * 57.2957795f;
  1319. }
  1320. void bmx_b2revolutejointdef_setupperangle(b2RevoluteJointDef * def, float32 angle) {
  1321. def->upperAngle = angle * 0.0174533f;
  1322. }
  1323. int bmx_b2revolutejointdef_ismotorenabled(b2RevoluteJointDef * def) {
  1324. return def->enableMotor;
  1325. }
  1326. void bmx_b2revolutejointdef_enablemotor(b2RevoluteJointDef * def, int value) {
  1327. def->enableMotor = value;
  1328. }
  1329. float32 bmx_b2revolutejointdef_getmotorspeed(b2RevoluteJointDef * def) {
  1330. return def->motorSpeed * 57.2957795f;
  1331. }
  1332. void bmx_b2revolutejointdef_setmotorspeed(b2RevoluteJointDef * def, float32 speed) {
  1333. def->motorSpeed = speed * 0.0174533f;
  1334. }
  1335. float32 bmx_b2revolutejointdef_getmaxmotortorque(b2RevoluteJointDef * def) {
  1336. return def->maxMotorTorque;
  1337. }
  1338. void bmx_b2revolutejointdef_setmaxmotortorque(b2RevoluteJointDef * def, float32 torque) {
  1339. def->maxMotorTorque = torque;
  1340. }
  1341. Maxb2Vec2 bmx_b2revolutejointdef_getlocalanchor1(b2RevoluteJointDef * def) {
  1342. Maxb2Vec2 v = {def->localAnchor1.x, def->localAnchor1.y};
  1343. return v;
  1344. }
  1345. void bmx_b2revolutejointdef_setlocalanchor1(b2RevoluteJointDef * def, Maxb2Vec2 *anchor) {
  1346. def->localAnchor1 = b2Vec2(anchor->x, anchor->y);
  1347. }
  1348. Maxb2Vec2 bmx_b2revolutejointdef_getlocalanchor2(b2RevoluteJointDef * def) {
  1349. Maxb2Vec2 v = {def->localAnchor2.x, def->localAnchor2.y};
  1350. return v;
  1351. }
  1352. void bmx_b2revolutejointdef_setlocalanchor2(b2RevoluteJointDef * def, Maxb2Vec2 *anchor) {
  1353. def->localAnchor2 = b2Vec2(anchor->x, anchor->y);
  1354. }
  1355. float32 bmx_b2revolutejointdef_getreferenceangle(b2RevoluteJointDef * def) {
  1356. return def->referenceAngle * 57.2957795f;
  1357. }
  1358. void bmx_b2revolutejointdef_setreferenceangle(b2RevoluteJointDef * def, float32 angle) {
  1359. def->referenceAngle = angle * 0.0174533f;
  1360. }
  1361. // *****************************************************
  1362. BBObject * bmx_b2joint_getmaxjoint(b2Joint * joint) {
  1363. void * obj = joint->GetUserData();
  1364. if (obj) {
  1365. return (BBObject *)obj;
  1366. }
  1367. return &bbNullObject;
  1368. }
  1369. b2Body * bmx_b2joint_getbody1(b2Joint * joint) {
  1370. return joint->GetBody1();
  1371. }
  1372. b2Body * bmx_b2joint_getbody2(b2Joint * joint) {
  1373. return joint->GetBody2();
  1374. }
  1375. b2Joint * bmx_b2joint_getnext(b2Joint * joint) {
  1376. return joint->GetNext();
  1377. }
  1378. // *****************************************************
  1379. b2MassData * bmx_b2massdata_new() {
  1380. return new b2MassData;
  1381. }
  1382. void bmx_b2massdata_delete(b2MassData * data) {
  1383. delete data;
  1384. }
  1385. void bmx_b2massdata_setmass(b2MassData * data, float32 mass) {
  1386. data->mass = mass;
  1387. }
  1388. void bmx_b2massdata_setcenter(b2MassData * data, Maxb2Vec2 * center) {
  1389. data->center = b2Vec2(center->x, center->y);
  1390. }
  1391. void bmx_b2massdata_seti(b2MassData * data, float32 i) {
  1392. data->I = i;
  1393. }
  1394. // *****************************************************
  1395. b2Body * bmx_b2jointedge_getother(b2JointEdge * joint) {
  1396. return joint->other;
  1397. }
  1398. b2Joint * bmx_b2jointedge_getjoint(b2JointEdge * joint) {
  1399. return joint->joint;
  1400. }
  1401. b2JointEdge * bmx_b2jointedge_getprev(b2JointEdge * joint) {
  1402. return joint->prev;
  1403. }
  1404. b2JointEdge * bmx_b2jointedge_getnext(b2JointEdge * joint) {
  1405. return joint->next;
  1406. }
  1407. // *****************************************************
  1408. class MaxContactFilter : public b2ContactFilter
  1409. {
  1410. public:
  1411. MaxContactFilter(BBObject * handle)
  1412. : maxHandle(handle)
  1413. {
  1414. }
  1415. bool ShouldCollide(b2Shape* shape1, b2Shape* shape2) {
  1416. return CB_PREF(physics_box2d_b2ContactFilter__ShouldCollide)(maxHandle, shape1, shape2);
  1417. }
  1418. private:
  1419. BBObject * maxHandle;
  1420. };
  1421. MaxContactFilter * bmx_b2contactfilter_new(BBObject * handle) {
  1422. return new MaxContactFilter(handle);
  1423. }
  1424. void bmx_b2contactfilter_delete(MaxContactFilter * filter) {
  1425. delete filter;
  1426. }
  1427. // *****************************************************
  1428. class MaxContactListener : public b2ContactListener
  1429. {
  1430. public:
  1431. MaxContactListener(BBObject * handle)
  1432. : maxHandle(handle)
  1433. {
  1434. }
  1435. void Add(const b2ContactPoint* point) {
  1436. Maxb2ContactPoint p = {
  1437. point->shape1,
  1438. point->shape2,
  1439. {point->position.x, point->position.y},
  1440. {point->velocity.x, point->velocity.y},
  1441. {point->normal.x, point->normal.y},
  1442. point->separation,
  1443. point->friction,
  1444. point->restitution,
  1445. point->id.key
  1446. };
  1447. CB_PREF(physics_box2d_b2ContactListener__Add)(maxHandle, p);
  1448. }
  1449. void Persist(const b2ContactPoint* point) {
  1450. Maxb2ContactPoint p = {
  1451. point->shape1,
  1452. point->shape2,
  1453. {point->position.x, point->position.y},
  1454. {point->velocity.x, point->velocity.y},
  1455. {point->normal.x, point->normal.y},
  1456. point->separation,
  1457. point->friction,
  1458. point->restitution,
  1459. point->id.key
  1460. };
  1461. CB_PREF(physics_box2d_b2ContactListener__Persist)(maxHandle, p);
  1462. }
  1463. void Remove(const b2ContactPoint* point) {
  1464. Maxb2ContactPoint p = {
  1465. point->shape1,
  1466. point->shape2,
  1467. {point->position.x, point->position.y},
  1468. {point->velocity.x, point->velocity.y},
  1469. {point->normal.x, point->normal.y},
  1470. point->separation,
  1471. point->friction,
  1472. point->restitution,
  1473. point->id.key
  1474. };
  1475. CB_PREF(physics_box2d_b2ContactListener__Remove)(maxHandle, p);
  1476. }
  1477. void Result(const b2ContactResult* result) {
  1478. Maxb2ContactResult r = {
  1479. result->shape1,
  1480. result->shape2,
  1481. {result->position.x, result->position.y},
  1482. {result->normal.x, result->normal.y},
  1483. result->normalImpulse,
  1484. result->tangentImpulse,
  1485. result->id.key
  1486. };
  1487. CB_PREF(physics_box2d_b2ContactListener__Result)(maxHandle, r);
  1488. }
  1489. private:
  1490. BBObject * maxHandle;
  1491. };
  1492. MaxContactListener * bmx_b2contactlistener_new(BBObject * handle) {
  1493. return new MaxContactListener(handle);
  1494. }
  1495. void bmx_b2contactlistener_delete(MaxContactListener * listener) {
  1496. delete listener;
  1497. }
  1498. // *****************************************************
  1499. class MaxBoundaryListener : public b2BoundaryListener
  1500. {
  1501. public:
  1502. MaxBoundaryListener(BBObject * handle)
  1503. : maxHandle(handle)
  1504. {
  1505. }
  1506. void Violation(b2Body* body) {
  1507. CB_PREF(physics_box2d_b2BoundaryListener__Violation)(maxHandle, body);
  1508. }
  1509. private:
  1510. BBObject * maxHandle;
  1511. };
  1512. MaxBoundaryListener * bmx_b2boundarylistener_new(BBObject * handle) {
  1513. return new MaxBoundaryListener(handle);
  1514. }
  1515. void bmx_b2boundarylistener_delete(MaxBoundaryListener * listener) {
  1516. delete listener;
  1517. }
  1518. // *****************************************************
  1519. void bmx_b2jointdef_setcollideconnected(b2JointDef * def, int collideConnected) {
  1520. def->collideConnected = collideConnected;
  1521. }
  1522. int bmx_b2jointdef_getcollideconnected(b2JointDef * def) {
  1523. return def->collideConnected;
  1524. }
  1525. void bmx_b2jointdef_setbody1(b2JointDef * def, b2Body * body) {
  1526. def->body1 = body;
  1527. }
  1528. b2Body * bmx_b2jointdef_getbody1(b2JointDef * def) {
  1529. return def->body1;
  1530. }
  1531. void bmx_b2jointdef_setbody2(b2JointDef * def, b2Body * body) {
  1532. def->body2 = body;
  1533. }
  1534. b2Body * bmx_b2jointdef_getbody2(b2JointDef * def) {
  1535. return def->body2;
  1536. }
  1537. // *****************************************************
  1538. b2DistanceJointDef * bmx_b2distancejointdef_new() {
  1539. return new b2DistanceJointDef;
  1540. }
  1541. void bmx_b2distancejointdef_setlocalanchor1(b2DistanceJointDef * def, Maxb2Vec2 * anchor) {
  1542. def->localAnchor1 = b2Vec2(anchor->x, anchor->y);
  1543. }
  1544. Maxb2Vec2 bmx_b2distancejointdef_getlocalanchor1(b2DistanceJointDef * def) {
  1545. return {def->localAnchor1.x, def->localAnchor1.y};
  1546. }
  1547. void bmx_b2distancejointdef_setlocalanchor2(b2DistanceJointDef * def, Maxb2Vec2 * anchor) {
  1548. def->localAnchor2 = b2Vec2(anchor->x, anchor->y);
  1549. }
  1550. Maxb2Vec2 bmx_b2distancejointdef_getlocalanchor2(b2DistanceJointDef * def) {
  1551. return {def->localAnchor2.x, def->localAnchor2.y};
  1552. }
  1553. void bmx_b2distancejointdef_setlength(b2DistanceJointDef * def, float32 length) {
  1554. def->length = length;
  1555. }
  1556. float32 bmx_b2distancejointdef_getlength(b2DistanceJointDef * def) {
  1557. return def->length;
  1558. }
  1559. void bmx_b2distancejointdef_delete(b2DistanceJointDef * def) {
  1560. delete def;
  1561. }
  1562. void bmx_b2distancejointdef_setfrequencyhz(b2DistanceJointDef * def, float32 freq) {
  1563. def->frequencyHz = freq;
  1564. }
  1565. void bmx_b2distancejointdef_setdampingratio(b2DistanceJointDef * def, float32 ratio) {
  1566. def->dampingRatio = ratio;
  1567. }
  1568. void bmx_b2distancejointdef_initialize(b2DistanceJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor1, Maxb2Vec2 * anchor2) {
  1569. def->Initialize(body1, body2, b2Vec2(anchor1->x, anchor1->y), b2Vec2(anchor2->x, anchor2->y));
  1570. }
  1571. // *****************************************************
  1572. b2PrismaticJointDef * bmx_b2prismaticjointdef_create() {
  1573. return new b2PrismaticJointDef;
  1574. }
  1575. void bmx_b2prismaticjointdef_enablelimit(b2PrismaticJointDef * def, int value) {
  1576. def->enableLimit = value;
  1577. }
  1578. int bmx_b2prismaticjointdef_islimitenabled(b2PrismaticJointDef * def) {
  1579. return def->enableLimit;
  1580. }
  1581. void bmx_b2prismaticjointdef_setlowertranslation(b2PrismaticJointDef * def, float32 translation) {
  1582. def->lowerTranslation = translation;
  1583. }
  1584. float32 bmx_b2prismaticjointdef_getlowertranslation(b2PrismaticJointDef * def) {
  1585. return def->lowerTranslation;
  1586. }
  1587. void bmx_b2prismaticjointdef_setuppertranslation(b2PrismaticJointDef * def, float32 translation) {
  1588. def->upperTranslation = translation;
  1589. }
  1590. float32 bmx_b2prismaticjointdef_getuppertranslation(b2PrismaticJointDef * def) {
  1591. return def->upperTranslation;
  1592. }
  1593. void bmx_b2prismaticjointdef_enablemotor(b2PrismaticJointDef * def, int value) {
  1594. def->enableMotor = value;
  1595. }
  1596. int bmx_b2prismaticjointdef_ismotorenabled(b2PrismaticJointDef * def) {
  1597. return def->enableMotor;
  1598. }
  1599. void bmx_b2prismaticjointdef_setmaxmotorforce(b2PrismaticJointDef * def, float32 force) {
  1600. def->maxMotorForce = force;
  1601. }
  1602. float32 bmx_b2prismaticjointdef_getmaxmotorforce(b2PrismaticJointDef * def) {
  1603. return def->maxMotorForce;
  1604. }
  1605. void bmx_b2prismaticjointdef_setmotorspeed(b2PrismaticJointDef * def, float32 speed) {
  1606. def->motorSpeed = speed * 0.0174533f;
  1607. }
  1608. float32 bmx_b2prismaticjointdef_getmotorspeed(b2PrismaticJointDef * def) {
  1609. return def->motorSpeed * 57.2957795f;
  1610. }
  1611. void bmx_b2prismaticjointdef_delete(b2PrismaticJointDef * def) {
  1612. delete def;
  1613. }
  1614. void bmx_b2prismaticjointdef_initialize(b2PrismaticJointDef * def, b2Body * body1, b2Body * body2,
  1615. Maxb2Vec2 * anchor, Maxb2Vec2 * axis) {
  1616. def->Initialize(body1, body2, b2Vec2(anchor->x, anchor->y), b2Vec2(axis->x, axis->y));
  1617. }
  1618. void bmx_b2prismaticjointdef_setlocalanchor1(b2PrismaticJointDef * def, Maxb2Vec2 * anchor) {
  1619. def->localAnchor1 = b2Vec2(anchor->x, anchor->y);
  1620. }
  1621. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalanchor1(b2PrismaticJointDef * def) {
  1622. b2Vec2 a(def->localAnchor1);
  1623. return {a.x, a.y};
  1624. }
  1625. void bmx_b2prismaticjointdef_setlocalanchor2(b2PrismaticJointDef * def, Maxb2Vec2 * anchor) {
  1626. def->localAnchor2 = b2Vec2(anchor->x, anchor->y);
  1627. }
  1628. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalanchor2(b2PrismaticJointDef * def) {
  1629. b2Vec2 a(def->localAnchor2);
  1630. return {a.x, a.y};
  1631. }
  1632. void bmx_b2prismaticjointdef_setlocalaxis1(b2PrismaticJointDef * def, Maxb2Vec2 * axis) {
  1633. def->localAxis1 = b2Vec2(axis->x, axis->y);
  1634. }
  1635. Maxb2Vec2 bmx_b2prismaticjointdef_getlocalaxis1(b2PrismaticJointDef * def) {
  1636. b2Vec2 a(def->localAxis1);
  1637. return {a.x, a.y};
  1638. }
  1639. void bmx_b2prismaticjointdef_setreferenceangle(b2PrismaticJointDef * def, float32 angle) {
  1640. def->referenceAngle = angle * 0.0174533f;
  1641. }
  1642. float32 bmx_b2prismaticjointdef_getreferenceangle(b2PrismaticJointDef * def) {
  1643. return def->referenceAngle * 57.2957795f;
  1644. }
  1645. // *****************************************************
  1646. float32 bmx_b2revolutejoint_getlowerlimit(b2RevoluteJoint * joint) {
  1647. return joint->GetLowerLimit() * 57.2957795f;
  1648. }
  1649. float32 bmx_b2revolutejoint_getupperlimit(b2RevoluteJoint * joint) {
  1650. return joint->GetUpperLimit() * 57.2957795f;
  1651. }
  1652. void bmx_b2revolutejoint_setlimits(b2RevoluteJoint * joint, float32 lowerLimit, float32 upperLimit) {
  1653. joint->SetLimits(lowerLimit * 0.0174533f, upperLimit * 0.0174533f);
  1654. }
  1655. int bmx_b2revolutejoint_ismotorenabled(b2RevoluteJoint * joint) {
  1656. return joint->IsMotorEnabled();
  1657. }
  1658. void bmx_b2revolutejoint_enablemotor(b2RevoluteJoint * joint, int flag) {
  1659. joint->EnableMotor(flag);
  1660. }
  1661. void bmx_b2revolutejoint_setmotorspeed(b2RevoluteJoint * joint, float32 speed) {
  1662. joint->SetMotorSpeed(speed * 0.0174533f);
  1663. }
  1664. float32 bmx_b2revolutejoint_getmotorspeed(b2RevoluteJoint * joint) {
  1665. return joint->GetMotorSpeed() * 57.2957795f;
  1666. }
  1667. void bmx_b2revolutejoint_setmaxmotortorque(b2RevoluteJoint * joint, float32 torque) {
  1668. joint->SetMaxMotorTorque(torque);
  1669. }
  1670. float32 bmx_b2revolutejoint_getmotortorque(b2RevoluteJoint * joint) {
  1671. return joint->GetMotorTorque();
  1672. }
  1673. int bmx_b2revolutejoint_islimitenabled(b2RevoluteJoint * joint) {
  1674. return joint->IsLimitEnabled();
  1675. }
  1676. void bmx_b2revolutejoint_enablelimit(b2RevoluteJoint * joint, int flag) {
  1677. joint->EnableLimit(flag);
  1678. }
  1679. Maxb2Vec2 bmx_b2revolutejoint_getanchor1(b2RevoluteJoint * joint) {
  1680. b2Vec2 v(joint->GetAnchor1());
  1681. return {v.x, v.y};
  1682. }
  1683. Maxb2Vec2 bmx_b2revolutejoint_getanchor2(b2RevoluteJoint * joint) {
  1684. b2Vec2 v(joint->GetAnchor2());
  1685. return {v.x, v.y};
  1686. }
  1687. Maxb2Vec2 bmx_b2revolutejoint_getreactionforce(b2RevoluteJoint * joint, float32 inv_dt) {
  1688. b2Vec2 v(joint->GetReactionForce(inv_dt));
  1689. return {v.x, v.y};
  1690. }
  1691. float32 bmx_b2revolutejoint_getreactiontorque(b2RevoluteJoint * joint, float32 inv_dt) {
  1692. return joint->GetReactionTorque(inv_dt);
  1693. }
  1694. float32 bmx_b2revolutejoint_getjointangle(b2RevoluteJoint * joint) {
  1695. return joint->GetJointAngle() * 57.2957795f;
  1696. }
  1697. float32 bmx_b2revolutejoint_getjointspeed(b2RevoluteJoint * joint) {
  1698. return joint->GetJointSpeed() * 57.2957795f;
  1699. }
  1700. // *****************************************************
  1701. float32 bmx_b2prismaticjoint_getjointspeed(b2PrismaticJoint * joint) {
  1702. return joint->GetJointSpeed();
  1703. }
  1704. int bmx_b2prismaticjoint_islimitenabled(b2PrismaticJoint * joint) {
  1705. return joint->IsLimitEnabled();
  1706. }
  1707. void bmx_b2prismaticjoint_enablelimit(b2PrismaticJoint * joint, int flag) {
  1708. joint->EnableLimit(flag);
  1709. }
  1710. float32 bmx_b2prismaticjoint_getlowerlimit(b2PrismaticJoint * joint) {
  1711. return joint->GetLowerLimit();
  1712. }
  1713. float32 bmx_b2prismaticjoint_getupperlimit(b2PrismaticJoint * joint) {
  1714. return joint->GetUpperLimit();
  1715. }
  1716. void bmx_b2prismaticjoint_setlimits(b2PrismaticJoint * joint, float32 lowerLimit, float32 upperLimit) {
  1717. joint->SetLimits(lowerLimit, upperLimit);
  1718. }
  1719. int bmx_b2prismaticjoint_ismotorenabled(b2PrismaticJoint * joint) {
  1720. return joint->IsMotorEnabled();
  1721. }
  1722. void bmx_b2prismaticjoint_enablemotor(b2PrismaticJoint * joint, int flag) {
  1723. joint->EnableMotor(flag);
  1724. }
  1725. void bmx_b2prismaticjoint_setmotorspeed(b2PrismaticJoint * joint, float32 speed) {
  1726. joint->SetMotorSpeed(speed);
  1727. }
  1728. float32 bmx_b2prismaticjoint_getmotorspeed(b2PrismaticJoint * joint) {
  1729. return joint->GetMotorSpeed();
  1730. }
  1731. void bmx_b2prismaticjoint_setmaxmotorforce(b2PrismaticJoint * joint, float32 force) {
  1732. joint->SetMaxMotorForce(force);
  1733. }
  1734. float32 bmx_b2prismaticjoint_getmotorforce(b2PrismaticJoint * joint) {
  1735. return joint->GetMotorForce();
  1736. }
  1737. Maxb2Vec2 bmx_b2prismaticjoint_getanchor1(b2PrismaticJoint * joint) {
  1738. b2Vec2 a(joint->GetAnchor1());
  1739. return {a.x, a.y};
  1740. }
  1741. Maxb2Vec2 bmx_b2prismaticjoint_getanchor2(b2PrismaticJoint * joint) {
  1742. b2Vec2 a(joint->GetAnchor2());
  1743. return {a.x, a.y};
  1744. }
  1745. Maxb2Vec2 bmx_b2prismaticjoint_getreactionforce(b2PrismaticJoint * joint, float32 inv_dt) {
  1746. b2Vec2 f(joint->GetReactionForce(inv_dt));
  1747. return {f.x, f.y};
  1748. }
  1749. float32 bmx_b2prismaticjoint_getreactiontorque(b2PrismaticJoint * joint, float32 inv_dt) {
  1750. return joint->GetReactionTorque(inv_dt);
  1751. }
  1752. float32 bmx_b2prismaticjoint_getjointtranslation(b2PrismaticJoint * joint) {
  1753. return joint->GetJointTranslation();
  1754. }
  1755. // *****************************************************
  1756. Maxb2Vec2 bmx_b2cross(Maxb2Vec2 * a, float32 s) {
  1757. b2Vec2 c(b2Cross(b2Vec2(a->x, a->y), s));
  1758. return {c.x, c.y};
  1759. }
  1760. Maxb2Vec2 bmx_b2crossf(float32 s, Maxb2Vec2 * a) {
  1761. b2Vec2 c(b2Cross(s, b2Vec2(a->x, a->y)));
  1762. return {c.x, c.y};
  1763. }
  1764. Maxb2Vec2 bmx_b2mul(Maxb2Mat22 * A, Maxb2Vec2 * v) {
  1765. b2Mat22 mat(b2Vec2(A->col1.x, A->col1.y), b2Vec2(A->col2.x, A->col2.y));
  1766. b2Vec2 m(b2Mul(mat, b2Vec2(v->x, v->y)));
  1767. return {m.x, m.y};
  1768. }
  1769. Maxb2Vec2 bmx_b2mult(Maxb2Mat22 * A, Maxb2Vec2 * v) {
  1770. b2Mat22 mat(b2Vec2(A->col1.x, A->col1.y), b2Vec2(A->col2.x, A->col2.y));
  1771. b2Vec2 m(b2MulT(mat, b2Vec2(v->x, v->y)));
  1772. return {m.x, m.y};
  1773. }
  1774. Maxb2Vec2 bmx_b2mulf(Maxb2XForm * T, Maxb2Vec2 * v) {
  1775. b2XForm t;
  1776. bmx_Maxb2XFormtob2XForm(T, &t);
  1777. b2Vec2 m(b2Mul(t, b2Vec2(v->x, v->y)));
  1778. return {m.x, m.y};
  1779. }
  1780. Maxb2Vec2 bmx_b2multf(Maxb2XForm * T, Maxb2Vec2 * v) {
  1781. b2XForm t;
  1782. bmx_Maxb2XFormtob2XForm(T, &t);
  1783. b2Vec2 m(b2MulT(t, b2Vec2(v->x, v->y)));
  1784. return {m.x, m.y};
  1785. }
  1786. float32 bmx_b2dot(Maxb2Vec2 * a, Maxb2Vec2 * b) {
  1787. return b2Dot(b2Vec2(a->x, a->y), b2Vec2(b->x, b->y));
  1788. }
  1789. // *****************************************************
  1790. void bmx_b2mat22_setangle(Maxb2Mat22 * mat, float32 angle) {
  1791. b2Mat22 m(b2Vec2(mat->col1.x, mat->col1.y), b2Vec2(mat->col2.x, mat->col2.y));
  1792. m.Set(angle * 0.0174533f);
  1793. mat->col1.x = m.col1.x;
  1794. mat->col1.y = m.col1.y;
  1795. mat->col2.x = m.col2.x;
  1796. mat->col2.y = m.col2.y;
  1797. }
  1798. float32 bmx_b2mat22_getangle(Maxb2Mat22 * mat) {
  1799. b2Mat22 m(b2Vec2(mat->col1.x, mat->col1.y), b2Vec2(mat->col2.x, mat->col2.y));
  1800. return m.GetAngle() * 57.2957795f;
  1801. }
  1802. void bmx_b2mat22_createangle(Maxb2Mat22 * m, float32 angle) {
  1803. b2Mat22 b(angle * 0.0174533f);
  1804. m->col1.x = b.col1.x;
  1805. m->col1.y = b.col1.y;
  1806. m->col2.x = b.col2.x;
  1807. m->col2.y = b.col2.y;
  1808. }
  1809. Maxb2Mat22 bmx_b2mat22_getinverse(Maxb2Mat22 * mat) {
  1810. Maxb2Mat22 result;
  1811. b2Vec2 c1(mat->col1.x, mat->col1.y);
  1812. b2Vec2 c2(mat->col2.x, mat->col2.y);
  1813. b2Mat22 m(c1, c2);
  1814. b2Mat22 imat(m.GetInverse());
  1815. result.col1.x = imat.col1.x;
  1816. result.col1.y = imat.col1.y;
  1817. result.col2.x = imat.col2.x;
  1818. result.col2.y = imat.col2.y;
  1819. return result;
  1820. }
  1821. // *****************************************************
  1822. b2Shape * bmx_b2contact_getshape1(b2Contact * contact) {
  1823. return contact->GetShape1();
  1824. }
  1825. b2Shape * bmx_b2contact_getshape2(b2Contact * contact) {
  1826. return contact->GetShape2();
  1827. }
  1828. b2Contact * bmx_b2contact_getnext(b2Contact * contact) {
  1829. return contact->GetNext();
  1830. }
  1831. int bmx_b2contact_issolid(b2Contact * contact) {
  1832. return contact->IsSolid();
  1833. }
  1834. int32 bmx_b2contact_getmanifoldcount(b2Contact * contact) {
  1835. return contact->GetManifoldCount();
  1836. }
  1837. // *****************************************************
  1838. b2GearJointDef * bmx_b2gearjointdef_new() {
  1839. return new b2GearJointDef;
  1840. }
  1841. void bmx_b2gearjointdef_setjoint1(b2GearJointDef * def, b2Joint * joint) {
  1842. def->joint1 = joint;
  1843. }
  1844. void bmx_b2gearjointdef_setjoint2(b2GearJointDef * def, b2Joint * joint) {
  1845. def->joint2 = joint;
  1846. }
  1847. void bmx_b2gearjointdef_setratio(b2GearJointDef * def, float32 ratio) {
  1848. def->ratio = ratio;
  1849. }
  1850. void bmx_b2gearjointdef_delete(b2GearJointDef * def) {
  1851. delete def;
  1852. }
  1853. // *****************************************************
  1854. Maxb2Vec2 bmx_b2gearjoint_getanchor1(b2GearJoint * joint) {
  1855. b2Vec2 a(joint->GetAnchor1());
  1856. return {a.x, a.y};
  1857. }
  1858. Maxb2Vec2 bmx_b2gearjoint_getanchor2(b2GearJoint * joint) {
  1859. b2Vec2 a(joint->GetAnchor2());
  1860. return {a.x, a.y};
  1861. }
  1862. Maxb2Vec2 bmx_b2gearjoint_getreactionforce(b2GearJoint * joint, float32 inv_dt) {
  1863. b2Vec2 f(joint->GetReactionForce(inv_dt));
  1864. return {f.x, f.y};
  1865. }
  1866. float32 bmx_b2gearjoint_getreactiontorque(b2GearJoint * joint, float32 inv_dt) {
  1867. return joint->GetReactionTorque(inv_dt);
  1868. }
  1869. float32 bmx_b2gearjoint_getratio(b2GearJoint * joint) {
  1870. return joint->GetRatio();
  1871. }
  1872. // *****************************************************
  1873. Maxb2Vec2 bmx_b2mousejoint_getanchor1(b2MouseJoint * joint) {
  1874. b2Vec2 a(joint->GetAnchor1());
  1875. return {a.x, a.y};
  1876. }
  1877. Maxb2Vec2 bmx_b2mousejoint_getanchor2(b2MouseJoint * joint) {
  1878. b2Vec2 a(joint->GetAnchor2());
  1879. return {a.x, a.y};
  1880. }
  1881. Maxb2Vec2 bmx_b2mousejoint_getreactionforce(b2MouseJoint * joint, float32 inv_dt) {
  1882. b2Vec2 f(joint->GetReactionForce(inv_dt));
  1883. return {f.x, f.y};
  1884. }
  1885. float32 bmx_b2mousejoint_getreactiontorque(b2MouseJoint * joint, float32 inv_dt) {
  1886. return joint->GetReactionTorque(inv_dt);
  1887. }
  1888. void bmx_b2mousejoint_settarget(b2MouseJoint * joint, Maxb2Vec2 * target) {
  1889. joint->SetTarget(b2Vec2(target->x, target->y));
  1890. }
  1891. Maxb2Vec2 bmx_b2mousejoint_gettarget(b2MouseJoint * joint) {
  1892. return {joint->m_target.x, joint->m_target.y};
  1893. }
  1894. Maxb2Vec2 bmx_b2mousejoint_getlocalanchor(b2MouseJoint * joint) {
  1895. return {joint->m_localAnchor.x, joint->m_localAnchor.y};
  1896. }
  1897. // *****************************************************
  1898. Maxb2Vec2 bmx_b2pulleyjoint_getanchor1(b2PulleyJoint * joint) {
  1899. b2Vec2 a(joint->GetAnchor1());
  1900. return {a.x, a.y};
  1901. }
  1902. Maxb2Vec2 bmx_b2pulleyjoint_getanchor2(b2PulleyJoint * joint) {
  1903. b2Vec2 a(joint->GetAnchor2());
  1904. return {a.x, a.y};
  1905. }
  1906. Maxb2Vec2 bmx_b2pulleyjoint_getreactionforce(b2PulleyJoint * joint, float32 inv_dt) {
  1907. b2Vec2 f(joint->GetReactionForce(inv_dt));
  1908. return {f.x, f.y};
  1909. }
  1910. float32 bmx_b2pulleyjoint_getreactiontorque(b2PulleyJoint * joint, float32 inv_dt) {
  1911. return joint->GetReactionTorque(inv_dt);
  1912. }
  1913. Maxb2Vec2 bmx_b2pulleyjoint_getgroundanchor1(b2PulleyJoint * joint) {
  1914. b2Vec2 a(joint->GetGroundAnchor1());
  1915. return {a.x, a.y};
  1916. }
  1917. Maxb2Vec2 bmx_b2pulleyjoint_getgroundanchor2(b2PulleyJoint * joint) {
  1918. b2Vec2 a(joint->GetGroundAnchor2());
  1919. return {a.x, a.y};
  1920. }
  1921. float32 bmx_b2pulleyjoint_getlength1(b2PulleyJoint * joint) {
  1922. return joint->GetLength1();
  1923. }
  1924. float32 bmx_b2pulleyjoint_getlength2(b2PulleyJoint * joint) {
  1925. return joint->GetLength2();
  1926. }
  1927. float32 bmx_b2pulleyjoint_getratio(b2PulleyJoint * joint) {
  1928. return joint->GetRatio();
  1929. }
  1930. // *****************************************************
  1931. Maxb2Vec2 bmx_b2distancejoint_getanchor1(b2DistanceJoint * joint) {
  1932. b2Vec2 a(joint->GetAnchor1());
  1933. return {a.x, a.y};
  1934. }
  1935. Maxb2Vec2 bmx_b2distancejoint_getanchor2(b2DistanceJoint * joint) {
  1936. b2Vec2 a(joint->GetAnchor2());
  1937. return {a.x, a.y};
  1938. }
  1939. Maxb2Vec2 bmx_b2distancejoint_getreactionforce(b2DistanceJoint * joint, float32 inv_dt) {
  1940. b2Vec2 f(joint->GetReactionForce(inv_dt));
  1941. return {f.x, f.y};
  1942. }
  1943. float32 bmx_b2distancejoint_getreactiontorque(b2DistanceJoint * joint, float32 inv_dt) {
  1944. return joint->GetReactionTorque(inv_dt);
  1945. }
  1946. // *****************************************************
  1947. b2MouseJointDef * bmx_b2mousejointdef_new() {
  1948. return new b2MouseJointDef;
  1949. }
  1950. void bmx_b2mousejointdef_settarget(b2MouseJointDef * def, Maxb2Vec2 * target) {
  1951. def->target = b2Vec2(target->x, target->y);
  1952. }
  1953. Maxb2Vec2 bmx_b2mousejointdef_gettarget(b2MouseJointDef * def) {
  1954. return {def->target.x, def->target.y};
  1955. }
  1956. void bmx_b2mousejointdef_setmaxforce(b2MouseJointDef * def, float32 maxForce) {
  1957. def->maxForce = maxForce;
  1958. }
  1959. float32 bmx_b2mousejointdef_getmaxforce(b2MouseJointDef * def) {
  1960. return def->maxForce;
  1961. }
  1962. void bmx_b2mousejointdef_setfrequencyhz(b2MouseJointDef * def, float32 frequency) {
  1963. def->frequencyHz = frequency;
  1964. }
  1965. float32 bmx_b2mousejointdef_getfrequencyhz(b2MouseJointDef * def) {
  1966. return def->frequencyHz;
  1967. }
  1968. void bmx_b2mousejointdef_setdampingration(b2MouseJointDef * def, float32 ratio) {
  1969. def->dampingRatio = ratio;
  1970. }
  1971. float32 bmx_b2mousejointdef_getdampingratio(b2MouseJointDef * def) {
  1972. return def->dampingRatio;
  1973. }
  1974. void bmx_b2mousejointdef_delete(b2MouseJointDef * def) {
  1975. delete def;
  1976. }
  1977. // *****************************************************
  1978. b2PulleyJointDef * bmx_b2pulleyjointdef_create() {
  1979. return new b2PulleyJointDef;
  1980. }
  1981. void bmx_b2pulleyjointdef_initialize(b2PulleyJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * groundAnchor1,
  1982. Maxb2Vec2 * groundAnchor2, Maxb2Vec2 * anchor1, Maxb2Vec2 * anchor2, float32 ratio) {
  1983. def->Initialize(body1, body2, b2Vec2(groundAnchor1->x, groundAnchor1->y), b2Vec2(groundAnchor2->x, groundAnchor2->y),
  1984. b2Vec2(anchor1->x, anchor1->y), b2Vec2(anchor2->x, anchor2->y), ratio);
  1985. }
  1986. void bmx_b2pulleyjointdef_setgroundanchor1(b2PulleyJointDef * def, Maxb2Vec2 * anchor) {
  1987. def->groundAnchor1 = b2Vec2(anchor->x, anchor->y);
  1988. }
  1989. Maxb2Vec2 bmx_b2pulleyjointdef_getgroundanchor1(b2PulleyJointDef * def) {
  1990. return {def->groundAnchor1.x, def->groundAnchor1.y};
  1991. }
  1992. void bmx_b2pulleyjointdef_setgroundanchor2(b2PulleyJointDef * def, Maxb2Vec2 * anchor) {
  1993. def->groundAnchor2 = b2Vec2(anchor->x, anchor->y);
  1994. }
  1995. Maxb2Vec2 bmx_b2pulleyjointdef_getgroundanchor2(b2PulleyJointDef * def) {
  1996. return {def->groundAnchor2.x, def->groundAnchor2.y};
  1997. }
  1998. void bmx_b2pulleyjointdef_setlocalanchor1(b2PulleyJointDef * def, Maxb2Vec2 * anchor) {
  1999. def->localAnchor1 = b2Vec2(anchor->x, anchor->y);
  2000. }
  2001. Maxb2Vec2 bmx_b2pulleyjointdef_getlocalanchor1(b2PulleyJointDef * def) {
  2002. return {def->localAnchor1.x, def->localAnchor1.y};
  2003. }
  2004. void bmx_b2pulleyjointdef_setlocalanchor2(b2PulleyJointDef * def, Maxb2Vec2 * anchor) {
  2005. def->localAnchor2 = b2Vec2(anchor->x, anchor->y);
  2006. }
  2007. Maxb2Vec2 bmx_b2pulleyjointdef_getlocalanchor2(b2PulleyJointDef * def) {
  2008. return {def->localAnchor2.x, def->localAnchor2.y};
  2009. }
  2010. void bmx_b2pulleyjointdef_setlength1(b2PulleyJointDef * def, float32 length) {
  2011. def->length1 = length;
  2012. }
  2013. float32 bmx_b2pulleyjointdef_getlength1(b2PulleyJointDef * def) {
  2014. return def->length1;
  2015. }
  2016. void bmx_b2pulleyjointdef_setmaxlength1(b2PulleyJointDef * def, float32 maxLength) {
  2017. def->maxLength1 = maxLength;
  2018. }
  2019. float32 bmx_b2pulleyjointdef_getmaxlength1(b2PulleyJointDef * def) {
  2020. return def->maxLength1;
  2021. }
  2022. void bmx_b2pulleyjointdef_setlength2(b2PulleyJointDef * def, float32 length) {
  2023. def->length2 = length;
  2024. }
  2025. float32 bmx_b2pulleyjointdef_getlength2(b2PulleyJointDef * def) {
  2026. return def->length2;
  2027. }
  2028. void bmx_b2pulleyjointdef_setmaxlength2(b2PulleyJointDef * def, float32 maxLength) {
  2029. def->maxLength2 = maxLength;
  2030. }
  2031. float32 bmx_b2pulleyjointdef_getmaxlength2(b2PulleyJointDef * def) {
  2032. return def->maxLength2;
  2033. }
  2034. void bmx_b2pulleyjointdef_setratio(b2PulleyJointDef * def, float32 ratio) {
  2035. def->ratio = ratio;
  2036. }
  2037. float32 bmx_b2pulleyjointdef_getratio(b2PulleyJointDef * def) {
  2038. return def->ratio;
  2039. }
  2040. void bmx_b2pulleyjointdef_delete(b2PulleyJointDef * def) {
  2041. delete def;
  2042. }
  2043. // *****************************************************
  2044. class MaxDestructionListener : public b2DestructionListener
  2045. {
  2046. public:
  2047. MaxDestructionListener(BBObject * handle)
  2048. : maxHandle(handle)
  2049. {
  2050. }
  2051. void SayGoodbye(b2Joint * joint) {
  2052. CB_PREF(physics_box2d_b2DestructionListener__SayGoodbyeJoint)(maxHandle, joint);
  2053. void * data = joint->GetUserData();
  2054. if (data && data != &bbNullObject) {
  2055. BBRELEASE((BBObject*)data);
  2056. joint->SetUserData(0);
  2057. }
  2058. }
  2059. void SayGoodbye(b2Shape * shape) {
  2060. CB_PREF(physics_box2d_b2DestructionListener__SayGoodbyeShape)(maxHandle, shape);
  2061. void * data = shape->GetUserData();
  2062. if (data && data != &bbNullObject) {
  2063. BBRELEASE((BBObject*)data);
  2064. shape->SetUserData(0);
  2065. }
  2066. }
  2067. private:
  2068. BBObject * maxHandle;
  2069. };
  2070. MaxDestructionListener * bmx_b2destructionlistener_new(BBObject * handle) {
  2071. return new MaxDestructionListener(handle);
  2072. }
  2073. void bmx_b2destructionlistener_delete(MaxDestructionListener * listener) {
  2074. delete listener;
  2075. }
  2076. // *****************************************************
  2077. Maxb2Mat22 bmx_b2obb_getrotationmatrix(b2OBB * obb) {
  2078. Maxb2Mat22 m;
  2079. m.col1.x = obb->R.col1.x;
  2080. m.col1.y = obb->R.col1.y;
  2081. m.col2.x = obb->R.col2.x;
  2082. m.col2.y = obb->R.col2.y;
  2083. return m;
  2084. }
  2085. Maxb2Vec2 bmx_b2obb_getcenter(b2OBB * obb) {
  2086. return {obb->center.x, obb->center.y};
  2087. }
  2088. Maxb2Vec2 bmx_b2obb_getextents(b2OBB * obb) {
  2089. return {obb->extents.x, obb->extents.y};
  2090. }
  2091. // *****************************************************
  2092. BBArray * bmx_b2polygonshape_getvertices(b2PolygonShape * shape) {
  2093. return bmx_b2vec2_getvertexarray(shape->GetVertices(), shape->GetVertexCount());
  2094. }
  2095. BBArray * bmx_b2polygonshape_getcorevertices(b2PolygonShape * shape) {
  2096. return bmx_b2vec2_getvertexarray(shape->GetCoreVertices(), shape->GetVertexCount());
  2097. }
  2098. BBArray * bmx_b2polygonshape_getnormals(b2PolygonShape * shape) {
  2099. return bmx_b2vec2_getvertexarray(shape->GetNormals(), shape->GetVertexCount());
  2100. }
  2101. const b2OBB * bmx_b2polygonshape_getobb(b2PolygonShape * shape) {
  2102. return &shape->GetOBB();
  2103. }
  2104. Maxb2Vec2 bmx_b2polygonshape_getcentroid(b2PolygonShape * shape) {
  2105. b2Vec2 v(shape->GetCentroid());
  2106. return {v.x, v.y};
  2107. }
  2108. int bmx_b2polygonshape_getvertexcount(b2PolygonShape * shape) {
  2109. return shape->GetVertexCount();
  2110. }
  2111. Maxb2Vec2 bmx_b2polygonshape_getfirstvertex(b2PolygonShape * shape, Maxb2XForm * xf) {
  2112. b2XForm f;
  2113. bmx_Maxb2XFormtob2XForm(xf, &f);
  2114. b2Vec2 v(shape->GetFirstVertex(f));
  2115. return {v.x, v.y};
  2116. }
  2117. Maxb2Vec2 bmx_b2polygonshape_centroid(b2PolygonShape * shape, Maxb2XForm * xf) {
  2118. b2XForm f;
  2119. bmx_Maxb2XFormtob2XForm(xf, &f);
  2120. b2Vec2 c(shape->Centroid(f));
  2121. return {c.x, c.y};
  2122. }
  2123. Maxb2Vec2 bmx_b2polygonshape_support(b2PolygonShape * shape, Maxb2XForm * xf, Maxb2Vec2 * d) {
  2124. b2XForm f;
  2125. bmx_Maxb2XFormtob2XForm(xf, &f);
  2126. b2Vec2 v(d->x, d->y);
  2127. b2Vec2 s(shape->Support(f, v));
  2128. return {s.x, s.y};
  2129. }
  2130. // *****************************************************
  2131. Maxb2Vec2 bmx_b2circleshape_getlocalposition(b2CircleShape * shape) {
  2132. b2Vec2 p(shape->GetLocalPosition());
  2133. return {p.x, p.y};
  2134. }
  2135. float32 bmx_b2circleshape_getradius(b2CircleShape * shape) {
  2136. return shape->GetRadius();
  2137. }
  2138. // *****************************************************
  2139. b2LineJointDef * bmx_b2linejointdef_create() {
  2140. return new b2LineJointDef();
  2141. }
  2142. void bmx_b2linejointdef_initialize(b2LineJointDef * def, b2Body * body1, b2Body * body2, Maxb2Vec2 * anchor, Maxb2Vec2 * axis) {
  2143. def->Initialize(body1, body2, b2Vec2(anchor->x, anchor->y), b2Vec2(axis->x, axis->y));
  2144. }
  2145. void bmx_b2linejointdef_setlocalanchor1(b2LineJointDef * def, Maxb2Vec2 * anchor) {
  2146. def->localAnchor1 = b2Vec2(anchor->x, anchor->y);
  2147. }
  2148. Maxb2Vec2 bmx_b2linejointdef_getlocalanchor1(b2LineJointDef * def) {
  2149. return {def->localAnchor1.x, def->localAnchor1.y};
  2150. }
  2151. void bmx_b2linejointdef_setlocalanchor2(b2LineJointDef * def, Maxb2Vec2 * anchor) {
  2152. def->localAnchor2 = b2Vec2(anchor->x, anchor->y);
  2153. }
  2154. Maxb2Vec2 bmx_b2linejointdef_getlocalanchor2(b2LineJointDef * def) {
  2155. return {def->localAnchor2.x, def->localAnchor2.y};
  2156. }
  2157. void bmx_b2linejointdef_setlocalaxis1(b2LineJointDef * def, Maxb2Vec2 * axis) {
  2158. def->localAxis1 = b2Vec2(axis->x, axis->y);
  2159. }
  2160. Maxb2Vec2 bmx_b2linejointdef_getlocalaxis1(b2LineJointDef * def) {
  2161. return {def->localAxis1.x, def->localAxis1.y};
  2162. }
  2163. void bmx_b2linejointdef_enablelimit(b2LineJointDef * def, int limit) {
  2164. def->enableLimit = limit;
  2165. }
  2166. int bmx_b2linejointdef_getlimit(b2LineJointDef * def) {
  2167. return def->enableLimit;
  2168. }
  2169. void bmx_b2linejointdef_setlowertranslation(b2LineJointDef * def, float32 translation) {
  2170. def->lowerTranslation = translation;
  2171. }
  2172. float32 bmx_b2linejointdef_getlowertranslation(b2LineJointDef * def) {
  2173. return def->lowerTranslation;
  2174. }
  2175. void bmx_b2linejointdef_setuppertranslation(b2LineJointDef * def, float32 translation) {
  2176. def->upperTranslation = translation;
  2177. }
  2178. float32 bmx_b2linejointdef_getuppertranslation(b2LineJointDef * def) {
  2179. return def->upperTranslation;
  2180. }
  2181. void bmx_b2linejointdef_enablemotor(b2LineJointDef * def, int enable) {
  2182. def->enableMotor = enable;
  2183. }
  2184. int bmx_b2linejointdef_ismotorenabled(b2LineJointDef * def) {
  2185. return def->enableMotor;
  2186. }
  2187. void bmx_b2linejointdef_setmaxmotorforce(b2LineJointDef * def, float32 maxForce) {
  2188. def->maxMotorForce = maxForce;
  2189. }
  2190. float32 bmx_b2linejointdef_getmaxmotorforce(b2LineJointDef * def) {
  2191. return def->maxMotorForce;
  2192. }
  2193. void bmx_b2linejointdef_setmotorspeed(b2LineJointDef * def, float32 speed) {
  2194. def->motorSpeed = speed * 0.0174533f;
  2195. }
  2196. float32 bmx_b2linejointdef_getmotorspeed(b2LineJointDef * def) {
  2197. return def->motorSpeed * 57.2957795f;
  2198. }
  2199. void bmx_b2linejointdef_delete(b2LineJointDef * def) {
  2200. delete def;
  2201. }
  2202. // *****************************************************
  2203. Maxb2Vec2 bmx_b2linejoint_getanchor1(b2LineJoint * joint) {
  2204. b2Vec2 a(joint->GetAnchor1());
  2205. return {a.x, a.y};
  2206. }
  2207. Maxb2Vec2 bmx_b2linejoint_getanchor2(b2LineJoint * joint) {
  2208. b2Vec2 a(joint->GetAnchor2());
  2209. return {a.x, a.y};
  2210. }
  2211. Maxb2Vec2 bmx_b2linejoint_getreactionforce(b2LineJoint * joint, float32 inv_dt) {
  2212. b2Vec2 f(joint->GetReactionForce(inv_dt));
  2213. return {f.x, f.y};
  2214. }
  2215. float32 bmx_b2linejoint_getreactiontorque(b2LineJoint * joint, float32 inv_dt) {
  2216. return joint->GetReactionTorque(inv_dt);
  2217. }
  2218. float32 bmx_b2linejoint_getjointtranslation(b2LineJoint * joint) {
  2219. return joint->GetJointTranslation();
  2220. }
  2221. float32 bmx_b2linejoint_getjointspeed(b2LineJoint * joint) {
  2222. return joint->GetJointSpeed();
  2223. }
  2224. int bmx_b2linejoint_islimitenabled(b2LineJoint * joint) {
  2225. return joint->IsLimitEnabled();
  2226. }
  2227. void bmx_b2linejoint_enablelimit(b2LineJoint * joint, int flag) {
  2228. return joint->EnableLimit(flag);
  2229. }
  2230. float32 bmx_b2linejoint_getlowerlimit(b2LineJoint * joint) {
  2231. return joint->GetLowerLimit();
  2232. }
  2233. float32 bmx_b2linejoint_getupperlimit(b2LineJoint * joint) {
  2234. return joint->GetUpperLimit();
  2235. }
  2236. void bmx_b2linejoint_setlimits(b2LineJoint * joint, float32 _lower, float32 _upper) {
  2237. joint->SetLimits(_lower, _upper);
  2238. }
  2239. int bmx_b2linejoint_ismotorenabled(b2LineJoint * joint) {
  2240. return joint->IsMotorEnabled();
  2241. }
  2242. void bmx_b2linejoint_enablemotor(b2LineJoint * joint, int flag) {
  2243. joint->EnableMotor(flag);
  2244. }
  2245. void bmx_b2linejoint_setmotorspeed(b2LineJoint * joint, float32 speed) {
  2246. joint->SetMotorSpeed(speed);
  2247. }
  2248. float32 bmx_b2linejoint_getmotorspeed(b2LineJoint * joint) {
  2249. return joint->GetMotorSpeed();
  2250. }
  2251. void bmx_b2linejoint_setmaxmotorforce(b2LineJoint * joint, float32 force) {
  2252. joint->SetMaxMotorForce(force);
  2253. }
  2254. float32 bmx_b2linejoint_getmotorforce(b2LineJoint * joint) {
  2255. return joint->GetMotorForce();
  2256. }
  2257. // *****************************************************
  2258. Maxb2EdgeChainDef * bmx_b2edgechaindef_create() {
  2259. return new Maxb2EdgeChainDef;
  2260. }
  2261. b2EdgeChainDef * bmx_b2edgechaindef_getdef(Maxb2EdgeChainDef * def) {
  2262. return def->def;
  2263. }
  2264. int bmx_b2edgechaindef_isaloop(Maxb2EdgeChainDef * def) {
  2265. return def->def->isALoop;
  2266. }
  2267. void bmx_b2edgechaindef_setisaloop(Maxb2EdgeChainDef * def, int value) {
  2268. def->def->isALoop = value;
  2269. }
  2270. void bmx_b2edgechaindef_delete(Maxb2EdgeChainDef * def) {
  2271. delete def;
  2272. }
  2273. void bmx_b2edgechaindef_setvertices(Maxb2EdgeChainDef * def, BBArray * vertices) {
  2274. int n = vertices->scales[0];
  2275. def->initVertices(n);
  2276. Maxb2Vec2* mv=(Maxb2Vec2*)BBARRAYDATA( vertices,vertices->dims );
  2277. b2Vec2* vp = def->vertices;
  2278. for (int i = 0; i < n; i++) {
  2279. vp->x = mv->x;
  2280. vp->y = mv->y;
  2281. vp++;
  2282. mv++;
  2283. }
  2284. }
  2285. // *****************************************************
  2286. float32 bmx_b2edgeshape_getlength(b2EdgeShape * shape) {
  2287. return shape->GetLength();
  2288. }
  2289. Maxb2Vec2 bmx_b2edgeshape_getvertex1(b2EdgeShape * shape) {
  2290. b2Vec2 v(shape->GetVertex1());
  2291. return {v.x, v.y};
  2292. }
  2293. Maxb2Vec2 bmx_b2edgeshape_getvertex2(b2EdgeShape * shape) {
  2294. b2Vec2 v(shape->GetVertex2());
  2295. return {v.x, v.y};
  2296. }
  2297. Maxb2Vec2 bmx_b2edgeshape_getcorevertex1(b2EdgeShape * shape) {
  2298. b2Vec2 v(shape->GetCoreVertex1());
  2299. return {v.x, v.y};
  2300. }
  2301. Maxb2Vec2 bmx_b2edgeshape_getcorevertex2(b2EdgeShape * shape) {
  2302. b2Vec2 v(shape->GetCoreVertex2());
  2303. return {v.x, v.y};
  2304. }
  2305. Maxb2Vec2 bmx_b2edgeshape_getnormalvector(b2EdgeShape * shape) {
  2306. b2Vec2 v(shape->GetNormalVector());
  2307. return {v.x, v.y};
  2308. }
  2309. Maxb2Vec2 bmx_b2edgeshape_getdirectionvector(b2EdgeShape * shape) {
  2310. b2Vec2 v(shape->GetDirectionVector());
  2311. return {v.x, v.y};
  2312. }
  2313. Maxb2Vec2 bmx_b2edgeshape_getcorner1vector(b2EdgeShape * shape) {
  2314. b2Vec2 v(shape->GetCorner1Vector());
  2315. return {v.x, v.y};
  2316. }
  2317. Maxb2Vec2 bmx_b2edgeshape_getcorner2vector(b2EdgeShape * shape) {
  2318. b2Vec2 v(shape->GetCorner2Vector());
  2319. return {v.x, v.y};
  2320. }
  2321. int bmx_b2edgeshape_corner1isconvex(b2EdgeShape * shape) {
  2322. return shape->Corner1IsConvex();
  2323. }
  2324. int bmx_b2edgeshape_corner2isconvex(b2EdgeShape * shape) {
  2325. return shape->Corner2IsConvex();
  2326. }
  2327. Maxb2Vec2 bmx_b2edgeshape_getfirstvertex(b2EdgeShape * shape, Maxb2XForm * xf) {
  2328. b2XForm f;
  2329. bmx_Maxb2XFormtob2XForm(xf, &f);
  2330. b2Vec2 v(shape->GetFirstVertex(f));
  2331. return {v.x, v.y};
  2332. }
  2333. Maxb2Vec2 bmx_b2edgeshape_support(b2EdgeShape * shape, Maxb2XForm * xf, Maxb2Vec2 * d) {
  2334. b2XForm f;
  2335. bmx_Maxb2XFormtob2XForm(xf, &f);
  2336. b2Vec2 dv(d->x, d->y);
  2337. b2Vec2 v(shape->Support(f, dv));
  2338. return {v.x, v.y};
  2339. }
  2340. b2EdgeShape * bmx_b2edgeshape_getnextedge(b2EdgeShape * shape) {
  2341. return shape->GetNextEdge();
  2342. }
  2343. b2EdgeShape * bmx_b2edgeshape_getprevedge(b2EdgeShape * shape) {
  2344. return shape->GetPrevEdge();
  2345. }
  2346. // *****************************************************
  2347. b2BuoyancyControllerDef * bmx_b2buoyancycontrollerdef_create() {
  2348. return new b2BuoyancyControllerDef;
  2349. }
  2350. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getnormal(b2BuoyancyControllerDef * def) {
  2351. return {def->normal.x, def->normal.y};
  2352. }
  2353. void bmx_b2buoyancycontrollerdef_setnormal(b2BuoyancyControllerDef * def, Maxb2Vec2 * normal) {
  2354. def->normal = b2Vec2(normal->x, normal->y);
  2355. }
  2356. float32 bmx_b2buoyancycontrollerdef_getoffset(b2BuoyancyControllerDef * def) {
  2357. return def->offset;
  2358. }
  2359. void bmx_b2buoyancycontrollerdef_setoffset(b2BuoyancyControllerDef * def, float32 offset) {
  2360. def->offset = offset;
  2361. }
  2362. float32 bmx_b2buoyancycontrollerdef_getdensity(b2BuoyancyControllerDef * def) {
  2363. return def->density;
  2364. }
  2365. void bmx_b2buoyancycontrollerdef_setdensity(b2BuoyancyControllerDef * def, float32 density) {
  2366. def->density = density;
  2367. }
  2368. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getvelocity(b2BuoyancyControllerDef * def) {
  2369. return {def->velocity.x, def->velocity.y};
  2370. }
  2371. void bmx_b2buoyancycontrollerdef_setvelocity(b2BuoyancyControllerDef * def, Maxb2Vec2 * velocity) {
  2372. def->velocity = b2Vec2(velocity->x, velocity->y);
  2373. }
  2374. float32 bmx_b2buoyancycontrollerdef_getlineardrag(b2BuoyancyControllerDef * def) {
  2375. return def->linearDrag;
  2376. }
  2377. void bmx_b2buoyancycontrollerdef_setlineardrag(b2BuoyancyControllerDef * def, float32 drag) {
  2378. def->linearDrag = drag;
  2379. }
  2380. float32 bmx_b2buoyancycontrollerdef_getangulardrag(b2BuoyancyControllerDef * def) {
  2381. return def->angularDrag;
  2382. }
  2383. void bmx_b2buoyancycontrollerdef_setangulardrag(b2BuoyancyControllerDef * def, float32 drag) {
  2384. def->angularDrag = drag;
  2385. }
  2386. int bmx_b2buoyancycontrollerdef_usesdensity(b2BuoyancyControllerDef * def) {
  2387. return def->useDensity;
  2388. }
  2389. void bmx_b2buoyancycontrollerdef_setusesdensity(b2BuoyancyControllerDef * def, int value) {
  2390. def->useDensity = value;
  2391. }
  2392. int bmx_b2buoyancycontrollerdef_usesworldgravity(b2BuoyancyControllerDef * def) {
  2393. return def->useWorldGravity;
  2394. }
  2395. void bmx_b2buoyancycontrollerdef_setusesworldgravity(b2BuoyancyControllerDef * def, int value) {
  2396. def->useWorldGravity = value;
  2397. }
  2398. Maxb2Vec2 bmx_b2buoyancycontrollerdef_getgravity(b2BuoyancyControllerDef * def) {
  2399. return {def->gravity.x, def->gravity.y};
  2400. }
  2401. void bmx_b2buoyancycontrollerdef_setgravity(b2BuoyancyControllerDef * def, Maxb2Vec2 * gravity) {
  2402. def->gravity = b2Vec2(gravity->x, gravity->y);
  2403. }
  2404. void bmx_b2buoyancycontrollerdef_delete(b2BuoyancyControllerDef * def) {
  2405. delete def;
  2406. }
  2407. // *****************************************************
  2408. Maxb2Vec2 bmx_b2buoyancycontroller_getnormal(b2BuoyancyController * c) {
  2409. return {c->normal.x, c->normal.y};
  2410. }
  2411. void bmx_b2buoyancycontroller_setnormal(b2BuoyancyController * c, Maxb2Vec2 * normal) {
  2412. c->normal = b2Vec2(normal->x, normal->y);
  2413. }
  2414. float32 bmx_b2buoyancycontroller_getoffset(b2BuoyancyController * c) {
  2415. return c->offset;
  2416. }
  2417. void bmx_b2buoyancycontroller_setoffset(b2BuoyancyController * c, float32 offset) {
  2418. c->offset = offset;
  2419. }
  2420. float32 bmx_b2buoyancycontroller_getdensity(b2BuoyancyController * c) {
  2421. return c->density;
  2422. }
  2423. void bmx_b2buoyancycontroller_setdensity(b2BuoyancyController * c, float32 density) {
  2424. c->density = density;
  2425. }
  2426. Maxb2Vec2 bmx_b2buoyancycontroller_getvelocity(b2BuoyancyController * c) {
  2427. return {c->velocity.x, c->velocity.y};
  2428. }
  2429. void bmx_b2buoyancycontroller_setvelocity(b2BuoyancyController * c, Maxb2Vec2 * velocity) {
  2430. c->velocity = b2Vec2(velocity->x, velocity->y);
  2431. }
  2432. float32 bmx_b2buoyancycontroller_getlineardrag(b2BuoyancyController * c) {
  2433. return c->linearDrag;
  2434. }
  2435. void bmx_b2buoyancycontroller_setlineardrag(b2BuoyancyController * c, float32 drag) {
  2436. c->linearDrag = drag;
  2437. }
  2438. float32 bmx_b2buoyancycontroller_getangulardrag(b2BuoyancyController * c) {
  2439. return c->angularDrag;
  2440. }
  2441. void bmx_b2buoyancycontroller_setangulardrag(b2BuoyancyController * c, float32 drag) {
  2442. c->angularDrag = drag;
  2443. }
  2444. int bmx_b2buoyancycontroller_usesdensity(b2BuoyancyController * c) {
  2445. return c->useDensity;
  2446. }
  2447. void bmx_b2buoyancycontroller_setusesdensity(b2BuoyancyController * c, int value) {
  2448. c->useDensity = value;
  2449. }
  2450. int bmx_b2buoyancycontroller_usesworldgravity(b2BuoyancyController * c) {
  2451. return c->useWorldGravity;
  2452. }
  2453. void bmx_b2buoyancycontroller_setusesworldgravity(b2BuoyancyController * c, int value) {
  2454. c->useWorldGravity = value;
  2455. }
  2456. Maxb2Vec2 bmx_b2buoyancycontroller_getgravity(b2BuoyancyController * c) {
  2457. return {c->gravity.x, c->gravity.y};
  2458. }
  2459. void bmx_b2buoyancycontroller_setgravity(b2BuoyancyController * c, Maxb2Vec2 * gravity) {
  2460. c->gravity = b2Vec2(gravity->x, gravity->y);
  2461. }
  2462. // *****************************************************
  2463. b2TensorDampingControllerDef * bmx_b2tensordampingcontrollerdef_create() {
  2464. return new b2TensorDampingControllerDef;
  2465. }
  2466. void bmx_b2tensordampingcontrollerdef_delete(b2TensorDampingControllerDef * def) {
  2467. delete def;
  2468. }
  2469. Maxb2Mat22 bmx_b2tensordampingcontrollerdef_gettensor(b2TensorDampingControllerDef * def) {
  2470. Maxb2Mat22 m;
  2471. m.col1.x = def->T.col1.x;
  2472. m.col1.y = def->T.col1.y;
  2473. m.col2.x = def->T.col2.x;
  2474. m.col2.y = def->T.col2.y;
  2475. return m;
  2476. }
  2477. void bmx_b2tensordampingcontrollerdef_settensor(b2TensorDampingControllerDef * def, Maxb2Mat22 * tensor) {
  2478. b2Mat22 m;
  2479. m.col1.x = tensor->col1.x;
  2480. m.col1.y = tensor->col1.y;
  2481. m.col2.x = tensor->col2.x;
  2482. m.col2.y = tensor->col2.y;
  2483. def->T = m;
  2484. }
  2485. float32 bmx_b2tensordampingcontrollerdef_getmaxtimestep(b2TensorDampingControllerDef * def) {
  2486. return def->maxTimestep;
  2487. }
  2488. void bmx_b2tensordampingcontrollerdef_setmaxtimestep(b2TensorDampingControllerDef * def, float32 timestep) {
  2489. def->maxTimestep = timestep;
  2490. }
  2491. void bmx_b2tensordampingcontrollerdef_setaxisaligned(b2TensorDampingControllerDef * def, float32 xDamping, float32 yDamping) {
  2492. def->SetAxisAligned(xDamping, yDamping);
  2493. }
  2494. // *****************************************************
  2495. Maxb2Mat22 bmx_b2tensordampingcontroller_gettensor(b2TensorDampingController * c) {
  2496. Maxb2Mat22 m;
  2497. m.col1.x = c->T.col1.x;
  2498. m.col1.y = c->T.col1.y;
  2499. m.col2.x = c->T.col2.x;
  2500. m.col2.y = c->T.col2.y;
  2501. return m;
  2502. }
  2503. void bmx_b2tensordampingcontroller_settensor(b2TensorDampingController * c, Maxb2Mat22 * tensor) {
  2504. c->T.col1.x = tensor->col1.x;
  2505. c->T.col1.y = tensor->col1.y;
  2506. c->T.col2.x = tensor->col2.x;
  2507. c->T.col2.y = tensor->col2.y;
  2508. }
  2509. float32 bmx_b2tensordampingcontroller_getmaxtimestep(b2TensorDampingController * c) {
  2510. return c->maxTimestep;
  2511. }
  2512. void bmx_b2tensordampingcontroller_setmaxtimestep(b2TensorDampingController * c, float32 timestep) {
  2513. c->maxTimestep = timestep;
  2514. }
  2515. // *****************************************************
  2516. b2GravityControllerDef * bmx_b2gravitycontrollerdef_create() {
  2517. return new b2GravityControllerDef;
  2518. }
  2519. void bmx_b2gravitycontrollerdef_delete(b2GravityControllerDef * def) {
  2520. delete def;
  2521. }
  2522. float32 bmx_b2gravitycontrollerdef_getforce(b2GravityControllerDef * def) {
  2523. return def->G;
  2524. }
  2525. void bmx_b2gravitycontrollerdef_setforce(b2GravityControllerDef * def, float32 force) {
  2526. def->G = force;
  2527. }
  2528. int bmx_b2gravitycontrollerdef_isinvsqr(b2GravityControllerDef * def) {
  2529. return def->invSqr;
  2530. }
  2531. void bmx_b2gravitycontrollerdef_setisinvsqr(b2GravityControllerDef * def, int value) {
  2532. def->invSqr = value;
  2533. }
  2534. // *****************************************************
  2535. float32 bmx_b2gravitycontroller_getforce(b2GravityController * c) {
  2536. return c->G;
  2537. }
  2538. void bmx_b2gravitycontroller_setforce(b2GravityController * c, float32 force) {
  2539. c->G = force;
  2540. }
  2541. int bmx_b2gravitycontroller_isinvsqr(b2GravityController * c) {
  2542. return c->invSqr;
  2543. }
  2544. void bmx_b2gravitycontroller_setisinvsqr(b2GravityController * c, int value) {
  2545. c->invSqr = value;
  2546. }
  2547. // *****************************************************
  2548. b2ConstantForceControllerDef * bmx_b2constantforcecontrollerdef_create() {
  2549. return new b2ConstantForceControllerDef;
  2550. }
  2551. void bmx_b2constantforcecontrollerdef_delete(b2ConstantForceControllerDef * def) {
  2552. delete def;
  2553. }
  2554. Maxb2Vec2 bmx_b2constantforcecontrollerdef_getforce(b2ConstantForceControllerDef * def) {
  2555. return {def->F.x, def->F.y};
  2556. }
  2557. void bmx_b2constantforcecontrollerdef_setforce(b2ConstantForceControllerDef * def, Maxb2Vec2 * force) {
  2558. def->F = b2Vec2(force->x, force->y);
  2559. }
  2560. // *****************************************************
  2561. Maxb2Vec2 bmx_b2constantforcecontroller_getforce(b2ConstantForceController * c) {
  2562. return {c->F.x, c->F.y};
  2563. }
  2564. void bmx_b2constantforcecontroller_setforce(b2ConstantForceController * c, Maxb2Vec2 * force) {
  2565. c->F = b2Vec2(force->x, force->y);
  2566. }
  2567. // *****************************************************
  2568. b2ConstantAccelControllerDef * bmx_b2constantaccelcontrollerdef_create() {
  2569. return new b2ConstantAccelControllerDef;
  2570. }
  2571. Maxb2Vec2 bmx_b2constantaccelcontrollerdef_getforce(b2ConstantAccelControllerDef * def) {
  2572. return {def->A.x, def->A.y};
  2573. }
  2574. void bmx_b2constantaccelcontrollerdef_setforce(b2ConstantAccelControllerDef * def, Maxb2Vec2 * force) {
  2575. def->A = b2Vec2(force->x, force->y);
  2576. }
  2577. void bmx_b2constantaccelcontrollerdef_delete(b2ConstantAccelControllerDef * def) {
  2578. delete def;
  2579. }
  2580. // *****************************************************
  2581. Maxb2Vec2 bmx_b2constantaccelcontroller_getforce(b2ConstantAccelController * c) {
  2582. return {c->A.x, c->A.y};
  2583. }
  2584. void bmx_b2constantaccelcontroller_setforce(b2ConstantAccelController * c, Maxb2Vec2 * force) {
  2585. c->A = b2Vec2(force->x, force->y);
  2586. }
  2587. // *****************************************************
  2588. b2Controller * bmx_b2controlleredge_getcontroller(b2ControllerEdge * edge) {
  2589. return edge->controller;
  2590. }
  2591. b2Body * bmx_b2controlleredge_getbody(b2ControllerEdge * edge) {
  2592. return edge->body;
  2593. }
  2594. b2ControllerEdge * bmx_b2controlleredge_getprevbody(b2ControllerEdge * edge) {
  2595. return edge->prevBody;
  2596. }
  2597. b2ControllerEdge * bmx_b2controlleredge_getnextbody(b2ControllerEdge * edge) {
  2598. return edge->nextBody;
  2599. }
  2600. b2ControllerEdge * bmx_b2controlleredge_getprevcontroller(b2ControllerEdge * edge) {
  2601. return edge->prevController;
  2602. }
  2603. b2ControllerEdge * bmx_b2controlleredge_getnextcontroller(b2ControllerEdge * edge) {
  2604. return edge->nextController;
  2605. }
  2606. // *****************************************************
  2607. BBObject * bmx_b2controller_getmaxcontroller(b2Controller * c) {
  2608. void * obj = c->GetUserData();
  2609. if (obj) {
  2610. return (BBObject *)obj;
  2611. }
  2612. return &bbNullObject;
  2613. }
  2614. void bmx_b2controller_addbody(b2Controller * c, b2Body * body) {
  2615. c->AddBody(body);
  2616. }
  2617. void bmx_b2controller_removebody(b2Controller * c, b2Body * body) {
  2618. c->RemoveBody(body);
  2619. }
  2620. void bmx_b2controller_clear(b2Controller * c) {
  2621. c->Clear();
  2622. }
  2623. b2Controller * bmx_b2controller_getnext(b2Controller * c) {
  2624. return c->GetNext();
  2625. }
  2626. b2World * bmx_b2controller_getworld(b2Controller * c) {
  2627. return c->GetWorld();
  2628. }
  2629. b2ControllerEdge * bmx_b2controller_getbodylist(b2Controller * c) {
  2630. return c->GetBodyList();
  2631. }