godot_body_direct_state_3d.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**************************************************************************/
  2. /* godot_body_direct_state_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "godot_body_direct_state_3d.h"
  31. #include "godot_body_3d.h"
  32. #include "godot_space_3d.h"
  33. Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const {
  34. return body->gravity;
  35. }
  36. real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() const {
  37. return body->total_angular_damp;
  38. }
  39. real_t GodotPhysicsDirectBodyState3D::get_total_linear_damp() const {
  40. return body->total_linear_damp;
  41. }
  42. Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const {
  43. return body->get_center_of_mass();
  44. }
  45. Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass_local() const {
  46. return body->get_center_of_mass_local();
  47. }
  48. Basis GodotPhysicsDirectBodyState3D::get_principal_inertia_axes() const {
  49. return body->get_principal_inertia_axes();
  50. }
  51. real_t GodotPhysicsDirectBodyState3D::get_inverse_mass() const {
  52. return body->get_inv_mass();
  53. }
  54. Vector3 GodotPhysicsDirectBodyState3D::get_inverse_inertia() const {
  55. return body->get_inv_inertia();
  56. }
  57. Basis GodotPhysicsDirectBodyState3D::get_inverse_inertia_tensor() const {
  58. return body->get_inv_inertia_tensor();
  59. }
  60. void GodotPhysicsDirectBodyState3D::set_linear_velocity(const Vector3 &p_velocity) {
  61. body->wakeup();
  62. body->set_linear_velocity(p_velocity);
  63. }
  64. Vector3 GodotPhysicsDirectBodyState3D::get_linear_velocity() const {
  65. return body->get_linear_velocity();
  66. }
  67. void GodotPhysicsDirectBodyState3D::set_angular_velocity(const Vector3 &p_velocity) {
  68. body->wakeup();
  69. body->set_angular_velocity(p_velocity);
  70. }
  71. Vector3 GodotPhysicsDirectBodyState3D::get_angular_velocity() const {
  72. return body->get_angular_velocity();
  73. }
  74. void GodotPhysicsDirectBodyState3D::set_transform(const Transform3D &p_transform) {
  75. body->set_state(PhysicsServer3D::BODY_STATE_TRANSFORM, p_transform);
  76. }
  77. Transform3D GodotPhysicsDirectBodyState3D::get_transform() const {
  78. return body->get_transform();
  79. }
  80. Vector3 GodotPhysicsDirectBodyState3D::get_velocity_at_local_position(const Vector3 &p_position) const {
  81. return body->get_velocity_in_local_point(p_position);
  82. }
  83. void GodotPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impulse) {
  84. body->wakeup();
  85. body->apply_central_impulse(p_impulse);
  86. }
  87. void GodotPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
  88. body->wakeup();
  89. body->apply_impulse(p_impulse, p_position);
  90. }
  91. void GodotPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) {
  92. body->wakeup();
  93. body->apply_torque_impulse(p_impulse);
  94. }
  95. void GodotPhysicsDirectBodyState3D::apply_central_force(const Vector3 &p_force) {
  96. body->wakeup();
  97. body->apply_central_force(p_force);
  98. }
  99. void GodotPhysicsDirectBodyState3D::apply_force(const Vector3 &p_force, const Vector3 &p_position) {
  100. body->wakeup();
  101. body->apply_force(p_force, p_position);
  102. }
  103. void GodotPhysicsDirectBodyState3D::apply_torque(const Vector3 &p_torque) {
  104. body->wakeup();
  105. body->apply_torque(p_torque);
  106. }
  107. void GodotPhysicsDirectBodyState3D::add_constant_central_force(const Vector3 &p_force) {
  108. body->wakeup();
  109. body->add_constant_central_force(p_force);
  110. }
  111. void GodotPhysicsDirectBodyState3D::add_constant_force(const Vector3 &p_force, const Vector3 &p_position) {
  112. body->wakeup();
  113. body->add_constant_force(p_force, p_position);
  114. }
  115. void GodotPhysicsDirectBodyState3D::add_constant_torque(const Vector3 &p_torque) {
  116. body->wakeup();
  117. body->add_constant_torque(p_torque);
  118. }
  119. void GodotPhysicsDirectBodyState3D::set_constant_force(const Vector3 &p_force) {
  120. if (!p_force.is_zero_approx()) {
  121. body->wakeup();
  122. }
  123. body->set_constant_force(p_force);
  124. }
  125. Vector3 GodotPhysicsDirectBodyState3D::get_constant_force() const {
  126. return body->get_constant_force();
  127. }
  128. void GodotPhysicsDirectBodyState3D::set_constant_torque(const Vector3 &p_torque) {
  129. if (!p_torque.is_zero_approx()) {
  130. body->wakeup();
  131. }
  132. body->set_constant_torque(p_torque);
  133. }
  134. Vector3 GodotPhysicsDirectBodyState3D::get_constant_torque() const {
  135. return body->get_constant_torque();
  136. }
  137. void GodotPhysicsDirectBodyState3D::set_sleep_state(bool p_sleep) {
  138. body->set_active(!p_sleep);
  139. }
  140. bool GodotPhysicsDirectBodyState3D::is_sleeping() const {
  141. return !body->is_active();
  142. }
  143. int GodotPhysicsDirectBodyState3D::get_contact_count() const {
  144. return body->contact_count;
  145. }
  146. Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_position(int p_contact_idx) const {
  147. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  148. return body->contacts[p_contact_idx].local_pos;
  149. }
  150. Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_normal(int p_contact_idx) const {
  151. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  152. return body->contacts[p_contact_idx].local_normal;
  153. }
  154. Vector3 GodotPhysicsDirectBodyState3D::get_contact_impulse(int p_contact_idx) const {
  155. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  156. return body->contacts[p_contact_idx].impulse;
  157. }
  158. Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_velocity_at_position(int p_contact_idx) const {
  159. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  160. return body->contacts[p_contact_idx].local_velocity_at_pos;
  161. }
  162. int GodotPhysicsDirectBodyState3D::get_contact_local_shape(int p_contact_idx) const {
  163. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, -1);
  164. return body->contacts[p_contact_idx].local_shape;
  165. }
  166. RID GodotPhysicsDirectBodyState3D::get_contact_collider(int p_contact_idx) const {
  167. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID());
  168. return body->contacts[p_contact_idx].collider;
  169. }
  170. Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_position(int p_contact_idx) const {
  171. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  172. return body->contacts[p_contact_idx].collider_pos;
  173. }
  174. ObjectID GodotPhysicsDirectBodyState3D::get_contact_collider_id(int p_contact_idx) const {
  175. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, ObjectID());
  176. return body->contacts[p_contact_idx].collider_instance_id;
  177. }
  178. int GodotPhysicsDirectBodyState3D::get_contact_collider_shape(int p_contact_idx) const {
  179. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
  180. return body->contacts[p_contact_idx].collider_shape;
  181. }
  182. Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_velocity_at_position(int p_contact_idx) const {
  183. ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
  184. return body->contacts[p_contact_idx].collider_velocity_at_pos;
  185. }
  186. PhysicsDirectSpaceState3D *GodotPhysicsDirectBodyState3D::get_space_state() {
  187. return body->get_space()->get_direct_state();
  188. }
  189. real_t GodotPhysicsDirectBodyState3D::get_step() const {
  190. return body->get_space()->get_last_step();
  191. }