physics_server.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*************************************************************************/
  2. /* physics_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 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_server.h"
  30. #include "print_string.h"
  31. PhysicsServer * PhysicsServer::singleton=NULL;
  32. void PhysicsDirectBodyState::integrate_forces() {
  33. real_t step = get_step();
  34. Vector3 lv = get_linear_velocity();
  35. lv+=get_total_gravity() * step;
  36. Vector3 av = get_angular_velocity();
  37. float linear_damp = 1.0 - step * get_total_linear_damp();
  38. if (linear_damp<0) // reached zero in the given time
  39. linear_damp=0;
  40. float angular_damp = 1.0 - step * get_total_angular_damp();
  41. if (angular_damp<0) // reached zero in the given time
  42. angular_damp=0;
  43. lv*=linear_damp;
  44. av*=angular_damp;
  45. set_linear_velocity(lv);
  46. set_angular_velocity(av);
  47. }
  48. Object* PhysicsDirectBodyState::get_contact_collider_object(int p_contact_idx) const {
  49. ObjectID objid = get_contact_collider_id(p_contact_idx);
  50. Object *obj = ObjectDB::get_instance( objid );
  51. return obj;
  52. }
  53. PhysicsServer * PhysicsServer::get_singleton() {
  54. return singleton;
  55. }
  56. void PhysicsDirectBodyState::_bind_methods() {
  57. ObjectTypeDB::bind_method(_MD("get_total_gravity"),&PhysicsDirectBodyState::get_total_gravity);
  58. ObjectTypeDB::bind_method(_MD("get_total_linear_damp"),&PhysicsDirectBodyState::get_total_linear_damp);
  59. ObjectTypeDB::bind_method(_MD("get_total_angular_damp"),&PhysicsDirectBodyState::get_total_angular_damp);
  60. ObjectTypeDB::bind_method(_MD("get_inverse_mass"),&PhysicsDirectBodyState::get_inverse_mass);
  61. ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&PhysicsDirectBodyState::get_inverse_inertia);
  62. ObjectTypeDB::bind_method(_MD("set_linear_velocity","velocity"),&PhysicsDirectBodyState::set_linear_velocity);
  63. ObjectTypeDB::bind_method(_MD("get_linear_velocity"),&PhysicsDirectBodyState::get_linear_velocity);
  64. ObjectTypeDB::bind_method(_MD("set_angular_velocity","velocity"),&PhysicsDirectBodyState::set_angular_velocity);
  65. ObjectTypeDB::bind_method(_MD("get_angular_velocity"),&PhysicsDirectBodyState::get_angular_velocity);
  66. ObjectTypeDB::bind_method(_MD("set_transform","transform"),&PhysicsDirectBodyState::set_transform);
  67. ObjectTypeDB::bind_method(_MD("get_transform"),&PhysicsDirectBodyState::get_transform);
  68. ObjectTypeDB::bind_method(_MD("add_force","force","pos"),&PhysicsDirectBodyState::add_force);
  69. ObjectTypeDB::bind_method(_MD("apply_impulse","pos","j"),&PhysicsDirectBodyState::apply_impulse);
  70. ObjectTypeDB::bind_method(_MD("set_sleep_state","enabled"),&PhysicsDirectBodyState::set_sleep_state);
  71. ObjectTypeDB::bind_method(_MD("is_sleeping"),&PhysicsDirectBodyState::is_sleeping);
  72. ObjectTypeDB::bind_method(_MD("get_contact_count"),&PhysicsDirectBodyState::get_contact_count);
  73. ObjectTypeDB::bind_method(_MD("get_contact_local_pos","contact_idx"),&PhysicsDirectBodyState::get_contact_local_pos);
  74. ObjectTypeDB::bind_method(_MD("get_contact_local_normal","contact_idx"),&PhysicsDirectBodyState::get_contact_local_normal);
  75. ObjectTypeDB::bind_method(_MD("get_contact_local_shape","contact_idx"),&PhysicsDirectBodyState::get_contact_local_shape);
  76. ObjectTypeDB::bind_method(_MD("get_contact_collider","contact_idx"),&PhysicsDirectBodyState::get_contact_collider);
  77. ObjectTypeDB::bind_method(_MD("get_contact_collider_pos","contact_idx"),&PhysicsDirectBodyState::get_contact_collider_pos);
  78. ObjectTypeDB::bind_method(_MD("get_contact_collider_id","contact_idx"),&PhysicsDirectBodyState::get_contact_collider_id);
  79. ObjectTypeDB::bind_method(_MD("get_contact_collider_object","contact_idx"),&PhysicsDirectBodyState::get_contact_collider_object);
  80. ObjectTypeDB::bind_method(_MD("get_contact_collider_shape","contact_idx"),&PhysicsDirectBodyState::get_contact_collider_shape);
  81. ObjectTypeDB::bind_method(_MD("get_contact_collider_velocity_at_pos","contact_idx"),&PhysicsDirectBodyState::get_contact_collider_velocity_at_pos);
  82. ObjectTypeDB::bind_method(_MD("get_step"),&PhysicsDirectBodyState::get_step);
  83. ObjectTypeDB::bind_method(_MD("integrate_forces"),&PhysicsDirectBodyState::integrate_forces);
  84. ObjectTypeDB::bind_method(_MD("get_space_state:PhysicsDirectSpaceState"),&PhysicsDirectBodyState::get_space_state);
  85. }
  86. PhysicsDirectBodyState::PhysicsDirectBodyState() {}
  87. ///////////////////////////////////////////////////////
  88. void PhysicsShapeQueryParameters::set_shape(const RES &p_shape) {
  89. ERR_FAIL_COND(p_shape.is_null());
  90. shape=p_shape->get_rid();
  91. }
  92. void PhysicsShapeQueryParameters::set_shape_rid(const RID& p_shape) {
  93. shape=p_shape;
  94. }
  95. RID PhysicsShapeQueryParameters::get_shape_rid() const {
  96. return shape;
  97. }
  98. void PhysicsShapeQueryParameters::set_transform(const Transform& p_transform){
  99. transform=p_transform;
  100. }
  101. Transform PhysicsShapeQueryParameters::get_transform() const{
  102. return transform;
  103. }
  104. void PhysicsShapeQueryParameters::set_margin(float p_margin){
  105. margin=p_margin;
  106. }
  107. float PhysicsShapeQueryParameters::get_margin() const{
  108. return margin;
  109. }
  110. void PhysicsShapeQueryParameters::set_layer_mask(int p_layer_mask){
  111. layer_mask=p_layer_mask;
  112. }
  113. int PhysicsShapeQueryParameters::get_layer_mask() const{
  114. return layer_mask;
  115. }
  116. void PhysicsShapeQueryParameters::set_object_type_mask(int p_object_type_mask){
  117. object_type_mask=p_object_type_mask;
  118. }
  119. int PhysicsShapeQueryParameters::get_object_type_mask() const{
  120. return object_type_mask;
  121. }
  122. void PhysicsShapeQueryParameters::set_exclude(const Vector<RID>& p_exclude) {
  123. exclude.clear();;
  124. for(int i=0;i<p_exclude.size();i++)
  125. exclude.insert(p_exclude[i]);
  126. }
  127. Vector<RID> PhysicsShapeQueryParameters::get_exclude() const{
  128. Vector<RID> ret;
  129. ret.resize(exclude.size());
  130. int idx=0;
  131. for(Set<RID>::Element *E=exclude.front();E;E=E->next()) {
  132. ret[idx]=E->get();
  133. }
  134. return ret;
  135. }
  136. void PhysicsShapeQueryParameters::_bind_methods() {
  137. ObjectTypeDB::bind_method(_MD("set_shape","shape:Shape"),&PhysicsShapeQueryParameters::set_shape);
  138. ObjectTypeDB::bind_method(_MD("set_shape_rid","shape"),&PhysicsShapeQueryParameters::set_shape_rid);
  139. ObjectTypeDB::bind_method(_MD("get_shape_rid"),&PhysicsShapeQueryParameters::get_shape_rid);
  140. ObjectTypeDB::bind_method(_MD("set_transform","transform"),&PhysicsShapeQueryParameters::set_transform);
  141. ObjectTypeDB::bind_method(_MD("get_transform"),&PhysicsShapeQueryParameters::get_transform);
  142. ObjectTypeDB::bind_method(_MD("set_margin","margin"),&PhysicsShapeQueryParameters::set_margin);
  143. ObjectTypeDB::bind_method(_MD("get_margin"),&PhysicsShapeQueryParameters::get_margin);
  144. ObjectTypeDB::bind_method(_MD("set_layer_mask","layer_mask"),&PhysicsShapeQueryParameters::set_layer_mask);
  145. ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsShapeQueryParameters::get_layer_mask);
  146. ObjectTypeDB::bind_method(_MD("set_object_type_mask","object_type_mask"),&PhysicsShapeQueryParameters::set_object_type_mask);
  147. ObjectTypeDB::bind_method(_MD("get_object_type_mask"),&PhysicsShapeQueryParameters::get_object_type_mask);
  148. ObjectTypeDB::bind_method(_MD("set_exclude","exclude"),&PhysicsShapeQueryParameters::set_exclude);
  149. ObjectTypeDB::bind_method(_MD("get_exclude"),&PhysicsShapeQueryParameters::get_exclude);
  150. }
  151. PhysicsShapeQueryParameters::PhysicsShapeQueryParameters() {
  152. margin=0;
  153. layer_mask=0x7FFFFFFF;
  154. object_type_mask=PhysicsDirectSpaceState::TYPE_MASK_COLLISION;
  155. }
  156. /////////////////////////////////////
  157. /*
  158. Variant PhysicsDirectSpaceState::_intersect_shape(const RID& p_shape, const Transform& p_xform,int p_result_max,const Vector<RID>& p_exclude,uint32_t p_collision_mask) {
  159. ERR_FAIL_INDEX_V(p_result_max,4096,Variant());
  160. if (p_result_max<=0)
  161. return Variant();
  162. Set<RID> exclude;
  163. for(int i=0;i<p_exclude.size();i++)
  164. exclude.insert(p_exclude[i]);
  165. ShapeResult *res=(ShapeResult*)alloca(p_result_max*sizeof(ShapeResult));
  166. int rc = intersect_shape(p_shape,p_xform,0,res,p_result_max,exclude);
  167. if (rc==0)
  168. return Variant();
  169. Ref<PhysicsShapeQueryResult> result = memnew( PhysicsShapeQueryResult );
  170. result->result.resize(rc);
  171. for(int i=0;i<rc;i++)
  172. result->result[i]=res[i];
  173. return result;
  174. }
  175. */
  176. Dictionary PhysicsDirectSpaceState::_intersect_ray(const Vector3& p_from, const Vector3& p_to,const Vector<RID>& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) {
  177. RayResult inters;
  178. Set<RID> exclude;
  179. for(int i=0;i<p_exclude.size();i++)
  180. exclude.insert(p_exclude[i]);
  181. bool res = intersect_ray(p_from,p_to,inters,exclude,p_layers,p_object_type_mask);
  182. if (!res)
  183. return Dictionary(true);
  184. Dictionary d(true);
  185. d["position"]=inters.position;
  186. d["normal"]=inters.normal;
  187. d["collider_id"]=inters.collider_id;
  188. d["collider"]=inters.collider;
  189. d["shape"]=inters.shape;
  190. d["rid"]=inters.rid;
  191. return d;
  192. }
  193. Array PhysicsDirectSpaceState::_intersect_shape(const Ref<PhysicsShapeQueryParameters> &psq, int p_max_results) {
  194. Vector<ShapeResult> sr;
  195. sr.resize(p_max_results);
  196. int rc = intersect_shape(psq->shape,psq->transform,psq->margin,sr.ptr(),sr.size(),psq->exclude,psq->layer_mask,psq->object_type_mask);
  197. Array ret;
  198. ret.resize(rc);
  199. for(int i=0;i<rc;i++) {
  200. Dictionary d;
  201. d["rid"]=sr[i].rid;
  202. d["collider_id"]=sr[i].collider_id;
  203. d["collider"]=sr[i].collider;
  204. d["shape"]=sr[i].shape;
  205. ret[i]=d;
  206. }
  207. return ret;
  208. }
  209. Array PhysicsDirectSpaceState::_cast_motion(const Ref<PhysicsShapeQueryParameters> &psq,const Vector3& p_motion){
  210. float closest_safe,closest_unsafe;
  211. bool res = cast_motion(psq->shape,psq->transform,p_motion,psq->margin,closest_safe,closest_unsafe,psq->exclude,psq->layer_mask,psq->object_type_mask);
  212. if (!res)
  213. return Array();
  214. Array ret(true);
  215. ret.resize(2);
  216. ret[0]=closest_safe;
  217. ret[1]=closest_unsafe;
  218. return ret;
  219. }
  220. Array PhysicsDirectSpaceState::_collide_shape(const Ref<PhysicsShapeQueryParameters> &psq, int p_max_results){
  221. Vector<Vector3> ret;
  222. ret.resize(p_max_results*2);
  223. int rc=0;
  224. bool res = collide_shape(psq->shape,psq->transform,psq->margin,ret.ptr(),p_max_results,rc,psq->exclude,psq->layer_mask,psq->object_type_mask);
  225. if (!res)
  226. return Array();
  227. Array r;
  228. r.resize(rc*2);
  229. for(int i=0;i<rc*2;i++)
  230. r[i]=ret[i];
  231. return r;
  232. }
  233. Dictionary PhysicsDirectSpaceState::_get_rest_info(const Ref<PhysicsShapeQueryParameters> &psq){
  234. ShapeRestInfo sri;
  235. bool res = rest_info(psq->shape,psq->transform,psq->margin,&sri,psq->exclude,psq->layer_mask,psq->object_type_mask);
  236. Dictionary r(true);
  237. if (!res)
  238. return r;
  239. r["point"]=sri.point;
  240. r["normal"]=sri.normal;
  241. r["rid"]=sri.rid;
  242. r["collider_id"]=sri.collider_id;
  243. r["shape"]=sri.shape;
  244. r["linear_velocity"]=sri.linear_velocity;
  245. return r;
  246. }
  247. PhysicsDirectSpaceState::PhysicsDirectSpaceState() {
  248. }
  249. void PhysicsDirectSpaceState::_bind_methods() {
  250. // ObjectTypeDB::bind_method(_MD("intersect_ray","from","to","exclude","umask"),&PhysicsDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0));
  251. // ObjectTypeDB::bind_method(_MD("intersect_shape:PhysicsShapeQueryResult","shape","xform","result_max","exclude","umask"),&PhysicsDirectSpaceState::_intersect_shape,DEFVAL(Array()),DEFVAL(0));
  252. ObjectTypeDB::bind_method(_MD("intersect_ray:Dictionary","from","to","exclude","layer_mask","type_mask"),&PhysicsDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION));
  253. ObjectTypeDB::bind_method(_MD("intersect_shape","shape:PhysicsShapeQueryParameters","max_results"),&PhysicsDirectSpaceState::_intersect_shape,DEFVAL(32));
  254. ObjectTypeDB::bind_method(_MD("cast_motion","shape:PhysicsShapeQueryParameters","motion"),&PhysicsDirectSpaceState::_cast_motion);
  255. ObjectTypeDB::bind_method(_MD("collide_shape","shape:PhysicsShapeQueryParameters","max_results"),&PhysicsDirectSpaceState::_collide_shape,DEFVAL(32));
  256. ObjectTypeDB::bind_method(_MD("get_rest_info","shape:PhysicsShapeQueryParameters"),&PhysicsDirectSpaceState::_get_rest_info);
  257. BIND_CONSTANT( TYPE_MASK_STATIC_BODY );
  258. BIND_CONSTANT( TYPE_MASK_KINEMATIC_BODY );
  259. BIND_CONSTANT( TYPE_MASK_RIGID_BODY );
  260. BIND_CONSTANT( TYPE_MASK_CHARACTER_BODY );
  261. BIND_CONSTANT( TYPE_MASK_AREA );
  262. BIND_CONSTANT( TYPE_MASK_COLLISION );
  263. }
  264. int PhysicsShapeQueryResult::get_result_count() const {
  265. return result.size();
  266. }
  267. RID PhysicsShapeQueryResult::get_result_rid(int p_idx) const {
  268. return result[p_idx].rid;
  269. }
  270. ObjectID PhysicsShapeQueryResult::get_result_object_id(int p_idx) const {
  271. return result[p_idx].collider_id;
  272. }
  273. Object* PhysicsShapeQueryResult::get_result_object(int p_idx) const {
  274. return result[p_idx].collider;
  275. }
  276. int PhysicsShapeQueryResult::get_result_object_shape(int p_idx) const {
  277. return result[p_idx].shape;
  278. }
  279. PhysicsShapeQueryResult::PhysicsShapeQueryResult() {
  280. }
  281. void PhysicsShapeQueryResult::_bind_methods() {
  282. ObjectTypeDB::bind_method(_MD("get_result_count"),&PhysicsShapeQueryResult::get_result_count);
  283. ObjectTypeDB::bind_method(_MD("get_result_rid","idx"),&PhysicsShapeQueryResult::get_result_rid);
  284. ObjectTypeDB::bind_method(_MD("get_result_object_id","idx"),&PhysicsShapeQueryResult::get_result_object_id);
  285. ObjectTypeDB::bind_method(_MD("get_result_object","idx"),&PhysicsShapeQueryResult::get_result_object);
  286. ObjectTypeDB::bind_method(_MD("get_result_object_shape","idx"),&PhysicsShapeQueryResult::get_result_object_shape);
  287. }
  288. ///////////////////////////////////////
  289. void PhysicsServer::_bind_methods() {
  290. ObjectTypeDB::bind_method(_MD("shape_create","type"),&PhysicsServer::shape_create);
  291. ObjectTypeDB::bind_method(_MD("shape_set_data","shape","data"),&PhysicsServer::shape_set_data);
  292. ObjectTypeDB::bind_method(_MD("shape_get_type","shape"),&PhysicsServer::shape_get_type);
  293. ObjectTypeDB::bind_method(_MD("shape_get_data","shape"),&PhysicsServer::shape_get_data);
  294. ObjectTypeDB::bind_method(_MD("space_create"),&PhysicsServer::space_create);
  295. ObjectTypeDB::bind_method(_MD("space_set_active","space","active"),&PhysicsServer::space_set_active);
  296. ObjectTypeDB::bind_method(_MD("space_is_active","space"),&PhysicsServer::space_is_active);
  297. ObjectTypeDB::bind_method(_MD("space_set_param","space","param","value"),&PhysicsServer::space_set_param);
  298. ObjectTypeDB::bind_method(_MD("space_get_param","space","param"),&PhysicsServer::space_get_param);
  299. ObjectTypeDB::bind_method(_MD("space_get_direct_state:PhysicsDirectSpaceState","space"),&PhysicsServer::space_get_direct_state);
  300. ObjectTypeDB::bind_method(_MD("area_create"),&PhysicsServer::area_create);
  301. ObjectTypeDB::bind_method(_MD("area_set_space","area","space"),&PhysicsServer::area_set_space);
  302. ObjectTypeDB::bind_method(_MD("area_get_space","area"),&PhysicsServer::area_get_space);
  303. ObjectTypeDB::bind_method(_MD("area_set_space_override_mode","area","mode"),&PhysicsServer::area_set_space_override_mode);
  304. ObjectTypeDB::bind_method(_MD("area_get_space_override_mode","area"),&PhysicsServer::area_get_space_override_mode);
  305. ObjectTypeDB::bind_method(_MD("area_add_shape","area","shape","transform"),&PhysicsServer::area_add_shape,DEFVAL(Transform()));
  306. ObjectTypeDB::bind_method(_MD("area_set_shape","area","shape_idx","shape"),&PhysicsServer::area_set_shape);
  307. ObjectTypeDB::bind_method(_MD("area_set_shape_transform","area","shape_idx","transform"),&PhysicsServer::area_set_shape_transform);
  308. ObjectTypeDB::bind_method(_MD("area_get_shape_count","area"),&PhysicsServer::area_get_shape_count);
  309. ObjectTypeDB::bind_method(_MD("area_get_shape","area","shape_idx"),&PhysicsServer::area_get_shape);
  310. ObjectTypeDB::bind_method(_MD("area_get_shape_transform","area","shape_idx"),&PhysicsServer::area_get_shape_transform);
  311. ObjectTypeDB::bind_method(_MD("area_remove_shape","area","shape_idx"),&PhysicsServer::area_remove_shape);
  312. ObjectTypeDB::bind_method(_MD("area_clear_shapes","area"),&PhysicsServer::area_clear_shapes);
  313. ObjectTypeDB::bind_method(_MD("area_set_param","area","param","value"),&PhysicsServer::area_set_param);
  314. ObjectTypeDB::bind_method(_MD("area_set_transform","area","transform"),&PhysicsServer::area_set_transform);
  315. ObjectTypeDB::bind_method(_MD("area_get_param","area","param"),&PhysicsServer::area_get_param);
  316. ObjectTypeDB::bind_method(_MD("area_get_transform","area"),&PhysicsServer::area_get_transform);
  317. ObjectTypeDB::bind_method(_MD("area_attach_object_instance_ID","area","id"),&PhysicsServer::area_attach_object_instance_ID);
  318. ObjectTypeDB::bind_method(_MD("area_get_object_instance_ID","area"),&PhysicsServer::area_get_object_instance_ID);
  319. ObjectTypeDB::bind_method(_MD("area_set_monitor_callback","area","receiver","method"),&PhysicsServer::area_set_monitor_callback);
  320. ObjectTypeDB::bind_method(_MD("area_set_ray_pickable","area","enable"),&PhysicsServer::area_set_ray_pickable);
  321. ObjectTypeDB::bind_method(_MD("area_is_ray_pickable","area"),&PhysicsServer::area_is_ray_pickable);
  322. ObjectTypeDB::bind_method(_MD("body_create","mode","init_sleeping"),&PhysicsServer::body_create,DEFVAL(BODY_MODE_RIGID),DEFVAL(false));
  323. ObjectTypeDB::bind_method(_MD("body_set_space","body","space"),&PhysicsServer::body_set_space);
  324. ObjectTypeDB::bind_method(_MD("body_get_space","body"),&PhysicsServer::body_get_space);
  325. ObjectTypeDB::bind_method(_MD("body_set_mode","body","mode"),&PhysicsServer::body_set_mode);
  326. ObjectTypeDB::bind_method(_MD("body_get_mode","body"),&PhysicsServer::body_get_mode);
  327. ObjectTypeDB::bind_method(_MD("body_add_shape","body","shape","transform"),&PhysicsServer::body_add_shape,DEFVAL(Transform()));
  328. ObjectTypeDB::bind_method(_MD("body_set_shape","body","shape_idx","shape"),&PhysicsServer::body_set_shape);
  329. ObjectTypeDB::bind_method(_MD("body_set_shape_transform","body","shape_idx","transform"),&PhysicsServer::body_set_shape_transform);
  330. ObjectTypeDB::bind_method(_MD("body_get_shape_count","body"),&PhysicsServer::body_get_shape_count);
  331. ObjectTypeDB::bind_method(_MD("body_get_shape","body","shape_idx"),&PhysicsServer::body_get_shape);
  332. ObjectTypeDB::bind_method(_MD("body_get_shape_transform","body","shape_idx"),&PhysicsServer::body_get_shape_transform);
  333. ObjectTypeDB::bind_method(_MD("body_remove_shape","body","shape_idx"),&PhysicsServer::body_remove_shape);
  334. ObjectTypeDB::bind_method(_MD("body_clear_shapes","body"),&PhysicsServer::body_clear_shapes);
  335. ObjectTypeDB::bind_method(_MD("body_attach_object_instance_ID","body","id"),&PhysicsServer::body_attach_object_instance_ID);
  336. ObjectTypeDB::bind_method(_MD("body_get_object_instance_ID","body"),&PhysicsServer::body_get_object_instance_ID);
  337. ObjectTypeDB::bind_method(_MD("body_set_enable_continuous_collision_detection","body","enable"),&PhysicsServer::body_set_enable_continuous_collision_detection);
  338. ObjectTypeDB::bind_method(_MD("body_is_continuous_collision_detection_enabled","body"),&PhysicsServer::body_is_continuous_collision_detection_enabled);
  339. //ObjectTypeDB::bind_method(_MD("body_set_user_flags","flags""),&PhysicsServer::body_set_shape,DEFVAL(Transform));
  340. //ObjectTypeDB::bind_method(_MD("body_get_user_flags","body","shape_idx","shape"),&PhysicsServer::body_get_shape);
  341. ObjectTypeDB::bind_method(_MD("body_set_param","body","param","value"),&PhysicsServer::body_set_param);
  342. ObjectTypeDB::bind_method(_MD("body_get_param","body","param"),&PhysicsServer::body_get_param);
  343. ObjectTypeDB::bind_method(_MD("body_set_state","body","state","value"),&PhysicsServer::body_set_state);
  344. ObjectTypeDB::bind_method(_MD("body_get_state","body","state"),&PhysicsServer::body_get_state);
  345. ObjectTypeDB::bind_method(_MD("body_apply_impulse","body","pos","impulse"),&PhysicsServer::body_apply_impulse);
  346. ObjectTypeDB::bind_method(_MD("body_set_axis_velocity","body","axis_velocity"),&PhysicsServer::body_set_axis_velocity);
  347. ObjectTypeDB::bind_method(_MD("body_set_axis_lock","body","axis"),&PhysicsServer::body_set_axis_lock);
  348. ObjectTypeDB::bind_method(_MD("body_get_axis_lock","body"),&PhysicsServer::body_get_axis_lock);
  349. ObjectTypeDB::bind_method(_MD("body_add_collision_exception","body","excepted_body"),&PhysicsServer::body_add_collision_exception);
  350. ObjectTypeDB::bind_method(_MD("body_remove_collision_exception","body","excepted_body"),&PhysicsServer::body_remove_collision_exception);
  351. // virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions)=0;
  352. ObjectTypeDB::bind_method(_MD("body_set_max_contacts_reported","body","amount"),&PhysicsServer::body_set_max_contacts_reported);
  353. ObjectTypeDB::bind_method(_MD("body_get_max_contacts_reported","body"),&PhysicsServer::body_get_max_contacts_reported);
  354. ObjectTypeDB::bind_method(_MD("body_set_omit_force_integration","body","enable"),&PhysicsServer::body_set_omit_force_integration);
  355. ObjectTypeDB::bind_method(_MD("body_is_omitting_force_integration","body"),&PhysicsServer::body_is_omitting_force_integration);
  356. ObjectTypeDB::bind_method(_MD("body_set_force_integration_callback","body","receiver","method","userdata"),&PhysicsServer::body_set_force_integration_callback,DEFVAL(Variant()));
  357. ObjectTypeDB::bind_method(_MD("body_set_ray_pickable","body","enable"),&PhysicsServer::body_set_ray_pickable);
  358. ObjectTypeDB::bind_method(_MD("body_is_ray_pickable","body"),&PhysicsServer::body_is_ray_pickable);
  359. /* JOINT API */
  360. BIND_CONSTANT( JOINT_PIN );
  361. BIND_CONSTANT( JOINT_HINGE );
  362. BIND_CONSTANT( JOINT_SLIDER );
  363. BIND_CONSTANT( JOINT_CONE_TWIST );
  364. BIND_CONSTANT( JOINT_6DOF );
  365. ObjectTypeDB::bind_method(_MD("joint_create_pin","body_A","local_A","body_B","local_B"),&PhysicsServer::joint_create_pin);
  366. ObjectTypeDB::bind_method(_MD("pin_joint_set_param","joint","param","value"),&PhysicsServer::pin_joint_set_param);
  367. ObjectTypeDB::bind_method(_MD("pin_joint_get_param","joint","param"),&PhysicsServer::pin_joint_get_param);
  368. ObjectTypeDB::bind_method(_MD("pin_joint_set_local_A","joint","local_A"),&PhysicsServer::pin_joint_set_local_A);
  369. ObjectTypeDB::bind_method(_MD("pin_joint_get_local_A","joint"),&PhysicsServer::pin_joint_get_local_A);
  370. ObjectTypeDB::bind_method(_MD("pin_joint_set_local_B","joint","local_B"),&PhysicsServer::pin_joint_set_local_B);
  371. ObjectTypeDB::bind_method(_MD("pin_joint_get_local_B","joint"),&PhysicsServer::pin_joint_get_local_B);
  372. BIND_CONSTANT(PIN_JOINT_BIAS );
  373. BIND_CONSTANT(PIN_JOINT_DAMPING );
  374. BIND_CONSTANT(PIN_JOINT_IMPULSE_CLAMP );
  375. BIND_CONSTANT(HINGE_JOINT_BIAS);
  376. BIND_CONSTANT(HINGE_JOINT_LIMIT_UPPER);
  377. BIND_CONSTANT(HINGE_JOINT_LIMIT_LOWER);
  378. BIND_CONSTANT(HINGE_JOINT_LIMIT_BIAS);
  379. BIND_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);
  380. BIND_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);
  381. BIND_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);
  382. BIND_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);
  383. BIND_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);
  384. BIND_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);
  385. ObjectTypeDB::bind_method(_MD("joint_create_hinge","body_A","hinge_A","body_B","hinge_B"),&PhysicsServer::joint_create_hinge);
  386. ObjectTypeDB::bind_method(_MD("hinge_joint_set_param","joint","param","value"),&PhysicsServer::hinge_joint_set_param);
  387. ObjectTypeDB::bind_method(_MD("hinge_joint_get_param","joint","param"),&PhysicsServer::hinge_joint_get_param);
  388. ObjectTypeDB::bind_method(_MD("hinge_joint_set_flag","joint","flag","enabled"),&PhysicsServer::hinge_joint_set_flag);
  389. ObjectTypeDB::bind_method(_MD("hinge_joint_get_flag","joint","flag"),&PhysicsServer::hinge_joint_get_flag);
  390. ObjectTypeDB::bind_method(_MD("joint_create_slider","body_A","local_ref_A","body_B","local_ref_B"),&PhysicsServer::joint_create_slider);
  391. ObjectTypeDB::bind_method(_MD("slider_joint_set_param","joint","param","value"),&PhysicsServer::slider_joint_set_param);
  392. ObjectTypeDB::bind_method(_MD("slider_joint_get_param","joint","param"),&PhysicsServer::slider_joint_get_param);
  393. BIND_CONSTANT( SLIDER_JOINT_LINEAR_LIMIT_UPPER );
  394. BIND_CONSTANT( SLIDER_JOINT_LINEAR_LIMIT_LOWER );
  395. BIND_CONSTANT( SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS );
  396. BIND_CONSTANT( SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION );
  397. BIND_CONSTANT( SLIDER_JOINT_LINEAR_LIMIT_DAMPING );
  398. BIND_CONSTANT( SLIDER_JOINT_LINEAR_MOTION_SOFTNESS );
  399. BIND_CONSTANT( SLIDER_JOINT_LINEAR_MOTION_RESTITUTION );
  400. BIND_CONSTANT( SLIDER_JOINT_LINEAR_MOTION_DAMPING );
  401. BIND_CONSTANT( SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS );
  402. BIND_CONSTANT( SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION );
  403. BIND_CONSTANT( SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING );
  404. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_LIMIT_UPPER );
  405. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_LIMIT_LOWER );
  406. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS );
  407. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION );
  408. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_LIMIT_DAMPING );
  409. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS );
  410. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION );
  411. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_MOTION_DAMPING );
  412. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS );
  413. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION );
  414. BIND_CONSTANT( SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING );
  415. BIND_CONSTANT( SLIDER_JOINT_MAX );
  416. ObjectTypeDB::bind_method(_MD("joint_create_cone_twist","body_A","local_ref_A","body_B","local_ref_B"),&PhysicsServer::joint_create_cone_twist);
  417. ObjectTypeDB::bind_method(_MD("cone_twist_joint_set_param","joint","param","value"),&PhysicsServer::cone_twist_joint_set_param);
  418. ObjectTypeDB::bind_method(_MD("cone_twist_joint_get_param","joint","param"),&PhysicsServer::cone_twist_joint_get_param);
  419. BIND_CONSTANT( CONE_TWIST_JOINT_SWING_SPAN );
  420. BIND_CONSTANT( CONE_TWIST_JOINT_TWIST_SPAN );
  421. BIND_CONSTANT( CONE_TWIST_JOINT_BIAS );
  422. BIND_CONSTANT( CONE_TWIST_JOINT_SOFTNESS );
  423. BIND_CONSTANT( CONE_TWIST_JOINT_RELAXATION );
  424. BIND_CONSTANT( G6DOF_JOINT_LINEAR_LOWER_LIMIT );
  425. BIND_CONSTANT( G6DOF_JOINT_LINEAR_UPPER_LIMIT );
  426. BIND_CONSTANT( G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS );
  427. BIND_CONSTANT( G6DOF_JOINT_LINEAR_RESTITUTION );
  428. BIND_CONSTANT( G6DOF_JOINT_LINEAR_DAMPING );
  429. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_LOWER_LIMIT );
  430. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_UPPER_LIMIT );
  431. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS );
  432. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_DAMPING );
  433. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_RESTITUTION );
  434. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_FORCE_LIMIT );
  435. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_ERP );
  436. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY );
  437. BIND_CONSTANT( G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT );
  438. BIND_CONSTANT( G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT );
  439. BIND_CONSTANT( G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT );
  440. BIND_CONSTANT( G6DOF_JOINT_FLAG_ENABLE_MOTOR );
  441. ObjectTypeDB::bind_method(_MD("joint_get_type","joint"),&PhysicsServer::joint_get_type);
  442. ObjectTypeDB::bind_method(_MD("joint_set_solver_priority","joint","priority"),&PhysicsServer::joint_set_solver_priority);
  443. ObjectTypeDB::bind_method(_MD("joint_get_solver_priority","joint"),&PhysicsServer::joint_get_solver_priority);
  444. ObjectTypeDB::bind_method(_MD("joint_create_generic_6dof","body_A","local_ref_A","body_B","local_ref_B"),&PhysicsServer::joint_create_generic_6dof);
  445. ObjectTypeDB::bind_method(_MD("generic_6dof_joint_set_param","joint","axis","param","value"),&PhysicsServer::generic_6dof_joint_set_param);
  446. ObjectTypeDB::bind_method(_MD("generic_6dof_joint_get_param","joint","axis","param"),&PhysicsServer::generic_6dof_joint_get_param);
  447. ObjectTypeDB::bind_method(_MD("generic_6dof_joint_set_flag","joint","axis","flag","enable"),&PhysicsServer::generic_6dof_joint_set_flag);
  448. ObjectTypeDB::bind_method(_MD("generic_6dof_joint_get_flag","joint","axis","flag"),&PhysicsServer::generic_6dof_joint_get_flag);
  449. /*
  450. ObjectTypeDB::bind_method(_MD("joint_set_param","joint","param","value"),&PhysicsServer::joint_set_param);
  451. ObjectTypeDB::bind_method(_MD("joint_get_param","joint","param"),&PhysicsServer::joint_get_param);
  452. ObjectTypeDB::bind_method(_MD("pin_joint_create","anchor","body_a","body_b"),&PhysicsServer::pin_joint_create,DEFVAL(RID()));
  453. ObjectTypeDB::bind_method(_MD("groove_joint_create","groove1_a","groove2_a","anchor_b","body_a","body_b"),&PhysicsServer::groove_joint_create,DEFVAL(RID()),DEFVAL(RID()));
  454. ObjectTypeDB::bind_method(_MD("damped_spring_joint_create","anchor_a","anchor_b","body_a","body_b"),&PhysicsServer::damped_spring_joint_create,DEFVAL(RID()));
  455. ObjectTypeDB::bind_method(_MD("damped_string_joint_set_param","joint","param","value"),&PhysicsServer::damped_string_joint_set_param,DEFVAL(RID()));
  456. ObjectTypeDB::bind_method(_MD("damped_string_joint_get_param","joint","param"),&PhysicsServer::damped_string_joint_get_param);
  457. ObjectTypeDB::bind_method(_MD("joint_get_type","joint"),&PhysicsServer::joint_get_type);
  458. */
  459. ObjectTypeDB::bind_method(_MD("free_rid","rid"),&PhysicsServer::free);
  460. ObjectTypeDB::bind_method(_MD("set_active","active"),&PhysicsServer::set_active);
  461. // ObjectTypeDB::bind_method(_MD("init"),&PhysicsServer::init);
  462. // ObjectTypeDB::bind_method(_MD("step"),&PhysicsServer::step);
  463. // ObjectTypeDB::bind_method(_MD("sync"),&PhysicsServer::sync);
  464. //ObjectTypeDB::bind_method(_MD("flush_queries"),&PhysicsServer::flush_queries);
  465. ObjectTypeDB::bind_method(_MD("get_process_info","process_info"),&PhysicsServer::get_process_info);
  466. BIND_CONSTANT( SHAPE_PLANE );
  467. BIND_CONSTANT( SHAPE_RAY );
  468. BIND_CONSTANT( SHAPE_SPHERE );
  469. BIND_CONSTANT( SHAPE_BOX );
  470. BIND_CONSTANT( SHAPE_CAPSULE );
  471. BIND_CONSTANT( SHAPE_CONVEX_POLYGON );
  472. BIND_CONSTANT( SHAPE_CONCAVE_POLYGON );
  473. BIND_CONSTANT( SHAPE_HEIGHTMAP );
  474. BIND_CONSTANT( SHAPE_CUSTOM );
  475. BIND_CONSTANT( AREA_PARAM_GRAVITY );
  476. BIND_CONSTANT( AREA_PARAM_GRAVITY_VECTOR );
  477. BIND_CONSTANT( AREA_PARAM_GRAVITY_IS_POINT );
  478. BIND_CONSTANT( AREA_PARAM_GRAVITY_DISTANCE_SCALE );
  479. BIND_CONSTANT( AREA_PARAM_GRAVITY_POINT_ATTENUATION );
  480. BIND_CONSTANT( AREA_PARAM_LINEAR_DAMP );
  481. BIND_CONSTANT( AREA_PARAM_ANGULAR_DAMP );
  482. BIND_CONSTANT( AREA_PARAM_PRIORITY );
  483. BIND_CONSTANT( AREA_SPACE_OVERRIDE_DISABLED );
  484. BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
  485. BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE_REPLACE );
  486. BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE );
  487. BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE_COMBINE );
  488. BIND_CONSTANT( BODY_MODE_STATIC );
  489. BIND_CONSTANT( BODY_MODE_KINEMATIC );
  490. BIND_CONSTANT( BODY_MODE_RIGID );
  491. BIND_CONSTANT( BODY_MODE_CHARACTER );
  492. BIND_CONSTANT( BODY_PARAM_BOUNCE );
  493. BIND_CONSTANT( BODY_PARAM_FRICTION );
  494. BIND_CONSTANT( BODY_PARAM_MASS );
  495. BIND_CONSTANT( BODY_PARAM_GRAVITY_SCALE );
  496. BIND_CONSTANT( BODY_PARAM_ANGULAR_DAMP );
  497. BIND_CONSTANT( BODY_PARAM_LINEAR_DAMP );
  498. BIND_CONSTANT( BODY_PARAM_MAX );
  499. BIND_CONSTANT( BODY_STATE_TRANSFORM );
  500. BIND_CONSTANT( BODY_STATE_LINEAR_VELOCITY );
  501. BIND_CONSTANT( BODY_STATE_ANGULAR_VELOCITY );
  502. BIND_CONSTANT( BODY_STATE_SLEEPING );
  503. BIND_CONSTANT( BODY_STATE_CAN_SLEEP );
  504. /*
  505. BIND_CONSTANT( JOINT_PIN );
  506. BIND_CONSTANT( JOINT_GROOVE );
  507. BIND_CONSTANT( JOINT_DAMPED_SPRING );
  508. BIND_CONSTANT( DAMPED_STRING_REST_LENGTH );
  509. BIND_CONSTANT( DAMPED_STRING_STIFFNESS );
  510. BIND_CONSTANT( DAMPED_STRING_DAMPING );
  511. */
  512. // BIND_CONSTANT( TYPE_BODY );
  513. // BIND_CONSTANT( TYPE_AREA );
  514. BIND_CONSTANT( AREA_BODY_ADDED );
  515. BIND_CONSTANT( AREA_BODY_REMOVED );
  516. BIND_CONSTANT( INFO_ACTIVE_OBJECTS );
  517. BIND_CONSTANT( INFO_COLLISION_PAIRS );
  518. BIND_CONSTANT( INFO_ISLAND_COUNT );
  519. }
  520. PhysicsServer::PhysicsServer() {
  521. ERR_FAIL_COND( singleton!=NULL );
  522. singleton=this;
  523. }
  524. PhysicsServer::~PhysicsServer() {
  525. singleton=NULL;
  526. }