physics_2d_server.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*************************************************************************/
  2. /* physics_2d_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "physics_2d_server.h"
  30. #include "print_string.h"
  31. Physics2DServer * Physics2DServer::singleton=NULL;
  32. void Physics2DDirectBodyState::integrate_forces() {
  33. real_t step = get_step();
  34. Vector2 lv = get_linear_velocity();
  35. lv+=get_total_gravity() * step;
  36. real_t av = get_angular_velocity();
  37. float damp = 1.0 - step * get_total_density();
  38. if (damp<0) // reached zero in the given time
  39. damp=0;
  40. lv*=damp;
  41. av*=damp;
  42. set_linear_velocity(lv);
  43. set_angular_velocity(av);
  44. }
  45. Object* Physics2DDirectBodyState::get_contact_collider_object(int p_contact_idx) const {
  46. ObjectID objid = get_contact_collider_id(p_contact_idx);
  47. Object *obj = ObjectDB::get_instance( objid );
  48. return obj;
  49. }
  50. Physics2DServer * Physics2DServer::get_singleton() {
  51. return singleton;
  52. }
  53. void Physics2DDirectBodyState::_bind_methods() {
  54. ObjectTypeDB::bind_method(_MD("get_total_gravity"),&Physics2DDirectBodyState::get_total_gravity);
  55. ObjectTypeDB::bind_method(_MD("get_total_density"),&Physics2DDirectBodyState::get_total_density);
  56. ObjectTypeDB::bind_method(_MD("get_inverse_mass"),&Physics2DDirectBodyState::get_inverse_mass);
  57. ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&Physics2DDirectBodyState::get_inverse_inertia);
  58. ObjectTypeDB::bind_method(_MD("set_linear_velocity","velocity"),&Physics2DDirectBodyState::set_linear_velocity);
  59. ObjectTypeDB::bind_method(_MD("get_linear_velocity"),&Physics2DDirectBodyState::get_linear_velocity);
  60. ObjectTypeDB::bind_method(_MD("set_angular_velocity","velocity"),&Physics2DDirectBodyState::set_angular_velocity);
  61. ObjectTypeDB::bind_method(_MD("get_angular_velocity"),&Physics2DDirectBodyState::get_angular_velocity);
  62. ObjectTypeDB::bind_method(_MD("set_transform","transform"),&Physics2DDirectBodyState::set_transform);
  63. ObjectTypeDB::bind_method(_MD("get_transform"),&Physics2DDirectBodyState::get_transform);
  64. ObjectTypeDB::bind_method(_MD("set_sleep_state","enabled"),&Physics2DDirectBodyState::set_sleep_state);
  65. ObjectTypeDB::bind_method(_MD("is_sleeping"),&Physics2DDirectBodyState::is_sleeping);
  66. ObjectTypeDB::bind_method(_MD("get_contact_count"),&Physics2DDirectBodyState::get_contact_count);
  67. ObjectTypeDB::bind_method(_MD("get_contact_local_pos","contact_idx"),&Physics2DDirectBodyState::get_contact_local_pos);
  68. ObjectTypeDB::bind_method(_MD("get_contact_local_normal","contact_idx"),&Physics2DDirectBodyState::get_contact_local_normal);
  69. ObjectTypeDB::bind_method(_MD("get_contact_local_shape","contact_idx"),&Physics2DDirectBodyState::get_contact_local_shape);
  70. ObjectTypeDB::bind_method(_MD("get_contact_collider","contact_idx"),&Physics2DDirectBodyState::get_contact_collider);
  71. ObjectTypeDB::bind_method(_MD("get_contact_collider_pos","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_pos);
  72. ObjectTypeDB::bind_method(_MD("get_contact_collider_id","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_id);
  73. ObjectTypeDB::bind_method(_MD("get_contact_collider_object","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_object);
  74. ObjectTypeDB::bind_method(_MD("get_contact_collider_shape","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_shape);
  75. ObjectTypeDB::bind_method(_MD("get_contact_collider_shape_metadata:var","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_shape_metadata);
  76. ObjectTypeDB::bind_method(_MD("get_contact_collider_velocity_at_pos","contact_idx"),&Physics2DDirectBodyState::get_contact_collider_velocity_at_pos);
  77. ObjectTypeDB::bind_method(_MD("get_step"),&Physics2DDirectBodyState::get_step);
  78. ObjectTypeDB::bind_method(_MD("integrate_forces"),&Physics2DDirectBodyState::integrate_forces);
  79. ObjectTypeDB::bind_method(_MD("get_space_state:Physics2DDirectSpaceState"),&Physics2DDirectBodyState::get_space_state);
  80. }
  81. Physics2DDirectBodyState::Physics2DDirectBodyState() {}
  82. ///////////////////////////////////////////////////////
  83. void Physics2DShapeQueryParameters::set_shape(const RES &p_shape) {
  84. ERR_FAIL_COND(p_shape.is_null());
  85. shape=p_shape->get_rid();
  86. }
  87. void Physics2DShapeQueryParameters::set_shape_rid(const RID& p_shape) {
  88. shape=p_shape;
  89. }
  90. RID Physics2DShapeQueryParameters::get_shape_rid() const {
  91. return shape;
  92. }
  93. void Physics2DShapeQueryParameters::set_transform(const Matrix32& p_transform){
  94. transform=p_transform;
  95. }
  96. Matrix32 Physics2DShapeQueryParameters::get_transform() const{
  97. return transform;
  98. }
  99. void Physics2DShapeQueryParameters::set_motion(const Vector2& p_motion){
  100. motion=p_motion;
  101. }
  102. Vector2 Physics2DShapeQueryParameters::get_motion() const{
  103. return motion;
  104. }
  105. void Physics2DShapeQueryParameters::set_margin(float p_margin){
  106. margin=p_margin;
  107. }
  108. float Physics2DShapeQueryParameters::get_margin() const{
  109. return margin;
  110. }
  111. void Physics2DShapeQueryParameters::set_layer_mask(int p_layer_mask){
  112. layer_mask=p_layer_mask;
  113. }
  114. int Physics2DShapeQueryParameters::get_layer_mask() const{
  115. return layer_mask;
  116. }
  117. void Physics2DShapeQueryParameters::set_object_type_mask(int p_object_type_mask){
  118. object_type_mask=p_object_type_mask;
  119. }
  120. int Physics2DShapeQueryParameters::get_object_type_mask() const{
  121. return object_type_mask;
  122. }
  123. void Physics2DShapeQueryParameters::set_exclude(const Vector<RID>& p_exclude) {
  124. exclude.clear();;
  125. for(int i=0;i<p_exclude.size();i++)
  126. exclude.insert(p_exclude[i]);
  127. }
  128. Vector<RID> Physics2DShapeQueryParameters::get_exclude() const{
  129. Vector<RID> ret;
  130. ret.resize(exclude.size());
  131. int idx=0;
  132. for(Set<RID>::Element *E=exclude.front();E;E=E->next()) {
  133. ret[idx]=E->get();
  134. }
  135. return ret;
  136. }
  137. void Physics2DShapeQueryParameters::_bind_methods() {
  138. ObjectTypeDB::bind_method(_MD("set_shape","shape:Shape2D"),&Physics2DShapeQueryParameters::set_shape);
  139. ObjectTypeDB::bind_method(_MD("set_shape_rid","shape"),&Physics2DShapeQueryParameters::set_shape_rid);
  140. ObjectTypeDB::bind_method(_MD("get_shape_rid"),&Physics2DShapeQueryParameters::get_shape_rid);
  141. ObjectTypeDB::bind_method(_MD("set_transform","transform"),&Physics2DShapeQueryParameters::set_transform);
  142. ObjectTypeDB::bind_method(_MD("get_transform"),&Physics2DShapeQueryParameters::get_transform);
  143. ObjectTypeDB::bind_method(_MD("set_motion","motion"),&Physics2DShapeQueryParameters::set_motion);
  144. ObjectTypeDB::bind_method(_MD("get_motion"),&Physics2DShapeQueryParameters::get_motion);
  145. ObjectTypeDB::bind_method(_MD("set_margin","margin"),&Physics2DShapeQueryParameters::set_margin);
  146. ObjectTypeDB::bind_method(_MD("get_margin"),&Physics2DShapeQueryParameters::get_margin);
  147. ObjectTypeDB::bind_method(_MD("set_layer_mask","layer_mask"),&Physics2DShapeQueryParameters::set_layer_mask);
  148. ObjectTypeDB::bind_method(_MD("get_layer_mask"),&Physics2DShapeQueryParameters::get_layer_mask);
  149. ObjectTypeDB::bind_method(_MD("set_object_type_mask","object_type_mask"),&Physics2DShapeQueryParameters::set_object_type_mask);
  150. ObjectTypeDB::bind_method(_MD("get_object_type_mask"),&Physics2DShapeQueryParameters::get_object_type_mask);
  151. ObjectTypeDB::bind_method(_MD("set_exclude","exclude"),&Physics2DShapeQueryParameters::set_exclude);
  152. ObjectTypeDB::bind_method(_MD("get_exclude"),&Physics2DShapeQueryParameters::get_exclude);
  153. }
  154. Physics2DShapeQueryParameters::Physics2DShapeQueryParameters() {
  155. margin=0;
  156. layer_mask=0x7FFFFFFF;
  157. object_type_mask=Physics2DDirectSpaceState::TYPE_MASK_COLLISION;
  158. }
  159. Dictionary Physics2DDirectSpaceState::_intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector<RID>& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) {
  160. RayResult inters;
  161. Set<RID> exclude;
  162. for(int i=0;i<p_exclude.size();i++)
  163. exclude.insert(p_exclude[i]);
  164. bool res = intersect_ray(p_from,p_to,inters,exclude,p_layers,p_object_type_mask);
  165. if (!res)
  166. return Dictionary(true);
  167. Dictionary d(true);
  168. d["position"]=inters.position;
  169. d["normal"]=inters.normal;
  170. d["collider_id"]=inters.collider_id;
  171. d["collider"]=inters.collider;
  172. d["shape"]=inters.shape;
  173. d["rid"]=inters.rid;
  174. d["metadata"]=inters.metadata;
  175. return d;
  176. }
  177. Array Physics2DDirectSpaceState::_intersect_shape(const Ref<Physics2DShapeQueryParameters> &psq, int p_max_results) {
  178. Vector<ShapeResult> sr;
  179. sr.resize(p_max_results);
  180. int rc = intersect_shape(psq->shape,psq->transform,psq->motion,psq->margin,sr.ptr(),sr.size(),psq->exclude,psq->layer_mask,psq->object_type_mask);
  181. Array ret;
  182. ret.resize(rc);
  183. for(int i=0;i<rc;i++) {
  184. Dictionary d;
  185. d["rid"]=sr[i].rid;
  186. d["collider_id"]=sr[i].collider_id;
  187. d["collider"]=sr[i].collider;
  188. d["shape"]=sr[i].shape;
  189. d["metadata"]=sr[i].metadata;
  190. ret[i]=d;
  191. }
  192. return ret;
  193. }
  194. Array Physics2DDirectSpaceState::_cast_motion(const Ref<Physics2DShapeQueryParameters> &psq){
  195. float closest_safe,closest_unsafe;
  196. bool res = cast_motion(psq->shape,psq->transform,psq->motion,psq->margin,closest_safe,closest_unsafe,psq->exclude,psq->layer_mask,psq->object_type_mask);
  197. if (!res)
  198. return Array();
  199. Array ret(true);
  200. ret.resize(2);
  201. ret[0]=closest_safe;
  202. ret[0]=closest_unsafe;
  203. return ret;
  204. }
  205. Array Physics2DDirectSpaceState::_collide_shape(const Ref<Physics2DShapeQueryParameters> &psq, int p_max_results){
  206. Vector<Vector2> ret;
  207. ret.resize(p_max_results*2);
  208. int rc=0;
  209. bool res = collide_shape(psq->shape,psq->transform,psq->motion,psq->margin,ret.ptr(),p_max_results,rc,psq->exclude,psq->layer_mask,psq->object_type_mask);
  210. if (!res)
  211. return Array();
  212. Array r;
  213. r.resize(rc*2);
  214. for(int i=0;i<rc*2;i++)
  215. r[i]=ret[i];
  216. return r;
  217. }
  218. Dictionary Physics2DDirectSpaceState::_get_rest_info(const Ref<Physics2DShapeQueryParameters> &psq){
  219. ShapeRestInfo sri;
  220. bool res = rest_info(psq->shape,psq->transform,psq->motion,psq->margin,&sri,psq->exclude,psq->layer_mask,psq->object_type_mask);
  221. Dictionary r(true);
  222. if (!res)
  223. return r;
  224. r["point"]=sri.point;
  225. r["normal"]=sri.normal;
  226. r["rid"]=sri.rid;
  227. r["collider_id"]=sri.collider_id;
  228. r["shape"]=sri.shape;
  229. r["linear_velocity"]=sri.linear_velocity;
  230. r["metadata"]=sri.metadata;
  231. return r;
  232. }
  233. Physics2DDirectSpaceState::Physics2DDirectSpaceState() {
  234. }
  235. void Physics2DDirectSpaceState::_bind_methods() {
  236. ObjectTypeDB::bind_method(_MD("intersect_ray:Dictionary","from","to","exclude","layer_mask","type_mask"),&Physics2DDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION));
  237. ObjectTypeDB::bind_method(_MD("intersect_shape","shape:Physics2DShapeQueryParameters","max_results"),&Physics2DDirectSpaceState::_intersect_shape,DEFVAL(32));
  238. ObjectTypeDB::bind_method(_MD("cast_motion","shape:Physics2DShapeQueryParameters"),&Physics2DDirectSpaceState::_cast_motion);
  239. ObjectTypeDB::bind_method(_MD("collide_shape","shape:Physics2DShapeQueryParameters","max_results"),&Physics2DDirectSpaceState::_collide_shape,DEFVAL(32));
  240. ObjectTypeDB::bind_method(_MD("get_rest_info","shape:Physics2DShapeQueryParameters"),&Physics2DDirectSpaceState::_get_rest_info);
  241. //ObjectTypeDB::bind_method(_MD("cast_motion","shape","xform","motion","exclude","umask"),&Physics2DDirectSpaceState::_intersect_shape,DEFVAL(Array()),DEFVAL(0));
  242. BIND_CONSTANT( TYPE_MASK_STATIC_BODY );
  243. BIND_CONSTANT( TYPE_MASK_KINEMATIC_BODY );
  244. BIND_CONSTANT( TYPE_MASK_RIGID_BODY );
  245. BIND_CONSTANT( TYPE_MASK_CHARACTER_BODY );
  246. BIND_CONSTANT( TYPE_MASK_AREA );
  247. BIND_CONSTANT( TYPE_MASK_COLLISION );
  248. }
  249. int Physics2DShapeQueryResult::get_result_count() const {
  250. return result.size();
  251. }
  252. RID Physics2DShapeQueryResult::get_result_rid(int p_idx) const {
  253. return result[p_idx].rid;
  254. }
  255. ObjectID Physics2DShapeQueryResult::get_result_object_id(int p_idx) const {
  256. return result[p_idx].collider_id;
  257. }
  258. Object* Physics2DShapeQueryResult::get_result_object(int p_idx) const {
  259. return result[p_idx].collider;
  260. }
  261. int Physics2DShapeQueryResult::get_result_object_shape(int p_idx) const {
  262. return result[p_idx].shape;
  263. }
  264. Physics2DShapeQueryResult::Physics2DShapeQueryResult() {
  265. }
  266. void Physics2DShapeQueryResult::_bind_methods() {
  267. ObjectTypeDB::bind_method(_MD("get_result_count"),&Physics2DShapeQueryResult::get_result_count);
  268. ObjectTypeDB::bind_method(_MD("get_result_rid","idx"),&Physics2DShapeQueryResult::get_result_rid);
  269. ObjectTypeDB::bind_method(_MD("get_result_object_id","idx"),&Physics2DShapeQueryResult::get_result_object_id);
  270. ObjectTypeDB::bind_method(_MD("get_result_object","idx"),&Physics2DShapeQueryResult::get_result_object);
  271. ObjectTypeDB::bind_method(_MD("get_result_object_shape","idx"),&Physics2DShapeQueryResult::get_result_object_shape);
  272. }
  273. ///////////////////////////////////////
  274. void Physics2DServer::_bind_methods() {
  275. ObjectTypeDB::bind_method(_MD("shape_create","type"),&Physics2DServer::shape_create);
  276. ObjectTypeDB::bind_method(_MD("shape_set_data","shape","data"),&Physics2DServer::shape_set_data);
  277. ObjectTypeDB::bind_method(_MD("shape_get_type","shape"),&Physics2DServer::shape_get_type);
  278. ObjectTypeDB::bind_method(_MD("shape_get_data","shape"),&Physics2DServer::shape_get_data);
  279. ObjectTypeDB::bind_method(_MD("space_create"),&Physics2DServer::space_create);
  280. ObjectTypeDB::bind_method(_MD("space_set_active","space","active"),&Physics2DServer::space_set_active);
  281. ObjectTypeDB::bind_method(_MD("space_is_active","space"),&Physics2DServer::space_is_active);
  282. ObjectTypeDB::bind_method(_MD("space_set_param","space","param","value"),&Physics2DServer::space_set_param);
  283. ObjectTypeDB::bind_method(_MD("space_get_param","space","param"),&Physics2DServer::space_get_param);
  284. ObjectTypeDB::bind_method(_MD("space_get_direct_state:Physics2DDirectSpaceState","space"),&Physics2DServer::space_get_direct_state);
  285. ObjectTypeDB::bind_method(_MD("area_create"),&Physics2DServer::area_create);
  286. ObjectTypeDB::bind_method(_MD("area_set_space","area","space"),&Physics2DServer::area_set_space);
  287. ObjectTypeDB::bind_method(_MD("area_get_space","area"),&Physics2DServer::area_get_space);
  288. ObjectTypeDB::bind_method(_MD("area_set_space_override_mode","area","mode"),&Physics2DServer::area_set_space_override_mode);
  289. ObjectTypeDB::bind_method(_MD("area_get_space_override_mode","area"),&Physics2DServer::area_get_space_override_mode);
  290. ObjectTypeDB::bind_method(_MD("area_add_shape","area","shape","transform"),&Physics2DServer::area_add_shape,DEFVAL(Matrix32()));
  291. ObjectTypeDB::bind_method(_MD("area_set_shape","area","shape_idx","shape"),&Physics2DServer::area_set_shape);
  292. ObjectTypeDB::bind_method(_MD("area_set_shape_transform","area","shape_idx","transform"),&Physics2DServer::area_set_shape_transform);
  293. ObjectTypeDB::bind_method(_MD("area_get_shape_count","area"),&Physics2DServer::area_get_shape_count);
  294. ObjectTypeDB::bind_method(_MD("area_get_shape","area","shape_idx"),&Physics2DServer::area_get_shape);
  295. ObjectTypeDB::bind_method(_MD("area_get_shape_transform","area","shape_idx"),&Physics2DServer::area_get_shape_transform);
  296. ObjectTypeDB::bind_method(_MD("area_remove_shape","area","shape_idx"),&Physics2DServer::area_remove_shape);
  297. ObjectTypeDB::bind_method(_MD("area_clear_shapes","area"),&Physics2DServer::area_clear_shapes);
  298. ObjectTypeDB::bind_method(_MD("area_set_param","area","param","value"),&Physics2DServer::area_set_param);
  299. ObjectTypeDB::bind_method(_MD("area_set_transform","area","transform"),&Physics2DServer::area_set_transform);
  300. ObjectTypeDB::bind_method(_MD("area_get_param","area","param"),&Physics2DServer::area_get_param);
  301. ObjectTypeDB::bind_method(_MD("area_get_transform","area"),&Physics2DServer::area_get_transform);
  302. ObjectTypeDB::bind_method(_MD("area_attach_object_instance_ID","area","id"),&Physics2DServer::area_attach_object_instance_ID);
  303. ObjectTypeDB::bind_method(_MD("area_get_object_instance_ID","area"),&Physics2DServer::area_get_object_instance_ID);
  304. ObjectTypeDB::bind_method(_MD("area_set_monitor_callback","receiver","method"),&Physics2DServer::area_set_monitor_callback);
  305. ObjectTypeDB::bind_method(_MD("body_create","mode","init_sleeping"),&Physics2DServer::body_create,DEFVAL(BODY_MODE_RIGID),DEFVAL(false));
  306. ObjectTypeDB::bind_method(_MD("body_set_space","body","space"),&Physics2DServer::body_set_space);
  307. ObjectTypeDB::bind_method(_MD("body_get_space","body"),&Physics2DServer::body_get_space);
  308. ObjectTypeDB::bind_method(_MD("body_set_mode","body","mode"),&Physics2DServer::body_set_mode);
  309. ObjectTypeDB::bind_method(_MD("body_get_mode","body"),&Physics2DServer::body_get_mode);
  310. ObjectTypeDB::bind_method(_MD("body_add_shape","body","shape","transform"),&Physics2DServer::body_add_shape,DEFVAL(Matrix32()));
  311. ObjectTypeDB::bind_method(_MD("body_set_shape","body","shape_idx","shape"),&Physics2DServer::body_set_shape);
  312. ObjectTypeDB::bind_method(_MD("body_set_shape_transform","body","shape_idx","transform"),&Physics2DServer::body_set_shape_transform);
  313. ObjectTypeDB::bind_method(_MD("body_set_shape_metadata","body","shape_idx","metadata"),&Physics2DServer::body_set_shape_metadata);
  314. ObjectTypeDB::bind_method(_MD("body_get_shape_count","body"),&Physics2DServer::body_get_shape_count);
  315. ObjectTypeDB::bind_method(_MD("body_get_shape","body","shape_idx"),&Physics2DServer::body_get_shape);
  316. ObjectTypeDB::bind_method(_MD("body_get_shape_transform","body","shape_idx"),&Physics2DServer::body_get_shape_transform);
  317. ObjectTypeDB::bind_method(_MD("body_get_shape_metadata","body","shape_idx"),&Physics2DServer::body_get_shape_metadata);
  318. ObjectTypeDB::bind_method(_MD("body_remove_shape","body","shape_idx"),&Physics2DServer::body_remove_shape);
  319. ObjectTypeDB::bind_method(_MD("body_clear_shapes","body"),&Physics2DServer::body_clear_shapes);
  320. ObjectTypeDB::bind_method(_MD("body_set_shape_as_trigger","body","shape_idx","enable"),&Physics2DServer::body_set_shape_as_trigger);
  321. ObjectTypeDB::bind_method(_MD("body_is_shape_set_as_trigger","body","shape_idx"),&Physics2DServer::body_is_shape_set_as_trigger);
  322. ObjectTypeDB::bind_method(_MD("body_attach_object_instance_ID","body","id"),&Physics2DServer::body_attach_object_instance_ID);
  323. ObjectTypeDB::bind_method(_MD("body_get_object_instance_ID","body"),&Physics2DServer::body_get_object_instance_ID);
  324. ObjectTypeDB::bind_method(_MD("body_set_continuous_collision_detection_mode","body","mode"),&Physics2DServer::body_set_continuous_collision_detection_mode);
  325. ObjectTypeDB::bind_method(_MD("body_get_continuous_collision_detection_mode","body"),&Physics2DServer::body_get_continuous_collision_detection_mode);
  326. ObjectTypeDB::bind_method(_MD("body_set_layer_mask","body","mask"),&Physics2DServer::body_set_layer_mask);
  327. ObjectTypeDB::bind_method(_MD("body_get_layer_mask","body"),&Physics2DServer::body_get_layer_mask);
  328. ObjectTypeDB::bind_method(_MD("body_set_user_mask","body","mask"),&Physics2DServer::body_set_user_mask);
  329. ObjectTypeDB::bind_method(_MD("body_get_user_mask","body"),&Physics2DServer::body_get_user_mask);
  330. ObjectTypeDB::bind_method(_MD("body_set_param","body","param","value"),&Physics2DServer::body_set_param);
  331. ObjectTypeDB::bind_method(_MD("body_get_param","body","param"),&Physics2DServer::body_get_param);
  332. ObjectTypeDB::bind_method(_MD("body_set_state","body","state","value"),&Physics2DServer::body_set_state);
  333. ObjectTypeDB::bind_method(_MD("body_get_state","body","state"),&Physics2DServer::body_get_state);
  334. ObjectTypeDB::bind_method(_MD("body_apply_impulse","body","pos","impulse"),&Physics2DServer::body_apply_impulse);
  335. ObjectTypeDB::bind_method(_MD("body_set_axis_velocity","body","axis_velocity"),&Physics2DServer::body_set_axis_velocity);
  336. ObjectTypeDB::bind_method(_MD("body_add_collision_exception","body","excepted_body"),&Physics2DServer::body_add_collision_exception);
  337. ObjectTypeDB::bind_method(_MD("body_remove_collision_exception","body","excepted_body"),&Physics2DServer::body_remove_collision_exception);
  338. // virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions)=0;
  339. ObjectTypeDB::bind_method(_MD("body_set_max_contacts_reported","body","amount"),&Physics2DServer::body_set_max_contacts_reported);
  340. ObjectTypeDB::bind_method(_MD("body_get_max_contacts_reported","body"),&Physics2DServer::body_get_max_contacts_reported);
  341. ObjectTypeDB::bind_method(_MD("body_set_omit_force_integration","body","enable"),&Physics2DServer::body_set_omit_force_integration);
  342. ObjectTypeDB::bind_method(_MD("body_is_omitting_force_integration","body"),&Physics2DServer::body_is_omitting_force_integration);
  343. ObjectTypeDB::bind_method(_MD("body_set_force_integration_callback","body","receiver","method"),&Physics2DServer::body_set_force_integration_callback);
  344. /* JOINT API */
  345. ObjectTypeDB::bind_method(_MD("joint_set_param","joint","param","value"),&Physics2DServer::joint_set_param);
  346. ObjectTypeDB::bind_method(_MD("joint_get_param","joint","param"),&Physics2DServer::joint_get_param);
  347. ObjectTypeDB::bind_method(_MD("pin_joint_create","anchor","body_a","body_b"),&Physics2DServer::pin_joint_create,DEFVAL(RID()));
  348. ObjectTypeDB::bind_method(_MD("groove_joint_create","groove1_a","groove2_a","anchor_b","body_a","body_b"),&Physics2DServer::groove_joint_create,DEFVAL(RID()),DEFVAL(RID()));
  349. ObjectTypeDB::bind_method(_MD("damped_spring_joint_create","anchor_a","anchor_b","body_a","body_b"),&Physics2DServer::damped_spring_joint_create,DEFVAL(RID()));
  350. ObjectTypeDB::bind_method(_MD("damped_string_joint_set_param","joint","param","value"),&Physics2DServer::damped_string_joint_set_param,DEFVAL(RID()));
  351. ObjectTypeDB::bind_method(_MD("damped_string_joint_get_param","joint","param"),&Physics2DServer::damped_string_joint_get_param);
  352. ObjectTypeDB::bind_method(_MD("joint_get_type","joint"),&Physics2DServer::joint_get_type);
  353. ObjectTypeDB::bind_method(_MD("free_rid","rid"),&Physics2DServer::free);
  354. ObjectTypeDB::bind_method(_MD("set_active","active"),&Physics2DServer::set_active);
  355. ObjectTypeDB::bind_method(_MD("get_process_info"),&Physics2DServer::get_process_info);
  356. // ObjectTypeDB::bind_method(_MD("init"),&Physics2DServer::init);
  357. // ObjectTypeDB::bind_method(_MD("step"),&Physics2DServer::step);
  358. // ObjectTypeDB::bind_method(_MD("sync"),&Physics2DServer::sync);
  359. //ObjectTypeDB::bind_method(_MD("flush_queries"),&Physics2DServer::flush_queries);
  360. BIND_CONSTANT( SHAPE_LINE );
  361. BIND_CONSTANT( SHAPE_SEGMENT );
  362. BIND_CONSTANT( SHAPE_CIRCLE );
  363. BIND_CONSTANT( SHAPE_RECTANGLE );
  364. BIND_CONSTANT( SHAPE_CAPSULE );
  365. BIND_CONSTANT( SHAPE_CONVEX_POLYGON );
  366. BIND_CONSTANT( SHAPE_CONCAVE_POLYGON );
  367. BIND_CONSTANT( SHAPE_CUSTOM );
  368. BIND_CONSTANT( AREA_PARAM_GRAVITY );
  369. BIND_CONSTANT( AREA_PARAM_GRAVITY_VECTOR );
  370. BIND_CONSTANT( AREA_PARAM_GRAVITY_IS_POINT );
  371. BIND_CONSTANT( AREA_PARAM_GRAVITY_POINT_ATTENUATION );
  372. BIND_CONSTANT( AREA_PARAM_DENSITY );
  373. BIND_CONSTANT( AREA_PARAM_PRIORITY );
  374. BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
  375. BIND_CONSTANT( AREA_SPACE_OVERRIDE_DISABLED );
  376. BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE );
  377. BIND_CONSTANT( BODY_MODE_STATIC );
  378. BIND_CONSTANT( BODY_MODE_KINEMATIC );
  379. BIND_CONSTANT( BODY_MODE_RIGID );
  380. BIND_CONSTANT( BODY_MODE_CHARACTER );
  381. BIND_CONSTANT( BODY_PARAM_BOUNCE );
  382. BIND_CONSTANT( BODY_PARAM_FRICTION );
  383. BIND_CONSTANT( BODY_PARAM_MASS );
  384. BIND_CONSTANT( BODY_PARAM_MAX );
  385. BIND_CONSTANT( BODY_STATE_TRANSFORM );
  386. BIND_CONSTANT( BODY_STATE_LINEAR_VELOCITY );
  387. BIND_CONSTANT( BODY_STATE_ANGULAR_VELOCITY );
  388. BIND_CONSTANT( BODY_STATE_SLEEPING );
  389. BIND_CONSTANT( BODY_STATE_CAN_SLEEP );
  390. BIND_CONSTANT( JOINT_PIN );
  391. BIND_CONSTANT( JOINT_GROOVE );
  392. BIND_CONSTANT( JOINT_DAMPED_SPRING );
  393. BIND_CONSTANT( DAMPED_STRING_REST_LENGTH );
  394. BIND_CONSTANT( DAMPED_STRING_STIFFNESS );
  395. BIND_CONSTANT( DAMPED_STRING_DAMPING );
  396. BIND_CONSTANT( CCD_MODE_DISABLED );
  397. BIND_CONSTANT( CCD_MODE_CAST_RAY );
  398. BIND_CONSTANT( CCD_MODE_CAST_SHAPE );
  399. // BIND_CONSTANT( TYPE_BODY );
  400. // BIND_CONSTANT( TYPE_AREA );
  401. BIND_CONSTANT( AREA_BODY_ADDED );
  402. BIND_CONSTANT( AREA_BODY_REMOVED );
  403. BIND_CONSTANT( INFO_ACTIVE_OBJECTS );
  404. BIND_CONSTANT( INFO_COLLISION_PAIRS );
  405. BIND_CONSTANT( INFO_ISLAND_COUNT );
  406. }
  407. Physics2DServer::Physics2DServer() {
  408. ERR_FAIL_COND( singleton!=NULL );
  409. singleton=this;
  410. }
  411. Physics2DServer::~Physics2DServer() {
  412. singleton=NULL;
  413. }