joint_3d.cpp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /**************************************************************************/
  2. /* joint_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 "joint_3d.h"
  31. #include "scene/scene_string_names.h"
  32. void Joint3D::_disconnect_signals() {
  33. Node *node_a = get_node_or_null(a);
  34. PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a);
  35. if (body_a) {
  36. body_a->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint3D::_body_exit_tree));
  37. }
  38. Node *node_b = get_node_or_null(b);
  39. PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b);
  40. if (body_b) {
  41. body_b->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint3D::_body_exit_tree));
  42. }
  43. }
  44. void Joint3D::_body_exit_tree() {
  45. _disconnect_signals();
  46. _update_joint(true);
  47. update_configuration_warnings();
  48. }
  49. void Joint3D::_update_joint(bool p_only_free) {
  50. if (ba.is_valid() && bb.is_valid()) {
  51. PhysicsServer3D::get_singleton()->body_remove_collision_exception(ba, bb);
  52. PhysicsServer3D::get_singleton()->body_remove_collision_exception(bb, ba);
  53. }
  54. ba = RID();
  55. bb = RID();
  56. configured = false;
  57. if (p_only_free || !is_inside_tree()) {
  58. PhysicsServer3D::get_singleton()->joint_clear(joint);
  59. warning = String();
  60. return;
  61. }
  62. Node *node_a = get_node_or_null(a);
  63. Node *node_b = get_node_or_null(b);
  64. PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a);
  65. PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b);
  66. if (node_a && !body_a && node_b && !body_b) {
  67. warning = RTR("Node A and Node B must be PhysicsBody3Ds");
  68. } else if (node_a && !body_a) {
  69. warning = RTR("Node A must be a PhysicsBody3D");
  70. } else if (node_b && !body_b) {
  71. warning = RTR("Node B must be a PhysicsBody3D");
  72. } else if (!body_a && !body_b) {
  73. warning = RTR("Joint is not connected to any PhysicsBody3Ds");
  74. } else if (body_a == body_b) {
  75. warning = RTR("Node A and Node B must be different PhysicsBody3Ds");
  76. } else {
  77. warning = String();
  78. }
  79. update_configuration_warnings();
  80. if (!warning.is_empty()) {
  81. PhysicsServer3D::get_singleton()->joint_clear(joint);
  82. return;
  83. }
  84. configured = true;
  85. if (body_a) {
  86. _configure_joint(joint, body_a, body_b);
  87. } else if (body_b) {
  88. _configure_joint(joint, body_b, nullptr);
  89. }
  90. PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority);
  91. if (body_a) {
  92. ba = body_a->get_rid();
  93. body_a->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint3D::_body_exit_tree));
  94. }
  95. if (body_b) {
  96. bb = body_b->get_rid();
  97. body_b->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint3D::_body_exit_tree));
  98. }
  99. PhysicsServer3D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
  100. }
  101. void Joint3D::set_node_a(const NodePath &p_node_a) {
  102. if (a == p_node_a) {
  103. return;
  104. }
  105. if (is_configured()) {
  106. _disconnect_signals();
  107. }
  108. a = p_node_a;
  109. _update_joint();
  110. }
  111. NodePath Joint3D::get_node_a() const {
  112. return a;
  113. }
  114. void Joint3D::set_node_b(const NodePath &p_node_b) {
  115. if (b == p_node_b) {
  116. return;
  117. }
  118. if (is_configured()) {
  119. _disconnect_signals();
  120. }
  121. b = p_node_b;
  122. _update_joint();
  123. }
  124. NodePath Joint3D::get_node_b() const {
  125. return b;
  126. }
  127. void Joint3D::set_solver_priority(int p_priority) {
  128. solver_priority = p_priority;
  129. if (joint.is_valid()) {
  130. PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority);
  131. }
  132. }
  133. int Joint3D::get_solver_priority() const {
  134. return solver_priority;
  135. }
  136. void Joint3D::_notification(int p_what) {
  137. switch (p_what) {
  138. case NOTIFICATION_POST_ENTER_TREE: {
  139. if (is_configured()) {
  140. _disconnect_signals();
  141. }
  142. _update_joint();
  143. } break;
  144. case NOTIFICATION_EXIT_TREE: {
  145. if (is_configured()) {
  146. _disconnect_signals();
  147. }
  148. _update_joint(true);
  149. } break;
  150. }
  151. }
  152. void Joint3D::set_exclude_nodes_from_collision(bool p_enable) {
  153. if (exclude_from_collision == p_enable) {
  154. return;
  155. }
  156. if (is_configured()) {
  157. _disconnect_signals();
  158. }
  159. _update_joint(true);
  160. exclude_from_collision = p_enable;
  161. _update_joint();
  162. }
  163. bool Joint3D::get_exclude_nodes_from_collision() const {
  164. return exclude_from_collision;
  165. }
  166. PackedStringArray Joint3D::get_configuration_warnings() const {
  167. PackedStringArray warnings = Node3D::get_configuration_warnings();
  168. if (!warning.is_empty()) {
  169. warnings.push_back(warning);
  170. }
  171. return warnings;
  172. }
  173. void Joint3D::_bind_methods() {
  174. ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint3D::set_node_a);
  175. ClassDB::bind_method(D_METHOD("get_node_a"), &Joint3D::get_node_a);
  176. ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint3D::set_node_b);
  177. ClassDB::bind_method(D_METHOD("get_node_b"), &Joint3D::get_node_b);
  178. ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint3D::set_solver_priority);
  179. ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint3D::get_solver_priority);
  180. ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint3D::set_exclude_nodes_from_collision);
  181. ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint3D::get_exclude_nodes_from_collision);
  182. ClassDB::bind_method(D_METHOD("get_rid"), &Joint3D::get_rid);
  183. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PhysicsBody3D"), "set_node_a", "get_node_a");
  184. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PhysicsBody3D"), "set_node_b", "get_node_b");
  185. ADD_PROPERTY(PropertyInfo(Variant::INT, "solver_priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority");
  186. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_nodes_from_collision"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision");
  187. }
  188. Joint3D::Joint3D() {
  189. set_notify_transform(true);
  190. joint = PhysicsServer3D::get_singleton()->joint_create();
  191. }
  192. Joint3D::~Joint3D() {
  193. ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
  194. PhysicsServer3D::get_singleton()->free(joint);
  195. }
  196. ///////////////////////////////////
  197. void PinJoint3D::_bind_methods() {
  198. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint3D::set_param);
  199. ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint3D::get_param);
  200. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
  201. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/damping", PROPERTY_HINT_RANGE, "0.01,8.0,0.01"), "set_param", "get_param", PARAM_DAMPING);
  202. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/impulse_clamp", PROPERTY_HINT_RANGE, "0.0,64.0,0.01"), "set_param", "get_param", PARAM_IMPULSE_CLAMP);
  203. BIND_ENUM_CONSTANT(PARAM_BIAS);
  204. BIND_ENUM_CONSTANT(PARAM_DAMPING);
  205. BIND_ENUM_CONSTANT(PARAM_IMPULSE_CLAMP);
  206. }
  207. void PinJoint3D::set_param(Param p_param, real_t p_value) {
  208. ERR_FAIL_INDEX(p_param, 3);
  209. params[p_param] = p_value;
  210. if (is_configured()) {
  211. PhysicsServer3D::get_singleton()->pin_joint_set_param(get_rid(), PhysicsServer3D::PinJointParam(p_param), p_value);
  212. }
  213. }
  214. real_t PinJoint3D::get_param(Param p_param) const {
  215. ERR_FAIL_INDEX_V(p_param, 3, 0);
  216. return params[p_param];
  217. }
  218. void PinJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
  219. Vector3 pinpos = get_global_transform().origin;
  220. Vector3 local_a = body_a->to_local(pinpos);
  221. Vector3 local_b;
  222. if (body_b) {
  223. local_b = body_b->to_local(pinpos);
  224. } else {
  225. local_b = pinpos;
  226. }
  227. PhysicsServer3D::get_singleton()->joint_make_pin(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  228. for (int i = 0; i < 3; i++) {
  229. PhysicsServer3D::get_singleton()->pin_joint_set_param(p_joint, PhysicsServer3D::PinJointParam(i), params[i]);
  230. }
  231. }
  232. PinJoint3D::PinJoint3D() {
  233. params[PARAM_BIAS] = 0.3;
  234. params[PARAM_DAMPING] = 1;
  235. params[PARAM_IMPULSE_CLAMP] = 0;
  236. }
  237. /////////////////////////////////////////////////
  238. ///////////////////////////////////
  239. void HingeJoint3D::_bind_methods() {
  240. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint3D::set_param);
  241. ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint3D::get_param);
  242. ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint3D::set_flag);
  243. ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint3D::get_flag);
  244. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.00,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
  245. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit/enable"), "set_flag", "get_flag", FLAG_USE_LIMIT);
  246. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/upper", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_LIMIT_UPPER);
  247. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/lower", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_LIMIT_LOWER);
  248. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_LIMIT_BIAS);
  249. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_SOFTNESS);
  250. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/relaxation", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_RELAXATION);
  251. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "motor/enable"), "set_flag", "get_flag", FLAG_ENABLE_MOTOR);
  252. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "motor/target_velocity", PROPERTY_HINT_RANGE, U"-200,200,0.01,or_greater,or_less,radians_as_degrees,suffix:\u00B0/s"), "set_param", "get_param", PARAM_MOTOR_TARGET_VELOCITY);
  253. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "motor/max_impulse", PROPERTY_HINT_RANGE, "0.01,1024,0.01"), "set_param", "get_param", PARAM_MOTOR_MAX_IMPULSE);
  254. BIND_ENUM_CONSTANT(PARAM_BIAS);
  255. BIND_ENUM_CONSTANT(PARAM_LIMIT_UPPER);
  256. BIND_ENUM_CONSTANT(PARAM_LIMIT_LOWER);
  257. BIND_ENUM_CONSTANT(PARAM_LIMIT_BIAS);
  258. BIND_ENUM_CONSTANT(PARAM_LIMIT_SOFTNESS);
  259. BIND_ENUM_CONSTANT(PARAM_LIMIT_RELAXATION);
  260. BIND_ENUM_CONSTANT(PARAM_MOTOR_TARGET_VELOCITY);
  261. BIND_ENUM_CONSTANT(PARAM_MOTOR_MAX_IMPULSE);
  262. BIND_ENUM_CONSTANT(PARAM_MAX);
  263. BIND_ENUM_CONSTANT(FLAG_USE_LIMIT);
  264. BIND_ENUM_CONSTANT(FLAG_ENABLE_MOTOR);
  265. BIND_ENUM_CONSTANT(FLAG_MAX);
  266. }
  267. void HingeJoint3D::set_param(Param p_param, real_t p_value) {
  268. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  269. params[p_param] = p_value;
  270. if (is_configured()) {
  271. PhysicsServer3D::get_singleton()->hinge_joint_set_param(get_rid(), PhysicsServer3D::HingeJointParam(p_param), p_value);
  272. }
  273. update_gizmos();
  274. }
  275. real_t HingeJoint3D::get_param(Param p_param) const {
  276. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  277. return params[p_param];
  278. }
  279. void HingeJoint3D::set_flag(Flag p_flag, bool p_value) {
  280. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  281. flags[p_flag] = p_value;
  282. if (is_configured()) {
  283. PhysicsServer3D::get_singleton()->hinge_joint_set_flag(get_rid(), PhysicsServer3D::HingeJointFlag(p_flag), p_value);
  284. }
  285. update_gizmos();
  286. }
  287. bool HingeJoint3D::get_flag(Flag p_flag) const {
  288. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  289. return flags[p_flag];
  290. }
  291. void HingeJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
  292. Transform3D gt = get_global_transform();
  293. Transform3D ainv = body_a->get_global_transform().affine_inverse();
  294. Transform3D local_a = ainv * gt;
  295. local_a.orthonormalize();
  296. Transform3D local_b = gt;
  297. if (body_b) {
  298. Transform3D binv = body_b->get_global_transform().affine_inverse();
  299. local_b = binv * gt;
  300. }
  301. local_b.orthonormalize();
  302. PhysicsServer3D::get_singleton()->joint_make_hinge(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  303. for (int i = 0; i < PARAM_MAX; i++) {
  304. PhysicsServer3D::get_singleton()->hinge_joint_set_param(p_joint, PhysicsServer3D::HingeJointParam(i), params[i]);
  305. }
  306. for (int i = 0; i < FLAG_MAX; i++) {
  307. set_flag(Flag(i), flags[i]);
  308. PhysicsServer3D::get_singleton()->hinge_joint_set_flag(p_joint, PhysicsServer3D::HingeJointFlag(i), flags[i]);
  309. }
  310. }
  311. HingeJoint3D::HingeJoint3D() {
  312. params[PARAM_BIAS] = 0.3;
  313. params[PARAM_LIMIT_UPPER] = Math_PI * 0.5;
  314. params[PARAM_LIMIT_LOWER] = -Math_PI * 0.5;
  315. params[PARAM_LIMIT_BIAS] = 0.3;
  316. params[PARAM_LIMIT_SOFTNESS] = 0.9;
  317. params[PARAM_LIMIT_RELAXATION] = 1.0;
  318. params[PARAM_MOTOR_TARGET_VELOCITY] = 1;
  319. params[PARAM_MOTOR_MAX_IMPULSE] = 1;
  320. flags[FLAG_USE_LIMIT] = false;
  321. flags[FLAG_ENABLE_MOTOR] = false;
  322. }
  323. /////////////////////////////////////////////////
  324. void SliderJoint3D::_bind_methods() {
  325. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint3D::set_param);
  326. ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint3D::get_param);
  327. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/upper_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01,suffix:m"), "set_param", "get_param", PARAM_LINEAR_LIMIT_UPPER);
  328. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/lower_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01,suffix:m"), "set_param", "get_param", PARAM_LINEAR_LIMIT_LOWER);
  329. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_SOFTNESS);
  330. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_RESTITUTION);
  331. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_DAMPING);
  332. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_SOFTNESS);
  333. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_RESTITUTION);
  334. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_DAMPING);
  335. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
  336. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
  337. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_DAMPING);
  338. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_UPPER);
  339. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_LOWER);
  340. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_SOFTNESS);
  341. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_RESTITUTION);
  342. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_DAMPING);
  343. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_SOFTNESS);
  344. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_RESTITUTION);
  345. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_DAMPING);
  346. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
  347. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
  348. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_DAMPING);
  349. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_UPPER);
  350. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_LOWER);
  351. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
  352. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_RESTITUTION);
  353. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_DAMPING);
  354. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_SOFTNESS);
  355. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_RESTITUTION);
  356. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_DAMPING);
  357. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
  358. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
  359. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_DAMPING);
  360. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_UPPER);
  361. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_LOWER);
  362. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
  363. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_RESTITUTION);
  364. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_DAMPING);
  365. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_SOFTNESS);
  366. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_RESTITUTION);
  367. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_DAMPING);
  368. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
  369. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
  370. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_DAMPING);
  371. BIND_ENUM_CONSTANT(PARAM_MAX);
  372. }
  373. void SliderJoint3D::set_param(Param p_param, real_t p_value) {
  374. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  375. params[p_param] = p_value;
  376. if (is_configured()) {
  377. PhysicsServer3D::get_singleton()->slider_joint_set_param(get_rid(), PhysicsServer3D::SliderJointParam(p_param), p_value);
  378. }
  379. update_gizmos();
  380. }
  381. real_t SliderJoint3D::get_param(Param p_param) const {
  382. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  383. return params[p_param];
  384. }
  385. void SliderJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
  386. Transform3D gt = get_global_transform();
  387. Transform3D ainv = body_a->get_global_transform().affine_inverse();
  388. Transform3D local_a = ainv * gt;
  389. local_a.orthonormalize();
  390. Transform3D local_b = gt;
  391. if (body_b) {
  392. Transform3D binv = body_b->get_global_transform().affine_inverse();
  393. local_b = binv * gt;
  394. }
  395. local_b.orthonormalize();
  396. PhysicsServer3D::get_singleton()->joint_make_slider(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  397. for (int i = 0; i < PARAM_MAX; i++) {
  398. PhysicsServer3D::get_singleton()->slider_joint_set_param(p_joint, PhysicsServer3D::SliderJointParam(i), params[i]);
  399. }
  400. }
  401. SliderJoint3D::SliderJoint3D() {
  402. params[PARAM_LINEAR_LIMIT_UPPER] = 1.0;
  403. params[PARAM_LINEAR_LIMIT_LOWER] = -1.0;
  404. params[PARAM_LINEAR_LIMIT_SOFTNESS] = 1.0;
  405. params[PARAM_LINEAR_LIMIT_RESTITUTION] = 0.7;
  406. params[PARAM_LINEAR_LIMIT_DAMPING] = 1.0;
  407. params[PARAM_LINEAR_MOTION_SOFTNESS] = 1.0;
  408. params[PARAM_LINEAR_MOTION_RESTITUTION] = 0.7;
  409. params[PARAM_LINEAR_MOTION_DAMPING] = 0; //1.0;
  410. params[PARAM_LINEAR_ORTHOGONAL_SOFTNESS] = 1.0;
  411. params[PARAM_LINEAR_ORTHOGONAL_RESTITUTION] = 0.7;
  412. params[PARAM_LINEAR_ORTHOGONAL_DAMPING] = 1.0;
  413. params[PARAM_ANGULAR_LIMIT_UPPER] = 0;
  414. params[PARAM_ANGULAR_LIMIT_LOWER] = 0;
  415. params[PARAM_ANGULAR_LIMIT_SOFTNESS] = 1.0;
  416. params[PARAM_ANGULAR_LIMIT_RESTITUTION] = 0.7;
  417. params[PARAM_ANGULAR_LIMIT_DAMPING] = 0; //1.0;
  418. params[PARAM_ANGULAR_MOTION_SOFTNESS] = 1.0;
  419. params[PARAM_ANGULAR_MOTION_RESTITUTION] = 0.7;
  420. params[PARAM_ANGULAR_MOTION_DAMPING] = 1.0;
  421. params[PARAM_ANGULAR_ORTHOGONAL_SOFTNESS] = 1.0;
  422. params[PARAM_ANGULAR_ORTHOGONAL_RESTITUTION] = 0.7;
  423. params[PARAM_ANGULAR_ORTHOGONAL_DAMPING] = 1.0;
  424. }
  425. //////////////////////////////////
  426. void ConeTwistJoint3D::_bind_methods() {
  427. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint3D::set_param);
  428. ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint3D::get_param);
  429. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_SWING_SPAN);
  430. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_TWIST_SPAN);
  431. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "bias", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_BIAS);
  432. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_SOFTNESS);
  433. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_RELAXATION);
  434. BIND_ENUM_CONSTANT(PARAM_SWING_SPAN);
  435. BIND_ENUM_CONSTANT(PARAM_TWIST_SPAN);
  436. BIND_ENUM_CONSTANT(PARAM_BIAS);
  437. BIND_ENUM_CONSTANT(PARAM_SOFTNESS);
  438. BIND_ENUM_CONSTANT(PARAM_RELAXATION);
  439. BIND_ENUM_CONSTANT(PARAM_MAX);
  440. }
  441. void ConeTwistJoint3D::set_param(Param p_param, real_t p_value) {
  442. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  443. params[p_param] = p_value;
  444. if (is_configured()) {
  445. PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_rid(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value);
  446. }
  447. update_gizmos();
  448. }
  449. real_t ConeTwistJoint3D::get_param(Param p_param) const {
  450. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  451. return params[p_param];
  452. }
  453. void ConeTwistJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
  454. Transform3D gt = get_global_transform();
  455. Transform3D ainv = body_a->get_global_transform().affine_inverse();
  456. Transform3D local_a = ainv * gt;
  457. local_a.orthonormalize();
  458. Transform3D local_b = gt;
  459. if (body_b) {
  460. Transform3D binv = body_b->get_global_transform().affine_inverse();
  461. local_b = binv * gt;
  462. }
  463. local_b.orthonormalize();
  464. PhysicsServer3D::get_singleton()->joint_make_cone_twist(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  465. for (int i = 0; i < PARAM_MAX; i++) {
  466. PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(p_joint, PhysicsServer3D::ConeTwistJointParam(i), params[i]);
  467. }
  468. }
  469. ConeTwistJoint3D::ConeTwistJoint3D() {
  470. params[PARAM_SWING_SPAN] = Math_PI * 0.25;
  471. params[PARAM_TWIST_SPAN] = Math_PI;
  472. params[PARAM_BIAS] = 0.3;
  473. params[PARAM_SOFTNESS] = 0.8;
  474. params[PARAM_RELAXATION] = 1.0;
  475. }
  476. /////////////////////////////////////////////////////////////////////
  477. void Generic6DOFJoint3D::_bind_methods() {
  478. ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint3D::set_param_x);
  479. ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint3D::get_param_x);
  480. ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint3D::set_param_y);
  481. ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint3D::get_param_y);
  482. ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint3D::set_param_z);
  483. ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint3D::get_param_z);
  484. ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint3D::set_flag_x);
  485. ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint3D::get_flag_x);
  486. ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint3D::set_flag_y);
  487. ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint3D::get_flag_y);
  488. ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint3D::set_flag_z);
  489. ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint3D::get_flag_z);
  490. ADD_GROUP("Linear Limit", "linear_limit_");
  491. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT);
  492. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/upper_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT);
  493. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/lower_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_x", "get_param_x", PARAM_LINEAR_LOWER_LIMIT);
  494. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_LIMIT_SOFTNESS);
  495. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_RESTITUTION);
  496. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_DAMPING);
  497. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_LIMIT);
  498. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_y/upper_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_y", "get_param_y", PARAM_LINEAR_UPPER_LIMIT);
  499. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_y/lower_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_y", "get_param_y", PARAM_LINEAR_LOWER_LIMIT);
  500. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_LIMIT_SOFTNESS);
  501. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_RESTITUTION);
  502. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_DAMPING);
  503. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_LIMIT);
  504. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_z/upper_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_z", "get_param_z", PARAM_LINEAR_UPPER_LIMIT);
  505. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_z/lower_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_param_z", "get_param_z", PARAM_LINEAR_LOWER_LIMIT);
  506. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_LIMIT_SOFTNESS);
  507. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_RESTITUTION);
  508. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_DAMPING);
  509. ADD_GROUP("Linear Motor", "linear_motor_");
  510. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_MOTOR);
  511. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_x/target_velocity", PROPERTY_HINT_NONE, "suffix:m/s"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  512. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_x/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m/s\u00B2 (N)"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  513. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_MOTOR);
  514. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_y/target_velocity", PROPERTY_HINT_NONE, "suffix:m/s"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  515. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_y/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m/s\u00B2 (N)"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  516. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_MOTOR);
  517. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_z/target_velocity", PROPERTY_HINT_NONE, "suffix:m/s"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  518. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_motor_z/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m/s\u00B2 (N)"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  519. ADD_GROUP("Linear Spring", "linear_spring_");
  520. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_SPRING);
  521. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_x/stiffness"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_STIFFNESS);
  522. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_x/damping"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_DAMPING);
  523. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_x/equilibrium_point", PROPERTY_HINT_NONE, "suffix:m"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  524. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_SPRING);
  525. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_y/stiffness"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_STIFFNESS);
  526. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_y/damping"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_DAMPING);
  527. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_y/equilibrium_point", PROPERTY_HINT_NONE, "suffix:m"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  528. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_SPRING);
  529. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_z/stiffness"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_STIFFNESS);
  530. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_z/damping"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_DAMPING);
  531. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_spring_z/equilibrium_point", PROPERTY_HINT_NONE, "suffix:m"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  532. ADD_GROUP("Angular Limit", "angular_limit_");
  533. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_LIMIT);
  534. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_x", "get_param_x", PARAM_ANGULAR_UPPER_LIMIT);
  535. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_x", "get_param_x", PARAM_ANGULAR_LOWER_LIMIT);
  536. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_LIMIT_SOFTNESS);
  537. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_RESTITUTION);
  538. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_DAMPING);
  539. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_x", "get_param_x", PARAM_ANGULAR_FORCE_LIMIT);
  540. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_x/erp"), "set_param_x", "get_param_x", PARAM_ANGULAR_ERP);
  541. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_LIMIT);
  542. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_y", "get_param_y", PARAM_ANGULAR_UPPER_LIMIT);
  543. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_y", "get_param_y", PARAM_ANGULAR_LOWER_LIMIT);
  544. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_LIMIT_SOFTNESS);
  545. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_RESTITUTION);
  546. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_DAMPING);
  547. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_y", "get_param_y", PARAM_ANGULAR_FORCE_LIMIT);
  548. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_y/erp"), "set_param_y", "get_param_y", PARAM_ANGULAR_ERP);
  549. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_LIMIT);
  550. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_z", "get_param_z", PARAM_ANGULAR_UPPER_LIMIT);
  551. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_z", "get_param_z", PARAM_ANGULAR_LOWER_LIMIT);
  552. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_LIMIT_SOFTNESS);
  553. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_RESTITUTION);
  554. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_DAMPING);
  555. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_z", "get_param_z", PARAM_ANGULAR_FORCE_LIMIT);
  556. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_limit_z/erp"), "set_param_z", "get_param_z", PARAM_ANGULAR_ERP);
  557. ADD_GROUP("Angular Motor", "angular_motor_");
  558. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_MOTOR);
  559. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_x/target_velocity", PROPERTY_HINT_NONE, U"radians_as_degrees,suffix:\u00B0/s"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  560. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_x/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  561. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_MOTOR);
  562. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_y/target_velocity", PROPERTY_HINT_NONE, U"radians_as_degrees,suffix:\u00B0/s"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  563. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_y/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  564. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_MOTOR);
  565. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_z/target_velocity", PROPERTY_HINT_NONE, U"radians_as_degrees,suffix:\u00B0/s"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  566. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_motor_z/force_limit", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m\u00B2/s\u00B2 (Nm)"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  567. ADD_GROUP("Angular Spring", "angular_spring_");
  568. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_SPRING);
  569. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_x/stiffness"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_STIFFNESS);
  570. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_x/damping"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_DAMPING);
  571. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_x/equilibrium_point", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  572. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_SPRING);
  573. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_y/stiffness"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_STIFFNESS);
  574. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_y/damping"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_DAMPING);
  575. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_y/equilibrium_point", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  576. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_SPRING);
  577. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/stiffness"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_STIFFNESS);
  578. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/damping"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_DAMPING);
  579. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/equilibrium_point", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  580. BIND_ENUM_CONSTANT(PARAM_LINEAR_LOWER_LIMIT);
  581. BIND_ENUM_CONSTANT(PARAM_LINEAR_UPPER_LIMIT);
  582. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
  583. BIND_ENUM_CONSTANT(PARAM_LINEAR_RESTITUTION);
  584. BIND_ENUM_CONSTANT(PARAM_LINEAR_DAMPING);
  585. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  586. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  587. BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_STIFFNESS);
  588. BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_DAMPING);
  589. BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  590. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LOWER_LIMIT);
  591. BIND_ENUM_CONSTANT(PARAM_ANGULAR_UPPER_LIMIT);
  592. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
  593. BIND_ENUM_CONSTANT(PARAM_ANGULAR_DAMPING);
  594. BIND_ENUM_CONSTANT(PARAM_ANGULAR_RESTITUTION);
  595. BIND_ENUM_CONSTANT(PARAM_ANGULAR_FORCE_LIMIT);
  596. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ERP);
  597. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  598. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  599. BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_STIFFNESS);
  600. BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_DAMPING);
  601. BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  602. BIND_ENUM_CONSTANT(PARAM_MAX);
  603. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_LIMIT);
  604. BIND_ENUM_CONSTANT(FLAG_ENABLE_ANGULAR_LIMIT);
  605. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_SPRING);
  606. BIND_ENUM_CONSTANT(FLAG_ENABLE_ANGULAR_SPRING);
  607. BIND_ENUM_CONSTANT(FLAG_ENABLE_MOTOR);
  608. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_MOTOR);
  609. BIND_ENUM_CONSTANT(FLAG_MAX);
  610. }
  611. void Generic6DOFJoint3D::set_param_x(Param p_param, real_t p_value) {
  612. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  613. params_x[p_param] = p_value;
  614. if (is_configured()) {
  615. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_rid(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
  616. }
  617. update_gizmos();
  618. }
  619. real_t Generic6DOFJoint3D::get_param_x(Param p_param) const {
  620. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  621. return params_x[p_param];
  622. }
  623. void Generic6DOFJoint3D::set_param_y(Param p_param, real_t p_value) {
  624. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  625. params_y[p_param] = p_value;
  626. if (is_configured()) {
  627. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_rid(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
  628. }
  629. update_gizmos();
  630. }
  631. real_t Generic6DOFJoint3D::get_param_y(Param p_param) const {
  632. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  633. return params_y[p_param];
  634. }
  635. void Generic6DOFJoint3D::set_param_z(Param p_param, real_t p_value) {
  636. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  637. params_z[p_param] = p_value;
  638. if (is_configured()) {
  639. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_rid(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
  640. }
  641. update_gizmos();
  642. }
  643. real_t Generic6DOFJoint3D::get_param_z(Param p_param) const {
  644. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  645. return params_z[p_param];
  646. }
  647. void Generic6DOFJoint3D::set_flag_x(Flag p_flag, bool p_enabled) {
  648. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  649. flags_x[p_flag] = p_enabled;
  650. if (is_configured()) {
  651. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_rid(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
  652. }
  653. update_gizmos();
  654. }
  655. bool Generic6DOFJoint3D::get_flag_x(Flag p_flag) const {
  656. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  657. return flags_x[p_flag];
  658. }
  659. void Generic6DOFJoint3D::set_flag_y(Flag p_flag, bool p_enabled) {
  660. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  661. flags_y[p_flag] = p_enabled;
  662. if (is_configured()) {
  663. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_rid(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
  664. }
  665. update_gizmos();
  666. }
  667. bool Generic6DOFJoint3D::get_flag_y(Flag p_flag) const {
  668. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  669. return flags_y[p_flag];
  670. }
  671. void Generic6DOFJoint3D::set_flag_z(Flag p_flag, bool p_enabled) {
  672. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  673. flags_z[p_flag] = p_enabled;
  674. if (is_configured()) {
  675. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_rid(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
  676. }
  677. update_gizmos();
  678. }
  679. bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const {
  680. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  681. return flags_z[p_flag];
  682. }
  683. void Generic6DOFJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
  684. Transform3D gt = get_global_transform();
  685. //Vector3 cone_twistpos = gt.origin;
  686. //Vector3 cone_twistdir = gt.basis.get_axis(2);
  687. Transform3D ainv = body_a->get_global_transform().affine_inverse();
  688. Transform3D local_a = ainv * gt;
  689. local_a.orthonormalize();
  690. Transform3D local_b = gt;
  691. if (body_b) {
  692. Transform3D binv = body_b->get_global_transform().affine_inverse();
  693. local_b = binv * gt;
  694. }
  695. local_b.orthonormalize();
  696. PhysicsServer3D::get_singleton()->joint_make_generic_6dof(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  697. for (int i = 0; i < PARAM_MAX; i++) {
  698. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(p_joint, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(i), params_x[i]);
  699. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(p_joint, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(i), params_y[i]);
  700. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(p_joint, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(i), params_z[i]);
  701. }
  702. for (int i = 0; i < FLAG_MAX; i++) {
  703. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(p_joint, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_x[i]);
  704. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(p_joint, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_y[i]);
  705. PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(p_joint, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_z[i]);
  706. }
  707. }
  708. Generic6DOFJoint3D::Generic6DOFJoint3D() {
  709. set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0);
  710. set_param_x(PARAM_LINEAR_UPPER_LIMIT, 0);
  711. set_param_x(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  712. set_param_x(PARAM_LINEAR_RESTITUTION, 0.5);
  713. set_param_x(PARAM_LINEAR_DAMPING, 1.0);
  714. set_param_x(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  715. set_param_x(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  716. set_param_x(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  717. set_param_x(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  718. set_param_x(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  719. set_param_x(PARAM_ANGULAR_LOWER_LIMIT, 0);
  720. set_param_x(PARAM_ANGULAR_UPPER_LIMIT, 0);
  721. set_param_x(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  722. set_param_x(PARAM_ANGULAR_DAMPING, 1.0f);
  723. set_param_x(PARAM_ANGULAR_RESTITUTION, 0);
  724. set_param_x(PARAM_ANGULAR_FORCE_LIMIT, 0);
  725. set_param_x(PARAM_ANGULAR_ERP, 0.5);
  726. set_param_x(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  727. set_param_x(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  728. set_param_x(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  729. set_param_x(PARAM_ANGULAR_SPRING_DAMPING, 0);
  730. set_param_x(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  731. set_flag_x(FLAG_ENABLE_ANGULAR_LIMIT, true);
  732. set_flag_x(FLAG_ENABLE_LINEAR_LIMIT, true);
  733. set_flag_x(FLAG_ENABLE_ANGULAR_SPRING, false);
  734. set_flag_x(FLAG_ENABLE_LINEAR_SPRING, false);
  735. set_flag_x(FLAG_ENABLE_MOTOR, false);
  736. set_flag_x(FLAG_ENABLE_LINEAR_MOTOR, false);
  737. set_param_y(PARAM_LINEAR_LOWER_LIMIT, 0);
  738. set_param_y(PARAM_LINEAR_UPPER_LIMIT, 0);
  739. set_param_y(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  740. set_param_y(PARAM_LINEAR_RESTITUTION, 0.5);
  741. set_param_y(PARAM_LINEAR_DAMPING, 1.0);
  742. set_param_y(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  743. set_param_y(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  744. set_param_y(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  745. set_param_y(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  746. set_param_y(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  747. set_param_y(PARAM_ANGULAR_LOWER_LIMIT, 0);
  748. set_param_y(PARAM_ANGULAR_UPPER_LIMIT, 0);
  749. set_param_y(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  750. set_param_y(PARAM_ANGULAR_DAMPING, 1.0f);
  751. set_param_y(PARAM_ANGULAR_RESTITUTION, 0);
  752. set_param_y(PARAM_ANGULAR_FORCE_LIMIT, 0);
  753. set_param_y(PARAM_ANGULAR_ERP, 0.5);
  754. set_param_y(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  755. set_param_y(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  756. set_param_y(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  757. set_param_y(PARAM_ANGULAR_SPRING_DAMPING, 0);
  758. set_param_y(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  759. set_flag_y(FLAG_ENABLE_ANGULAR_LIMIT, true);
  760. set_flag_y(FLAG_ENABLE_LINEAR_LIMIT, true);
  761. set_flag_y(FLAG_ENABLE_ANGULAR_SPRING, false);
  762. set_flag_y(FLAG_ENABLE_LINEAR_SPRING, false);
  763. set_flag_y(FLAG_ENABLE_MOTOR, false);
  764. set_flag_y(FLAG_ENABLE_LINEAR_MOTOR, false);
  765. set_param_z(PARAM_LINEAR_LOWER_LIMIT, 0);
  766. set_param_z(PARAM_LINEAR_UPPER_LIMIT, 0);
  767. set_param_z(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  768. set_param_z(PARAM_LINEAR_RESTITUTION, 0.5);
  769. set_param_z(PARAM_LINEAR_DAMPING, 1.0);
  770. set_param_z(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  771. set_param_z(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  772. set_param_z(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  773. set_param_z(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  774. set_param_z(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  775. set_param_z(PARAM_ANGULAR_LOWER_LIMIT, 0);
  776. set_param_z(PARAM_ANGULAR_UPPER_LIMIT, 0);
  777. set_param_z(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  778. set_param_z(PARAM_ANGULAR_DAMPING, 1.0f);
  779. set_param_z(PARAM_ANGULAR_RESTITUTION, 0);
  780. set_param_z(PARAM_ANGULAR_FORCE_LIMIT, 0);
  781. set_param_z(PARAM_ANGULAR_ERP, 0.5);
  782. set_param_z(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  783. set_param_z(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  784. set_param_z(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  785. set_param_z(PARAM_ANGULAR_SPRING_DAMPING, 0);
  786. set_param_z(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  787. set_flag_z(FLAG_ENABLE_ANGULAR_LIMIT, true);
  788. set_flag_z(FLAG_ENABLE_LINEAR_LIMIT, true);
  789. set_flag_z(FLAG_ENABLE_ANGULAR_SPRING, false);
  790. set_flag_z(FLAG_ENABLE_LINEAR_SPRING, false);
  791. set_flag_z(FLAG_ENABLE_MOTOR, false);
  792. set_flag_z(FLAG_ENABLE_LINEAR_MOTOR, false);
  793. }