JoltC.cpp 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  1. #include <Jolt/Jolt.h>
  2. #include <Jolt/Core/Factory.h>
  3. #include <Jolt/Core/JobSystem.h>
  4. #include <Jolt/Core/JobSystemSingleThreaded.h>
  5. #include <Jolt/Core/JobSystemThreadPool.h>
  6. #include <Jolt/Core/TempAllocator.h>
  7. #include <Jolt/Physics/Body/BodyActivationListener.h>
  8. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  9. #include <Jolt/Physics/Body/BodyLockMulti.h>
  10. #include <Jolt/Physics/Collision/CastResult.h>
  11. #include <Jolt/Physics/Collision/CollideShape.h>
  12. #include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
  13. #include <Jolt/Physics/Collision/ContactListener.h>
  14. #include <Jolt/Physics/Collision/EstimateCollisionResponse.h>
  15. #include <Jolt/Physics/Collision/RayCast.h>
  16. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  17. #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
  18. #include <Jolt/Physics/Collision/Shape/CompoundShape.h>
  19. #include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
  20. #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
  21. #include <Jolt/Physics/Collision/Shape/MeshShape.h>
  22. #include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
  23. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  24. #include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
  25. #include <Jolt/Physics/Collision/Shape/TriangleShape.h>
  26. #include <Jolt/Physics/Collision/ShapeCast.h>
  27. #include <Jolt/Physics/Collision/SimShapeFilter.h>
  28. #include <Jolt/Physics/Constraints/ConstraintPart/SwingTwistConstraintPart.h>
  29. #include <Jolt/Physics/Constraints/FixedConstraint.h>
  30. #include <Jolt/Physics/Constraints/SixDOFConstraint.h>
  31. #include <Jolt/Physics/Constraints/HingeConstraint.h>
  32. #include <Jolt/Physics/Constraints/DistanceConstraint.h>
  33. #include <Jolt/Physics/Constraints/SliderConstraint.h>
  34. #include <Jolt/Physics/PhysicsSettings.h>
  35. #include <Jolt/Physics/PhysicsSystem.h>
  36. #include <Jolt/RegisterTypes.h>
  37. #include <Jolt/Renderer/DebugRendererSimple.h>
  38. #include <JoltC/JoltC.h>
  39. #define JPC_IMPL static
  40. #define OPAQUE_WRAPPER(c_type, cpp_type) \
  41. static c_type* to_jpc(cpp_type *in) { return reinterpret_cast<c_type*>(in); } \
  42. static const c_type* to_jpc(const cpp_type *in) { return reinterpret_cast<const c_type*>(in); } \
  43. static cpp_type* to_jph(c_type *in) { return reinterpret_cast<cpp_type*>(in); } \
  44. static const cpp_type* to_jph(const c_type *in) { return reinterpret_cast<const cpp_type*>(in); } \
  45. static cpp_type** to_jph(c_type **in) { return reinterpret_cast<cpp_type**>(in); }
  46. #define DESTRUCTOR(c_type) \
  47. JPC_API void c_type##_delete(c_type* object) { \
  48. delete to_jph(object); \
  49. }
  50. #define ENUM_CONVERSION(c_type, cpp_type) \
  51. static c_type to_jpc(cpp_type in) { return static_cast<c_type>(in); } \
  52. static cpp_type to_jph(c_type in) { return static_cast<cpp_type>(in); }
  53. #define LAYOUT_COMPATIBLE(c_type, cpp_type) \
  54. static c_type to_jpc(cpp_type in) { \
  55. c_type out; \
  56. memcpy(&out, &in, sizeof(c_type)); \
  57. return out; \
  58. } \
  59. static cpp_type to_jph(c_type in) { \
  60. cpp_type out; \
  61. memcpy(&out, &in, sizeof(cpp_type)); \
  62. return out; \
  63. } \
  64. static c_type* to_jpc(cpp_type* in) { \
  65. return reinterpret_cast<c_type*>(in); \
  66. } \
  67. static cpp_type* to_jph(c_type* in) { \
  68. return reinterpret_cast<cpp_type*>(in); \
  69. } \
  70. static const c_type* to_jpc(const cpp_type* in) { \
  71. return reinterpret_cast<const c_type*>(in); \
  72. } \
  73. static const cpp_type* to_jph(const c_type* in) { \
  74. return reinterpret_cast<const cpp_type*>(in); \
  75. } \
  76. static_assert(sizeof(c_type) == sizeof(cpp_type), "size of " #c_type " did not match size of " #cpp_type); \
  77. static_assert(alignof(c_type) == alignof(cpp_type), "align of " #c_type " did not match align of " #cpp_type); \
  78. static_assert(!std::is_polymorphic_v<cpp_type>, #cpp_type " is polymorphic and cannot be made layout compatible");
  79. template<typename E>
  80. constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
  81. {
  82. return static_cast<typename std::underlying_type<E>::type>(e);
  83. }
  84. ENUM_CONVERSION(JPC_MotionType, JPH::EMotionType)
  85. ENUM_CONVERSION(JPC_AllowedDOFs, JPH::EAllowedDOFs)
  86. ENUM_CONVERSION(JPC_Activation, JPH::EActivation)
  87. ENUM_CONVERSION(JPC_BodyType, JPH::EBodyType)
  88. ENUM_CONVERSION(JPC_MotionQuality, JPH::EMotionQuality)
  89. ENUM_CONVERSION(JPC_OverrideMassProperties, JPH::EOverrideMassProperties)
  90. ENUM_CONVERSION(JPC_ShapeType, JPH::EShapeType)
  91. ENUM_CONVERSION(JPC_ShapeSubType, JPH::EShapeSubType)
  92. ENUM_CONVERSION(JPC_SpringMode, JPH::ESpringMode)
  93. ENUM_CONVERSION(JPC_MotorState, JPH::EMotorState)
  94. ENUM_CONVERSION(JPC_ValidateResult, JPH::ValidateResult)
  95. OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
  96. DESTRUCTOR(JPC_PhysicsSystem)
  97. OPAQUE_WRAPPER(JPC_BodyInterface, JPH::BodyInterface)
  98. OPAQUE_WRAPPER(JPC_BodyLockInterface, JPH::BodyLockInterface)
  99. OPAQUE_WRAPPER(JPC_BodyLockRead, JPH::BodyLockRead)
  100. OPAQUE_WRAPPER(JPC_BodyLockWrite, JPH::BodyLockWrite)
  101. OPAQUE_WRAPPER(JPC_BodyLockMultiRead, JPH::BodyLockMultiRead)
  102. OPAQUE_WRAPPER(JPC_BodyLockMultiWrite, JPH::BodyLockMultiWrite)
  103. OPAQUE_WRAPPER(JPC_NarrowPhaseQuery, JPH::NarrowPhaseQuery)
  104. OPAQUE_WRAPPER(JPC_TempAllocatorImpl, JPH::TempAllocatorImpl)
  105. DESTRUCTOR(JPC_TempAllocatorImpl)
  106. OPAQUE_WRAPPER(JPC_JobSystem, JPH::JobSystem)
  107. DESTRUCTOR(JPC_JobSystem)
  108. OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
  109. DESTRUCTOR(JPC_JobSystemThreadPool)
  110. OPAQUE_WRAPPER(JPC_JobSystemSingleThreaded, JPH::JobSystemSingleThreaded)
  111. DESTRUCTOR(JPC_JobSystemSingleThreaded)
  112. OPAQUE_WRAPPER(JPC_Shape, JPH::Shape)
  113. OPAQUE_WRAPPER(JPC_CompoundShape, JPH::CompoundShape)
  114. OPAQUE_WRAPPER(JPC_Body, JPH::Body)
  115. OPAQUE_WRAPPER(JPC_VertexList, JPH::VertexList)
  116. DESTRUCTOR(JPC_VertexList)
  117. OPAQUE_WRAPPER(JPC_IndexedTriangleList, JPH::IndexedTriangleList)
  118. DESTRUCTOR(JPC_IndexedTriangleList)
  119. OPAQUE_WRAPPER(JPC_String, JPH::String)
  120. DESTRUCTOR(JPC_String)
  121. LAYOUT_COMPATIBLE(JPC_BodyManager_DrawSettings, JPH::BodyManager::DrawSettings)
  122. LAYOUT_COMPATIBLE(JPC_ShapeCastSettings, JPH::ShapeCastSettings)
  123. LAYOUT_COMPATIBLE(JPC_CollideShapeSettings, JPH::CollideShapeSettings)
  124. LAYOUT_COMPATIBLE(JPC_BodyID, JPH::BodyID)
  125. static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
  126. static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
  127. static JPC_Vec2 to_jpc(JPH::Vector<2> in) {
  128. return JPC_Vec2{in[0], in[1]};
  129. }
  130. static JPH::Vector<2> to_jph(JPC_Vec2 in) {
  131. JPH::Vector<2> out;
  132. out[0] = in.x;
  133. out[1] = in.y;
  134. return out;
  135. }
  136. static JPC_Vec3 to_jpc(JPH::Vec3 in) {
  137. return JPC_Vec3{in.GetX(), in.GetY(), in.GetZ(), in.GetZ()};
  138. }
  139. static JPH::Vec3 to_jph(JPC_Vec3 in) {
  140. return JPH::Vec3(in.x, in.y, in.z);
  141. }
  142. static JPC_Vec4 to_jpc(JPH::Vec4 in) {
  143. return JPC_Vec4{in.GetX(), in.GetY(), in.GetZ(), in.GetW()};
  144. }
  145. static JPH::Vec4 to_jph(JPC_Vec4 in) {
  146. return JPH::Vec4(in.x, in.y, in.z, in.w);
  147. }
  148. static JPH::Array<JPH::Vec3> to_jph(const JPC_Vec3* src, size_t n) {
  149. JPH::Array<JPH::Vec3> vec;
  150. vec.resize(n);
  151. if (src != nullptr) {
  152. memcpy(vec.data(), src, n * sizeof(*src));
  153. }
  154. return vec;
  155. }
  156. static JPC_DVec3 to_jpc(JPH::DVec3 in) {
  157. return JPC_DVec3{in.GetX(), in.GetY(), in.GetZ(), in.GetZ()};
  158. }
  159. static JPH::DVec3 to_jph(JPC_DVec3 in) {
  160. return JPH::DVec3(in.x, in.y, in.z);
  161. }
  162. static JPC_Quat to_jpc(JPH::Quat in) {
  163. return JPC_Quat{in.GetX(), in.GetY(), in.GetZ(), in.GetW()};
  164. }
  165. static JPH::Quat to_jph(JPC_Quat in) {
  166. return JPH::Quat(in.x, in.y, in.z, in.w);
  167. }
  168. static JPC_Mat44 to_jpc(JPH::Mat44 in) {
  169. JPC_Mat44 out;
  170. in.StoreFloat4x4(reinterpret_cast<JPH::Float4*>(&out));
  171. return out;
  172. }
  173. static JPH::Mat44 to_jph(JPC_Mat44 in) {
  174. return JPH::Mat44::sLoadFloat4x4Aligned(reinterpret_cast<const JPH::Float4*>(&in));
  175. }
  176. static JPC_DMat44 to_jpc(JPH::DMat44 in) {
  177. JPC_DMat44 out;
  178. out.col[0] = to_jpc(in.GetColumn4(0));
  179. out.col[1] = to_jpc(in.GetColumn4(1));
  180. out.col[2] = to_jpc(in.GetColumn4(2));
  181. out.col3 = to_jpc(in.GetTranslation());
  182. return out;
  183. }
  184. static JPH::DMat44 to_jph(JPC_DMat44 in) {
  185. JPH::DVec3 col3 = to_jph(in.col3);
  186. JPH::DMat44 out(
  187. to_jph(in.col[0]),
  188. to_jph(in.col[1]),
  189. to_jph(in.col[2]),
  190. col3);
  191. return out;
  192. }
  193. static JPC_Color to_jpc(JPH::Color in) {
  194. return JPC_Color{in.r, in.g, in.b, in.a};
  195. }
  196. static JPH::Color to_jph(JPC_Color in) {
  197. return JPH::Color(in.r, in.g, in.b, in.a);
  198. }
  199. static JPH::RayCast to_jph(JPC_RayCast in) {
  200. return JPH::RayCast(to_jph(in.Origin), to_jph(in.Direction));
  201. }
  202. static JPH::RRayCast to_jph(JPC_RRayCast in) {
  203. return JPH::RRayCast(to_jph(in.Origin), to_jph(in.Direction));
  204. }
  205. static JPH::RShapeCast to_jph(JPC_RShapeCast in) {
  206. return JPH::RShapeCast(
  207. to_jph(in.Shape),
  208. to_jph(in.Scale),
  209. to_jph(in.CenterOfMassStart),
  210. to_jph(in.Direction));
  211. }
  212. static JPH::SubShapeID JPC_SubShapeID_to_jph(JPC_SubShapeID in) {
  213. JPH::SubShapeID out;
  214. out.SetValue(in);
  215. return out;
  216. }
  217. static JPC_SubShapeID to_jpc(JPH::SubShapeID in) {
  218. return in.GetValue();
  219. }
  220. static JPC_RayCastResult to_jpc(JPH::RayCastResult in) {
  221. JPC_RayCastResult out{0};
  222. out.BodyID = to_jpc(in.mBodyID);
  223. out.Fraction = in.mFraction;
  224. out.SubShapeID2 = to_jpc(in.mSubShapeID2);
  225. return out;
  226. }
  227. JPC_IMPL JPC_ShapeCastResult JPC_ShapeCastResult_to_jpc(JPH::ShapeCastResult in) {
  228. JPC_ShapeCastResult out{};
  229. // CollideShapeResult
  230. out.ContactPointOn1 = to_jpc(in.mContactPointOn1);
  231. out.ContactPointOn2 = to_jpc(in.mContactPointOn2);
  232. out.PenetrationAxis = to_jpc(in.mPenetrationAxis);
  233. out.PenetrationDepth = in.mPenetrationDepth;
  234. out.SubShapeID1 = to_jpc(in.mSubShapeID1);
  235. out.SubShapeID2 = to_jpc(in.mSubShapeID2);
  236. out.BodyID2 = to_jpc(in.mBodyID2);
  237. // Face Shape1Face;
  238. // Face Shape2Face;
  239. // ShapeCastResult
  240. out.Fraction = in.mFraction;
  241. out.IsBackFaceHit = in.mIsBackFaceHit;
  242. return out;
  243. }
  244. JPC_IMPL JPH::ShapeCastSettings JPC_ShapeCastSettings_to_jph(JPC_ShapeCastSettings in) {
  245. JPH::ShapeCastSettings out{};
  246. // JPH::CollideSettingsBase
  247. // EActiveEdgeMode ActiveEdgeMode;
  248. // ECollectFacesMode CollectFacesMode;
  249. out.mCollisionTolerance = in.CollisionTolerance;
  250. out.mPenetrationTolerance = in.PenetrationTolerance;
  251. out.mActiveEdgeMovementDirection = to_jph(in.ActiveEdgeMovementDirection);
  252. // JPH::ShapeCastSettings
  253. out.mBackFaceModeTriangles = static_cast<JPH::EBackFaceMode>(in.BackFaceModeTriangles);
  254. out.mBackFaceModeConvex = static_cast<JPH::EBackFaceMode>(in.BackFaceModeConvex);
  255. out.mUseShrunkenShapeAndConvexRadius = in.UseShrunkenShapeAndConvexRadius;
  256. out.mReturnDeepestPoint = in.ReturnDeepestPoint;
  257. return out;
  258. }
  259. JPC_IMPL JPC_CollideShapeResult JPC_CollideShapeResult_to_jpc(JPH::CollideShapeResult in) {
  260. JPC_CollideShapeResult out{};
  261. // CollideShapeResult
  262. out.ContactPointOn1 = to_jpc(in.mContactPointOn1);
  263. out.ContactPointOn2 = to_jpc(in.mContactPointOn2);
  264. out.PenetrationAxis = to_jpc(in.mPenetrationAxis);
  265. out.PenetrationDepth = in.mPenetrationDepth;
  266. out.SubShapeID1 = to_jpc(in.mSubShapeID1);
  267. out.SubShapeID2 = to_jpc(in.mSubShapeID2);
  268. out.BodyID2 = to_jpc(in.mBodyID2);
  269. // Face Shape1Face;
  270. // Face Shape2Face;
  271. return out;
  272. }
  273. JPC_API void JPC_RegisterDefaultAllocator() {
  274. JPH::RegisterDefaultAllocator();
  275. }
  276. JPC_API void JPC_FactoryInit() {
  277. JPH::Factory::sInstance = new JPH::Factory();
  278. }
  279. JPC_API void JPC_FactoryDelete() {
  280. delete JPH::Factory::sInstance;
  281. JPH::Factory::sInstance = nullptr;
  282. }
  283. JPC_API void JPC_RegisterTypes() {
  284. JPH::RegisterTypes();
  285. }
  286. JPC_API void JPC_UnregisterTypes() {
  287. JPH::UnregisterTypes();
  288. }
  289. ////////////////////////////////////////////////////////////////////////////////
  290. // VertexList == Array<Float3> == std::vector<Float3>
  291. JPC_API JPC_VertexList* JPC_VertexList_new(const JPC_Float3* storage, size_t len) {
  292. const JPH::Float3* new_storage = (const JPH::Float3*)storage;
  293. return to_jpc(new JPH::VertexList(new_storage, new_storage + len));
  294. }
  295. ////////////////////////////////////////////////////////////////////////////////
  296. // IndexedTriangleList == Array<IndexedTriangle> == std::vector<IndexedTriangle>
  297. JPC_API JPC_IndexedTriangleList* JPC_IndexedTriangleList_new(const JPC_IndexedTriangle* storage, size_t len) {
  298. const JPH::IndexedTriangle* new_storage = (const JPH::IndexedTriangle*)storage;
  299. return to_jpc(new JPH::IndexedTriangleList(new_storage, new_storage + len));
  300. }
  301. ////////////////////////////////////////////////////////////////////////////////
  302. // TempAllocatorImpl
  303. JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size) {
  304. return to_jpc(new JPH::TempAllocatorImpl(size));
  305. }
  306. ////////////////////////////////////////////////////////////////////////////////
  307. // JobSystemThreadPool
  308. JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new2(
  309. uint inMaxJobs,
  310. uint inMaxBarriers)
  311. {
  312. return to_jpc(new JPH::JobSystemThreadPool(inMaxJobs, inMaxBarriers));
  313. }
  314. JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
  315. uint inMaxJobs,
  316. uint inMaxBarriers,
  317. int inNumThreads)
  318. {
  319. return to_jpc(new JPH::JobSystemThreadPool(inMaxJobs, inMaxBarriers, inNumThreads));
  320. }
  321. ////////////////////////////////////////////////////////////////////////////////
  322. // JobSystemSingleThreaded
  323. JPC_API JPC_JobSystemSingleThreaded* JPC_JobSystemSingleThreaded_new(uint inMaxJobs) {
  324. return to_jpc(new JPH::JobSystemSingleThreaded(inMaxJobs));
  325. }
  326. ////////////////////////////////////////////////////////////////////////////////
  327. // CollisionGroup
  328. JPC_IMPL JPC_CollisionGroup JPC_CollisionGroup_to_jpc(const JPH::CollisionGroup* input);
  329. class JPC_GroupFilterBridge final : public JPH::GroupFilter {
  330. public:
  331. explicit JPC_GroupFilterBridge(const void *self, JPC_GroupFilterFns fns) : self(self), fns(fns) {}
  332. bool CanCollide(const JPH::CollisionGroup &inGroup1, const JPH::CollisionGroup &inGroup2) const override {
  333. JPC_CollisionGroup jpcGroup1 = JPC_CollisionGroup_to_jpc(&inGroup1);
  334. JPC_CollisionGroup jpcGroup2 = JPC_CollisionGroup_to_jpc(&inGroup2);
  335. return fns.CanCollide(self, &jpcGroup1, &jpcGroup2);
  336. }
  337. void SaveBinaryState([[maybe_unused]] JPH::StreamOut &inStream) const override {}
  338. void RestoreBinaryState([[maybe_unused]] JPH::StreamIn &inStream) override {}
  339. private:
  340. const void* self;
  341. JPC_GroupFilterFns fns;
  342. };
  343. OPAQUE_WRAPPER(JPC_GroupFilter, JPC_GroupFilterBridge)
  344. DESTRUCTOR(JPC_GroupFilter)
  345. JPC_IMPL JPH::CollisionGroup JPC_CollisionGroup_to_jph(const JPC_CollisionGroup* self) {
  346. const JPC_GroupFilterBridge* filter_group = to_jph(self->GroupFilter);
  347. JPH::CollisionGroup group(filter_group, self->GroupID, self->SubGroupID);
  348. return group;
  349. }
  350. JPC_IMPL JPC_CollisionGroup JPC_CollisionGroup_to_jpc(const JPH::CollisionGroup* input) {
  351. JPC_CollisionGroup group{};
  352. group.GroupFilter; // NOTE: This member doesn't matter for callers of this function
  353. group.GroupID = input->GetGroupID();
  354. group.SubGroupID = input->GetSubGroupID();
  355. return group;
  356. }
  357. JPC_API JPC_GroupFilter* JPC_GroupFilter_new(
  358. const void *self,
  359. JPC_GroupFilterFns fns)
  360. {
  361. return to_jpc(new JPC_GroupFilterBridge(self, fns));
  362. }
  363. ////////////////////////////////////////////////////////////////////////////////
  364. // BroadPhaseLayerInterface
  365. class JPC_BroadPhaseLayerInterfaceBridge final : public JPH::BroadPhaseLayerInterface {
  366. public:
  367. explicit JPC_BroadPhaseLayerInterfaceBridge(const void *self, JPC_BroadPhaseLayerInterfaceFns fns) : self(self), fns(fns) {}
  368. virtual uint GetNumBroadPhaseLayers() const override {
  369. return fns.GetNumBroadPhaseLayers(self);
  370. }
  371. virtual JPH::BroadPhaseLayer GetBroadPhaseLayer(JPH::ObjectLayer inLayer) const override {
  372. return to_jph(fns.GetBroadPhaseLayer(self, inLayer));
  373. }
  374. #if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
  375. virtual const char * GetBroadPhaseLayerName([[maybe_unused]] JPH::BroadPhaseLayer inLayer) const override {
  376. return "FIXME";
  377. }
  378. #endif
  379. private:
  380. const void* self;
  381. JPC_BroadPhaseLayerInterfaceFns fns;
  382. };
  383. OPAQUE_WRAPPER(JPC_BroadPhaseLayerInterface, JPC_BroadPhaseLayerInterfaceBridge)
  384. DESTRUCTOR(JPC_BroadPhaseLayerInterface)
  385. JPC_API JPC_BroadPhaseLayerInterface* JPC_BroadPhaseLayerInterface_new(
  386. const void *self,
  387. JPC_BroadPhaseLayerInterfaceFns fns)
  388. {
  389. return to_jpc(new JPC_BroadPhaseLayerInterfaceBridge(self, fns));
  390. }
  391. ////////////////////////////////////////////////////////////////////////////////
  392. // ObjectVsBroadPhaseLayerFilter
  393. class JPC_ObjectVsBroadPhaseLayerFilterBridge final : public JPH::ObjectVsBroadPhaseLayerFilter {
  394. public:
  395. explicit JPC_ObjectVsBroadPhaseLayerFilterBridge(const void *self, JPC_ObjectVsBroadPhaseLayerFilterFns fns) : self(self), fns(fns) {}
  396. virtual bool ShouldCollide(JPH::ObjectLayer inLayer1, JPH::BroadPhaseLayer inLayer2) const override {
  397. return fns.ShouldCollide(self, inLayer1, to_jpc(inLayer2));
  398. }
  399. private:
  400. const void* self;
  401. JPC_ObjectVsBroadPhaseLayerFilterFns fns;
  402. };
  403. OPAQUE_WRAPPER(JPC_ObjectVsBroadPhaseLayerFilter, JPC_ObjectVsBroadPhaseLayerFilterBridge)
  404. DESTRUCTOR(JPC_ObjectVsBroadPhaseLayerFilter)
  405. JPC_API JPC_ObjectVsBroadPhaseLayerFilter* JPC_ObjectVsBroadPhaseLayerFilter_new(
  406. const void *self,
  407. JPC_ObjectVsBroadPhaseLayerFilterFns fns)
  408. {
  409. return to_jpc(new JPC_ObjectVsBroadPhaseLayerFilterBridge(self, fns));
  410. }
  411. ////////////////////////////////////////////////////////////////////////////////
  412. // BroadPhaseLayerFilter
  413. class JPC_BroadPhaseLayerFilterBridge final : public JPH::BroadPhaseLayerFilter {
  414. public:
  415. explicit JPC_BroadPhaseLayerFilterBridge(const void *self, JPC_BroadPhaseLayerFilterFns fns) : self(self), fns(fns) {}
  416. virtual bool ShouldCollide(JPH::BroadPhaseLayer inLayer) const override {
  417. return fns.ShouldCollide(self, to_jpc(inLayer));
  418. }
  419. private:
  420. const void* self;
  421. JPC_BroadPhaseLayerFilterFns fns;
  422. };
  423. OPAQUE_WRAPPER(JPC_BroadPhaseLayerFilter, JPC_BroadPhaseLayerFilterBridge)
  424. DESTRUCTOR(JPC_BroadPhaseLayerFilter)
  425. JPC_API JPC_BroadPhaseLayerFilter* JPC_BroadPhaseLayerFilter_new(
  426. const void *self,
  427. JPC_BroadPhaseLayerFilterFns fns)
  428. {
  429. return to_jpc(new JPC_BroadPhaseLayerFilterBridge(self, fns));
  430. }
  431. ////////////////////////////////////////////////////////////////////////////////
  432. // ObjectLayerFilter
  433. class JPC_ObjectLayerFilterBridge final : public JPH::ObjectLayerFilter {
  434. public:
  435. explicit JPC_ObjectLayerFilterBridge(const void *self, JPC_ObjectLayerFilterFns fns) : self(self), fns(fns) {}
  436. virtual bool ShouldCollide(JPH::ObjectLayer inLayer) const override {
  437. return fns.ShouldCollide(self, inLayer);
  438. }
  439. private:
  440. const void* self;
  441. JPC_ObjectLayerFilterFns fns;
  442. };
  443. OPAQUE_WRAPPER(JPC_ObjectLayerFilter, JPC_ObjectLayerFilterBridge)
  444. DESTRUCTOR(JPC_ObjectLayerFilter)
  445. JPC_API JPC_ObjectLayerFilter* JPC_ObjectLayerFilter_new(
  446. const void *self,
  447. JPC_ObjectLayerFilterFns fns)
  448. {
  449. return to_jpc(new JPC_ObjectLayerFilterBridge(self, fns));
  450. }
  451. ////////////////////////////////////////////////////////////////////////////////
  452. // BodyFilter
  453. class JPC_BodyFilterBridge final : public JPH::BodyFilter {
  454. public:
  455. explicit JPC_BodyFilterBridge(const void *self, JPC_BodyFilterFns fns) : self(self), fns(fns) {}
  456. virtual bool ShouldCollide(const JPH::BodyID &inBodyID) const override {
  457. return fns.ShouldCollide(self, to_jpc(inBodyID));
  458. }
  459. virtual bool ShouldCollideLocked(const JPH::Body &inBody) const override {
  460. return fns.ShouldCollideLocked(self, to_jpc(&inBody));
  461. }
  462. private:
  463. const void* self;
  464. JPC_BodyFilterFns fns;
  465. };
  466. OPAQUE_WRAPPER(JPC_BodyFilter, JPC_BodyFilterBridge)
  467. DESTRUCTOR(JPC_BodyFilter)
  468. JPC_API JPC_BodyFilter* JPC_BodyFilter_new(
  469. const void *self,
  470. JPC_BodyFilterFns fns)
  471. {
  472. return to_jpc(new JPC_BodyFilterBridge(self, fns));
  473. }
  474. ////////////////////////////////////////////////////////////////////////////////
  475. // ShapeFilter
  476. class JPC_ShapeFilterBridge final : public JPH::ShapeFilter {
  477. public:
  478. explicit JPC_ShapeFilterBridge(const void *self, JPC_ShapeFilterFns fns) : self(self), fns(fns) {}
  479. virtual bool ShouldCollide(const JPH::Shape *inShape2, const JPH::SubShapeID &inSubShapeIDOfShape2) const override {
  480. if (fns.ShouldCollide == nullptr) {
  481. return true;
  482. }
  483. return fns.ShouldCollide(self, to_jpc(inShape2), to_jpc(inSubShapeIDOfShape2));
  484. }
  485. virtual bool ShouldCollide(
  486. const JPH::Shape *inShape1, const JPH::SubShapeID &inSubShapeIDOfShape1,
  487. const JPH::Shape *inShape2, const JPH::SubShapeID &inSubShapeIDOfShape2) const override
  488. {
  489. if (fns.ShouldCollideTwoShapes == nullptr) {
  490. return true;
  491. }
  492. return fns.ShouldCollideTwoShapes(self,
  493. to_jpc(inShape1), to_jpc(inSubShapeIDOfShape1),
  494. to_jpc(inShape2), to_jpc(inSubShapeIDOfShape2));
  495. }
  496. private:
  497. const void* self;
  498. JPC_ShapeFilterFns fns;
  499. };
  500. OPAQUE_WRAPPER(JPC_ShapeFilter, JPC_ShapeFilterBridge)
  501. DESTRUCTOR(JPC_ShapeFilter)
  502. JPC_API JPC_ShapeFilter* JPC_ShapeFilter_new(
  503. const void *self,
  504. JPC_ShapeFilterFns fns)
  505. {
  506. return to_jpc(new JPC_ShapeFilterBridge(self, fns));
  507. }
  508. ////////////////////////////////////////////////////////////////////////////////
  509. // SimShapeFilter
  510. class JPC_SimShapeFilterBridge final : public JPH::SimShapeFilter {
  511. public:
  512. explicit JPC_SimShapeFilterBridge(const void *self, JPC_SimShapeFilterFns fns) : self(self), fns(fns) {}
  513. virtual bool ShouldCollide(
  514. const JPH::Body &inBody1, const JPH::Shape *inShape1, const JPH::SubShapeID &inSubShapeIDOfShape1,
  515. const JPH::Body &inBody2, const JPH::Shape *inShape2, const JPH::SubShapeID &inSubShapeIDOfShape2) const override
  516. {
  517. if (fns.ShouldCollide == nullptr) {
  518. return true;
  519. }
  520. return fns.ShouldCollide(self,
  521. to_jpc(&inBody1), to_jpc(inShape1), to_jpc(inSubShapeIDOfShape1),
  522. to_jpc(&inBody2), to_jpc(inShape2), to_jpc(inSubShapeIDOfShape2));
  523. }
  524. private:
  525. const void* self;
  526. JPC_SimShapeFilterFns fns;
  527. };
  528. OPAQUE_WRAPPER(JPC_SimShapeFilter, JPC_SimShapeFilterBridge)
  529. DESTRUCTOR(JPC_SimShapeFilter)
  530. JPC_API JPC_SimShapeFilter* JPC_SimShapeFilter_new(
  531. const void *self,
  532. JPC_SimShapeFilterFns fns)
  533. {
  534. return to_jpc(new JPC_SimShapeFilterBridge(self, fns));
  535. }
  536. ////////////////////////////////////////////////////////////////////////////////
  537. // JPC_ObjectLayerPairFilter
  538. class JPC_ObjectLayerPairFilterBridge final : public JPH::ObjectLayerPairFilter {
  539. public:
  540. explicit JPC_ObjectLayerPairFilterBridge(const void *self, JPC_ObjectLayerPairFilterFns fns) : self(self), fns(fns) {}
  541. virtual bool ShouldCollide(JPH::ObjectLayer inLayer1, JPH::ObjectLayer inLayer2) const override {
  542. return fns.ShouldCollide(self, inLayer1, inLayer2);
  543. }
  544. private:
  545. const void* self;
  546. JPC_ObjectLayerPairFilterFns fns;
  547. };
  548. OPAQUE_WRAPPER(JPC_ObjectLayerPairFilter, JPC_ObjectLayerPairFilterBridge)
  549. DESTRUCTOR(JPC_ObjectLayerPairFilter)
  550. JPC_API JPC_ObjectLayerPairFilter* JPC_ObjectLayerPairFilter_new(
  551. const void *self,
  552. JPC_ObjectLayerPairFilterFns fns)
  553. {
  554. return to_jpc(new JPC_ObjectLayerPairFilterBridge(self, fns));
  555. }
  556. ////////////////////////////////////////////////////////////////////////////////
  557. // JPC_ContactListener
  558. class JPC_ContactListenerBridge final : public JPH::ContactListener {
  559. public:
  560. explicit JPC_ContactListenerBridge(void *self, JPC_ContactListenerFns fns) : self(self), fns(fns) {}
  561. JPH::ValidateResult OnContactValidate(
  562. const JPH::Body &inBody1,
  563. const JPH::Body &inBody2,
  564. JPH::RVec3Arg inBaseOffset,
  565. const JPH::CollideShapeResult &inCollisionResult) override
  566. {
  567. if (fns.OnContactValidate != nullptr) {
  568. JPC_CollideShapeResult collisionResult = JPC_CollideShapeResult_to_jpc(inCollisionResult);
  569. return to_jph(fns.OnContactValidate(self, to_jpc(&inBody1), to_jpc(&inBody2), to_jpc(inBaseOffset), &collisionResult));
  570. }
  571. return ContactListener::OnContactValidate(inBody1, inBody2, inBaseOffset, inCollisionResult);
  572. }
  573. void OnContactAdded(
  574. const JPH::Body &inBody1,
  575. const JPH::Body &inBody2,
  576. const JPH::ContactManifold &inManifold,
  577. JPH::ContactSettings &ioSettings) override
  578. {
  579. if (fns.OnContactAdded != nullptr) {
  580. const auto* cManifold = reinterpret_cast<const JPC_ContactManifold*>(&inManifold);
  581. auto* cSettings = reinterpret_cast<JPC_ContactSettings*>(&ioSettings);
  582. fns.OnContactAdded(self, to_jpc(&inBody1), to_jpc(&inBody2), cManifold, cSettings);
  583. }
  584. }
  585. void OnContactPersisted(
  586. const JPH::Body &inBody1,
  587. const JPH::Body &inBody2,
  588. const JPH::ContactManifold &inManifold,
  589. JPH::ContactSettings &ioSettings) override
  590. {
  591. if (fns.OnContactPersisted != nullptr) {
  592. const auto* cManifold = reinterpret_cast<const JPC_ContactManifold*>(&inManifold);
  593. auto* cSettings = reinterpret_cast<JPC_ContactSettings*>(&ioSettings);
  594. fns.OnContactPersisted(self, to_jpc(&inBody1), to_jpc(&inBody2), cManifold, cSettings);
  595. }
  596. }
  597. void OnContactRemoved(const JPH::SubShapeIDPair &inSubShapePair) override {
  598. if (fns.OnContactRemoved != nullptr) {
  599. const auto* cSubShapePair = reinterpret_cast<const JPC_SubShapeIDPair*>(&inSubShapePair);
  600. fns.OnContactRemoved(self, cSubShapePair);
  601. }
  602. }
  603. private:
  604. void* self;
  605. JPC_ContactListenerFns fns;
  606. };
  607. OPAQUE_WRAPPER(JPC_ContactListener, JPC_ContactListenerBridge)
  608. DESTRUCTOR(JPC_ContactListener)
  609. JPC_API JPC_ContactListener* JPC_ContactListener_new(
  610. void *self,
  611. JPC_ContactListenerFns fns)
  612. {
  613. return to_jpc(new JPC_ContactListenerBridge(self, fns));
  614. }
  615. JPC_API void JPC_EstimateCollisionResponse(
  616. const JPC_Body* inBody1,
  617. const JPC_Body* inBody2,
  618. const JPC_ContactManifold* inManifold,
  619. JPC_CollisionEstimationResult* outResult,
  620. float inCombinedFriction,
  621. float inCombinedRestitution,
  622. float inMinVelocityForRestitution, ///< = 1.0f
  623. uint inNumIterations ///< = 10
  624. ) {
  625. const auto* jphManifold = reinterpret_cast<const JPH::ContactManifold*>(inManifold);
  626. auto* jphResult = reinterpret_cast<JPH::CollisionEstimationResult*>(outResult);
  627. JPH::EstimateCollisionResponse(
  628. *to_jph(inBody1),
  629. *to_jph(inBody2),
  630. *jphManifold,
  631. *jphResult,
  632. inCombinedFriction,
  633. inCombinedRestitution,
  634. inMinVelocityForRestitution,
  635. inNumIterations);
  636. }
  637. ////////////////////////////////////////////////////////////////////////////////
  638. // JPC_CastShapeCollector
  639. class JPC_CastShapeCollectorBridge;
  640. OPAQUE_WRAPPER(JPC_CastShapeCollector, JPC_CastShapeCollectorBridge)
  641. class JPC_CastShapeCollectorBridge final : public JPH::CastShapeCollector {
  642. using ResultType = JPH::ShapeCastResult;
  643. public:
  644. explicit JPC_CastShapeCollectorBridge(void *self, JPC_CastShapeCollectorFns fns) : self(self), fns(fns) {}
  645. void Reset() override {
  646. JPH::CastShapeCollector::Reset();
  647. if (fns.Reset != nullptr) {
  648. fns.Reset(self);
  649. }
  650. }
  651. void AddHit(const ResultType &inResult) override {
  652. JPC_ShapeCastResult result = JPC_ShapeCastResult_to_jpc(inResult);
  653. JPC_CastShapeCollector *base = to_jpc(this);
  654. fns.AddHit(self, base, &result);
  655. }
  656. private:
  657. void* self;
  658. JPC_CastShapeCollectorFns fns;
  659. };
  660. DESTRUCTOR(JPC_CastShapeCollector)
  661. JPC_API JPC_CastShapeCollector* JPC_CastShapeCollector_new(
  662. void *self,
  663. JPC_CastShapeCollectorFns fns)
  664. {
  665. return to_jpc(new JPC_CastShapeCollectorBridge(self, fns));
  666. }
  667. JPC_API void JPC_CastShapeCollector_UpdateEarlyOutFraction(JPC_CastShapeCollector* self, float inFraction) {
  668. to_jph(self)->UpdateEarlyOutFraction(inFraction);
  669. }
  670. ////////////////////////////////////////////////////////////////////////////////
  671. // JPC_CollideShapeCollector
  672. class JPC_CollideShapeCollectorBridge;
  673. OPAQUE_WRAPPER(JPC_CollideShapeCollector, JPC_CollideShapeCollectorBridge)
  674. class JPC_CollideShapeCollectorBridge final : public JPH::CollideShapeCollector {
  675. using ResultType = JPH::CollideShapeResult;
  676. public:
  677. explicit JPC_CollideShapeCollectorBridge(void *self, JPC_CollideShapeCollectorFns fns) : self(self), fns(fns) {}
  678. void Reset() override {
  679. JPH::CollideShapeCollector::Reset();
  680. if (fns.Reset != nullptr) {
  681. fns.Reset(self);
  682. }
  683. }
  684. void AddHit(const ResultType &inResult) override {
  685. JPC_CollideShapeResult result = JPC_CollideShapeResult_to_jpc(inResult);
  686. JPC_CollideShapeCollector *base = to_jpc(this);
  687. fns.AddHit(self, base, &result);
  688. }
  689. private:
  690. void* self;
  691. JPC_CollideShapeCollectorFns fns;
  692. };
  693. DESTRUCTOR(JPC_CollideShapeCollector)
  694. JPC_API JPC_CollideShapeCollector* JPC_CollideShapeCollector_new(
  695. void *self,
  696. JPC_CollideShapeCollectorFns fns)
  697. {
  698. return to_jpc(new JPC_CollideShapeCollectorBridge(self, fns));
  699. }
  700. JPC_API void JPC_CollideShapeCollector_UpdateEarlyOutFraction(JPC_CollideShapeCollector* self, float inFraction) {
  701. to_jph(self)->UpdateEarlyOutFraction(inFraction);
  702. }
  703. ////////////////////////////////////////////////////////////////////////////////
  704. // BodyManager::DrawSettings
  705. JPC_API void JPC_BodyManager_DrawSettings_default(JPC_BodyManager_DrawSettings* object) {
  706. *object = to_jpc(JPH::BodyManager::DrawSettings());
  707. }
  708. ////////////////////////////////////////////////////////////////////////////////
  709. // DebugRendererSimple
  710. class JPC_DebugRendererSimpleBridge final : public JPH::DebugRendererSimple {
  711. public:
  712. explicit JPC_DebugRendererSimpleBridge(const void *self, JPC_DebugRendererSimpleFns fns) : self(self), fns(fns) {}
  713. virtual void DrawLine(JPH::RVec3Arg inFrom, JPH::RVec3Arg inTo, JPH::ColorArg inColor) override {
  714. fns.DrawLine(self, to_jpc(inFrom), to_jpc(inTo), to_jpc(inColor));
  715. }
  716. virtual void DrawText3D(
  717. [[maybe_unused]] JPH::RVec3Arg inPosition,
  718. [[maybe_unused]] const std::string_view &inString,
  719. [[maybe_unused]] JPH::ColorArg inColor = JPH::Color::sWhite,
  720. [[maybe_unused]] float inHeight = 0.5f) override
  721. {
  722. // TODO
  723. }
  724. private:
  725. const void* self;
  726. JPC_DebugRendererSimpleFns fns;
  727. };
  728. OPAQUE_WRAPPER(JPC_DebugRendererSimple, JPC_DebugRendererSimpleBridge)
  729. DESTRUCTOR(JPC_DebugRendererSimple)
  730. JPC_API JPC_DebugRendererSimple* JPC_DebugRendererSimple_new(
  731. const void *self,
  732. JPC_DebugRendererSimpleFns fns)
  733. {
  734. return to_jpc(new JPC_DebugRendererSimpleBridge(self, fns));
  735. }
  736. ////////////////////////////////////////////////////////////////////////////////
  737. // String
  738. JPC_API const char* JPC_String_c_str(JPC_String* self) {
  739. return to_jph(self)->c_str();
  740. }
  741. ////////////////////////////////////////////////////////////////////////////////
  742. // Constraint -> RefTarget<Constraint>
  743. OPAQUE_WRAPPER(JPC_Constraint, JPH::Constraint);
  744. // RefTarget<Constraint>
  745. JPC_API uint32_t JPC_Constraint_GetRefCount(const JPC_Constraint* self) {
  746. return to_jph(self)->GetRefCount();
  747. }
  748. JPC_API void JPC_Constraint_AddRef(const JPC_Constraint* self) {
  749. to_jph(self)->AddRef();
  750. }
  751. JPC_API void JPC_Constraint_Release(const JPC_Constraint* self) {
  752. to_jph(self)->Release();
  753. }
  754. // Constraint
  755. JPC_API void JPC_Constraint_delete(JPC_Constraint* self) {
  756. delete to_jph(self);
  757. }
  758. // JPC_API JPC_ConstraintType JPC_Constraint_GetType(const JPC_Constraint* self);
  759. // JPC_API JPC_ConstraintSubType JPC_Constraint_GetSubType(const JPC_Constraint* self);
  760. JPC_API uint32_t JPC_Constraint_GetConstraintPriority(const JPC_Constraint* self) {
  761. return to_jph(self)->GetConstraintPriority();
  762. }
  763. JPC_API void JPC_Constraint_SetConstraintPriority(JPC_Constraint* self, uint32_t inPriority) {
  764. to_jph(self)->SetConstraintPriority(inPriority);
  765. }
  766. JPC_API uint JPC_Constraint_GetNumVelocityStepsOverride(const JPC_Constraint* self) {
  767. return to_jph(self)->GetNumVelocityStepsOverride();
  768. }
  769. JPC_API void JPC_Constraint_SetNumVelocityStepsOverride(JPC_Constraint* self, uint inN) {
  770. to_jph(self)->SetNumVelocityStepsOverride(inN);
  771. }
  772. JPC_API uint JPC_Constraint_GetNumPositionStepsOverride(const JPC_Constraint* self) {
  773. return to_jph(self)->GetNumPositionStepsOverride();
  774. }
  775. JPC_API void JPC_Constraint_SetNumPositionStepsOverride(JPC_Constraint* self, uint inN) {
  776. to_jph(self)->SetNumPositionStepsOverride(inN);
  777. }
  778. JPC_API bool JPC_Constraint_GetEnabled(const JPC_Constraint* self) {
  779. return to_jph(self)->GetEnabled();
  780. }
  781. JPC_API void JPC_Constraint_SetEnabled(JPC_Constraint* self, bool inEnabled) {
  782. to_jph(self)->SetEnabled(inEnabled);
  783. }
  784. JPC_API uint64_t JPC_Constraint_GetUserData(const JPC_Constraint* self) {
  785. return to_jph(self)->GetUserData();
  786. }
  787. JPC_API void JPC_Constraint_SetUserData(JPC_Constraint* self, uint64_t inUserData) {
  788. to_jph(self)->SetUserData(inUserData);
  789. }
  790. JPC_API void JPC_Constraint_NotifyShapeChanged(JPC_Constraint* self, JPC_BodyID inBodyID, JPC_Vec3 inDeltaCOM) {
  791. to_jph(self)->NotifyShapeChanged(to_jph(inBodyID), to_jph(inDeltaCOM));
  792. }
  793. ////////////////////////////////////////////////////////////////////////////////
  794. // TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  795. OPAQUE_WRAPPER(JPC_TwoBodyConstraint, JPH::TwoBodyConstraint);
  796. JPC_API JPC_Body* JPC_TwoBodyConstraint_GetBody1(const JPC_TwoBodyConstraint* self) {
  797. return to_jpc(to_jph(self)->GetBody1());
  798. }
  799. JPC_API JPC_Body* JPC_TwoBodyConstraint_GetBody2(const JPC_TwoBodyConstraint* self) {
  800. return to_jpc(to_jph(self)->GetBody2());
  801. }
  802. JPC_API JPC_Mat44 JPC_TwoBodyConstraint_GetConstraintToBody1Matrix(const JPC_TwoBodyConstraint* self) {
  803. return to_jpc(to_jph(self)->GetConstraintToBody1Matrix());
  804. }
  805. JPC_API JPC_Mat44 JPC_TwoBodyConstraint_GetConstraintToBody2Matrix(const JPC_TwoBodyConstraint* self) {
  806. return to_jpc(to_jph(self)->GetConstraintToBody2Matrix());
  807. }
  808. ////////////////////////////////////////////////////////////////////////////////
  809. // FixedConstraint -> TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  810. OPAQUE_WRAPPER(JPC_FixedConstraint, JPH::FixedConstraint);
  811. JPC_API JPC_Vec3 JPC_FixedConstraint_GetTotalLambdaPosition(const JPC_FixedConstraint* self) {
  812. return to_jpc(to_jph(self)->GetTotalLambdaPosition());
  813. }
  814. JPC_API JPC_Vec3 JPC_FixedConstraint_GetTotalLambdaRotation(const JPC_FixedConstraint* self) {
  815. return to_jpc(to_jph(self)->GetTotalLambdaRotation());
  816. }
  817. ////////////////////////////////////////////////////////////////////////////////
  818. // DistanceConstraint -> TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  819. OPAQUE_WRAPPER(JPC_DistanceConstraint, JPH::DistanceConstraint);
  820. JPC_API float JPC_DistanceConstraint_GetTotalLambdaPosition(const JPC_DistanceConstraint* self) {
  821. return to_jph(self)->GetTotalLambdaPosition();
  822. }
  823. ////////////////////////////////////////////////////////////////////////////////
  824. // SixDOFConstraint -> TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  825. OPAQUE_WRAPPER(JPC_SixDOFConstraint, JPH::SixDOFConstraint);
  826. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTranslationLimitsMin(const JPC_SixDOFConstraint* self) {
  827. return to_jpc(to_jph(self)->GetTranslationLimitsMin());
  828. }
  829. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTranslationLimitsMax(const JPC_SixDOFConstraint* self) {
  830. return to_jpc(to_jph(self)->GetTranslationLimitsMax());
  831. }
  832. JPC_API void JPC_SixDOFConstraint_SetTranslationLimits(JPC_SixDOFConstraint* self, JPC_Vec3 inLimitMin, JPC_Vec3 inLimitMax) {
  833. to_jph(self)->SetTranslationLimits(to_jph(inLimitMin), to_jph(inLimitMax));
  834. }
  835. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetRotationLimitsMin(const JPC_SixDOFConstraint* self) {
  836. return to_jpc(to_jph(self)->GetRotationLimitsMin());
  837. }
  838. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetRotationLimitsMax(const JPC_SixDOFConstraint* self) {
  839. return to_jpc(to_jph(self)->GetRotationLimitsMax());
  840. }
  841. JPC_API void JPC_SixDOFConstraint_SetRotationLimits(JPC_SixDOFConstraint* self, JPC_Vec3 inLimitMin, JPC_Vec3 inLimitMax) {
  842. to_jph(self)->SetRotationLimits(to_jph(inLimitMin), to_jph(inLimitMax));
  843. }
  844. JPC_API float JPC_SixDOFConstraint_GetLimitsMin(const JPC_SixDOFConstraint* self, JPC_SixDOFConstraint_Axis inAxis) {
  845. return to_jph(self)->GetLimitsMin((JPH::SixDOFConstraint::EAxis)inAxis);
  846. }
  847. JPC_API float JPC_SixDOFConstraint_GetLimitsMax(const JPC_SixDOFConstraint* self, JPC_SixDOFConstraint_Axis inAxis) {
  848. return to_jph(self)->GetLimitsMax((JPH::SixDOFConstraint::EAxis)inAxis);
  849. }
  850. JPC_API bool JPC_SixDOFConstraint_IsFreeAxis(const JPC_SixDOFConstraint* self, JPC_SixDOFConstraint_Axis inAxis);
  851. // const SpringSettings & GetLimitsSpringSettings(JPC_SixDOFConstraint_Axis inAxis) const { JPH_ASSERT(inAxis < JPC_SixDOFConstraint_Axis::NumTranslation); return mLimitsSpringSettings[inAxis]; }
  852. // void SetLimitsSpringSettings(JPC_SixDOFConstraint_Axis inAxis, const SpringSettings& inLimitsSpringSettings) { JPH_ASSERT(inAxis < JPC_SixDOFConstraint_Axis::NumTranslation); mLimitsSpringSettings[inAxis] = inLimitsSpringSettings; CacheHasSpringLimits(); }
  853. JPC_API void JPC_SixDOFConstraint_SetMaxFriction(JPC_SixDOFConstraint* self, JPC_SixDOFConstraint_Axis inAxis, float inFriction) {
  854. to_jph(self)->SetMaxFriction((JPH::SixDOFConstraint::EAxis)inAxis, inFriction);
  855. }
  856. JPC_API float JPC_SixDOFConstraint_GetMaxFriction(const JPC_SixDOFConstraint* self, JPC_SixDOFConstraint_Axis inAxis) {
  857. return to_jph(self)->GetMaxFriction((JPH::SixDOFConstraint::EAxis)inAxis);
  858. }
  859. JPC_API JPC_Quat JPC_SixDOFConstraint_GetRotationInConstraintSpace(const JPC_SixDOFConstraint* self) {
  860. return to_jpc(to_jph(self)->GetRotationInConstraintSpace());
  861. }
  862. /// Motor settings
  863. // MotorSettings & GetMotorSettings(EAxis inAxis)
  864. // const MotorSettings & GetMotorSettings(EAxis inAxis) const
  865. // void SetMotorState(EAxis inAxis, EMotorState inState);
  866. // EMotorState GetMotorState(EAxis inAxis) const
  867. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTargetVelocityCS(const JPC_SixDOFConstraint* self) {
  868. return to_jpc(to_jph(self)->GetTargetVelocityCS());
  869. }
  870. JPC_API void JPC_SixDOFConstraint_SetTargetVelocityCS(JPC_SixDOFConstraint* self, JPC_Vec3 inVelocity) {
  871. to_jph(self)->SetTargetVelocityCS(to_jph(inVelocity));
  872. }
  873. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTargetAngularVelocityCS(const JPC_SixDOFConstraint* self) {
  874. return to_jpc(to_jph(self)->GetTargetAngularVelocityCS());
  875. }
  876. JPC_API void JPC_SixDOFConstraint_SetTargetAngularVelocityCS(JPC_SixDOFConstraint* self, JPC_Vec3 inAngularVelocity) {
  877. to_jph(self)->SetTargetAngularVelocityCS(to_jph(inAngularVelocity));
  878. }
  879. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTargetPositionCS(const JPC_SixDOFConstraint* self) {
  880. return to_jpc(to_jph(self)->GetTargetPositionCS());
  881. }
  882. JPC_API void JPC_SixDOFConstraint_SetTargetPositionCS(JPC_SixDOFConstraint* self, JPC_Vec3 inPosition) {
  883. to_jph(self)->SetTargetPositionCS(to_jph(inPosition));
  884. }
  885. JPC_API JPC_Quat JPC_SixDOFConstraint_GetTargetOrientationCS(const JPC_SixDOFConstraint* self) {
  886. return to_jpc(to_jph(self)->GetTargetOrientationCS());
  887. }
  888. JPC_API void JPC_SixDOFConstraint_SetTargetOrientationCS(JPC_SixDOFConstraint* self, JPC_Quat inOrientation) {
  889. to_jph(self)->SetTargetOrientationCS(to_jph(inOrientation));
  890. }
  891. JPC_API void JPC_SixDOFConstraint_SetTargetOrientationBS(JPC_SixDOFConstraint* self, JPC_Quat inOrientation) {
  892. to_jph(self)->SetTargetOrientationBS(to_jph(inOrientation));
  893. }
  894. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTotalLambdaPosition(JPC_SixDOFConstraint* self) {
  895. return to_jpc(to_jph(self)->GetTotalLambdaPosition());
  896. }
  897. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTotalLambdaRotation(JPC_SixDOFConstraint* self) {
  898. return to_jpc(to_jph(self)->GetTotalLambdaRotation());
  899. }
  900. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTotalLambdaMotorTranslation(JPC_SixDOFConstraint* self) {
  901. return to_jpc(to_jph(self)->GetTotalLambdaMotorTranslation());
  902. }
  903. JPC_API JPC_Vec3 JPC_SixDOFConstraint_GetTotalLambdaMotorRotation(JPC_SixDOFConstraint* self) {
  904. return to_jpc(to_jph(self)->GetTotalLambdaMotorRotation());
  905. }
  906. ////////////////////////////////////////////////////////////////////////////////
  907. // HingeConstraint -> TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  908. OPAQUE_WRAPPER(JPC_HingeConstraint, JPH::HingeConstraint);
  909. JPC_API JPC_Constraint* JPC_HingeConstraint_to_Constraint(JPC_HingeConstraint* self) {
  910. return (JPC_Constraint*)(self);
  911. }
  912. JPC_API void JPC_HingeConstraint_SetMotorState(JPC_HingeConstraint* self, JPC_MotorState inState) {
  913. to_jph(self)->SetMotorState(to_jph(inState));
  914. }
  915. JPC_API JPC_MotorState JPC_HingeConstraint_GetMotorState(const JPC_HingeConstraint* self) {
  916. return to_jpc(to_jph(self)->GetMotorState());
  917. }
  918. JPC_API void JPC_HingeConstraint_SetTargetAngularVelocity(JPC_HingeConstraint* self, float inAngularVelocity) {
  919. to_jph(self)->SetTargetAngularVelocity(inAngularVelocity);
  920. }
  921. JPC_API float JPC_HingeConstraint_GetTargetAngularVelocity(const JPC_HingeConstraint* self) {
  922. return to_jph(self)->GetTargetAngularVelocity();
  923. }
  924. JPC_API void JPC_HingeConstraint_SetTargetAngle(JPC_HingeConstraint* self, float inAngle) {
  925. to_jph(self)->SetTargetAngle(inAngle);
  926. }
  927. JPC_API float JPC_HingeConstraint_GetTargetAngle(const JPC_HingeConstraint* self) {
  928. return to_jph(self)->GetTargetAngle();
  929. }
  930. JPC_API JPC_Vec3 JPC_HingeConstraint_GetTotalLambdaPosition(const JPC_HingeConstraint* self) {
  931. return to_jpc(to_jph(self)->GetTotalLambdaPosition());
  932. }
  933. JPC_API JPC_Vec2 JPC_HingeConstraint_GetTotalLambdaRotation(const JPC_HingeConstraint* self) {
  934. return to_jpc(to_jph(self)->GetTotalLambdaRotation());
  935. }
  936. JPC_API float JPC_HingeConstraint_GetTotalLambdaRotationLimits(const JPC_HingeConstraint* self) {
  937. return to_jph(self)->GetTotalLambdaRotationLimits();
  938. }
  939. JPC_API float JPC_HingeConstraint_GetTotalLambdaMotor(const JPC_HingeConstraint* self) {
  940. return to_jph(self)->GetTotalLambdaMotor();
  941. }
  942. ////////////////////////////////////////////////////////////////////////////////
  943. // SliderConstraint -> TwoBodyConstraint -> Constraint -> RefTarget<Constraint>
  944. OPAQUE_WRAPPER(JPC_SliderConstraint, JPH::SliderConstraint);
  945. JPC_API void JPC_SliderConstraint_SetMotorState(JPC_SliderConstraint* self, JPC_MotorState inState) {
  946. to_jph(self)->SetMotorState(to_jph(inState));
  947. }
  948. JPC_API JPC_MotorState JPC_SliderConstraint_GetMotorState(const JPC_SliderConstraint* self) {
  949. return to_jpc(to_jph(self)->GetMotorState());
  950. }
  951. JPC_API void JPC_SliderConstraint_SetTargetVelocity(JPC_SliderConstraint* self, float inVelocity) {
  952. to_jph(self)->SetTargetVelocity(inVelocity);
  953. }
  954. JPC_API float JPC_SliderConstraint_GetTargetVelocity(const JPC_SliderConstraint* self) {
  955. return to_jph(self)->GetTargetVelocity();
  956. }
  957. JPC_API void JPC_SliderConstraint_SetTargetPosition(JPC_SliderConstraint* self, float inPosition) {
  958. to_jph(self)->SetTargetPosition(inPosition);
  959. }
  960. JPC_API float JPC_SliderConstraint_GetTargetPosition(const JPC_SliderConstraint* self) {
  961. return to_jph(self)->GetTargetPosition();
  962. }
  963. JPC_API JPC_Vec2 JPC_SliderConstraint_GetTotalLambdaPosition(const JPC_SliderConstraint* self) {
  964. return to_jpc(to_jph(self)->GetTotalLambdaPosition());
  965. }
  966. JPC_API float JPC_SliderConstraint_GetTotalLambdaPositionLimits(const JPC_SliderConstraint* self) {
  967. return to_jph(self)->GetTotalLambdaPositionLimits();
  968. }
  969. JPC_API JPC_Vec3 JPC_SliderConstraint_GetTotalLambdaRotation(const JPC_SliderConstraint* self) {
  970. return to_jpc(to_jph(self)->GetTotalLambdaRotation());
  971. }
  972. JPC_API float JPC_SliderConstraint_GetTotalLambdaMotor(const JPC_SliderConstraint* self) {
  973. return to_jph(self)->GetTotalLambdaMotor();
  974. }
  975. ////////////////////////////////////////////////////////////////////////////////
  976. // ConstraintSettings
  977. JPC_IMPL void JPC_ConstraintSettings_to_jpc(
  978. JPC_ConstraintSettings* outJpc,
  979. const JPH::ConstraintSettings* inJph)
  980. {
  981. outJpc->Enabled = inJph->mEnabled;
  982. outJpc->ConstraintPriority = inJph->mConstraintPriority;
  983. outJpc->NumVelocityStepsOverride = inJph->mNumVelocityStepsOverride;
  984. outJpc->NumPositionStepsOverride = inJph->mNumPositionStepsOverride;
  985. outJpc->DrawConstraintSize = inJph->mDrawConstraintSize;
  986. outJpc->UserData = inJph->mUserData;
  987. }
  988. JPC_IMPL void JPC_ConstraintSettings_to_jph(
  989. const JPC_ConstraintSettings* inJpc,
  990. JPH::ConstraintSettings* outJph)
  991. {
  992. outJph->mEnabled = inJpc->Enabled;
  993. outJph->mConstraintPriority = inJpc->ConstraintPriority;
  994. outJph->mNumVelocityStepsOverride = inJpc->NumVelocityStepsOverride;
  995. outJph->mNumPositionStepsOverride = inJpc->NumPositionStepsOverride;
  996. outJph->mDrawConstraintSize = inJpc->DrawConstraintSize;
  997. outJph->mUserData = inJpc->UserData;
  998. }
  999. JPC_API void JPC_ConstraintSettings_default(JPC_ConstraintSettings* settings) {
  1000. JPH::ConstraintSettings defaultSettings{};
  1001. JPC_ConstraintSettings_to_jpc(settings, &defaultSettings);
  1002. }
  1003. ////////////////////////////////////////////////////////////////////////////////
  1004. // SpringSettings
  1005. JPC_IMPL void JPC_SpringSettings_to_jpc(
  1006. JPC_SpringSettings* outJpc,
  1007. const JPH::SpringSettings* inJph)
  1008. {
  1009. outJpc->Mode = to_jpc(inJph->mMode);
  1010. outJpc->FrequencyOrStiffness = inJph->mFrequency;
  1011. outJpc->Damping = inJph->mDamping;
  1012. }
  1013. JPC_IMPL void JPC_SpringSettings_to_jph(
  1014. const JPC_SpringSettings* inJpc,
  1015. JPH::SpringSettings* outJph)
  1016. {
  1017. outJph->mMode = to_jph(inJpc->Mode);
  1018. outJph->mFrequency = inJpc->FrequencyOrStiffness;
  1019. outJph->mDamping = inJpc->Damping;
  1020. }
  1021. JPC_API void JPC_SpringSettings_default(JPC_SpringSettings* settings) {
  1022. JPH::SpringSettings defaultSettings{};
  1023. JPC_SpringSettings_to_jpc(settings, &defaultSettings);
  1024. }
  1025. ////////////////////////////////////////////////////////////////////////////////
  1026. // MotorSettings
  1027. JPC_IMPL void JPC_MotorSettings_to_jpc(
  1028. JPC_MotorSettings* outJpc,
  1029. const JPH::MotorSettings* inJph)
  1030. {
  1031. JPC_SpringSettings_to_jpc(&outJpc->SpringSettings, &inJph->mSpringSettings);
  1032. outJpc->MinForceLimit = inJph->mMinForceLimit;
  1033. outJpc->MaxForceLimit = inJph->mMaxForceLimit;
  1034. outJpc->MinTorqueLimit = inJph->mMinTorqueLimit;
  1035. outJpc->MaxTorqueLimit = inJph->mMaxTorqueLimit;
  1036. }
  1037. JPC_IMPL void JPC_MotorSettings_to_jph(
  1038. const JPC_MotorSettings* inJpc,
  1039. JPH::MotorSettings* outJph)
  1040. {
  1041. JPC_SpringSettings_to_jph(&inJpc->SpringSettings, &outJph->mSpringSettings);
  1042. outJph->mMinForceLimit = inJpc->MinForceLimit;
  1043. outJph->mMaxForceLimit = inJpc->MaxForceLimit;
  1044. outJph->mMinTorqueLimit = inJpc->MinTorqueLimit;
  1045. outJph->mMaxTorqueLimit = inJpc->MaxTorqueLimit;
  1046. }
  1047. JPC_API void JPC_MotorSettings_default(JPC_MotorSettings* settings) {
  1048. JPH::MotorSettings defaultSettings{};
  1049. JPC_MotorSettings_to_jpc(settings, &defaultSettings);
  1050. }
  1051. ////////////////////////////////////////////////////////////////////////////////
  1052. // FixedConstraintSettings -> TwoBodyConstraintSettings -> ConstraintSettings
  1053. JPC_IMPL void JPC_FixedConstraintSettings_to_jpc(
  1054. JPC_FixedConstraintSettings* outJpc,
  1055. const JPH::FixedConstraintSettings* inJph)
  1056. {
  1057. JPC_ConstraintSettings_to_jpc(&outJpc->ConstraintSettings, inJph);
  1058. outJpc->Space = static_cast<JPC_ConstraintSpace>(inJph->mSpace);
  1059. outJpc->AutoDetectPoint = inJph->mAutoDetectPoint;
  1060. outJpc->Point1 = to_jpc(inJph->mPoint1);
  1061. outJpc->AxisX1 = to_jpc(inJph->mAxisX1);
  1062. outJpc->AxisY1 = to_jpc(inJph->mAxisY1);
  1063. outJpc->Point2 = to_jpc(inJph->mPoint2);
  1064. outJpc->AxisX2 = to_jpc(inJph->mAxisX2);
  1065. outJpc->AxisY2 = to_jpc(inJph->mAxisY2);
  1066. }
  1067. JPC_IMPL void JPC_FixedConstraintSettings_to_jph(
  1068. const JPC_FixedConstraintSettings* inJpc,
  1069. JPH::FixedConstraintSettings* outJph)
  1070. {
  1071. JPC_ConstraintSettings_to_jph(&inJpc->ConstraintSettings, outJph);
  1072. outJph->mSpace = static_cast<JPH::EConstraintSpace>(inJpc->Space);
  1073. outJph->mAutoDetectPoint = inJpc->AutoDetectPoint;
  1074. outJph->mPoint1 = to_jph(inJpc->Point1);
  1075. outJph->mAxisX1 = to_jph(inJpc->AxisX1);
  1076. outJph->mAxisY1 = to_jph(inJpc->AxisY1);
  1077. outJph->mPoint2 = to_jph(inJpc->Point2);
  1078. outJph->mAxisX2 = to_jph(inJpc->AxisX2);
  1079. outJph->mAxisY2 = to_jph(inJpc->AxisY2);
  1080. }
  1081. JPC_API void JPC_FixedConstraintSettings_default(JPC_FixedConstraintSettings* settings) {
  1082. JPH::FixedConstraintSettings defaultSettings{};
  1083. JPC_FixedConstraintSettings_to_jpc(settings, &defaultSettings);
  1084. }
  1085. JPC_API JPC_Constraint* JPC_FixedConstraintSettings_Create(
  1086. const JPC_FixedConstraintSettings* self,
  1087. JPC_Body* inBody1,
  1088. JPC_Body* inBody2)
  1089. {
  1090. JPH::FixedConstraintSettings jphSettings;
  1091. JPC_FixedConstraintSettings_to_jph(self, &jphSettings);
  1092. JPH::FixedConstraint* outJph = new JPH::FixedConstraint(*to_jph(inBody1), *to_jph(inBody2), jphSettings);
  1093. return (JPC_Constraint*)outJph;
  1094. }
  1095. ////////////////////////////////////////////////////////////////////////////////
  1096. // SixDOFConstraintSettings -> TwoBodyConstraintSettings -> ConstraintSettings
  1097. JPC_IMPL void JPC_SixDOFConstraintSettings_to_jpc(
  1098. JPC_SixDOFConstraintSettings* outJpc,
  1099. const JPH::SixDOFConstraintSettings* inJph)
  1100. {
  1101. JPC_ConstraintSettings_to_jpc(&outJpc->ConstraintSettings, inJph);
  1102. outJpc->Space = static_cast<JPC_ConstraintSpace>(inJph->mSpace);
  1103. outJpc->Position1 = to_jpc(inJph->mPosition1);
  1104. outJpc->AxisX1 = to_jpc(inJph->mAxisX1);
  1105. outJpc->AxisY1 = to_jpc(inJph->mAxisY1);
  1106. outJpc->Position2 = to_jpc(inJph->mPosition2);
  1107. outJpc->AxisX2 = to_jpc(inJph->mAxisX2);
  1108. outJpc->AxisY2 = to_jpc(inJph->mAxisY2);
  1109. std::copy(inJph->mMaxFriction, inJph->mMaxFriction + 6, outJpc->MaxFriction);
  1110. std::copy(inJph->mLimitMin, inJph->mLimitMin + 6, outJpc->LimitMin);
  1111. std::copy(inJph->mLimitMax, inJph->mLimitMax + 6, outJpc->LimitMax);
  1112. // TODO: LimitsSpringSettings
  1113. }
  1114. JPC_IMPL void JPC_SixDOFConstraintSettings_to_jph(
  1115. const JPC_SixDOFConstraintSettings* inJpc,
  1116. JPH::SixDOFConstraintSettings* outJph)
  1117. {
  1118. JPC_ConstraintSettings_to_jph(&inJpc->ConstraintSettings, outJph);
  1119. outJph->mSpace = static_cast<JPH::EConstraintSpace>(inJpc->Space);
  1120. outJph->mPosition1 = to_jph(inJpc->Position1);
  1121. outJph->mAxisX1 = to_jph(inJpc->AxisX1);
  1122. outJph->mAxisY1 = to_jph(inJpc->AxisY1);
  1123. outJph->mPosition2 = to_jph(inJpc->Position2);
  1124. outJph->mAxisX2 = to_jph(inJpc->AxisX2);
  1125. outJph->mAxisY2 = to_jph(inJpc->AxisY2);
  1126. std::copy(inJpc->MaxFriction, inJpc->MaxFriction + 6, outJph->mMaxFriction);
  1127. std::copy(inJpc->LimitMin, inJpc->LimitMin + 6, outJph->mLimitMin);
  1128. std::copy(inJpc->LimitMax, inJpc->LimitMax + 6, outJph->mLimitMax);
  1129. // TODO: LimitsSpringSettings
  1130. }
  1131. JPC_API void JPC_SixDOFConstraintSettings_default(JPC_SixDOFConstraintSettings* settings) {
  1132. JPH::SixDOFConstraintSettings defaultSettings{};
  1133. JPC_SixDOFConstraintSettings_to_jpc(settings, &defaultSettings);
  1134. }
  1135. JPC_API JPC_Constraint* JPC_SixDOFConstraintSettings_Create(
  1136. const JPC_SixDOFConstraintSettings* self,
  1137. JPC_Body* inBody1,
  1138. JPC_Body* inBody2)
  1139. {
  1140. JPH::SixDOFConstraintSettings jphSettings;
  1141. JPC_SixDOFConstraintSettings_to_jph(self, &jphSettings);
  1142. JPH::SixDOFConstraint* outJph = new JPH::SixDOFConstraint(*to_jph(inBody1), *to_jph(inBody2), jphSettings);
  1143. return (JPC_Constraint*)outJph;
  1144. }
  1145. ////////////////////////////////////////////////////////////////////////////////
  1146. // HingeConstraintSettings -> TwoBodyConstraintSettings -> ConstraintSettings
  1147. JPC_IMPL void JPC_HingeConstraintSettings_to_jpc(
  1148. JPC_HingeConstraintSettings* outJpc,
  1149. const JPH::HingeConstraintSettings* inJph)
  1150. {
  1151. JPC_ConstraintSettings_to_jpc(&outJpc->ConstraintSettings, inJph);
  1152. outJpc->Space = static_cast<JPC_ConstraintSpace>(inJph->mSpace);
  1153. outJpc->Point1 = to_jpc(inJph->mPoint1);
  1154. outJpc->HingeAxis1 = to_jpc(inJph->mHingeAxis1);
  1155. outJpc->NormalAxis1 = to_jpc(inJph->mNormalAxis1);
  1156. outJpc->Point2 = to_jpc(inJph->mPoint2);
  1157. outJpc->HingeAxis2 = to_jpc(inJph->mHingeAxis2);
  1158. outJpc->NormalAxis2 = to_jpc(inJph->mNormalAxis2);
  1159. outJpc->LimitsMin = inJph->mLimitsMin;
  1160. outJpc->LimitsMax = inJph->mLimitsMax;
  1161. JPC_SpringSettings_to_jpc(&outJpc->LimitsSpringSettings, &inJph->mLimitsSpringSettings);
  1162. outJpc->MaxFrictionTorque = inJph->mMaxFrictionTorque;
  1163. JPC_MotorSettings_to_jpc(&outJpc->MotorSettings, &inJph->mMotorSettings);
  1164. }
  1165. JPC_IMPL void JPC_HingeConstraintSettings_to_jph(
  1166. const JPC_HingeConstraintSettings* inJpc,
  1167. JPH::HingeConstraintSettings* outJph)
  1168. {
  1169. JPC_ConstraintSettings_to_jph(&inJpc->ConstraintSettings, outJph);
  1170. outJph->mSpace = static_cast<JPH::EConstraintSpace>(inJpc->Space);
  1171. outJph->mPoint1 = to_jph(inJpc->Point1);
  1172. outJph->mHingeAxis1 = to_jph(inJpc->HingeAxis1);
  1173. outJph->mNormalAxis1 = to_jph(inJpc->NormalAxis1);
  1174. outJph->mPoint2 = to_jph(inJpc->Point2);
  1175. outJph->mHingeAxis2 = to_jph(inJpc->HingeAxis2);
  1176. outJph->mNormalAxis2 = to_jph(inJpc->NormalAxis2);
  1177. outJph->mLimitsMin = inJpc->LimitsMin;
  1178. outJph->mLimitsMax = inJpc->LimitsMax;
  1179. JPC_SpringSettings_to_jph(&inJpc->LimitsSpringSettings, &outJph->mLimitsSpringSettings);
  1180. outJph->mMaxFrictionTorque = inJpc->MaxFrictionTorque;
  1181. JPC_MotorSettings_to_jph(&inJpc->MotorSettings, &outJph->mMotorSettings);
  1182. }
  1183. JPC_API void JPC_HingeConstraintSettings_default(JPC_HingeConstraintSettings* settings) {
  1184. JPH::HingeConstraintSettings defaultSettings{};
  1185. JPC_HingeConstraintSettings_to_jpc(settings, &defaultSettings);
  1186. }
  1187. JPC_API JPC_HingeConstraint* JPC_HingeConstraintSettings_Create(
  1188. const JPC_HingeConstraintSettings* self,
  1189. JPC_Body* inBody1,
  1190. JPC_Body* inBody2)
  1191. {
  1192. JPH::HingeConstraintSettings jphSettings;
  1193. JPC_HingeConstraintSettings_to_jph(self, &jphSettings);
  1194. JPH::HingeConstraint* outJph = new JPH::HingeConstraint(*to_jph(inBody1), *to_jph(inBody2), jphSettings);
  1195. return (JPC_HingeConstraint*)outJph;
  1196. }
  1197. ////////////////////////////////////////////////////////////////////////////////
  1198. // DistanceConstraintSettings -> TwoBodyConstraintSettings -> ConstraintSettings
  1199. JPC_IMPL void JPC_DistanceConstraintSettings_to_jpc(
  1200. JPC_DistanceConstraintSettings* outJpc,
  1201. const JPH::DistanceConstraintSettings* inJph)
  1202. {
  1203. JPC_ConstraintSettings_to_jpc(&outJpc->ConstraintSettings, inJph);
  1204. outJpc->Space = static_cast<JPC_ConstraintSpace>(inJph->mSpace);
  1205. outJpc->Point1 = to_jpc(inJph->mPoint1);
  1206. outJpc->Point2 = to_jpc(inJph->mPoint2);
  1207. outJpc->MinDistance = inJph->mMinDistance;
  1208. outJpc->MaxDistance = inJph->mMaxDistance;
  1209. // TODO: Spring settings
  1210. }
  1211. JPC_IMPL void JPC_DistanceConstraintSettings_to_jph(
  1212. const JPC_DistanceConstraintSettings* inJpc,
  1213. JPH::DistanceConstraintSettings* outJph)
  1214. {
  1215. JPC_ConstraintSettings_to_jph(&inJpc->ConstraintSettings, outJph);
  1216. outJph->mSpace = static_cast<JPH::EConstraintSpace>(inJpc->Space);
  1217. outJph->mPoint1 = to_jph(inJpc->Point1);
  1218. outJph->mPoint2 = to_jph(inJpc->Point2);
  1219. outJph->mMinDistance = inJpc->MinDistance;
  1220. outJph->mMaxDistance = inJpc->MaxDistance;
  1221. // TODO: Spring settings
  1222. }
  1223. JPC_API void JPC_DistanceConstraintSettings_default(JPC_DistanceConstraintSettings* settings) {
  1224. JPH::DistanceConstraintSettings defaultSettings{};
  1225. JPC_DistanceConstraintSettings_to_jpc(settings, &defaultSettings);
  1226. }
  1227. JPC_API JPC_DistanceConstraint* JPC_DistanceConstraintSettings_Create(
  1228. const JPC_DistanceConstraintSettings* self,
  1229. JPC_Body* inBody1,
  1230. JPC_Body* inBody2)
  1231. {
  1232. JPH::DistanceConstraintSettings jphSettings;
  1233. JPC_DistanceConstraintSettings_to_jph(self, &jphSettings);
  1234. JPH::DistanceConstraint* outJph = new JPH::DistanceConstraint(*to_jph(inBody1), *to_jph(inBody2), jphSettings);
  1235. return (JPC_DistanceConstraint*)outJph;
  1236. }
  1237. ////////////////////////////////////////////////////////////////////////////////
  1238. // SliderConstraintSettings -> TwoBodyConstraintSettings -> ConstraintSettings
  1239. JPC_IMPL void JPC_SliderConstraintSettings_to_jpc(
  1240. JPC_SliderConstraintSettings* outJpc,
  1241. const JPH::SliderConstraintSettings* inJph)
  1242. {
  1243. JPC_ConstraintSettings_to_jpc(&outJpc->ConstraintSettings, inJph);
  1244. outJpc->Space = static_cast<JPC_ConstraintSpace>(inJph->mSpace);
  1245. outJpc->AutoDetectPoint = inJph->mAutoDetectPoint;
  1246. outJpc->Point1 = to_jpc(inJph->mPoint1);
  1247. outJpc->SliderAxis1 = to_jpc(inJph->mSliderAxis1);
  1248. outJpc->NormalAxis1 = to_jpc(inJph->mNormalAxis1);
  1249. outJpc->Point2 = to_jpc(inJph->mPoint2);
  1250. outJpc->SliderAxis2 = to_jpc(inJph->mSliderAxis2);
  1251. outJpc->NormalAxis2 = to_jpc(inJph->mNormalAxis2);
  1252. outJpc->LimitsMin = inJph->mLimitsMin;
  1253. outJpc->LimitsMax = inJph->mLimitsMax;
  1254. JPC_SpringSettings_to_jpc(&outJpc->LimitsSpringSettings, &inJph->mLimitsSpringSettings);
  1255. outJpc->MaxFrictionForce = inJph->mMaxFrictionForce;
  1256. JPC_MotorSettings_to_jpc(&outJpc->MotorSettings, &inJph->mMotorSettings);
  1257. }
  1258. JPC_IMPL void JPC_SliderConstraintSettings_to_jph(
  1259. const JPC_SliderConstraintSettings* inJpc,
  1260. JPH::SliderConstraintSettings* outJph)
  1261. {
  1262. JPC_ConstraintSettings_to_jph(&inJpc->ConstraintSettings, outJph);
  1263. outJph->mSpace = static_cast<JPH::EConstraintSpace>(inJpc->Space);
  1264. outJph->mAutoDetectPoint = inJpc->AutoDetectPoint;
  1265. outJph->mPoint1 = to_jph(inJpc->Point1);
  1266. outJph->mSliderAxis1 = to_jph(inJpc->SliderAxis1);
  1267. outJph->mNormalAxis1 = to_jph(inJpc->NormalAxis1);
  1268. outJph->mPoint2 = to_jph(inJpc->Point2);
  1269. outJph->mSliderAxis2 = to_jph(inJpc->SliderAxis2);
  1270. outJph->mNormalAxis2 = to_jph(inJpc->NormalAxis2);
  1271. outJph->mLimitsMin = inJpc->LimitsMin;
  1272. outJph->mLimitsMax = inJpc->LimitsMax;
  1273. JPC_SpringSettings_to_jph(&inJpc->LimitsSpringSettings, &outJph->mLimitsSpringSettings);
  1274. outJph->mMaxFrictionForce = inJpc->MaxFrictionForce;
  1275. JPC_MotorSettings_to_jph(&inJpc->MotorSettings, &outJph->mMotorSettings);
  1276. }
  1277. JPC_API void JPC_SliderConstraintSettings_default(JPC_SliderConstraintSettings* settings) {
  1278. JPH::SliderConstraintSettings defaultSettings{};
  1279. JPC_SliderConstraintSettings_to_jpc(settings, &defaultSettings);
  1280. }
  1281. JPC_API JPC_SliderConstraint* JPC_SliderConstraintSettings_Create(
  1282. const JPC_SliderConstraintSettings* self,
  1283. JPC_Body* inBody1,
  1284. JPC_Body* inBody2)
  1285. {
  1286. JPH::SliderConstraintSettings jphSettings;
  1287. JPC_SliderConstraintSettings_to_jph(self, &jphSettings);
  1288. JPH::SliderConstraint* outJph = new JPH::SliderConstraint(*to_jph(inBody1), *to_jph(inBody2), jphSettings);
  1289. return (JPC_SliderConstraint*)outJph;
  1290. }
  1291. ////////////////////////////////////////////////////////////////////////////////
  1292. // Shape -> RefTarget<Shape>
  1293. // RefTarget<Shape>
  1294. JPC_API uint32_t JPC_Shape_GetRefCount(const JPC_Shape* self) {
  1295. return to_jph(self)->GetRefCount();
  1296. }
  1297. JPC_API void JPC_Shape_AddRef(const JPC_Shape* self) {
  1298. to_jph(self)->AddRef();
  1299. }
  1300. JPC_API void JPC_Shape_Release(const JPC_Shape* self) {
  1301. to_jph(self)->Release();
  1302. }
  1303. // Shape
  1304. JPC_API uint64_t JPC_Shape_GetUserData(const JPC_Shape* self) {
  1305. return to_jph(self)->GetUserData();
  1306. }
  1307. JPC_API void JPC_Shape_SetUserData(JPC_Shape* self, uint64_t userData) {
  1308. to_jph(self)->SetUserData(userData);
  1309. }
  1310. JPC_API JPC_ShapeType JPC_Shape_GetType(const JPC_Shape* self) {
  1311. return to_jpc(to_jph(self)->GetType());
  1312. }
  1313. JPC_API JPC_ShapeSubType JPC_Shape_GetSubType(const JPC_Shape* self) {
  1314. return to_jpc(to_jph(self)->GetSubType());
  1315. }
  1316. JPC_API uint64_t JPC_Shape_GetSubShapeUserData(const JPC_Shape* self, JPC_SubShapeID inSubShapeID) {
  1317. return to_jph(self)->GetSubShapeUserData(JPC_SubShapeID_to_jph(inSubShapeID));
  1318. }
  1319. JPC_API JPC_Vec3 JPC_Shape_GetCenterOfMass(const JPC_Shape* self) {
  1320. return to_jpc(to_jph(self)->GetCenterOfMass());
  1321. }
  1322. JPC_API float JPC_Shape_GetVolume(const JPC_Shape* self) {
  1323. return to_jph(self)->GetVolume();
  1324. }
  1325. ////////////////////////////////////////////////////////////////////////////////
  1326. // CompoundShape
  1327. JPC_API const JPC_Shape* JPC_CompoundShape_GetSubShape_Shape(
  1328. const JPC_CompoundShape* self,
  1329. uint inIdx)
  1330. {
  1331. return to_jpc(to_jph(self)->GetSubShape(inIdx).mShape.GetPtr());
  1332. }
  1333. JPC_API uint32_t JPC_CompoundShape_GetSubShapeIndexFromID(
  1334. const JPC_CompoundShape* self,
  1335. JPC_SubShapeID inSubShapeID,
  1336. JPC_SubShapeID* outRemainder)
  1337. {
  1338. JPH::SubShapeID jphRemainder;
  1339. uint32_t res = to_jph(self)->GetSubShapeIndexFromID(JPC_SubShapeID_to_jph(inSubShapeID), jphRemainder);
  1340. *outRemainder = to_jpc(jphRemainder);
  1341. return res;
  1342. }
  1343. ////////////////////////////////////////////////////////////////////////////////
  1344. // ShapeSettings
  1345. // Unpack a ShapeResult into a bool and two pointers to be friendlier to C.
  1346. static bool HandleShapeResult(JPH::ShapeSettings::ShapeResult res, JPC_Shape** outShape, JPC_String** outError) {
  1347. if (res.HasError()) {
  1348. if (outError != nullptr) {
  1349. JPH::String* created = new JPH::String(std::move(res.GetError()));
  1350. *outError = to_jpc(created);
  1351. }
  1352. return false;
  1353. } else {
  1354. JPH::Ref<JPH::Shape> shape = res.Get();
  1355. shape->AddRef();
  1356. *outShape = to_jpc((JPH::Shape*)shape);
  1357. return true;
  1358. }
  1359. }
  1360. ////////////////////////////////////////////////////////////////////////////////
  1361. // TriangleShapeSettings
  1362. static void to_jph(const JPC_TriangleShapeSettings* input, JPH::TriangleShapeSettings* output) {
  1363. output->mUserData = input->UserData;
  1364. // TODO: Material
  1365. output->mDensity = input->Density;
  1366. output->mV1 = to_jph(input->V1);
  1367. output->mV2 = to_jph(input->V2);
  1368. output->mV3 = to_jph(input->V3);
  1369. output->mConvexRadius = input->ConvexRadius;
  1370. }
  1371. JPC_API void JPC_TriangleShapeSettings_default(JPC_TriangleShapeSettings* object) {
  1372. object->UserData = 0;
  1373. // TODO: Material
  1374. object->Density = 1000.0;
  1375. object->V1 = {0};
  1376. object->V2 = {0};
  1377. object->V3 = {0};
  1378. object->ConvexRadius = 0.0;
  1379. }
  1380. JPC_API bool JPC_TriangleShapeSettings_Create(const JPC_TriangleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1381. JPH::TriangleShapeSettings settings;
  1382. to_jph(self, &settings);
  1383. return HandleShapeResult(settings.Create(), outShape, outError);
  1384. }
  1385. ////////////////////////////////////////////////////////////////////////////////
  1386. // MeshShapeSettings
  1387. JPC_IMPL void JPC_MeshShapeSettings_to_jpc_borrowed(
  1388. JPC_MeshShapeSettings* outJpc,
  1389. const JPH::MeshShapeSettings* inJph)
  1390. {
  1391. outJpc->UserData = inJph->mUserData;
  1392. outJpc->TriangleVertices = (JPC_Float3*)inJph->mTriangleVertices.data();
  1393. outJpc->TriangleVerticesLen = inJph->mTriangleVertices.size();
  1394. outJpc->IndexedTriangles = (JPC_IndexedTriangle*)inJph->mIndexedTriangles.data();
  1395. outJpc->IndexedTrianglesLen = inJph->mIndexedTriangles.size();
  1396. }
  1397. JPC_IMPL void JPC_MeshShapeSettings_to_jph(
  1398. const JPC_MeshShapeSettings* inJpc,
  1399. JPH::MeshShapeSettings* outJph)
  1400. {
  1401. outJph->mUserData = inJpc->UserData;
  1402. auto triangleVertices = (const JPH::Float3*)inJpc->TriangleVertices;
  1403. outJph->mTriangleVertices = JPH::VertexList(triangleVertices, triangleVertices + inJpc->TriangleVerticesLen);
  1404. auto indexedTriangles = (const JPH::IndexedTriangle*)inJpc->IndexedTriangles;
  1405. outJph->mIndexedTriangles = JPH::IndexedTriangleList(indexedTriangles, indexedTriangles + inJpc->IndexedTrianglesLen);
  1406. }
  1407. JPC_API void JPC_MeshShapeSettings_default(JPC_MeshShapeSettings* object) {
  1408. JPH::MeshShapeSettings settings;
  1409. JPC_MeshShapeSettings_to_jpc_borrowed(object, &settings);
  1410. // Overwrite all pointers and lengths so that the default value doesn't
  1411. // contain pointers to freed memory.
  1412. object->TriangleVertices = nullptr;
  1413. object->TriangleVerticesLen = 0;
  1414. object->IndexedTriangles = nullptr;
  1415. object->IndexedTrianglesLen = 0;
  1416. }
  1417. JPC_API bool JPC_MeshShapeSettings_Create(const JPC_MeshShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1418. JPH::MeshShapeSettings settings;
  1419. JPC_MeshShapeSettings_to_jph(self, &settings);
  1420. // MeshShapeSettings calls Sanitize in its default constructor, but we don't
  1421. // have constructors in C. It's probably fine to always Sanitize.
  1422. settings.Sanitize();
  1423. return HandleShapeResult(settings.Create(), outShape, outError);
  1424. }
  1425. ////////////////////////////////////////////////////////////////////////////////
  1426. // BoxShapeSettings
  1427. static void to_jph(const JPC_BoxShapeSettings* input, JPH::BoxShapeSettings* output) {
  1428. output->mUserData = input->UserData;
  1429. // TODO: Material
  1430. output->mDensity = input->Density;
  1431. output->mHalfExtent = to_jph(input->HalfExtent);
  1432. output->mConvexRadius = input->ConvexRadius;
  1433. }
  1434. JPC_API void JPC_BoxShapeSettings_default(JPC_BoxShapeSettings* object) {
  1435. object->UserData = 0;
  1436. // TODO: Material
  1437. object->Density = 1000.0;
  1438. object->HalfExtent = JPC_Vec3{0};
  1439. object->ConvexRadius = 0.0;
  1440. }
  1441. JPC_API bool JPC_BoxShapeSettings_Create(const JPC_BoxShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1442. JPH::BoxShapeSettings settings;
  1443. to_jph(self, &settings);
  1444. return HandleShapeResult(settings.Create(), outShape, outError);
  1445. }
  1446. ////////////////////////////////////////////////////////////////////////////////
  1447. // SphereShapeSettings
  1448. static void to_jph(const JPC_SphereShapeSettings* input, JPH::SphereShapeSettings* output) {
  1449. output->mUserData = input->UserData;
  1450. // TODO: Material
  1451. output->mDensity = input->Density;
  1452. output->mRadius = input->Radius;
  1453. }
  1454. JPC_API void JPC_SphereShapeSettings_default(JPC_SphereShapeSettings* object) {
  1455. object->UserData = 0;
  1456. // TODO: Material
  1457. object->Density = 1000.0;
  1458. object->Radius = 0.0;
  1459. }
  1460. JPC_API bool JPC_SphereShapeSettings_Create(const JPC_SphereShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1461. JPH::SphereShapeSettings settings;
  1462. to_jph(self, &settings);
  1463. return HandleShapeResult(settings.Create(), outShape, outError);
  1464. }
  1465. ////////////////////////////////////////////////////////////////////////////////
  1466. // CapsuleShapeSettings
  1467. static void to_jph(const JPC_CapsuleShapeSettings* input, JPH::CapsuleShapeSettings* output) {
  1468. output->mUserData = input->UserData;
  1469. // TODO: Material
  1470. output->mDensity = input->Density;
  1471. output->mRadius = input->Radius;
  1472. output->mHalfHeightOfCylinder = input->HalfHeightOfCylinder;
  1473. }
  1474. JPC_API void JPC_CapsuleShapeSettings_default(JPC_CapsuleShapeSettings* object) {
  1475. object->UserData = 0;
  1476. // TODO: Material
  1477. object->Density = 1000.0;
  1478. object->Radius = 0.0;
  1479. object->HalfHeightOfCylinder = 0.0;
  1480. }
  1481. JPC_API bool JPC_CapsuleShapeSettings_Create(const JPC_CapsuleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1482. JPH::CapsuleShapeSettings settings;
  1483. to_jph(self, &settings);
  1484. return HandleShapeResult(settings.Create(), outShape, outError);
  1485. }
  1486. ////////////////////////////////////////////////////////////////////////////////
  1487. // CylinderShapeSettings
  1488. static void to_jph(const JPC_CylinderShapeSettings* input, JPH::CylinderShapeSettings* output) {
  1489. output->mUserData = input->UserData;
  1490. // TODO: Material
  1491. output->mDensity = input->Density;
  1492. output->mHalfHeight = input->HalfHeight;
  1493. output->mRadius = input->Radius;
  1494. output->mConvexRadius = input->ConvexRadius;
  1495. }
  1496. JPC_API void JPC_CylinderShapeSettings_default(JPC_CylinderShapeSettings* object) {
  1497. object->UserData = 0;
  1498. // TODO: Material
  1499. object->Density = 1000.0;
  1500. object->HalfHeight = 0.0;
  1501. object->Radius = 0.0;
  1502. object->ConvexRadius = 0.0;
  1503. }
  1504. JPC_API bool JPC_CylinderShapeSettings_Create(const JPC_CylinderShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1505. JPH::CylinderShapeSettings settings;
  1506. to_jph(self, &settings);
  1507. return HandleShapeResult(settings.Create(), outShape, outError);
  1508. }
  1509. ////////////////////////////////////////////////////////////////////////////////
  1510. // ConvexHullShapeSettings
  1511. static void to_jph(const JPC_ConvexHullShapeSettings* input, JPH::ConvexHullShapeSettings* output) {
  1512. output->mUserData = input->UserData;
  1513. // TODO: Material
  1514. output->mDensity = input->Density;
  1515. output->mPoints = to_jph(input->Points, input->PointsLen);
  1516. output->mMaxConvexRadius = input->MaxConvexRadius;
  1517. output->mMaxErrorConvexRadius = input->MaxErrorConvexRadius;
  1518. output->mHullTolerance = input->HullTolerance;
  1519. }
  1520. JPC_API void JPC_ConvexHullShapeSettings_default(JPC_ConvexHullShapeSettings* object) {
  1521. object->UserData = 0;
  1522. // TODO: Material
  1523. object->Density = 1000.0;
  1524. object->Points = nullptr;
  1525. object->PointsLen = 0;
  1526. object->MaxConvexRadius = 0.0;
  1527. object->MaxErrorConvexRadius = 0.05f;
  1528. object->HullTolerance = 1.0e-3f;
  1529. }
  1530. JPC_API bool JPC_ConvexHullShapeSettings_Create(const JPC_ConvexHullShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1531. JPH::ConvexHullShapeSettings settings;
  1532. to_jph(self, &settings);
  1533. return HandleShapeResult(settings.Create(), outShape, outError);
  1534. }
  1535. ////////////////////////////////////////////////////////////////////////////////
  1536. // CompoundShape::SubShapeSettings
  1537. static JPH::CompoundShapeSettings::SubShapeSettings to_jph(const JPC_SubShapeSettings* input) {
  1538. const JPH::Shape* shape = to_jph(input->Shape);
  1539. JPH::CompoundShapeSettings::SubShapeSettings output;
  1540. output.mShape = nullptr;
  1541. output.mShapePtr = shape;
  1542. output.mPosition = to_jph(input->Position);
  1543. output.mRotation = to_jph(input->Rotation);
  1544. output.mUserData = input->UserData;
  1545. return output;
  1546. }
  1547. static JPH::Array<JPH::CompoundShapeSettings::SubShapeSettings> to_jph(const JPC_SubShapeSettings* src, size_t n) {
  1548. JPH::Array<JPH::CompoundShapeSettings::SubShapeSettings> vec;
  1549. vec.reserve(n);
  1550. for (size_t i = 0; i < n; i++) {
  1551. vec.push_back(to_jph(&src[i]));
  1552. }
  1553. return vec;
  1554. }
  1555. JPC_API void JPC_SubShapeSettings_default(JPC_SubShapeSettings* object) {
  1556. object->Shape = nullptr;
  1557. object->Position = JPC_Vec3{0};
  1558. object->Rotation = JPC_Quat{0, 0, 0, 1};
  1559. object->UserData = 0;
  1560. }
  1561. ////////////////////////////////////////////////////////////////////////////////
  1562. // StaticCompoundShapeSettings -> CompoundShapeSettings -> ShapeSettings
  1563. static void to_jph(const JPC_StaticCompoundShapeSettings* input, JPH::StaticCompoundShapeSettings* output) {
  1564. output->mUserData = input->UserData;
  1565. output->mSubShapes = to_jph(input->SubShapes, input->SubShapesLen);
  1566. }
  1567. JPC_API void JPC_StaticCompoundShapeSettings_default(JPC_StaticCompoundShapeSettings* object) {
  1568. object->UserData = 0;
  1569. object->SubShapes = nullptr;
  1570. object->SubShapesLen = 0;
  1571. }
  1572. JPC_API bool JPC_StaticCompoundShapeSettings_Create(const JPC_StaticCompoundShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
  1573. JPH::StaticCompoundShapeSettings settings;
  1574. to_jph(self, &settings);
  1575. return HandleShapeResult(settings.Create(), outShape, outError);
  1576. }
  1577. ////////////////////////////////////////////////////////////////////////////////
  1578. // MutableCompoundShape -> CompoundShape -> Shape
  1579. JPC_IMPL JPH::MutableCompoundShape* JPC_MutableCompoundShape_to_jph(JPC_MutableCompoundShape* self) {
  1580. return reinterpret_cast<JPH::MutableCompoundShape*>(self);
  1581. }
  1582. JPC_API uint JPC_MutableCompoundShape_AddShape(
  1583. JPC_MutableCompoundShape* self,
  1584. JPC_Vec3 inPosition,
  1585. JPC_Quat inRotation,
  1586. const JPC_Shape* inShape,
  1587. uint32_t inUserData)
  1588. {
  1589. JPH::MutableCompoundShape* self_jph = JPC_MutableCompoundShape_to_jph(self);
  1590. return self_jph->AddShape(to_jph(inPosition), to_jph(inRotation), to_jph(inShape), inUserData);
  1591. }
  1592. JPC_API void JPC_MutableCompoundShape_RemoveShape(JPC_MutableCompoundShape* self, uint inIndex) {
  1593. JPH::MutableCompoundShape* self_jph = JPC_MutableCompoundShape_to_jph(self);
  1594. self_jph->RemoveShape(inIndex);
  1595. }
  1596. JPC_API void JPC_MutableCompoundShape_ModifyShape(JPC_MutableCompoundShape* self, uint inIndex, JPC_Vec3 inPosition, JPC_Quat inRotation) {
  1597. JPH::MutableCompoundShape* self_jph = JPC_MutableCompoundShape_to_jph(self);
  1598. self_jph->ModifyShape(inIndex, to_jph(inPosition), to_jph(inRotation));
  1599. }
  1600. JPC_API void JPC_MutableCompoundShape_ModifyShape2(JPC_MutableCompoundShape* self, uint inIndex, JPC_Vec3 inPosition, JPC_Quat inRotation, const JPC_Shape* inShape) {
  1601. JPH::MutableCompoundShape* self_jph = JPC_MutableCompoundShape_to_jph(self);
  1602. self_jph->ModifyShape(inIndex, to_jph(inPosition), to_jph(inRotation), to_jph(inShape));
  1603. }
  1604. JPC_API void JPC_MutableCompoundShape_AdjustCenterOfMass(JPC_MutableCompoundShape* self) {
  1605. JPH::MutableCompoundShape* self_jph = JPC_MutableCompoundShape_to_jph(self);
  1606. self_jph->AdjustCenterOfMass();
  1607. }
  1608. ////////////////////////////////////////////////////////////////////////////////
  1609. // MutableCompoundShapeSettings -> CompoundShapeSettings -> ShapeSettings
  1610. static void to_jph(const JPC_MutableCompoundShapeSettings* input, JPH::MutableCompoundShapeSettings* output) {
  1611. output->mUserData = input->UserData;
  1612. output->mSubShapes = to_jph(input->SubShapes, input->SubShapesLen);
  1613. }
  1614. JPC_API void JPC_MutableCompoundShapeSettings_default(JPC_MutableCompoundShapeSettings* object) {
  1615. object->UserData = 0;
  1616. object->SubShapes = nullptr;
  1617. object->SubShapesLen = 0;
  1618. }
  1619. JPC_API bool JPC_MutableCompoundShapeSettings_Create(const JPC_MutableCompoundShapeSettings* self, JPC_MutableCompoundShape** outShape, JPC_String** outError) {
  1620. JPH::MutableCompoundShapeSettings settings;
  1621. to_jph(self, &settings);
  1622. return HandleShapeResult(settings.Create(), (JPC_Shape**)outShape, outError);
  1623. }
  1624. ////////////////////////////////////////////////////////////////////////////////
  1625. // BodyCreationSettings
  1626. static JPH::BodyCreationSettings to_jph(const JPC_BodyCreationSettings* settings) {
  1627. JPH::BodyCreationSettings output{};
  1628. output.mPosition = to_jph(settings->Position);
  1629. output.mRotation = to_jph(settings->Rotation);
  1630. output.mLinearVelocity = to_jph(settings->LinearVelocity);
  1631. output.mAngularVelocity = to_jph(settings->AngularVelocity);
  1632. output.mUserData = settings->UserData;
  1633. output.mObjectLayer = settings->ObjectLayer;
  1634. // CollisionGroup
  1635. output.mMotionType = to_jph(settings->MotionType);
  1636. output.mAllowedDOFs = to_jph(settings->AllowedDOFs);
  1637. output.mAllowDynamicOrKinematic = settings->AllowDynamicOrKinematic;
  1638. output.mIsSensor = settings->IsSensor;
  1639. output.mCollideKinematicVsNonDynamic = settings->CollideKinematicVsNonDynamic;
  1640. output.mUseManifoldReduction = settings->UseManifoldReduction;
  1641. output.mApplyGyroscopicForce = settings->ApplyGyroscopicForce;
  1642. output.mMotionQuality = to_jph(settings->MotionQuality);
  1643. output.mEnhancedInternalEdgeRemoval = settings->EnhancedInternalEdgeRemoval;
  1644. output.mAllowSleeping = settings->AllowSleeping;
  1645. output.mFriction = settings->Friction;
  1646. output.mRestitution = settings->Restitution;
  1647. output.mLinearDamping = settings->LinearDamping;
  1648. output.mAngularDamping = settings->AngularDamping;
  1649. output.mMaxLinearVelocity = settings->MaxLinearVelocity;
  1650. output.mMaxAngularVelocity = settings->MaxAngularVelocity;
  1651. output.mGravityFactor = settings->GravityFactor;
  1652. output.mNumVelocityStepsOverride = settings->NumVelocityStepsOverride;
  1653. output.mNumPositionStepsOverride = settings->NumPositionStepsOverride;
  1654. output.mOverrideMassProperties = to_jph(settings->OverrideMassProperties);
  1655. output.mInertiaMultiplier = settings->InertiaMultiplier;
  1656. // output.mMassPropertiesOverride = settings->MassPropertiesOverride;
  1657. output.SetShape(to_jph(settings->Shape));
  1658. return output;
  1659. }
  1660. JPC_API void JPC_BodyCreationSettings_default(JPC_BodyCreationSettings* settings) {
  1661. JPH::BodyCreationSettings defaultSettings{};
  1662. settings->Position = to_jpc(defaultSettings.mPosition);
  1663. settings->Rotation = to_jpc(defaultSettings.mRotation);
  1664. settings->LinearVelocity = to_jpc(defaultSettings.mLinearVelocity);
  1665. settings->AngularVelocity = to_jpc(defaultSettings.mAngularVelocity);
  1666. settings->UserData = defaultSettings.mUserData;
  1667. settings->ObjectLayer = defaultSettings.mObjectLayer;
  1668. // CollisionGroup
  1669. settings->MotionType = to_jpc(defaultSettings.mMotionType);
  1670. settings->AllowedDOFs = to_jpc(defaultSettings.mAllowedDOFs);
  1671. settings->AllowDynamicOrKinematic = defaultSettings.mAllowDynamicOrKinematic;
  1672. settings->IsSensor = defaultSettings.mIsSensor;
  1673. settings->CollideKinematicVsNonDynamic = defaultSettings.mCollideKinematicVsNonDynamic;
  1674. settings->UseManifoldReduction = defaultSettings.mUseManifoldReduction;
  1675. settings->ApplyGyroscopicForce = defaultSettings.mApplyGyroscopicForce;
  1676. settings->MotionQuality = to_jpc(defaultSettings.mMotionQuality);
  1677. settings->EnhancedInternalEdgeRemoval = defaultSettings.mEnhancedInternalEdgeRemoval;
  1678. settings->AllowSleeping = defaultSettings.mAllowSleeping;
  1679. settings->Friction = defaultSettings.mFriction;
  1680. settings->Restitution = defaultSettings.mRestitution;
  1681. settings->LinearDamping = defaultSettings.mLinearDamping;
  1682. settings->AngularDamping = defaultSettings.mAngularDamping;
  1683. settings->MaxLinearVelocity = defaultSettings.mMaxLinearVelocity;
  1684. settings->MaxAngularVelocity = defaultSettings.mMaxAngularVelocity;
  1685. settings->GravityFactor = defaultSettings.mGravityFactor;
  1686. settings->NumVelocityStepsOverride = defaultSettings.mNumVelocityStepsOverride;
  1687. settings->NumPositionStepsOverride = defaultSettings.mNumPositionStepsOverride;
  1688. settings->OverrideMassProperties = to_jpc(defaultSettings.mOverrideMassProperties);
  1689. settings->InertiaMultiplier = defaultSettings.mInertiaMultiplier;
  1690. // MassPropertiesOverride
  1691. }
  1692. ////////////////////////////////////////////////////////////////////////////////
  1693. // Body
  1694. JPC_API JPC_BodyID JPC_Body_GetID(const JPC_Body* self) {
  1695. return to_jpc(to_jph(self)->GetID());
  1696. }
  1697. JPC_API JPC_BodyType JPC_Body_GetBodyType(const JPC_Body* self) {
  1698. return to_jpc(to_jph(self)->GetBodyType());
  1699. }
  1700. JPC_API bool JPC_Body_IsRigidBody(const JPC_Body* self) {
  1701. return to_jph(self)->IsRigidBody();
  1702. }
  1703. JPC_API bool JPC_Body_IsSoftBody(const JPC_Body* self) {
  1704. return to_jph(self)->IsSoftBody();
  1705. }
  1706. JPC_API bool JPC_Body_IsActive(const JPC_Body* self) {
  1707. return to_jph(self)->IsActive();
  1708. }
  1709. JPC_API bool JPC_Body_IsStatic(const JPC_Body* self) {
  1710. return to_jph(self)->IsStatic();
  1711. }
  1712. JPC_API bool JPC_Body_IsKinematic(const JPC_Body* self) {
  1713. return to_jph(self)->IsKinematic();
  1714. }
  1715. JPC_API bool JPC_Body_IsDynamic(const JPC_Body* self) {
  1716. return to_jph(self)->IsDynamic();
  1717. }
  1718. JPC_API bool JPC_Body_CanBeKinematicOrDynamic(const JPC_Body* self) {
  1719. return to_jph(self)->CanBeKinematicOrDynamic();
  1720. }
  1721. JPC_API void JPC_Body_SetIsSensor(JPC_Body* self, bool inIsSensor) {
  1722. to_jph(self)->SetIsSensor(inIsSensor);
  1723. }
  1724. JPC_API bool JPC_Body_IsSensor(const JPC_Body* self) {
  1725. return to_jph(self)->IsSensor();
  1726. }
  1727. JPC_API void JPC_Body_SetCollideKinematicVsNonDynamic(JPC_Body* self, bool inCollide) {
  1728. to_jph(self)->SetCollideKinematicVsNonDynamic(inCollide);
  1729. }
  1730. JPC_API bool JPC_Body_GetCollideKinematicVsNonDynamic(const JPC_Body* self) {
  1731. return to_jph(self)->GetCollideKinematicVsNonDynamic();
  1732. }
  1733. JPC_API void JPC_Body_SetUseManifoldReduction(JPC_Body* self, bool inUseReduction) {
  1734. to_jph(self)->SetUseManifoldReduction(inUseReduction);
  1735. }
  1736. JPC_API bool JPC_Body_GetUseManifoldReduction(const JPC_Body* self) {
  1737. return to_jph(self)->GetUseManifoldReduction();
  1738. }
  1739. JPC_API bool JPC_Body_GetUseManifoldReductionWithBody(const JPC_Body* self, const JPC_Body* inBody2) {
  1740. return to_jph(self)->GetUseManifoldReductionWithBody(*to_jph(inBody2));
  1741. }
  1742. JPC_API void JPC_Body_SetApplyGyroscopicForce(JPC_Body* self, bool inApply) {
  1743. to_jph(self)->SetApplyGyroscopicForce(inApply);
  1744. }
  1745. JPC_API bool JPC_Body_GetApplyGyroscopicForce(const JPC_Body* self) {
  1746. return to_jph(self)->GetApplyGyroscopicForce();
  1747. }
  1748. JPC_API void JPC_Body_SetEnhancedInternalEdgeRemoval(JPC_Body* self, bool inApply) {
  1749. to_jph(self)->SetEnhancedInternalEdgeRemoval(inApply);
  1750. }
  1751. JPC_API bool JPC_Body_GetEnhancedInternalEdgeRemoval(const JPC_Body* self) {
  1752. return to_jph(self)->GetEnhancedInternalEdgeRemoval();
  1753. }
  1754. JPC_API bool JPC_Body_GetEnhancedInternalEdgeRemovalWithBody(const JPC_Body* self, const JPC_Body* inBody2) {
  1755. return to_jph(self)->GetEnhancedInternalEdgeRemovalWithBody(*to_jph(inBody2));
  1756. }
  1757. JPC_API JPC_MotionType JPC_Body_GetMotionType(const JPC_Body* self) {
  1758. return to_jpc(to_jph(self)->GetMotionType());
  1759. }
  1760. JPC_API void JPC_Body_SetMotionType(JPC_Body* self, JPC_MotionType inMotionType) {
  1761. to_jph(self)->SetMotionType(to_jph(inMotionType));
  1762. }
  1763. JPC_API JPC_BroadPhaseLayer JPC_Body_GetBroadPhaseLayer(const JPC_Body* self) {
  1764. return to_jpc(to_jph(self)->GetBroadPhaseLayer());
  1765. }
  1766. JPC_API JPC_ObjectLayer JPC_Body_GetObjectLayer(const JPC_Body* self) {
  1767. return to_jph(self)->GetObjectLayer();
  1768. }
  1769. // JPC_API const CollisionGroup & JPC_Body_GetCollisionGroup(const JPC_Body* self);
  1770. // JPC_API CollisionGroup & JPC_Body_GetCollisionGroup(JPC_Body* self);
  1771. // JPC_API void JPC_Body_SetCollisionGroup(JPC_Body* self, const CollisionGroup &inGroup);
  1772. JPC_API bool JPC_Body_GetAllowSleeping(const JPC_Body* self) {
  1773. return to_jph(self)->GetAllowSleeping();
  1774. }
  1775. JPC_API void JPC_Body_SetAllowSleeping(JPC_Body* self, bool inAllow) {
  1776. to_jph(self)->SetAllowSleeping(inAllow);
  1777. }
  1778. JPC_API void JPC_Body_ResetSleepTimer(JPC_Body* self) {
  1779. to_jph(self)->ResetSleepTimer();
  1780. }
  1781. JPC_API float JPC_Body_GetFriction(const JPC_Body* self) {
  1782. return to_jph(self)->GetFriction();
  1783. }
  1784. JPC_API void JPC_Body_SetFriction(JPC_Body* self, float inFriction) {
  1785. to_jph(self)->SetFriction(inFriction);
  1786. }
  1787. JPC_API float JPC_Body_GetRestitution(const JPC_Body* self) {
  1788. return to_jph(self)->GetRestitution();
  1789. }
  1790. JPC_API void JPC_Body_SetRestitution(JPC_Body* self, float inRestitution) {
  1791. to_jph(self)->SetRestitution(inRestitution);
  1792. }
  1793. JPC_API JPC_Vec3 JPC_Body_GetLinearVelocity(const JPC_Body* self) {
  1794. return to_jpc(to_jph(self)->GetLinearVelocity());
  1795. }
  1796. JPC_API void JPC_Body_SetLinearVelocity(JPC_Body* self, JPC_Vec3 inLinearVelocity) {
  1797. to_jph(self)->SetLinearVelocity(to_jph(inLinearVelocity));
  1798. }
  1799. JPC_API void JPC_Body_SetLinearVelocityClamped(JPC_Body* self, JPC_Vec3 inLinearVelocity) {
  1800. to_jph(self)->SetLinearVelocityClamped(to_jph(inLinearVelocity));
  1801. }
  1802. JPC_API JPC_Vec3 JPC_Body_GetAngularVelocity(const JPC_Body* self) {
  1803. return to_jpc(to_jph(self)->GetAngularVelocity());
  1804. }
  1805. JPC_API void JPC_Body_SetAngularVelocity(JPC_Body* self, JPC_Vec3 inAngularVelocity) {
  1806. to_jph(self)->SetAngularVelocity(to_jph(inAngularVelocity));
  1807. }
  1808. JPC_API void JPC_Body_SetAngularVelocityClamped(JPC_Body* self, JPC_Vec3 inAngularVelocity) {
  1809. to_jph(self)->SetAngularVelocityClamped(to_jph(inAngularVelocity));
  1810. }
  1811. JPC_API JPC_Vec3 JPC_Body_GetPointVelocityCOM(const JPC_Body* self, JPC_Vec3 inPointRelativeToCOM) {
  1812. return to_jpc(to_jph(self)->GetPointVelocityCOM(to_jph(inPointRelativeToCOM)));
  1813. }
  1814. JPC_API JPC_Vec3 JPC_Body_GetPointVelocity(const JPC_Body* self, JPC_RVec3 inPoint) {
  1815. return to_jpc(to_jph(self)->GetPointVelocity(to_jph(inPoint)));
  1816. }
  1817. JPC_API void JPC_Body_AddForce(JPC_Body* self, JPC_Vec3 inForce) {
  1818. to_jph(self)->AddForce(to_jph(inForce));
  1819. }
  1820. // overload of Body::AddForce
  1821. JPC_API void JPC_Body_AddForceAtPoint(JPC_Body* self, JPC_Vec3 inForce, JPC_RVec3 inPosition) {
  1822. to_jph(self)->AddForce(to_jph(inForce), to_jph(inPosition));
  1823. }
  1824. JPC_API void JPC_Body_AddTorque(JPC_Body* self, JPC_Vec3 inTorque) {
  1825. to_jph(self)->AddTorque(to_jph(inTorque));
  1826. }
  1827. JPC_API JPC_Vec3 JPC_Body_GetAccumulatedForce(const JPC_Body* self) {
  1828. return to_jpc(to_jph(self)->GetAccumulatedForce());
  1829. }
  1830. JPC_API JPC_Vec3 JPC_Body_GetAccumulatedTorque(const JPC_Body* self) {
  1831. return to_jpc(to_jph(self)->GetAccumulatedTorque());
  1832. }
  1833. JPC_API void JPC_Body_ResetForce(JPC_Body* self) {
  1834. to_jph(self)->ResetForce();
  1835. }
  1836. JPC_API void JPC_Body_ResetTorque(JPC_Body* self) {
  1837. to_jph(self)->ResetTorque();
  1838. }
  1839. JPC_API void JPC_Body_ResetMotion(JPC_Body* self) {
  1840. to_jph(self)->ResetMotion();
  1841. }
  1842. JPC_API void JPC_Body_GetInverseInertia(const JPC_Body* self, JPC_Mat44* outMatrix) {
  1843. to_jph(self)->GetInverseInertia().StoreFloat4x4(reinterpret_cast<JPH::Float4*>(outMatrix));
  1844. }
  1845. JPC_API void JPC_Body_AddImpulse(JPC_Body* self, JPC_Vec3 inImpulse) {
  1846. to_jph(self)->AddImpulse(to_jph(inImpulse));
  1847. }
  1848. JPC_API void JPC_Body_AddImpulse2(JPC_Body* self, JPC_Vec3 inImpulse, JPC_RVec3 inPosition) {
  1849. to_jph(self)->AddImpulse(to_jph(inImpulse), to_jph(inPosition));
  1850. }
  1851. JPC_API void JPC_Body_AddAngularImpulse(JPC_Body* self, JPC_Vec3 inAngularImpulse) {
  1852. to_jph(self)->AddAngularImpulse(to_jph(inAngularImpulse));
  1853. }
  1854. JPC_API void JPC_Body_MoveKinematic(JPC_Body* self, JPC_RVec3 inTargetPosition, JPC_Quat inTargetRotation, float inDeltaTime) {
  1855. to_jph(self)->MoveKinematic(to_jph(inTargetPosition), to_jph(inTargetRotation), inDeltaTime);
  1856. }
  1857. JPC_API bool JPC_Body_ApplyBuoyancyImpulse(JPC_Body* self, JPC_RVec3 inSurfacePosition, JPC_Vec3 inSurfaceNormal, float inBuoyancy, float inLinearDrag, float inAngularDrag, JPC_Vec3 inFluidVelocity, JPC_Vec3 inGravity, float inDeltaTime) {
  1858. return to_jph(self)->ApplyBuoyancyImpulse(to_jph(inSurfacePosition), to_jph(inSurfaceNormal), inBuoyancy, inLinearDrag, inAngularDrag, to_jph(inFluidVelocity), to_jph(inGravity), inDeltaTime);
  1859. }
  1860. JPC_API bool JPC_Body_IsInBroadPhase(const JPC_Body* self) {
  1861. return to_jph(self)->IsInBroadPhase();
  1862. }
  1863. JPC_API bool JPC_Body_IsCollisionCacheInvalid(const JPC_Body* self) {
  1864. return to_jph(self)->IsCollisionCacheInvalid();
  1865. }
  1866. JPC_API const JPC_Shape* JPC_Body_GetShape(const JPC_Body* self) {
  1867. return to_jpc(to_jph(self)->GetShape());
  1868. }
  1869. JPC_API JPC_RVec3 JPC_Body_GetPosition(const JPC_Body* self) {
  1870. return to_jpc(to_jph(self)->GetPosition());
  1871. }
  1872. JPC_API JPC_Quat JPC_Body_GetRotation(const JPC_Body* self) {
  1873. return to_jpc(to_jph(self)->GetRotation());
  1874. }
  1875. JPC_API JPC_RMat44 JPC_Body_GetWorldTransform(const JPC_Body* self) {
  1876. return to_jpc(to_jph(self)->GetWorldTransform());
  1877. }
  1878. JPC_API JPC_RVec3 JPC_Body_GetCenterOfMassPosition(const JPC_Body* self) {
  1879. return to_jpc(to_jph(self)->GetCenterOfMassPosition());
  1880. }
  1881. JPC_API JPC_RMat44 JPC_Body_GetCenterOfMassTransform(const JPC_Body* self) {
  1882. return to_jpc(to_jph(self)->GetCenterOfMassTransform());
  1883. }
  1884. JPC_API JPC_RMat44 JPC_Body_GetInverseCenterOfMassTransform(const JPC_Body* self) {
  1885. return to_jpc(to_jph(self)->GetInverseCenterOfMassTransform());
  1886. }
  1887. // JPC_API const AABox & JPC_Body_GetWorldSpaceBounds(const JPC_Body* self);
  1888. // JPC_API const MotionProperties *JPC_Body_GetMotionProperties(const JPC_Body* self)
  1889. // JPC_API MotionProperties * JPC_Body_GetMotionProperties(JPC_Body* self);
  1890. // JPC_API const MotionProperties *JPC_Body_GetMotionPropertiesUnchecked(const JPC_Body* self)
  1891. // JPC_API MotionProperties * JPC_Body_GetMotionPropertiesUnchecked(JPC_Body* self);
  1892. JPC_API uint64_t JPC_Body_GetUserData(const JPC_Body* self) {
  1893. return to_jph(self)->GetUserData();
  1894. }
  1895. JPC_API void JPC_Body_SetUserData(JPC_Body* self, uint64_t inUserData) {
  1896. to_jph(self)->SetUserData(inUserData);
  1897. }
  1898. JPC_API JPC_Vec3 JPC_Body_GetWorldSpaceSurfaceNormal(const JPC_Body* self, JPC_SubShapeID inSubShapeID, JPC_RVec3 inPosition) {
  1899. JPH::SubShapeID jph_id = JPC_SubShapeID_to_jph(inSubShapeID);
  1900. return to_jpc(to_jph(self)->GetWorldSpaceSurfaceNormal(jph_id, to_jph(inPosition)));
  1901. }
  1902. // JPC_API TransformedShape JPC_Body_GetTransformedShape(const JPC_Body* self);
  1903. // JPC_API BodyCreationSettings JPC_Body_GetBodyCreationSettings(const JPC_Body* self);
  1904. // JPC_API SoftBodyCreationSettings JPC_Body_GetSoftBodyCreationSettings(const JPC_Body* self);
  1905. ////////////////////////////////////////////////////////////////////////////////
  1906. // BodyLockRead
  1907. JPC_API JPC_BodyLockRead* JPC_BodyLockRead_new(const JPC_BodyLockInterface* interface, JPC_BodyID bodyID) {
  1908. JPH::BodyLockRead* lockRead = new JPH::BodyLockRead(*to_jph(interface), to_jph(bodyID));
  1909. return to_jpc(lockRead);
  1910. }
  1911. JPC_API void JPC_BodyLockRead_delete(JPC_BodyLockRead* self) {
  1912. delete to_jph(self);
  1913. }
  1914. JPC_API bool JPC_BodyLockRead_Succeeded(JPC_BodyLockRead* self) {
  1915. return to_jph(self)->Succeeded();
  1916. }
  1917. JPC_API const JPC_Body* JPC_BodyLockRead_GetBody(JPC_BodyLockRead* self) {
  1918. return to_jpc(&to_jph(self)->GetBody());
  1919. }
  1920. ////////////////////////////////////////////////////////////////////////////////
  1921. // BodyLockWrite
  1922. JPC_API JPC_BodyLockWrite* JPC_BodyLockWrite_new(const JPC_BodyLockInterface* interface, JPC_BodyID bodyID) {
  1923. JPH::BodyLockWrite* lockWrite = new JPH::BodyLockWrite(*to_jph(interface), to_jph(bodyID));
  1924. return to_jpc(lockWrite);
  1925. }
  1926. JPC_API void JPC_BodyLockWrite_delete(JPC_BodyLockWrite* self) {
  1927. delete to_jph(self);
  1928. }
  1929. JPC_API bool JPC_BodyLockWrite_Succeeded(JPC_BodyLockWrite* self) {
  1930. return to_jph(self)->Succeeded();
  1931. }
  1932. JPC_API JPC_Body* JPC_BodyLockWrite_GetBody(JPC_BodyLockWrite* self) {
  1933. return to_jpc(&to_jph(self)->GetBody());
  1934. }
  1935. ////////////////////////////////////////////////////////////////////////////////
  1936. // BodyLockMultiRead
  1937. typedef struct JPC_BodyLockMultiRead JPC_BodyLockMultiRead;
  1938. JPC_API JPC_BodyLockMultiRead* JPC_BodyLockMultiRead_new(
  1939. const JPC_BodyLockInterface* interface,
  1940. const JPC_BodyID *inBodyIDs,
  1941. int inNumber)
  1942. {
  1943. JPH::BodyLockMultiRead* lockRead = new JPH::BodyLockMultiRead(*to_jph(interface), to_jph(inBodyIDs), inNumber);
  1944. return to_jpc(lockRead);
  1945. }
  1946. JPC_API void JPC_BodyLockMultiRead_delete(JPC_BodyLockMultiRead* self) {
  1947. delete to_jph(self);
  1948. }
  1949. JPC_API const JPC_Body* JPC_BodyLockMultiRead_GetBody(JPC_BodyLockMultiRead* self, int inBodyIndex) {
  1950. return to_jpc(to_jph(self)->GetBody(inBodyIndex));
  1951. }
  1952. ////////////////////////////////////////////////////////////////////////////////
  1953. // BodyLockMultiWrite
  1954. typedef struct JPC_BodyLockMultiWrite JPC_BodyLockMultiWrite;
  1955. JPC_API JPC_BodyLockMultiWrite* JPC_BodyLockMultiWrite_new(
  1956. const JPC_BodyLockInterface* interface,
  1957. const JPC_BodyID *inBodyIDs,
  1958. int inNumber)
  1959. {
  1960. JPH::BodyLockMultiWrite* lockWrite = new JPH::BodyLockMultiWrite(*to_jph(interface), to_jph(inBodyIDs), inNumber);
  1961. return to_jpc(lockWrite);
  1962. }
  1963. JPC_API void JPC_BodyLockMultiWrite_delete(JPC_BodyLockMultiWrite* self) {
  1964. delete to_jph(self);
  1965. }
  1966. JPC_API JPC_Body* JPC_BodyLockMultiWrite_GetBody(JPC_BodyLockMultiWrite* self, int inBodyIndex) {
  1967. return to_jpc(to_jph(self)->GetBody(inBodyIndex));
  1968. }
  1969. ////////////////////////////////////////////////////////////////////////////////
  1970. // BodyInterface
  1971. JPC_API JPC_Body* JPC_BodyInterface_CreateBody(JPC_BodyInterface* self, const JPC_BodyCreationSettings* inSettings) {
  1972. return to_jpc(to_jph(self)->CreateBody(to_jph(inSettings)));
  1973. }
  1974. // JPC_API JPC_Body* JPC_BodyInterface_CreateSoftBody(JPC_BodyInterface *self, const SoftBodyCreationSettings &inSettings);
  1975. JPC_API JPC_Body* JPC_BodyInterface_CreateBodyWithID(JPC_BodyInterface *self, JPC_BodyID inBodyID, const JPC_BodyCreationSettings* inSettings) {
  1976. return to_jpc(to_jph(self)->CreateBodyWithID(to_jph(inBodyID), to_jph(inSettings)));
  1977. }
  1978. // JPC_API JPC_Body* JPC_BodyInterface_CreateSoftBodyWithID(JPC_BodyInterface *self, JPC_BodyID inBodyID, const SoftBodyCreationSettings* inSettings);
  1979. JPC_API JPC_Body* JPC_BodyInterface_CreateBodyWithoutID(const JPC_BodyInterface *self, const JPC_BodyCreationSettings* inSettings) {
  1980. return to_jpc(to_jph(self)->CreateBodyWithoutID(to_jph(inSettings)));
  1981. }
  1982. // JPC_API JPC_Body* JPC_BodyInterface_CreateSoftBodyWithoutID(const JPC_BodyInterface *self, const SoftBodyCreationSettings* inSettings);
  1983. JPC_API void JPC_BodyInterface_DestroyBodyWithoutID(const JPC_BodyInterface *self, JPC_Body *inBody) {
  1984. to_jph(self)->DestroyBodyWithoutID(to_jph(inBody));
  1985. }
  1986. JPC_API bool JPC_BodyInterface_AssignBodyID(JPC_BodyInterface *self, JPC_Body *ioBody) {
  1987. return to_jph(self)->AssignBodyID(to_jph(ioBody));
  1988. }
  1989. // JPC_API bool JPC_BodyInterface_AssignBodyID(JPC_BodyInterface *self, JPC_Body *ioBody, JPC_BodyID inBodyID);
  1990. JPC_API JPC_Body* JPC_BodyInterface_UnassignBodyID(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  1991. return to_jpc(to_jph(self)->UnassignBodyID(to_jph(inBodyID)));
  1992. }
  1993. // JPC_API void JPC_BodyInterface_UnassignBodyIDs(JPC_BodyInterface *self, const JPC_BodyID *inBodyIDs, int inNumber, JPC_Body **outBodies) {
  1994. // return to_jph(self)->UnassignBodyIDs(to_jph(inBodyIDs), inNumber, to_jph(outBodies));
  1995. // }
  1996. JPC_API void JPC_BodyInterface_DestroyBody(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  1997. to_jph(self)->DestroyBody(to_jph(inBodyID));
  1998. }
  1999. // JPC_API void JPC_BodyInterface_DestroyBodies(JPC_BodyInterface *self, const JPC_BodyID *inBodyIDs, int inNumber) {
  2000. // return to_jph(self)->DestroyBodies(to_jph(inBodyIDs), int inNumber);
  2001. // }
  2002. JPC_API void JPC_BodyInterface_AddBody(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Activation inActivationMode) {
  2003. to_jph(self)->AddBody(to_jph(inBodyID), to_jph(inActivationMode));
  2004. }
  2005. JPC_API void JPC_BodyInterface_RemoveBody(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2006. to_jph(self)->RemoveBody(to_jph(inBodyID));
  2007. }
  2008. JPC_API bool JPC_BodyInterface_IsAdded(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2009. return to_jph(self)->IsAdded(to_jph(inBodyID));
  2010. }
  2011. JPC_API JPC_BodyID JPC_BodyInterface_CreateAndAddBody(JPC_BodyInterface *self, const JPC_BodyCreationSettings* inSettings, JPC_Activation inActivationMode) {
  2012. return to_jpc(to_jph(self)->CreateAndAddBody(to_jph(inSettings), to_jph(inActivationMode)));
  2013. }
  2014. // JPC_API JPC_BodyID JPC_BodyInterface_CreateAndAddSoftBody(JPC_BodyInterface *self, const SoftBodyCreationSettings &inSettings, JPC_Activation inActivationMode);
  2015. JPC_API void* JPC_BodyInterface_AddBodiesPrepare(JPC_BodyInterface *self, JPC_BodyID *ioBodies, int inNumber) {
  2016. return to_jph(self)->AddBodiesPrepare(to_jph(ioBodies), inNumber);
  2017. }
  2018. JPC_API void JPC_BodyInterface_AddBodiesFinalize(JPC_BodyInterface *self, JPC_BodyID *ioBodies, int inNumber, void* inAddState, JPC_Activation inActivationMode) {
  2019. to_jph(self)->AddBodiesFinalize(to_jph(ioBodies), inNumber, inAddState, to_jph(inActivationMode));
  2020. }
  2021. JPC_API void JPC_BodyInterface_AddBodiesAbort(JPC_BodyInterface *self, JPC_BodyID *ioBodies, int inNumber, void* inAddState) {
  2022. to_jph(self)->AddBodiesAbort(to_jph(ioBodies), inNumber, inAddState);
  2023. }
  2024. JPC_API void JPC_BodyInterface_RemoveBodies(JPC_BodyInterface *self, JPC_BodyID *ioBodies, int inNumber) {
  2025. to_jph(self)->RemoveBodies(to_jph(ioBodies), inNumber);
  2026. }
  2027. JPC_API void JPC_BodyInterface_ActivateBody(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2028. to_jph(self)->ActivateBody(to_jph(inBodyID));
  2029. }
  2030. JPC_API void JPC_BodyInterface_ActivateBodies(JPC_BodyInterface *self, JPC_BodyID *inBodyIDs, int inNumber) {
  2031. to_jph(self)->ActivateBodies(to_jph(inBodyIDs), inNumber);
  2032. }
  2033. // JPC_API void JPC_BodyInterface_ActivateBodiesInAABox(JPC_BodyInterface *self, const AABox &inBox, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter);
  2034. JPC_API void JPC_BodyInterface_DeactivateBody(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2035. to_jph(self)->DeactivateBody(to_jph(inBodyID));
  2036. }
  2037. JPC_API void JPC_BodyInterface_DeactivateBodies(JPC_BodyInterface *self, JPC_BodyID *inBodyIDs, int inNumber) {
  2038. to_jph(self)->DeactivateBodies(to_jph(inBodyIDs), inNumber);
  2039. }
  2040. JPC_API bool JPC_BodyInterface_IsActive(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2041. return to_jph(self)->IsActive(to_jph(inBodyID));
  2042. }
  2043. // TwoBodyConstraint * JPC_BodyInterface_CreateConstraint(JPC_BodyInterface *self, const TwoBodyConstraintSettings *inSettings, JPC_BodyID inBodyID1, JPC_BodyID inBodyID2);
  2044. // JPC_API void JPC_BodyInterface_ActivateConstraint(JPC_BodyInterface *self, const TwoBodyConstraint *inConstraint);
  2045. JPC_API const JPC_Shape* JPC_BodyInterface_GetShape(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2046. // NOTE: This pointer will only be alive as long as BodyInterface holds onto it!
  2047. return to_jpc(to_jph(self)->GetShape(to_jph(inBodyID)).GetPtr());
  2048. }
  2049. JPC_API void JPC_BodyInterface_SetShape(const JPC_BodyInterface *self, JPC_BodyID inBodyID, const JPC_Shape *inShape, bool inUpdateMassProperties, JPC_Activation inActivationMode) {
  2050. to_jph(self)->SetShape(to_jph(inBodyID), to_jph(inShape), inUpdateMassProperties, to_jph(inActivationMode));
  2051. }
  2052. JPC_API void JPC_BodyInterface_NotifyShapeChanged(const JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inPreviousCenterOfMass, bool inUpdateMassProperties, JPC_Activation inActivationMode) {
  2053. to_jph(self)->NotifyShapeChanged(to_jph(inBodyID), to_jph(inPreviousCenterOfMass), inUpdateMassProperties, to_jph(inActivationMode));
  2054. }
  2055. JPC_API void JPC_BodyInterface_SetObjectLayer(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_ObjectLayer inLayer) {
  2056. to_jph(self)->SetObjectLayer(to_jph(inBodyID), inLayer);
  2057. }
  2058. JPC_API JPC_ObjectLayer JPC_BodyInterface_GetObjectLayer(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2059. return to_jph(self)->GetObjectLayer(to_jph(inBodyID));
  2060. }
  2061. JPC_API void JPC_BodyInterface_SetPositionAndRotation(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inPosition, JPC_Quat inRotation, JPC_Activation inActivationMode) {
  2062. to_jph(self)->SetPositionAndRotation(to_jph(inBodyID), to_jph(inPosition), to_jph(inRotation), to_jph(inActivationMode));
  2063. }
  2064. JPC_API void JPC_BodyInterface_SetPositionAndRotationWhenChanged(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inPosition, JPC_Quat inRotation, JPC_Activation inActivationMode) {
  2065. to_jph(self)->SetPositionAndRotationWhenChanged(to_jph(inBodyID), to_jph(inPosition), to_jph(inRotation), to_jph(inActivationMode));
  2066. }
  2067. JPC_API void JPC_BodyInterface_GetPositionAndRotation(const JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 *outPosition, JPC_Quat *outRotation) {
  2068. JPH::RVec3 outPos{};
  2069. JPH::Quat outRot{};
  2070. to_jph(self)->GetPositionAndRotation(to_jph(inBodyID), outPos, outRot);
  2071. *outPosition = to_jpc(outPos);
  2072. *outRotation = to_jpc(outRot);
  2073. }
  2074. JPC_API void JPC_BodyInterface_SetPosition(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inPosition, JPC_Activation inActivationMode) {
  2075. to_jph(self)->SetPosition(to_jph(inBodyID), to_jph(inPosition), to_jph(inActivationMode));
  2076. }
  2077. JPC_API JPC_RVec3 JPC_BodyInterface_GetPosition(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2078. return to_jpc(to_jph(self)->GetPosition(to_jph(inBodyID)));
  2079. }
  2080. JPC_API JPC_RVec3 JPC_BodyInterface_GetCenterOfMassPosition(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2081. return to_jpc(to_jph(self)->GetCenterOfMassPosition(to_jph(inBodyID)));
  2082. }
  2083. JPC_API void JPC_BodyInterface_SetRotation(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Quat inRotation, JPC_Activation inActivationMode) {
  2084. to_jph(self)->SetRotation(to_jph(inBodyID), to_jph(inRotation), to_jph(inActivationMode));
  2085. }
  2086. JPC_API JPC_Quat JPC_BodyInterface_GetRotation(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2087. return to_jpc(to_jph(self)->GetRotation(to_jph(inBodyID)));
  2088. }
  2089. JPC_API JPC_RMat44 JPC_BodyInterface_GetWorldTransform(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2090. return to_jpc(to_jph(self)->GetWorldTransform(to_jph(inBodyID)));
  2091. }
  2092. JPC_API JPC_RMat44 JPC_BodyInterface_GetCenterOfMassTransform(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2093. return to_jpc(to_jph(self)->GetCenterOfMassTransform(to_jph(inBodyID)));
  2094. }
  2095. JPC_API void JPC_BodyInterface_MoveKinematic(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inTargetPosition, JPC_Quat inTargetRotation, float inDeltaTime) {
  2096. to_jph(self)->MoveKinematic(to_jph(inBodyID), to_jph(inTargetPosition), to_jph(inTargetRotation), inDeltaTime);
  2097. }
  2098. JPC_API void JPC_BodyInterface_SetLinearAndAngularVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inLinearVelocity, JPC_Vec3 inAngularVelocity) {
  2099. to_jph(self)->SetLinearAndAngularVelocity(to_jph(inBodyID), to_jph(inLinearVelocity), to_jph(inAngularVelocity));
  2100. }
  2101. JPC_API void JPC_BodyInterface_GetLinearAndAngularVelocity(const JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 *outLinearVelocity, JPC_Vec3 *outAngularVelocity) {
  2102. JPH::Vec3 outLinVel;
  2103. JPH::Vec3 outAngVel;
  2104. to_jph(self)->GetLinearAndAngularVelocity(to_jph(inBodyID), outLinVel, outAngVel);
  2105. *outLinearVelocity = to_jpc(outLinVel);
  2106. *outAngularVelocity = to_jpc(outAngVel);
  2107. }
  2108. JPC_API void JPC_BodyInterface_SetLinearVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inLinearVelocity) {
  2109. to_jph(self)->SetLinearVelocity(to_jph(inBodyID), to_jph(inLinearVelocity));
  2110. }
  2111. JPC_API JPC_Vec3 JPC_BodyInterface_GetLinearVelocity(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2112. return to_jpc(to_jph(self)->GetLinearVelocity(to_jph(inBodyID)));
  2113. }
  2114. JPC_API void JPC_BodyInterface_AddLinearVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inLinearVelocity) {
  2115. to_jph(self)->AddLinearVelocity(to_jph(inBodyID), to_jph(inLinearVelocity));
  2116. }
  2117. JPC_API void JPC_BodyInterface_AddLinearAndAngularVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inLinearVelocity, JPC_Vec3 inAngularVelocity) {
  2118. to_jph(self)->AddLinearAndAngularVelocity(to_jph(inBodyID), to_jph(inLinearVelocity), to_jph(inAngularVelocity));
  2119. }
  2120. JPC_API void JPC_BodyInterface_SetAngularVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inAngularVelocity) {
  2121. to_jph(self)->SetAngularVelocity(to_jph(inBodyID), to_jph(inAngularVelocity));
  2122. }
  2123. JPC_API JPC_Vec3 JPC_BodyInterface_GetAngularVelocity(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2124. return to_jpc(to_jph(self)->GetAngularVelocity(to_jph(inBodyID)));
  2125. }
  2126. JPC_API JPC_Vec3 JPC_BodyInterface_GetPointVelocity(const JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inPoint) {
  2127. return to_jpc(to_jph(self)->GetPointVelocity(to_jph(inBodyID), to_jph(inPoint)));
  2128. }
  2129. JPC_API void JPC_BodyInterface_SetPositionRotationAndVelocity(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_RVec3 inPosition, JPC_Quat inRotation, JPC_Vec3 inLinearVelocity, JPC_Vec3 inAngularVelocity) {
  2130. to_jph(self)->SetPositionRotationAndVelocity(to_jph(inBodyID), to_jph(inPosition), to_jph(inRotation), to_jph(inLinearVelocity), to_jph(inAngularVelocity));
  2131. }
  2132. JPC_API void JPC_BodyInterface_AddForce(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inForce) {
  2133. to_jph(self)->AddForce(to_jph(inBodyID), to_jph(inForce));
  2134. }
  2135. // overload of BodyInterface::AddForce
  2136. JPC_API void JPC_BodyInterface_AddForceAtPoint(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inForce, JPC_RVec3 inPoint) {
  2137. to_jph(self)->AddForce(to_jph(inBodyID), to_jph(inForce), to_jph(inPoint));
  2138. }
  2139. JPC_API void JPC_BodyInterface_AddTorque(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inTorque) {
  2140. to_jph(self)->AddTorque(to_jph(inBodyID), to_jph(inTorque));
  2141. }
  2142. JPC_API void JPC_BodyInterface_AddForceAndTorque(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inForce, JPC_Vec3 inTorque) {
  2143. to_jph(self)->AddForceAndTorque(to_jph(inBodyID), to_jph(inForce), to_jph(inTorque));
  2144. }
  2145. JPC_API void JPC_BodyInterface_AddImpulse(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inImpulse) {
  2146. to_jph(self)->AddImpulse(to_jph(inBodyID), to_jph(inImpulse));
  2147. }
  2148. JPC_API void JPC_BodyInterface_AddImpulse3(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inImpulse, JPC_RVec3 inPoint) {
  2149. to_jph(self)->AddImpulse(to_jph(inBodyID), to_jph(inImpulse), to_jph(inPoint));
  2150. }
  2151. JPC_API void JPC_BodyInterface_AddAngularImpulse(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Vec3 inAngularImpulse) {
  2152. to_jph(self)->AddAngularImpulse(to_jph(inBodyID), to_jph(inAngularImpulse));
  2153. }
  2154. JPC_API JPC_BodyType JPC_BodyInterface_GetBodyType(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2155. return to_jpc(to_jph(self)->GetBodyType(to_jph(inBodyID)));
  2156. }
  2157. JPC_API void JPC_BodyInterface_SetMotionType(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_MotionType inMotionType, JPC_Activation inActivationMode) {
  2158. to_jph(self)->SetMotionType(to_jph(inBodyID), to_jph(inMotionType), to_jph(inActivationMode));
  2159. }
  2160. JPC_API JPC_MotionType JPC_BodyInterface_GetMotionType(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2161. return to_jpc(to_jph(self)->GetMotionType(to_jph(inBodyID)));
  2162. }
  2163. JPC_API void JPC_BodyInterface_SetMotionQuality(JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_MotionQuality inMotionQuality) {
  2164. to_jph(self)->SetMotionQuality(to_jph(inBodyID), to_jph(inMotionQuality));
  2165. }
  2166. JPC_API JPC_MotionQuality JPC_BodyInterface_GetMotionQuality(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2167. return to_jpc(to_jph(self)->GetMotionQuality(to_jph(inBodyID)));
  2168. }
  2169. JPC_API void JPC_BodyInterface_GetInverseInertia(const JPC_BodyInterface *self, JPC_BodyID inBodyID, JPC_Mat44 *outMatrix) {
  2170. to_jph(self)->GetInverseInertia(to_jph(inBodyID)).StoreFloat4x4(reinterpret_cast<JPH::Float4*>(outMatrix));
  2171. }
  2172. JPC_API void JPC_BodyInterface_SetRestitution(JPC_BodyInterface *self, JPC_BodyID inBodyID, float inRestitution) {
  2173. to_jph(self)->SetRestitution(to_jph(inBodyID), inRestitution);
  2174. }
  2175. JPC_API float JPC_BodyInterface_GetRestitution(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2176. return to_jph(self)->GetRestitution(to_jph(inBodyID));
  2177. }
  2178. JPC_API void JPC_BodyInterface_SetFriction(JPC_BodyInterface *self, JPC_BodyID inBodyID, float inFriction) {
  2179. to_jph(self)->SetFriction(to_jph(inBodyID), inFriction);
  2180. }
  2181. JPC_API float JPC_BodyInterface_GetFriction(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2182. return to_jph(self)->GetFriction(to_jph(inBodyID));
  2183. }
  2184. JPC_API void JPC_BodyInterface_SetGravityFactor(JPC_BodyInterface *self, JPC_BodyID inBodyID, float inGravityFactor) {
  2185. to_jph(self)->SetGravityFactor(to_jph(inBodyID), inGravityFactor);
  2186. }
  2187. JPC_API float JPC_BodyInterface_GetGravityFactor(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2188. return to_jph(self)->GetGravityFactor(to_jph(inBodyID));
  2189. }
  2190. JPC_API void JPC_BodyInterface_SetUseManifoldReduction(JPC_BodyInterface *self, JPC_BodyID inBodyID, bool inUseReduction) {
  2191. to_jph(self)->SetUseManifoldReduction(to_jph(inBodyID), inUseReduction);
  2192. }
  2193. JPC_API bool JPC_BodyInterface_GetUseManifoldReduction(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2194. return to_jph(self)->GetUseManifoldReduction(to_jph(inBodyID));
  2195. }
  2196. // TransformedShape JPC_BodyInterface_GetTransformedShape(const JPC_BodyInterface *self, JPC_BodyID inBodyID);
  2197. JPC_API uint64_t JPC_BodyInterface_GetUserData(const JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2198. return to_jph(self)->GetUserData(to_jph(inBodyID));
  2199. }
  2200. JPC_API void JPC_BodyInterface_SetUserData(const JPC_BodyInterface *self, JPC_BodyID inBodyID, uint64_t inUserData) {
  2201. to_jph(self)->SetUserData(to_jph(inBodyID), inUserData);
  2202. }
  2203. // const PhysicsMaterial* JPC_BodyInterface_GetMaterial(const JPC_BodyInterface *self, JPC_BodyID inBodyID, const SubShapeID &inSubShapeID);
  2204. JPC_API void JPC_BodyInterface_InvalidateContactCache(JPC_BodyInterface *self, JPC_BodyID inBodyID) {
  2205. to_jph(self)->InvalidateContactCache(to_jph(inBodyID));
  2206. }
  2207. ////////////////////////////////////////////////////////////////////////////////
  2208. // NarrowPhaseQuery
  2209. JPC_API bool JPC_NarrowPhaseQuery_CastRay(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastRayArgs* args) {
  2210. JPH::RayCastResult result;
  2211. JPH::RayCastSettings settings;
  2212. JPH::BroadPhaseLayerFilter defaultBplFilter{};
  2213. const JPH::BroadPhaseLayerFilter* bplFilter = &defaultBplFilter;
  2214. if (args->BroadPhaseLayerFilter != nullptr) {
  2215. bplFilter = to_jph(args->BroadPhaseLayerFilter);
  2216. }
  2217. JPH::ObjectLayerFilter defaultOlFilter{};
  2218. const JPH::ObjectLayerFilter* olFilter = &defaultOlFilter;
  2219. if (args->ObjectLayerFilter != nullptr) {
  2220. olFilter = to_jph(args->ObjectLayerFilter);
  2221. }
  2222. JPH::BodyFilter defaultBodyFilter{};
  2223. const JPH::BodyFilter* bodyFilter = &defaultBodyFilter;
  2224. if (args->BodyFilter != nullptr) {
  2225. bodyFilter = to_jph(args->BodyFilter);
  2226. }
  2227. JPH::ShapeFilter defaultShapeFilter{};
  2228. const JPH::ShapeFilter* shapeFilter = &defaultShapeFilter;
  2229. if (args->ShapeFilter != nullptr) {
  2230. shapeFilter = to_jph(args->ShapeFilter);
  2231. }
  2232. JPH::ClosestHitCollisionCollector<JPH::CastRayCollector> collector;
  2233. to_jph(self)->CastRay(
  2234. to_jph(args->Ray),
  2235. settings,
  2236. collector,
  2237. *bplFilter,
  2238. *olFilter,
  2239. *bodyFilter,
  2240. *shapeFilter);
  2241. bool hit = collector.HadHit();
  2242. if (hit) {
  2243. args->Result = to_jpc(collector.mHit);
  2244. }
  2245. return hit;
  2246. }
  2247. JPC_API void JPC_ShapeCastSettings_default(JPC_ShapeCastSettings* object) {
  2248. JPH::ShapeCastSettings defaultSettings{};
  2249. *object = to_jpc(defaultSettings);
  2250. }
  2251. JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
  2252. JPH::ShapeCastSettings settings = to_jph(args->Settings);
  2253. JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> defaultCollector{};
  2254. JPH::CastShapeCollector* collector = &defaultCollector;
  2255. if (args->Collector != nullptr) {
  2256. collector = to_jph(args->Collector);
  2257. }
  2258. JPH::BroadPhaseLayerFilter defaultBplFilter{};
  2259. const JPH::BroadPhaseLayerFilter* bplFilter = &defaultBplFilter;
  2260. if (args->BroadPhaseLayerFilter != nullptr) {
  2261. bplFilter = to_jph(args->BroadPhaseLayerFilter);
  2262. }
  2263. JPH::ObjectLayerFilter defaultOlFilter{};
  2264. const JPH::ObjectLayerFilter* olFilter = &defaultOlFilter;
  2265. if (args->ObjectLayerFilter != nullptr) {
  2266. olFilter = to_jph(args->ObjectLayerFilter);
  2267. }
  2268. JPH::BodyFilter defaultBodyFilter{};
  2269. const JPH::BodyFilter* bodyFilter = &defaultBodyFilter;
  2270. if (args->BodyFilter != nullptr) {
  2271. bodyFilter = to_jph(args->BodyFilter);
  2272. }
  2273. JPH::ShapeFilter defaultShapeFilter{};
  2274. const JPH::ShapeFilter* shapeFilter = &defaultShapeFilter;
  2275. if (args->ShapeFilter != nullptr) {
  2276. shapeFilter = to_jph(args->ShapeFilter);
  2277. }
  2278. to_jph(self)->CastShape(
  2279. to_jph(args->ShapeCast),
  2280. settings,
  2281. to_jph(args->BaseOffset),
  2282. *collector,
  2283. *bplFilter,
  2284. *olFilter,
  2285. *bodyFilter,
  2286. *shapeFilter);
  2287. }
  2288. JPC_API void JPC_CollideShapeSettings_default(JPC_CollideShapeSettings* object) {
  2289. JPH::CollideShapeSettings defaultSettings{};
  2290. *object = to_jpc(defaultSettings);
  2291. }
  2292. JPC_API void JPC_NarrowPhaseQuery_CollideShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CollideShapeArgs* args) {
  2293. JPH::CollideShapeSettings settings = to_jph(args->Settings);
  2294. JPH::ClosestHitCollisionCollector<JPH::CollideShapeCollector> defaultCollector{};
  2295. JPH::CollideShapeCollector* collector = &defaultCollector;
  2296. if (args->Collector != nullptr) {
  2297. collector = to_jph(args->Collector);
  2298. }
  2299. JPH::BroadPhaseLayerFilter defaultBplFilter{};
  2300. const JPH::BroadPhaseLayerFilter* bplFilter = &defaultBplFilter;
  2301. if (args->BroadPhaseLayerFilter != nullptr) {
  2302. bplFilter = to_jph(args->BroadPhaseLayerFilter);
  2303. }
  2304. JPH::ObjectLayerFilter defaultOlFilter{};
  2305. const JPH::ObjectLayerFilter* olFilter = &defaultOlFilter;
  2306. if (args->ObjectLayerFilter != nullptr) {
  2307. olFilter = to_jph(args->ObjectLayerFilter);
  2308. }
  2309. JPH::BodyFilter defaultBodyFilter{};
  2310. const JPH::BodyFilter* bodyFilter = &defaultBodyFilter;
  2311. if (args->BodyFilter != nullptr) {
  2312. bodyFilter = to_jph(args->BodyFilter);
  2313. }
  2314. JPH::ShapeFilter defaultShapeFilter{};
  2315. const JPH::ShapeFilter* shapeFilter = &defaultShapeFilter;
  2316. if (args->ShapeFilter != nullptr) {
  2317. shapeFilter = to_jph(args->ShapeFilter);
  2318. }
  2319. to_jph(self)->CollideShape(
  2320. to_jph(args->Shape),
  2321. to_jph(args->ShapeScale),
  2322. to_jph(args->CenterOfMassTransform),
  2323. settings,
  2324. to_jph(args->BaseOffset),
  2325. *collector,
  2326. *bplFilter,
  2327. *olFilter,
  2328. *bodyFilter,
  2329. *shapeFilter);
  2330. }
  2331. ////////////////////////////////////////////////////////////////////////////////
  2332. // PhysicsSystem
  2333. JPC_API JPC_PhysicsSystem* JPC_PhysicsSystem_new() {
  2334. return to_jpc(new JPH::PhysicsSystem());
  2335. }
  2336. JPC_API void JPC_PhysicsSystem_Init(
  2337. JPC_PhysicsSystem* self,
  2338. uint inMaxBodies,
  2339. uint inNumBodyMutexes,
  2340. uint inMaxBodyPairs,
  2341. uint inMaxContactConstraints,
  2342. JPC_BroadPhaseLayerInterface* inBroadPhaseLayerInterface,
  2343. JPC_ObjectVsBroadPhaseLayerFilter* inObjectVsBroadPhaseLayerFilter,
  2344. JPC_ObjectLayerPairFilter* inObjectLayerPairFilter)
  2345. {
  2346. JPC_BroadPhaseLayerInterfaceBridge* impl_inBroadPhaseLayerInterface = to_jph(inBroadPhaseLayerInterface);
  2347. JPC_ObjectVsBroadPhaseLayerFilterBridge* impl_inObjectVsBroadPhaseLayerFilter = to_jph(inObjectVsBroadPhaseLayerFilter);
  2348. JPC_ObjectLayerPairFilterBridge* impl_inObjectLayerPairFilter = to_jph(inObjectLayerPairFilter);
  2349. to_jph(self)->Init(
  2350. inMaxBodies,
  2351. inNumBodyMutexes,
  2352. inMaxBodyPairs,
  2353. inMaxContactConstraints,
  2354. *impl_inBroadPhaseLayerInterface,
  2355. *impl_inObjectVsBroadPhaseLayerFilter,
  2356. *impl_inObjectLayerPairFilter);
  2357. }
  2358. JPC_API void JPC_PhysicsSystem_OptimizeBroadPhase(JPC_PhysicsSystem* self) {
  2359. to_jph(self)->OptimizeBroadPhase();
  2360. }
  2361. JPC_API void JPC_PhysicsSystem_AddConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint) {
  2362. to_jph(self)->AddConstraint(to_jph(constraint));
  2363. }
  2364. JPC_API void JPC_PhysicsSystem_RemoveConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint) {
  2365. to_jph(self)->RemoveConstraint(to_jph(constraint));
  2366. }
  2367. JPC_API JPC_BodyInterface* JPC_PhysicsSystem_GetBodyInterface(JPC_PhysicsSystem* self) {
  2368. return to_jpc(&to_jph(self)->GetBodyInterface());
  2369. }
  2370. JPC_API const JPC_BodyLockInterface* JPC_PhysicsSystem_GetBodyLockInterface(JPC_PhysicsSystem* self) {
  2371. return to_jpc(&to_jph(self)->GetBodyLockInterface());
  2372. }
  2373. JPC_API const JPC_NarrowPhaseQuery* JPC_PhysicsSystem_GetNarrowPhaseQuery(const JPC_PhysicsSystem* self) {
  2374. return to_jpc(&to_jph(self)->GetNarrowPhaseQuery());
  2375. }
  2376. JPC_API JPC_PhysicsUpdateError JPC_PhysicsSystem_Update(
  2377. JPC_PhysicsSystem* self,
  2378. float inDeltaTime,
  2379. int inCollisionSteps,
  2380. JPC_TempAllocatorImpl *inTempAllocator,
  2381. JPC_JobSystem *inJobSystem)
  2382. {
  2383. auto res = to_jph(self)->Update(
  2384. inDeltaTime,
  2385. inCollisionSteps,
  2386. to_jph(inTempAllocator),
  2387. to_jph(inJobSystem));
  2388. return to_integral(res);
  2389. }
  2390. JPC_API void JPC_PhysicsSystem_DrawBodies(
  2391. JPC_PhysicsSystem* self,
  2392. JPC_BodyManager_DrawSettings* inSettings,
  2393. JPC_DebugRendererSimple* inRenderer,
  2394. [[maybe_unused]] const void* inBodyFilter)
  2395. {
  2396. to_jph(self)->DrawBodies(to_jph(*inSettings), to_jph(inRenderer), nullptr);
  2397. }
  2398. JPC_API void JPC_PhysicsSystem_DrawConstraints(
  2399. JPC_PhysicsSystem* self,
  2400. JPC_DebugRendererSimple* inRenderer)
  2401. {
  2402. to_jph(self)->DrawConstraints(to_jph(inRenderer));
  2403. }
  2404. JPC_API void JPC_PhysicsSystem_SetSimShapeFilter(
  2405. JPC_PhysicsSystem* self,
  2406. const JPC_SimShapeFilter* inShapeFilter)
  2407. {
  2408. to_jph(self)->SetSimShapeFilter(to_jph(inShapeFilter));
  2409. }
  2410. JPC_API void JPC_PhysicsSystem_SetContactListener(
  2411. JPC_PhysicsSystem* self,
  2412. JPC_ContactListener* inContactListener)
  2413. {
  2414. to_jph(self)->SetContactListener(to_jph(inContactListener));
  2415. }