bullet_physics_server.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. /*************************************************************************/
  2. /* bullet_physics_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "bullet_physics_server.h"
  31. #include "bullet_utilities.h"
  32. #include "cone_twist_joint_bullet.h"
  33. #include "core/class_db.h"
  34. #include "core/error_macros.h"
  35. #include "core/ustring.h"
  36. #include "generic_6dof_joint_bullet.h"
  37. #include "hinge_joint_bullet.h"
  38. #include "pin_joint_bullet.h"
  39. #include "shape_bullet.h"
  40. #include "slider_joint_bullet.h"
  41. #include <LinearMath/btVector3.h>
  42. #include <assert.h>
  43. /**
  44. @author AndreaCatania
  45. */
  46. #define CreateThenReturnRID(owner, ridData) \
  47. RID rid = owner.make_rid(ridData); \
  48. ridData->set_self(rid); \
  49. ridData->_set_physics_server(this); \
  50. return rid;
  51. // <--------------- Joint creation asserts
  52. /// Assert the body is assigned to a space
  53. #define JointAssertSpace(body, bIndex, ret) \
  54. if (!body->get_space()) { \
  55. ERR_PRINTS("Before create a joint the Body" + String(bIndex) + " must be added to a space!"); \
  56. return ret; \
  57. }
  58. /// Assert the two bodies of joint are in the same space
  59. #define JointAssertSameSpace(bodyA, bodyB, ret) \
  60. if (bodyA->get_space() != bodyB->get_space()) { \
  61. ERR_PRINT("In order to create a joint the Body_A and Body_B must be in the same space!"); \
  62. return RID(); \
  63. }
  64. #define AddJointToSpace(body, joint) \
  65. body->get_space()->add_constraint(joint, joint->is_disabled_collisions_between_bodies());
  66. // <--------------- Joint creation asserts
  67. void BulletPhysicsServer::_bind_methods() {
  68. //ClassDB::bind_method(D_METHOD("DoTest"), &BulletPhysicsServer::DoTest);
  69. }
  70. BulletPhysicsServer::BulletPhysicsServer() :
  71. PhysicsServer(),
  72. active(true),
  73. active_spaces_count(0) {}
  74. BulletPhysicsServer::~BulletPhysicsServer() {}
  75. RID BulletPhysicsServer::shape_create(ShapeType p_shape) {
  76. ShapeBullet *shape = NULL;
  77. switch (p_shape) {
  78. case SHAPE_PLANE: {
  79. shape = bulletnew(PlaneShapeBullet);
  80. } break;
  81. case SHAPE_SPHERE: {
  82. shape = bulletnew(SphereShapeBullet);
  83. } break;
  84. case SHAPE_BOX: {
  85. shape = bulletnew(BoxShapeBullet);
  86. } break;
  87. case SHAPE_CAPSULE: {
  88. shape = bulletnew(CapsuleShapeBullet);
  89. } break;
  90. case SHAPE_CYLINDER: {
  91. shape = bulletnew(CylinderShapeBullet);
  92. } break;
  93. case SHAPE_CONVEX_POLYGON: {
  94. shape = bulletnew(ConvexPolygonShapeBullet);
  95. } break;
  96. case SHAPE_CONCAVE_POLYGON: {
  97. shape = bulletnew(ConcavePolygonShapeBullet);
  98. } break;
  99. case SHAPE_HEIGHTMAP: {
  100. shape = bulletnew(HeightMapShapeBullet);
  101. } break;
  102. case SHAPE_RAY: {
  103. shape = bulletnew(RayShapeBullet);
  104. } break;
  105. case SHAPE_CUSTOM:
  106. default:
  107. ERR_FAIL_V(RID());
  108. break;
  109. }
  110. CreateThenReturnRID(shape_owner, shape)
  111. }
  112. void BulletPhysicsServer::shape_set_data(RID p_shape, const Variant &p_data) {
  113. ShapeBullet *shape = shape_owner.get(p_shape);
  114. ERR_FAIL_COND(!shape);
  115. shape->set_data(p_data);
  116. }
  117. void BulletPhysicsServer::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {
  118. //WARN_PRINT("Bias not supported by Bullet physics engine");
  119. }
  120. PhysicsServer::ShapeType BulletPhysicsServer::shape_get_type(RID p_shape) const {
  121. ShapeBullet *shape = shape_owner.get(p_shape);
  122. ERR_FAIL_COND_V(!shape, PhysicsServer::SHAPE_CUSTOM);
  123. return shape->get_type();
  124. }
  125. Variant BulletPhysicsServer::shape_get_data(RID p_shape) const {
  126. ShapeBullet *shape = shape_owner.get(p_shape);
  127. ERR_FAIL_COND_V(!shape, Variant());
  128. return shape->get_data();
  129. }
  130. void BulletPhysicsServer::shape_set_margin(RID p_shape, real_t p_margin) {
  131. ShapeBullet *shape = shape_owner.get(p_shape);
  132. ERR_FAIL_COND(!shape);
  133. shape->set_margin(p_margin);
  134. }
  135. real_t BulletPhysicsServer::shape_get_margin(RID p_shape) const {
  136. ShapeBullet *shape = shape_owner.get(p_shape);
  137. ERR_FAIL_COND_V(!shape, 0.0);
  138. return shape->get_margin();
  139. }
  140. real_t BulletPhysicsServer::shape_get_custom_solver_bias(RID p_shape) const {
  141. //WARN_PRINT("Bias not supported by Bullet physics engine");
  142. return 0.;
  143. }
  144. RID BulletPhysicsServer::space_create() {
  145. SpaceBullet *space = bulletnew(SpaceBullet);
  146. CreateThenReturnRID(space_owner, space);
  147. }
  148. void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) {
  149. SpaceBullet *space = space_owner.get(p_space);
  150. ERR_FAIL_COND(!space);
  151. if (space_is_active(p_space) == p_active) {
  152. return;
  153. }
  154. if (p_active) {
  155. ++active_spaces_count;
  156. active_spaces.push_back(space);
  157. } else {
  158. --active_spaces_count;
  159. active_spaces.erase(space);
  160. }
  161. }
  162. bool BulletPhysicsServer::space_is_active(RID p_space) const {
  163. SpaceBullet *space = space_owner.get(p_space);
  164. ERR_FAIL_COND_V(!space, false);
  165. return -1 != active_spaces.find(space);
  166. }
  167. void BulletPhysicsServer::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
  168. SpaceBullet *space = space_owner.get(p_space);
  169. ERR_FAIL_COND(!space);
  170. space->set_param(p_param, p_value);
  171. }
  172. real_t BulletPhysicsServer::space_get_param(RID p_space, SpaceParameter p_param) const {
  173. SpaceBullet *space = space_owner.get(p_space);
  174. ERR_FAIL_COND_V(!space, 0);
  175. return space->get_param(p_param);
  176. }
  177. PhysicsDirectSpaceState *BulletPhysicsServer::space_get_direct_state(RID p_space) {
  178. SpaceBullet *space = space_owner.get(p_space);
  179. ERR_FAIL_COND_V(!space, NULL);
  180. return space->get_direct_state();
  181. }
  182. void BulletPhysicsServer::space_set_debug_contacts(RID p_space, int p_max_contacts) {
  183. SpaceBullet *space = space_owner.get(p_space);
  184. ERR_FAIL_COND(!space);
  185. space->set_debug_contacts(p_max_contacts);
  186. }
  187. Vector<Vector3> BulletPhysicsServer::space_get_contacts(RID p_space) const {
  188. SpaceBullet *space = space_owner.get(p_space);
  189. ERR_FAIL_COND_V(!space, Vector<Vector3>());
  190. return space->get_debug_contacts();
  191. }
  192. int BulletPhysicsServer::space_get_contact_count(RID p_space) const {
  193. SpaceBullet *space = space_owner.get(p_space);
  194. ERR_FAIL_COND_V(!space, 0);
  195. return space->get_debug_contact_count();
  196. }
  197. RID BulletPhysicsServer::area_create() {
  198. AreaBullet *area = bulletnew(AreaBullet);
  199. area->set_collision_layer(1);
  200. area->set_collision_mask(1);
  201. CreateThenReturnRID(area_owner, area)
  202. }
  203. void BulletPhysicsServer::area_set_space(RID p_area, RID p_space) {
  204. AreaBullet *area = area_owner.get(p_area);
  205. ERR_FAIL_COND(!area);
  206. SpaceBullet *space = NULL;
  207. if (p_space.is_valid()) {
  208. space = space_owner.get(p_space);
  209. ERR_FAIL_COND(!space);
  210. }
  211. area->set_space(space);
  212. }
  213. RID BulletPhysicsServer::area_get_space(RID p_area) const {
  214. AreaBullet *area = area_owner.get(p_area);
  215. return area->get_space()->get_self();
  216. }
  217. void BulletPhysicsServer::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
  218. AreaBullet *area = area_owner.get(p_area);
  219. ERR_FAIL_COND(!area)
  220. area->set_spOv_mode(p_mode);
  221. }
  222. PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_override_mode(RID p_area) const {
  223. AreaBullet *area = area_owner.get(p_area);
  224. ERR_FAIL_COND_V(!area, PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED);
  225. return area->get_spOv_mode();
  226. }
  227. void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform) {
  228. AreaBullet *area = area_owner.get(p_area);
  229. ERR_FAIL_COND(!area);
  230. ShapeBullet *shape = shape_owner.get(p_shape);
  231. ERR_FAIL_COND(!shape);
  232. area->add_shape(shape, p_transform);
  233. }
  234. void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
  235. AreaBullet *area = area_owner.get(p_area);
  236. ERR_FAIL_COND(!area);
  237. ShapeBullet *shape = shape_owner.get(p_shape);
  238. ERR_FAIL_COND(!shape);
  239. area->set_shape(p_shape_idx, shape);
  240. }
  241. void BulletPhysicsServer::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) {
  242. AreaBullet *area = area_owner.get(p_area);
  243. ERR_FAIL_COND(!area);
  244. area->set_shape_transform(p_shape_idx, p_transform);
  245. }
  246. int BulletPhysicsServer::area_get_shape_count(RID p_area) const {
  247. AreaBullet *area = area_owner.get(p_area);
  248. ERR_FAIL_COND_V(!area, 0);
  249. return area->get_shape_count();
  250. }
  251. RID BulletPhysicsServer::area_get_shape(RID p_area, int p_shape_idx) const {
  252. AreaBullet *area = area_owner.get(p_area);
  253. ERR_FAIL_COND_V(!area, RID());
  254. return area->get_shape(p_shape_idx)->get_self();
  255. }
  256. Transform BulletPhysicsServer::area_get_shape_transform(RID p_area, int p_shape_idx) const {
  257. AreaBullet *area = area_owner.get(p_area);
  258. ERR_FAIL_COND_V(!area, Transform());
  259. return area->get_shape_transform(p_shape_idx);
  260. }
  261. void BulletPhysicsServer::area_remove_shape(RID p_area, int p_shape_idx) {
  262. AreaBullet *area = area_owner.get(p_area);
  263. ERR_FAIL_COND(!area);
  264. return area->remove_shape_full(p_shape_idx);
  265. }
  266. void BulletPhysicsServer::area_clear_shapes(RID p_area) {
  267. AreaBullet *area = area_owner.get(p_area);
  268. ERR_FAIL_COND(!area);
  269. for (int i = area->get_shape_count(); 0 < i; --i)
  270. area->remove_shape_full(0);
  271. }
  272. void BulletPhysicsServer::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
  273. AreaBullet *area = area_owner.get(p_area);
  274. ERR_FAIL_COND(!area);
  275. area->set_shape_disabled(p_shape_idx, p_disabled);
  276. }
  277. void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_ID) {
  278. if (space_owner.owns(p_area)) {
  279. return;
  280. }
  281. AreaBullet *area = area_owner.get(p_area);
  282. ERR_FAIL_COND(!area);
  283. area->set_instance_id(p_ID);
  284. }
  285. ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const {
  286. if (space_owner.owns(p_area)) {
  287. return 0;
  288. }
  289. AreaBullet *area = area_owner.get(p_area);
  290. ERR_FAIL_COND_V(!area, ObjectID());
  291. return area->get_instance_id();
  292. }
  293. void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
  294. if (space_owner.owns(p_area)) {
  295. SpaceBullet *space = space_owner.get(p_area);
  296. if (space) {
  297. space->set_param(p_param, p_value);
  298. }
  299. } else {
  300. AreaBullet *area = area_owner.get(p_area);
  301. ERR_FAIL_COND(!area);
  302. area->set_param(p_param, p_value);
  303. }
  304. }
  305. Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) const {
  306. if (space_owner.owns(p_area)) {
  307. SpaceBullet *space = space_owner.get(p_area);
  308. return space->get_param(p_param);
  309. } else {
  310. AreaBullet *area = area_owner.get(p_area);
  311. ERR_FAIL_COND_V(!area, Variant());
  312. return area->get_param(p_param);
  313. }
  314. }
  315. void BulletPhysicsServer::area_set_transform(RID p_area, const Transform &p_transform) {
  316. AreaBullet *area = area_owner.get(p_area);
  317. ERR_FAIL_COND(!area);
  318. area->set_transform(p_transform);
  319. }
  320. Transform BulletPhysicsServer::area_get_transform(RID p_area) const {
  321. AreaBullet *area = area_owner.get(p_area);
  322. ERR_FAIL_COND_V(!area, Transform());
  323. return area->get_transform();
  324. }
  325. void BulletPhysicsServer::area_set_collision_mask(RID p_area, uint32_t p_mask) {
  326. AreaBullet *area = area_owner.get(p_area);
  327. ERR_FAIL_COND(!area);
  328. area->set_collision_mask(p_mask);
  329. }
  330. void BulletPhysicsServer::area_set_collision_layer(RID p_area, uint32_t p_layer) {
  331. AreaBullet *area = area_owner.get(p_area);
  332. ERR_FAIL_COND(!area);
  333. area->set_collision_layer(p_layer);
  334. }
  335. void BulletPhysicsServer::area_set_monitorable(RID p_area, bool p_monitorable) {
  336. AreaBullet *area = area_owner.get(p_area);
  337. ERR_FAIL_COND(!area);
  338. area->set_monitorable(p_monitorable);
  339. }
  340. void BulletPhysicsServer::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  341. AreaBullet *area = area_owner.get(p_area);
  342. ERR_FAIL_COND(!area);
  343. area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  344. }
  345. void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  346. AreaBullet *area = area_owner.get(p_area);
  347. ERR_FAIL_COND(!area);
  348. area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  349. }
  350. void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) {
  351. AreaBullet *area = area_owner.get(p_area);
  352. ERR_FAIL_COND(!area);
  353. area->set_ray_pickable(p_enable);
  354. }
  355. bool BulletPhysicsServer::area_is_ray_pickable(RID p_area) const {
  356. AreaBullet *area = area_owner.get(p_area);
  357. ERR_FAIL_COND_V(!area, false);
  358. return area->is_ray_pickable();
  359. }
  360. RID BulletPhysicsServer::body_create(BodyMode p_mode, bool p_init_sleeping) {
  361. RigidBodyBullet *body = bulletnew(RigidBodyBullet);
  362. body->set_mode(p_mode);
  363. body->set_collision_layer(1);
  364. body->set_collision_mask(1);
  365. if (p_init_sleeping)
  366. body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
  367. CreateThenReturnRID(rigid_body_owner, body);
  368. }
  369. void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) {
  370. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  371. ERR_FAIL_COND(!body);
  372. SpaceBullet *space = NULL;
  373. if (p_space.is_valid()) {
  374. space = space_owner.get(p_space);
  375. ERR_FAIL_COND(!space);
  376. }
  377. if (body->get_space() == space)
  378. return; //pointles
  379. body->set_space(space);
  380. }
  381. RID BulletPhysicsServer::body_get_space(RID p_body) const {
  382. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  383. ERR_FAIL_COND_V(!body, RID());
  384. SpaceBullet *space = body->get_space();
  385. if (!space)
  386. return RID();
  387. return space->get_self();
  388. }
  389. void BulletPhysicsServer::body_set_mode(RID p_body, PhysicsServer::BodyMode p_mode) {
  390. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  391. ERR_FAIL_COND(!body);
  392. body->set_mode(p_mode);
  393. }
  394. PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const {
  395. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  396. ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
  397. return body->get_mode();
  398. }
  399. void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform) {
  400. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  401. ERR_FAIL_COND(!body);
  402. ShapeBullet *shape = shape_owner.get(p_shape);
  403. ERR_FAIL_COND(!shape);
  404. body->add_shape(shape, p_transform);
  405. }
  406. void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
  407. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  408. ERR_FAIL_COND(!body);
  409. ShapeBullet *shape = shape_owner.get(p_shape);
  410. ERR_FAIL_COND(!shape);
  411. body->set_shape(p_shape_idx, shape);
  412. }
  413. void BulletPhysicsServer::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) {
  414. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  415. ERR_FAIL_COND(!body);
  416. body->set_shape_transform(p_shape_idx, p_transform);
  417. }
  418. int BulletPhysicsServer::body_get_shape_count(RID p_body) const {
  419. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  420. ERR_FAIL_COND_V(!body, 0);
  421. return body->get_shape_count();
  422. }
  423. RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const {
  424. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  425. ERR_FAIL_COND_V(!body, RID());
  426. ShapeBullet *shape = body->get_shape(p_shape_idx);
  427. ERR_FAIL_COND_V(!shape, RID());
  428. return shape->get_self();
  429. }
  430. Transform BulletPhysicsServer::body_get_shape_transform(RID p_body, int p_shape_idx) const {
  431. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  432. ERR_FAIL_COND_V(!body, Transform());
  433. return body->get_shape_transform(p_shape_idx);
  434. }
  435. void BulletPhysicsServer::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
  436. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  437. ERR_FAIL_COND(!body);
  438. body->set_shape_disabled(p_shape_idx, p_disabled);
  439. }
  440. void BulletPhysicsServer::body_remove_shape(RID p_body, int p_shape_idx) {
  441. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  442. ERR_FAIL_COND(!body);
  443. body->remove_shape_full(p_shape_idx);
  444. }
  445. void BulletPhysicsServer::body_clear_shapes(RID p_body) {
  446. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  447. ERR_FAIL_COND(!body);
  448. body->remove_all_shapes();
  449. }
  450. void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, uint32_t p_ID) {
  451. CollisionObjectBullet *body = get_collisin_object(p_body);
  452. ERR_FAIL_COND(!body);
  453. body->set_instance_id(p_ID);
  454. }
  455. uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const {
  456. CollisionObjectBullet *body = get_collisin_object(p_body);
  457. ERR_FAIL_COND_V(!body, 0);
  458. return body->get_instance_id();
  459. }
  460. void BulletPhysicsServer::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
  461. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  462. ERR_FAIL_COND(!body);
  463. body->set_continuous_collision_detection(p_enable);
  464. }
  465. bool BulletPhysicsServer::body_is_continuous_collision_detection_enabled(RID p_body) const {
  466. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  467. ERR_FAIL_COND_V(!body, false);
  468. return body->is_continuous_collision_detection_enabled();
  469. }
  470. void BulletPhysicsServer::body_set_collision_layer(RID p_body, uint32_t p_layer) {
  471. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  472. ERR_FAIL_COND(!body);
  473. body->set_collision_layer(p_layer);
  474. }
  475. uint32_t BulletPhysicsServer::body_get_collision_layer(RID p_body) const {
  476. const RigidBodyBullet *body = rigid_body_owner.get(p_body);
  477. ERR_FAIL_COND_V(!body, 0);
  478. return body->get_collision_layer();
  479. }
  480. void BulletPhysicsServer::body_set_collision_mask(RID p_body, uint32_t p_mask) {
  481. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  482. ERR_FAIL_COND(!body);
  483. body->set_collision_mask(p_mask);
  484. }
  485. uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const {
  486. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  487. ERR_FAIL_COND_V(!body, 0);
  488. return body->get_collision_mask();
  489. }
  490. void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) {
  491. // This function si not currently supported
  492. }
  493. uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const {
  494. // This function si not currently supported
  495. return 0;
  496. }
  497. void BulletPhysicsServer::body_set_param(RID p_body, BodyParameter p_param, float p_value) {
  498. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  499. ERR_FAIL_COND(!body);
  500. body->set_param(p_param, p_value);
  501. }
  502. float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) const {
  503. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  504. ERR_FAIL_COND_V(!body, 0);
  505. return body->get_param(p_param);
  506. }
  507. void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) {
  508. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  509. ERR_FAIL_COND(!body);
  510. if (body->get_kinematic_utilities()) {
  511. body->get_kinematic_utilities()->setSafeMargin(p_margin);
  512. }
  513. }
  514. real_t BulletPhysicsServer::body_get_kinematic_safe_margin(RID p_body) const {
  515. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  516. ERR_FAIL_COND_V(!body, 0);
  517. if (body->get_kinematic_utilities()) {
  518. return body->get_kinematic_utilities()->safe_margin;
  519. }
  520. return 0;
  521. }
  522. void BulletPhysicsServer::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  523. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  524. ERR_FAIL_COND(!body);
  525. body->set_state(p_state, p_variant);
  526. }
  527. Variant BulletPhysicsServer::body_get_state(RID p_body, BodyState p_state) const {
  528. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  529. ERR_FAIL_COND_V(!body, Variant());
  530. return body->get_state(p_state);
  531. }
  532. void BulletPhysicsServer::body_set_applied_force(RID p_body, const Vector3 &p_force) {
  533. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  534. ERR_FAIL_COND(!body);
  535. body->set_applied_force(p_force);
  536. }
  537. Vector3 BulletPhysicsServer::body_get_applied_force(RID p_body) const {
  538. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  539. ERR_FAIL_COND_V(!body, Vector3());
  540. return body->get_applied_force();
  541. }
  542. void BulletPhysicsServer::body_set_applied_torque(RID p_body, const Vector3 &p_torque) {
  543. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  544. ERR_FAIL_COND(!body);
  545. body->set_applied_torque(p_torque);
  546. }
  547. Vector3 BulletPhysicsServer::body_get_applied_torque(RID p_body) const {
  548. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  549. ERR_FAIL_COND_V(!body, Vector3());
  550. return body->get_applied_torque();
  551. }
  552. void BulletPhysicsServer::body_add_central_force(RID p_body, const Vector3 &p_force) {
  553. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  554. ERR_FAIL_COND(!body);
  555. body->apply_central_force(p_force);
  556. }
  557. void BulletPhysicsServer::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) {
  558. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  559. ERR_FAIL_COND(!body);
  560. body->apply_force(p_force, p_pos);
  561. }
  562. void BulletPhysicsServer::body_add_torque(RID p_body, const Vector3 &p_torque) {
  563. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  564. ERR_FAIL_COND(!body);
  565. body->apply_torque(p_torque);
  566. }
  567. void BulletPhysicsServer::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
  568. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  569. ERR_FAIL_COND(!body);
  570. body->apply_central_impulse(p_impulse);
  571. }
  572. void BulletPhysicsServer::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) {
  573. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  574. ERR_FAIL_COND(!body);
  575. body->apply_impulse(p_pos, p_impulse);
  576. }
  577. void BulletPhysicsServer::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
  578. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  579. ERR_FAIL_COND(!body);
  580. body->apply_torque_impulse(p_impulse);
  581. }
  582. void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {
  583. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  584. ERR_FAIL_COND(!body);
  585. Vector3 v = body->get_linear_velocity();
  586. Vector3 axis = p_axis_velocity.normalized();
  587. v -= axis * axis.dot(v);
  588. v += p_axis_velocity;
  589. body->set_linear_velocity(v);
  590. }
  591. void BulletPhysicsServer::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) {
  592. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  593. ERR_FAIL_COND(!body);
  594. body->set_axis_lock(p_axis, p_lock);
  595. }
  596. bool BulletPhysicsServer::body_is_axis_locked(RID p_body, BodyAxis p_axis) const {
  597. const RigidBodyBullet *body = rigid_body_owner.get(p_body);
  598. ERR_FAIL_COND_V(!body, 0);
  599. return body->is_axis_locked(p_axis);
  600. }
  601. void BulletPhysicsServer::body_add_collision_exception(RID p_body, RID p_body_b) {
  602. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  603. ERR_FAIL_COND(!body);
  604. RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b);
  605. ERR_FAIL_COND(!other_body);
  606. body->add_collision_exception(other_body);
  607. }
  608. void BulletPhysicsServer::body_remove_collision_exception(RID p_body, RID p_body_b) {
  609. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  610. ERR_FAIL_COND(!body);
  611. RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b);
  612. ERR_FAIL_COND(!other_body);
  613. body->remove_collision_exception(other_body);
  614. }
  615. void BulletPhysicsServer::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  616. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  617. ERR_FAIL_COND(!body);
  618. for (int i = 0; i < body->get_exceptions().size(); i++) {
  619. p_exceptions->push_back(body->get_exceptions()[i]);
  620. }
  621. }
  622. void BulletPhysicsServer::body_set_max_contacts_reported(RID p_body, int p_contacts) {
  623. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  624. ERR_FAIL_COND(!body);
  625. body->set_max_collisions_detection(p_contacts);
  626. }
  627. int BulletPhysicsServer::body_get_max_contacts_reported(RID p_body) const {
  628. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  629. ERR_FAIL_COND_V(!body, 0);
  630. return body->get_max_collisions_detection();
  631. }
  632. void BulletPhysicsServer::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) {
  633. // Not supported by bullet and even Godot
  634. }
  635. float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body) const {
  636. // Not supported by bullet and even Godot
  637. return 0.;
  638. }
  639. void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) {
  640. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  641. ERR_FAIL_COND(!body);
  642. body->set_omit_forces_integration(p_omit);
  643. }
  644. bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const {
  645. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  646. ERR_FAIL_COND_V(!body, false);
  647. return body->get_omit_forces_integration();
  648. }
  649. void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
  650. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  651. ERR_FAIL_COND(!body);
  652. body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata);
  653. }
  654. void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) {
  655. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  656. ERR_FAIL_COND(!body);
  657. body->set_ray_pickable(p_enable);
  658. }
  659. bool BulletPhysicsServer::body_is_ray_pickable(RID p_body) const {
  660. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  661. ERR_FAIL_COND_V(!body, false);
  662. return body->is_ray_pickable();
  663. }
  664. PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) {
  665. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  666. ERR_FAIL_COND_V(!body, NULL);
  667. return BulletPhysicsDirectBodyState::get_singleton(body);
  668. }
  669. bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) {
  670. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  671. ERR_FAIL_COND_V(!body, false);
  672. ERR_FAIL_COND_V(!body->get_space(), false);
  673. return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result, p_exclude_raycast_shapes);
  674. }
  675. int BulletPhysicsServer::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) {
  676. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  677. ERR_FAIL_COND_V(!body, 0);
  678. ERR_FAIL_COND_V(!body->get_space(), 0);
  679. return body->get_space()->test_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin);
  680. }
  681. RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) {
  682. SoftBodyBullet *body = bulletnew(SoftBodyBullet);
  683. body->set_collision_layer(1);
  684. body->set_collision_mask(1);
  685. if (p_init_sleeping)
  686. body->set_activation_state(false);
  687. CreateThenReturnRID(soft_body_owner, body);
  688. }
  689. void BulletPhysicsServer::soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler) {
  690. SoftBodyBullet *body = soft_body_owner.get(p_body);
  691. ERR_FAIL_COND(!body);
  692. body->update_visual_server(p_visual_server_handler);
  693. }
  694. void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) {
  695. SoftBodyBullet *body = soft_body_owner.get(p_body);
  696. ERR_FAIL_COND(!body);
  697. SpaceBullet *space = NULL;
  698. if (p_space.is_valid()) {
  699. space = space_owner.get(p_space);
  700. ERR_FAIL_COND(!space);
  701. }
  702. if (body->get_space() == space)
  703. return; //pointles
  704. body->set_space(space);
  705. }
  706. RID BulletPhysicsServer::soft_body_get_space(RID p_body) const {
  707. SoftBodyBullet *body = soft_body_owner.get(p_body);
  708. ERR_FAIL_COND_V(!body, RID());
  709. SpaceBullet *space = body->get_space();
  710. if (!space)
  711. return RID();
  712. return space->get_self();
  713. }
  714. void BulletPhysicsServer::soft_body_set_mesh(RID p_body, const REF &p_mesh) {
  715. SoftBodyBullet *body = soft_body_owner.get(p_body);
  716. ERR_FAIL_COND(!body);
  717. body->set_soft_mesh(p_mesh);
  718. }
  719. void BulletPhysicsServer::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
  720. SoftBodyBullet *body = soft_body_owner.get(p_body);
  721. ERR_FAIL_COND(!body);
  722. body->set_collision_layer(p_layer);
  723. }
  724. uint32_t BulletPhysicsServer::soft_body_get_collision_layer(RID p_body) const {
  725. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  726. ERR_FAIL_COND_V(!body, 0);
  727. return body->get_collision_layer();
  728. }
  729. void BulletPhysicsServer::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
  730. SoftBodyBullet *body = soft_body_owner.get(p_body);
  731. ERR_FAIL_COND(!body);
  732. body->set_collision_mask(p_mask);
  733. }
  734. uint32_t BulletPhysicsServer::soft_body_get_collision_mask(RID p_body) const {
  735. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  736. ERR_FAIL_COND_V(!body, 0);
  737. return body->get_collision_mask();
  738. }
  739. void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_body_b) {
  740. SoftBodyBullet *body = soft_body_owner.get(p_body);
  741. ERR_FAIL_COND(!body);
  742. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  743. if (!other_body) {
  744. other_body = soft_body_owner.get(p_body_b);
  745. }
  746. ERR_FAIL_COND(!other_body);
  747. body->add_collision_exception(other_body);
  748. }
  749. void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p_body_b) {
  750. SoftBodyBullet *body = soft_body_owner.get(p_body);
  751. ERR_FAIL_COND(!body);
  752. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  753. if (!other_body) {
  754. other_body = soft_body_owner.get(p_body_b);
  755. }
  756. ERR_FAIL_COND(!other_body);
  757. body->remove_collision_exception(other_body);
  758. }
  759. void BulletPhysicsServer::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  760. SoftBodyBullet *body = soft_body_owner.get(p_body);
  761. ERR_FAIL_COND(!body);
  762. for (int i = 0; i < body->get_exceptions().size(); i++) {
  763. p_exceptions->push_back(body->get_exceptions()[i]);
  764. }
  765. }
  766. void BulletPhysicsServer::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  767. // FIXME: Must be implemented.
  768. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  769. }
  770. Variant BulletPhysicsServer::soft_body_get_state(RID p_body, BodyState p_state) const {
  771. // FIXME: Must be implemented.
  772. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  773. return Variant();
  774. }
  775. void BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform &p_transform) {
  776. SoftBodyBullet *body = soft_body_owner.get(p_body);
  777. ERR_FAIL_COND(!body);
  778. body->set_soft_transform(p_transform);
  779. }
  780. Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int vertex_index) const {
  781. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  782. Vector3 pos;
  783. ERR_FAIL_COND_V(!body, pos);
  784. body->get_node_position(vertex_index, pos);
  785. return pos;
  786. }
  787. void BulletPhysicsServer::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
  788. SoftBodyBullet *body = soft_body_owner.get(p_body);
  789. ERR_FAIL_COND(!body);
  790. body->set_ray_pickable(p_enable);
  791. }
  792. bool BulletPhysicsServer::soft_body_is_ray_pickable(RID p_body) const {
  793. SoftBodyBullet *body = soft_body_owner.get(p_body);
  794. ERR_FAIL_COND_V(!body, false);
  795. return body->is_ray_pickable();
  796. }
  797. void BulletPhysicsServer::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) {
  798. SoftBodyBullet *body = soft_body_owner.get(p_body);
  799. ERR_FAIL_COND(!body);
  800. body->set_simulation_precision(p_simulation_precision);
  801. }
  802. int BulletPhysicsServer::soft_body_get_simulation_precision(RID p_body) {
  803. SoftBodyBullet *body = soft_body_owner.get(p_body);
  804. ERR_FAIL_COND_V(!body, 0.f);
  805. return body->get_simulation_precision();
  806. }
  807. void BulletPhysicsServer::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
  808. SoftBodyBullet *body = soft_body_owner.get(p_body);
  809. ERR_FAIL_COND(!body);
  810. body->set_total_mass(p_total_mass);
  811. }
  812. real_t BulletPhysicsServer::soft_body_get_total_mass(RID p_body) {
  813. SoftBodyBullet *body = soft_body_owner.get(p_body);
  814. ERR_FAIL_COND_V(!body, 0.f);
  815. return body->get_total_mass();
  816. }
  817. void BulletPhysicsServer::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) {
  818. SoftBodyBullet *body = soft_body_owner.get(p_body);
  819. ERR_FAIL_COND(!body);
  820. body->set_linear_stiffness(p_stiffness);
  821. }
  822. real_t BulletPhysicsServer::soft_body_get_linear_stiffness(RID p_body) {
  823. SoftBodyBullet *body = soft_body_owner.get(p_body);
  824. ERR_FAIL_COND_V(!body, 0.f);
  825. return body->get_linear_stiffness();
  826. }
  827. void BulletPhysicsServer::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) {
  828. SoftBodyBullet *body = soft_body_owner.get(p_body);
  829. ERR_FAIL_COND(!body);
  830. body->set_areaAngular_stiffness(p_stiffness);
  831. }
  832. real_t BulletPhysicsServer::soft_body_get_areaAngular_stiffness(RID p_body) {
  833. SoftBodyBullet *body = soft_body_owner.get(p_body);
  834. ERR_FAIL_COND_V(!body, 0.f);
  835. return body->get_areaAngular_stiffness();
  836. }
  837. void BulletPhysicsServer::soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) {
  838. SoftBodyBullet *body = soft_body_owner.get(p_body);
  839. ERR_FAIL_COND(!body);
  840. body->set_volume_stiffness(p_stiffness);
  841. }
  842. real_t BulletPhysicsServer::soft_body_get_volume_stiffness(RID p_body) {
  843. SoftBodyBullet *body = soft_body_owner.get(p_body);
  844. ERR_FAIL_COND_V(!body, 0.f);
  845. return body->get_volume_stiffness();
  846. }
  847. void BulletPhysicsServer::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) {
  848. SoftBodyBullet *body = soft_body_owner.get(p_body);
  849. ERR_FAIL_COND(!body);
  850. body->set_pressure_coefficient(p_pressure_coefficient);
  851. }
  852. real_t BulletPhysicsServer::soft_body_get_pressure_coefficient(RID p_body) {
  853. SoftBodyBullet *body = soft_body_owner.get(p_body);
  854. ERR_FAIL_COND_V(!body, 0.f);
  855. return body->get_pressure_coefficient();
  856. }
  857. void BulletPhysicsServer::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) {
  858. SoftBodyBullet *body = soft_body_owner.get(p_body);
  859. ERR_FAIL_COND(!body);
  860. return body->set_pose_matching_coefficient(p_pose_matching_coefficient);
  861. }
  862. real_t BulletPhysicsServer::soft_body_get_pose_matching_coefficient(RID p_body) {
  863. SoftBodyBullet *body = soft_body_owner.get(p_body);
  864. ERR_FAIL_COND_V(!body, 0.f);
  865. return body->get_pose_matching_coefficient();
  866. }
  867. void BulletPhysicsServer::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) {
  868. SoftBodyBullet *body = soft_body_owner.get(p_body);
  869. ERR_FAIL_COND(!body);
  870. body->set_damping_coefficient(p_damping_coefficient);
  871. }
  872. real_t BulletPhysicsServer::soft_body_get_damping_coefficient(RID p_body) {
  873. SoftBodyBullet *body = soft_body_owner.get(p_body);
  874. ERR_FAIL_COND_V(!body, 0.f);
  875. return body->get_damping_coefficient();
  876. }
  877. void BulletPhysicsServer::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) {
  878. SoftBodyBullet *body = soft_body_owner.get(p_body);
  879. ERR_FAIL_COND(!body);
  880. body->set_drag_coefficient(p_drag_coefficient);
  881. }
  882. real_t BulletPhysicsServer::soft_body_get_drag_coefficient(RID p_body) {
  883. SoftBodyBullet *body = soft_body_owner.get(p_body);
  884. ERR_FAIL_COND_V(!body, 0.f);
  885. return body->get_drag_coefficient();
  886. }
  887. void BulletPhysicsServer::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
  888. SoftBodyBullet *body = soft_body_owner.get(p_body);
  889. ERR_FAIL_COND(!body);
  890. body->set_node_position(p_point_index, p_global_position);
  891. }
  892. Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int p_point_index) {
  893. SoftBodyBullet *body = soft_body_owner.get(p_body);
  894. ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.));
  895. Vector3 pos;
  896. body->get_node_position(p_point_index, pos);
  897. return pos;
  898. }
  899. Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_index) const {
  900. SoftBodyBullet *body = soft_body_owner.get(p_body);
  901. ERR_FAIL_COND_V(!body, Vector3());
  902. Vector3 res;
  903. body->get_node_offset(p_point_index, res);
  904. return res;
  905. }
  906. void BulletPhysicsServer::soft_body_remove_all_pinned_points(RID p_body) {
  907. SoftBodyBullet *body = soft_body_owner.get(p_body);
  908. ERR_FAIL_COND(!body);
  909. body->reset_all_node_mass();
  910. }
  911. void BulletPhysicsServer::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
  912. SoftBodyBullet *body = soft_body_owner.get(p_body);
  913. ERR_FAIL_COND(!body);
  914. body->set_node_mass(p_point_index, p_pin ? 0 : 1);
  915. }
  916. bool BulletPhysicsServer::soft_body_is_point_pinned(RID p_body, int p_point_index) {
  917. SoftBodyBullet *body = soft_body_owner.get(p_body);
  918. ERR_FAIL_COND_V(!body, 0.f);
  919. return body->get_node_mass(p_point_index);
  920. }
  921. PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const {
  922. JointBullet *joint = joint_owner.get(p_joint);
  923. ERR_FAIL_COND_V(!joint, JOINT_PIN);
  924. return joint->get_type();
  925. }
  926. void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) {
  927. // Joint priority not supported by bullet
  928. }
  929. int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
  930. // Joint priority not supported by bullet
  931. return 0;
  932. }
  933. void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
  934. JointBullet *joint = joint_owner.get(p_joint);
  935. ERR_FAIL_COND(!joint);
  936. joint->disable_collisions_between_bodies(p_disable);
  937. }
  938. bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
  939. JointBullet *joint(joint_owner.get(p_joint));
  940. ERR_FAIL_COND_V(!joint, false);
  941. return joint->is_disabled_collisions_between_bodies();
  942. }
  943. RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
  944. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  945. ERR_FAIL_COND_V(!body_A, RID());
  946. JointAssertSpace(body_A, "A", RID());
  947. RigidBodyBullet *body_B = NULL;
  948. if (p_body_B.is_valid()) {
  949. body_B = rigid_body_owner.get(p_body_B);
  950. JointAssertSpace(body_B, "B", RID());
  951. JointAssertSameSpace(body_A, body_B, RID());
  952. }
  953. ERR_FAIL_COND_V(body_A == body_B, RID());
  954. JointBullet *joint = bulletnew(PinJointBullet(body_A, p_local_A, body_B, p_local_B));
  955. AddJointToSpace(body_A, joint);
  956. CreateThenReturnRID(joint_owner, joint);
  957. }
  958. void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) {
  959. JointBullet *joint = joint_owner.get(p_joint);
  960. ERR_FAIL_COND(!joint);
  961. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  962. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  963. pin_joint->set_param(p_param, p_value);
  964. }
  965. float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
  966. JointBullet *joint = joint_owner.get(p_joint);
  967. ERR_FAIL_COND_V(!joint, 0);
  968. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0);
  969. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  970. return pin_joint->get_param(p_param);
  971. }
  972. void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) {
  973. JointBullet *joint = joint_owner.get(p_joint);
  974. ERR_FAIL_COND(!joint);
  975. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  976. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  977. pin_joint->setPivotInA(p_A);
  978. }
  979. Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const {
  980. JointBullet *joint = joint_owner.get(p_joint);
  981. ERR_FAIL_COND_V(!joint, Vector3());
  982. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  983. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  984. return pin_joint->getPivotInA();
  985. }
  986. void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) {
  987. JointBullet *joint = joint_owner.get(p_joint);
  988. ERR_FAIL_COND(!joint);
  989. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  990. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  991. pin_joint->setPivotInB(p_B);
  992. }
  993. Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const {
  994. JointBullet *joint = joint_owner.get(p_joint);
  995. ERR_FAIL_COND_V(!joint, Vector3());
  996. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  997. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  998. return pin_joint->getPivotInB();
  999. }
  1000. RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) {
  1001. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1002. ERR_FAIL_COND_V(!body_A, RID());
  1003. JointAssertSpace(body_A, "A", RID());
  1004. RigidBodyBullet *body_B = NULL;
  1005. if (p_body_B.is_valid()) {
  1006. body_B = rigid_body_owner.get(p_body_B);
  1007. JointAssertSpace(body_B, "B", RID());
  1008. JointAssertSameSpace(body_A, body_B, RID());
  1009. }
  1010. ERR_FAIL_COND_V(body_A == body_B, RID());
  1011. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_hinge_A, p_hinge_B));
  1012. AddJointToSpace(body_A, joint);
  1013. CreateThenReturnRID(joint_owner, joint);
  1014. }
  1015. RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) {
  1016. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1017. ERR_FAIL_COND_V(!body_A, RID());
  1018. JointAssertSpace(body_A, "A", RID());
  1019. RigidBodyBullet *body_B = NULL;
  1020. if (p_body_B.is_valid()) {
  1021. body_B = rigid_body_owner.get(p_body_B);
  1022. JointAssertSpace(body_B, "B", RID());
  1023. JointAssertSameSpace(body_A, body_B, RID());
  1024. }
  1025. ERR_FAIL_COND_V(body_A == body_B, RID());
  1026. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
  1027. AddJointToSpace(body_A, joint);
  1028. CreateThenReturnRID(joint_owner, joint);
  1029. }
  1030. void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) {
  1031. JointBullet *joint = joint_owner.get(p_joint);
  1032. ERR_FAIL_COND(!joint);
  1033. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1034. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1035. hinge_joint->set_param(p_param, p_value);
  1036. }
  1037. float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
  1038. JointBullet *joint = joint_owner.get(p_joint);
  1039. ERR_FAIL_COND_V(!joint, 0);
  1040. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0);
  1041. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1042. return hinge_joint->get_param(p_param);
  1043. }
  1044. void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) {
  1045. JointBullet *joint = joint_owner.get(p_joint);
  1046. ERR_FAIL_COND(!joint);
  1047. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1048. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1049. hinge_joint->set_flag(p_flag, p_value);
  1050. }
  1051. bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
  1052. JointBullet *joint = joint_owner.get(p_joint);
  1053. ERR_FAIL_COND_V(!joint, false);
  1054. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false);
  1055. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1056. return hinge_joint->get_flag(p_flag);
  1057. }
  1058. RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
  1059. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1060. ERR_FAIL_COND_V(!body_A, RID());
  1061. JointAssertSpace(body_A, "A", RID());
  1062. RigidBodyBullet *body_B = NULL;
  1063. if (p_body_B.is_valid()) {
  1064. body_B = rigid_body_owner.get(p_body_B);
  1065. JointAssertSpace(body_B, "B", RID());
  1066. JointAssertSameSpace(body_A, body_B, RID());
  1067. }
  1068. ERR_FAIL_COND_V(body_A == body_B, RID());
  1069. JointBullet *joint = bulletnew(SliderJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1070. AddJointToSpace(body_A, joint);
  1071. CreateThenReturnRID(joint_owner, joint);
  1072. }
  1073. void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) {
  1074. JointBullet *joint = joint_owner.get(p_joint);
  1075. ERR_FAIL_COND(!joint);
  1076. ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER);
  1077. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1078. slider_joint->set_param(p_param, p_value);
  1079. }
  1080. float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
  1081. JointBullet *joint = joint_owner.get(p_joint);
  1082. ERR_FAIL_COND_V(!joint, 0);
  1083. ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0);
  1084. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1085. return slider_joint->get_param(p_param);
  1086. }
  1087. RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
  1088. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1089. ERR_FAIL_COND_V(!body_A, RID());
  1090. JointAssertSpace(body_A, "A", RID());
  1091. RigidBodyBullet *body_B = NULL;
  1092. if (p_body_B.is_valid()) {
  1093. body_B = rigid_body_owner.get(p_body_B);
  1094. JointAssertSpace(body_B, "B", RID());
  1095. JointAssertSameSpace(body_A, body_B, RID());
  1096. }
  1097. JointBullet *joint = bulletnew(ConeTwistJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1098. AddJointToSpace(body_A, joint);
  1099. CreateThenReturnRID(joint_owner, joint);
  1100. }
  1101. void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) {
  1102. JointBullet *joint = joint_owner.get(p_joint);
  1103. ERR_FAIL_COND(!joint);
  1104. ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST);
  1105. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1106. coneTwist_joint->set_param(p_param, p_value);
  1107. }
  1108. float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
  1109. JointBullet *joint = joint_owner.get(p_joint);
  1110. ERR_FAIL_COND_V(!joint, 0.);
  1111. ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.);
  1112. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1113. return coneTwist_joint->get_param(p_param);
  1114. }
  1115. RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
  1116. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1117. ERR_FAIL_COND_V(!body_A, RID());
  1118. JointAssertSpace(body_A, "A", RID());
  1119. RigidBodyBullet *body_B = NULL;
  1120. if (p_body_B.is_valid()) {
  1121. body_B = rigid_body_owner.get(p_body_B);
  1122. JointAssertSpace(body_B, "B", RID());
  1123. JointAssertSameSpace(body_A, body_B, RID());
  1124. }
  1125. ERR_FAIL_COND_V(body_A == body_B, RID());
  1126. JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1127. AddJointToSpace(body_A, joint);
  1128. CreateThenReturnRID(joint_owner, joint);
  1129. }
  1130. void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) {
  1131. JointBullet *joint = joint_owner.get(p_joint);
  1132. ERR_FAIL_COND(!joint);
  1133. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1134. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1135. generic_6dof_joint->set_param(p_axis, p_param, p_value);
  1136. }
  1137. float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) {
  1138. JointBullet *joint = joint_owner.get(p_joint);
  1139. ERR_FAIL_COND_V(!joint, 0);
  1140. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
  1141. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1142. return generic_6dof_joint->get_param(p_axis, p_param);
  1143. }
  1144. void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) {
  1145. JointBullet *joint = joint_owner.get(p_joint);
  1146. ERR_FAIL_COND(!joint);
  1147. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1148. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1149. generic_6dof_joint->set_flag(p_axis, p_flag, p_enable);
  1150. }
  1151. bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) {
  1152. JointBullet *joint = joint_owner.get(p_joint);
  1153. ERR_FAIL_COND_V(!joint, false);
  1154. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false);
  1155. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1156. return generic_6dof_joint->get_flag(p_axis, p_flag);
  1157. }
  1158. void BulletPhysicsServer::generic_6dof_joint_set_precision(RID p_joint, int p_precision) {
  1159. JointBullet *joint = joint_owner.get(p_joint);
  1160. ERR_FAIL_COND(!joint);
  1161. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1162. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1163. generic_6dof_joint->set_precision(p_precision);
  1164. }
  1165. int BulletPhysicsServer::generic_6dof_joint_get_precision(RID p_joint) {
  1166. JointBullet *joint = joint_owner.get(p_joint);
  1167. ERR_FAIL_COND_V(!joint, 0);
  1168. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
  1169. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1170. return generic_6dof_joint->get_precision();
  1171. }
  1172. void BulletPhysicsServer::free(RID p_rid) {
  1173. if (shape_owner.owns(p_rid)) {
  1174. ShapeBullet *shape = shape_owner.get(p_rid);
  1175. // Notify the shape is configured
  1176. for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) {
  1177. static_cast<ShapeOwnerBullet *>(element->key())->remove_shape_full(shape);
  1178. }
  1179. shape_owner.free(p_rid);
  1180. bulletdelete(shape);
  1181. } else if (rigid_body_owner.owns(p_rid)) {
  1182. RigidBodyBullet *body = rigid_body_owner.get(p_rid);
  1183. body->set_space(NULL);
  1184. body->remove_all_shapes(true, true);
  1185. rigid_body_owner.free(p_rid);
  1186. bulletdelete(body);
  1187. } else if (soft_body_owner.owns(p_rid)) {
  1188. SoftBodyBullet *body = soft_body_owner.get(p_rid);
  1189. body->set_space(NULL);
  1190. soft_body_owner.free(p_rid);
  1191. bulletdelete(body);
  1192. } else if (area_owner.owns(p_rid)) {
  1193. AreaBullet *area = area_owner.get(p_rid);
  1194. area->set_space(NULL);
  1195. area->remove_all_shapes(true, true);
  1196. area_owner.free(p_rid);
  1197. bulletdelete(area);
  1198. } else if (joint_owner.owns(p_rid)) {
  1199. JointBullet *joint = joint_owner.get(p_rid);
  1200. joint->destroy_internal_constraint();
  1201. joint_owner.free(p_rid);
  1202. bulletdelete(joint);
  1203. } else if (space_owner.owns(p_rid)) {
  1204. SpaceBullet *space = space_owner.get(p_rid);
  1205. space->remove_all_collision_objects();
  1206. space_set_active(p_rid, false);
  1207. space_owner.free(p_rid);
  1208. bulletdelete(space);
  1209. } else {
  1210. ERR_EXPLAIN("Invalid ID");
  1211. ERR_FAIL();
  1212. }
  1213. }
  1214. void BulletPhysicsServer::init() {
  1215. BulletPhysicsDirectBodyState::initSingleton();
  1216. }
  1217. void BulletPhysicsServer::step(float p_deltaTime) {
  1218. if (!active)
  1219. return;
  1220. BulletPhysicsDirectBodyState::singleton_setDeltaTime(p_deltaTime);
  1221. for (int i = 0; i < active_spaces_count; ++i) {
  1222. active_spaces[i]->step(p_deltaTime);
  1223. }
  1224. }
  1225. void BulletPhysicsServer::sync() {
  1226. }
  1227. void BulletPhysicsServer::flush_queries() {
  1228. }
  1229. void BulletPhysicsServer::finish() {
  1230. BulletPhysicsDirectBodyState::destroySingleton();
  1231. }
  1232. int BulletPhysicsServer::get_process_info(ProcessInfo p_info) {
  1233. return 0;
  1234. }
  1235. CollisionObjectBullet *BulletPhysicsServer::get_collisin_object(RID p_object) const {
  1236. if (rigid_body_owner.owns(p_object)) {
  1237. return rigid_body_owner.getornull(p_object);
  1238. }
  1239. if (area_owner.owns(p_object)) {
  1240. return area_owner.getornull(p_object);
  1241. }
  1242. if (soft_body_owner.owns(p_object)) {
  1243. return soft_body_owner.getornull(p_object);
  1244. }
  1245. return NULL;
  1246. }
  1247. RigidCollisionObjectBullet *BulletPhysicsServer::get_rigid_collisin_object(RID p_object) const {
  1248. if (rigid_body_owner.owns(p_object)) {
  1249. return rigid_body_owner.getornull(p_object);
  1250. }
  1251. if (area_owner.owns(p_object)) {
  1252. return area_owner.getornull(p_object);
  1253. }
  1254. return NULL;
  1255. }