physics_joint.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /*************************************************************************/
  2. /* physics_joint.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "physics_joint.h"
  31. void Joint::_update_joint(bool p_only_free) {
  32. if (joint.is_valid()) {
  33. if (ba.is_valid() && bb.is_valid())
  34. PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb);
  35. PhysicsServer::get_singleton()->free(joint);
  36. joint = RID();
  37. ba = RID();
  38. bb = RID();
  39. }
  40. if (p_only_free || !is_inside_tree())
  41. return;
  42. Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
  43. Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
  44. PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a);
  45. PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b);
  46. if (!body_a && body_b)
  47. SWAP(body_a, body_b);
  48. if (!body_a)
  49. return;
  50. joint = _configure_joint(body_a, body_b);
  51. if (!joint.is_valid())
  52. return;
  53. PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority);
  54. ba = body_a->get_rid();
  55. if (body_b)
  56. bb = body_b->get_rid();
  57. PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
  58. }
  59. void Joint::set_node_a(const NodePath &p_node_a) {
  60. if (a == p_node_a)
  61. return;
  62. a = p_node_a;
  63. _update_joint();
  64. }
  65. NodePath Joint::get_node_a() const {
  66. return a;
  67. }
  68. void Joint::set_node_b(const NodePath &p_node_b) {
  69. if (b == p_node_b)
  70. return;
  71. b = p_node_b;
  72. _update_joint();
  73. }
  74. NodePath Joint::get_node_b() const {
  75. return b;
  76. }
  77. void Joint::set_solver_priority(int p_priority) {
  78. solver_priority = p_priority;
  79. if (joint.is_valid())
  80. PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority);
  81. }
  82. int Joint::get_solver_priority() const {
  83. return solver_priority;
  84. }
  85. void Joint::_notification(int p_what) {
  86. switch (p_what) {
  87. case NOTIFICATION_READY: {
  88. _update_joint();
  89. } break;
  90. case NOTIFICATION_EXIT_TREE: {
  91. if (joint.is_valid()) {
  92. _update_joint(true);
  93. }
  94. } break;
  95. }
  96. }
  97. void Joint::set_exclude_nodes_from_collision(bool p_enable) {
  98. if (exclude_from_collision == p_enable)
  99. return;
  100. exclude_from_collision = p_enable;
  101. _update_joint();
  102. }
  103. bool Joint::get_exclude_nodes_from_collision() const {
  104. return exclude_from_collision;
  105. }
  106. void Joint::_bind_methods() {
  107. ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a);
  108. ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a);
  109. ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint::set_node_b);
  110. ClassDB::bind_method(D_METHOD("get_node_b"), &Joint::get_node_b);
  111. ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint::set_solver_priority);
  112. ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint::get_solver_priority);
  113. ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint::set_exclude_nodes_from_collision);
  114. ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision);
  115. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_a", "get_node_a");
  116. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_b", "get_node_b");
  117. ADD_PROPERTY(PropertyInfo(Variant::INT, "solver/priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority");
  118. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision");
  119. }
  120. Joint::Joint() {
  121. exclude_from_collision = true;
  122. solver_priority = 1;
  123. set_notify_transform(true);
  124. }
  125. ///////////////////////////////////
  126. void PinJoint::_bind_methods() {
  127. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint::set_param);
  128. ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint::get_param);
  129. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
  130. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/damping", PROPERTY_HINT_RANGE, "0.01,8.0,0.01"), "set_param", "get_param", PARAM_DAMPING);
  131. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/impulse_clamp", PROPERTY_HINT_RANGE, "0.0,64.0,0.01"), "set_param", "get_param", PARAM_IMPULSE_CLAMP);
  132. BIND_ENUM_CONSTANT(PARAM_BIAS);
  133. BIND_ENUM_CONSTANT(PARAM_DAMPING);
  134. BIND_ENUM_CONSTANT(PARAM_IMPULSE_CLAMP);
  135. }
  136. void PinJoint::set_param(Param p_param, float p_value) {
  137. ERR_FAIL_INDEX(p_param, 3);
  138. params[p_param] = p_value;
  139. if (get_joint().is_valid())
  140. PhysicsServer::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer::PinJointParam(p_param), p_value);
  141. }
  142. float PinJoint::get_param(Param p_param) const {
  143. ERR_FAIL_INDEX_V(p_param, 3, 0);
  144. return params[p_param];
  145. }
  146. RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
  147. Vector3 pinpos = get_global_transform().origin;
  148. Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos);
  149. Vector3 local_b;
  150. if (body_b)
  151. local_b = body_b->get_global_transform().affine_inverse().xform(pinpos);
  152. else
  153. local_b = pinpos;
  154. RID j = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  155. for (int i = 0; i < 3; i++) {
  156. PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PinJointParam(i), params[i]);
  157. }
  158. return j;
  159. }
  160. PinJoint::PinJoint() {
  161. params[PARAM_BIAS] = 0.3;
  162. params[PARAM_DAMPING] = 1;
  163. params[PARAM_IMPULSE_CLAMP] = 0;
  164. }
  165. /////////////////////////////////////////////////
  166. ///////////////////////////////////
  167. void HingeJoint::_set_upper_limit(float p_limit) {
  168. set_param(PARAM_LIMIT_UPPER, Math::deg2rad(p_limit));
  169. }
  170. float HingeJoint::_get_upper_limit() const {
  171. return Math::rad2deg(get_param(PARAM_LIMIT_UPPER));
  172. }
  173. void HingeJoint::_set_lower_limit(float p_limit) {
  174. set_param(PARAM_LIMIT_LOWER, Math::deg2rad(p_limit));
  175. }
  176. float HingeJoint::_get_lower_limit() const {
  177. return Math::rad2deg(get_param(PARAM_LIMIT_LOWER));
  178. }
  179. void HingeJoint::_bind_methods() {
  180. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint::set_param);
  181. ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint::get_param);
  182. ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint::set_flag);
  183. ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint::get_flag);
  184. ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint::_set_upper_limit);
  185. ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint::_get_upper_limit);
  186. ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint::_set_lower_limit);
  187. ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint::_get_lower_limit);
  188. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/bias", PROPERTY_HINT_RANGE, "0.00,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
  189. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit/enable"), "set_flag", "get_flag", FLAG_USE_LIMIT);
  190. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/upper", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_upper_limit", "_get_upper_limit");
  191. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/lower", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_lower_limit", "_get_lower_limit");
  192. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_LIMIT_BIAS);
  193. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_SOFTNESS);
  194. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/relaxation", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_RELAXATION);
  195. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "motor/enable"), "set_flag", "get_flag", FLAG_ENABLE_MOTOR);
  196. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "motor/target_velocity", PROPERTY_HINT_RANGE, "-200,200,0.01,or_greater,or_lesser"), "set_param", "get_param", PARAM_MOTOR_TARGET_VELOCITY);
  197. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "motor/max_impulse", PROPERTY_HINT_RANGE, "0.01,1024,0.01"), "set_param", "get_param", PARAM_MOTOR_MAX_IMPULSE);
  198. BIND_ENUM_CONSTANT(PARAM_BIAS);
  199. BIND_ENUM_CONSTANT(PARAM_LIMIT_UPPER);
  200. BIND_ENUM_CONSTANT(PARAM_LIMIT_LOWER);
  201. BIND_ENUM_CONSTANT(PARAM_LIMIT_BIAS);
  202. BIND_ENUM_CONSTANT(PARAM_LIMIT_SOFTNESS);
  203. BIND_ENUM_CONSTANT(PARAM_LIMIT_RELAXATION);
  204. BIND_ENUM_CONSTANT(PARAM_MOTOR_TARGET_VELOCITY);
  205. BIND_ENUM_CONSTANT(PARAM_MOTOR_MAX_IMPULSE);
  206. BIND_ENUM_CONSTANT(PARAM_MAX);
  207. BIND_ENUM_CONSTANT(FLAG_USE_LIMIT);
  208. BIND_ENUM_CONSTANT(FLAG_ENABLE_MOTOR);
  209. BIND_ENUM_CONSTANT(FLAG_MAX);
  210. }
  211. void HingeJoint::set_param(Param p_param, float p_value) {
  212. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  213. params[p_param] = p_value;
  214. if (get_joint().is_valid())
  215. PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer::HingeJointParam(p_param), p_value);
  216. update_gizmo();
  217. }
  218. float HingeJoint::get_param(Param p_param) const {
  219. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  220. return params[p_param];
  221. }
  222. void HingeJoint::set_flag(Flag p_flag, bool p_value) {
  223. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  224. flags[p_flag] = p_value;
  225. if (get_joint().is_valid())
  226. PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer::HingeJointFlag(p_flag), p_value);
  227. update_gizmo();
  228. }
  229. bool HingeJoint::get_flag(Flag p_flag) const {
  230. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  231. return flags[p_flag];
  232. }
  233. RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
  234. Transform gt = get_global_transform();
  235. Transform ainv = body_a->get_global_transform().affine_inverse();
  236. Transform local_a = ainv * gt;
  237. local_a.orthonormalize();
  238. Transform local_b = gt;
  239. if (body_b) {
  240. Transform binv = body_b->get_global_transform().affine_inverse();
  241. local_b = binv * gt;
  242. }
  243. local_b.orthonormalize();
  244. RID j = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  245. for (int i = 0; i < PARAM_MAX; i++) {
  246. PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HingeJointParam(i), params[i]);
  247. }
  248. for (int i = 0; i < FLAG_MAX; i++) {
  249. set_flag(Flag(i), flags[i]);
  250. PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HingeJointFlag(i), flags[i]);
  251. }
  252. return j;
  253. }
  254. HingeJoint::HingeJoint() {
  255. params[PARAM_BIAS] = 0.3;
  256. params[PARAM_LIMIT_UPPER] = Math_PI * 0.5;
  257. params[PARAM_LIMIT_LOWER] = -Math_PI * 0.5;
  258. params[PARAM_LIMIT_BIAS] = 0.3;
  259. params[PARAM_LIMIT_SOFTNESS] = 0.9;
  260. params[PARAM_LIMIT_RELAXATION] = 1.0;
  261. params[PARAM_MOTOR_TARGET_VELOCITY] = 1;
  262. params[PARAM_MOTOR_MAX_IMPULSE] = 1;
  263. flags[FLAG_USE_LIMIT] = false;
  264. flags[FLAG_ENABLE_MOTOR] = false;
  265. }
  266. /////////////////////////////////////////////////
  267. //////////////////////////////////
  268. void SliderJoint::_set_upper_limit_angular(float p_limit_angular) {
  269. set_param(PARAM_ANGULAR_LIMIT_UPPER, Math::deg2rad(p_limit_angular));
  270. }
  271. float SliderJoint::_get_upper_limit_angular() const {
  272. return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_UPPER));
  273. }
  274. void SliderJoint::_set_lower_limit_angular(float p_limit_angular) {
  275. set_param(PARAM_ANGULAR_LIMIT_LOWER, Math::deg2rad(p_limit_angular));
  276. }
  277. float SliderJoint::_get_lower_limit_angular() const {
  278. return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_LOWER));
  279. }
  280. void SliderJoint::_bind_methods() {
  281. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint::set_param);
  282. ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint::get_param);
  283. ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint::_set_upper_limit_angular);
  284. ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint::_get_upper_limit_angular);
  285. ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint::_set_lower_limit_angular);
  286. ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint::_get_lower_limit_angular);
  287. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/upper_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_UPPER);
  288. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/lower_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_LOWER);
  289. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_SOFTNESS);
  290. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_RESTITUTION);
  291. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_DAMPING);
  292. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_SOFTNESS);
  293. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_RESTITUTION);
  294. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_DAMPING);
  295. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
  296. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
  297. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_DAMPING);
  298. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_upper_limit_angular", "_get_upper_limit_angular");
  299. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_lower_limit_angular", "_get_lower_limit_angular");
  300. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_SOFTNESS);
  301. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_RESTITUTION);
  302. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_DAMPING);
  303. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_SOFTNESS);
  304. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_RESTITUTION);
  305. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_DAMPING);
  306. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
  307. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
  308. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_DAMPING);
  309. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_UPPER);
  310. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_LOWER);
  311. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
  312. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_RESTITUTION);
  313. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_DAMPING);
  314. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_SOFTNESS);
  315. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_RESTITUTION);
  316. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTION_DAMPING);
  317. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
  318. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
  319. BIND_ENUM_CONSTANT(PARAM_LINEAR_ORTHOGONAL_DAMPING);
  320. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_UPPER);
  321. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_LOWER);
  322. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
  323. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_RESTITUTION);
  324. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_DAMPING);
  325. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_SOFTNESS);
  326. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_RESTITUTION);
  327. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTION_DAMPING);
  328. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
  329. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
  330. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_DAMPING);
  331. BIND_ENUM_CONSTANT(PARAM_MAX);
  332. }
  333. void SliderJoint::set_param(Param p_param, float p_value) {
  334. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  335. params[p_param] = p_value;
  336. if (get_joint().is_valid())
  337. PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer::SliderJointParam(p_param), p_value);
  338. update_gizmo();
  339. }
  340. float SliderJoint::get_param(Param p_param) const {
  341. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  342. return params[p_param];
  343. }
  344. RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
  345. Transform gt = get_global_transform();
  346. Transform ainv = body_a->get_global_transform().affine_inverse();
  347. Transform local_a = ainv * gt;
  348. local_a.orthonormalize();
  349. Transform local_b = gt;
  350. if (body_b) {
  351. Transform binv = body_b->get_global_transform().affine_inverse();
  352. local_b = binv * gt;
  353. }
  354. local_b.orthonormalize();
  355. RID j = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  356. for (int i = 0; i < PARAM_MAX; i++) {
  357. PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SliderJointParam(i), params[i]);
  358. }
  359. return j;
  360. }
  361. SliderJoint::SliderJoint() {
  362. params[PARAM_LINEAR_LIMIT_UPPER] = 1.0;
  363. params[PARAM_LINEAR_LIMIT_LOWER] = -1.0;
  364. params[PARAM_LINEAR_LIMIT_SOFTNESS] = 1.0;
  365. params[PARAM_LINEAR_LIMIT_RESTITUTION] = 0.7;
  366. params[PARAM_LINEAR_LIMIT_DAMPING] = 1.0;
  367. params[PARAM_LINEAR_MOTION_SOFTNESS] = 1.0;
  368. params[PARAM_LINEAR_MOTION_RESTITUTION] = 0.7;
  369. params[PARAM_LINEAR_MOTION_DAMPING] = 0; //1.0;
  370. params[PARAM_LINEAR_ORTHOGONAL_SOFTNESS] = 1.0;
  371. params[PARAM_LINEAR_ORTHOGONAL_RESTITUTION] = 0.7;
  372. params[PARAM_LINEAR_ORTHOGONAL_DAMPING] = 1.0;
  373. params[PARAM_ANGULAR_LIMIT_UPPER] = 0;
  374. params[PARAM_ANGULAR_LIMIT_LOWER] = 0;
  375. params[PARAM_ANGULAR_LIMIT_SOFTNESS] = 1.0;
  376. params[PARAM_ANGULAR_LIMIT_RESTITUTION] = 0.7;
  377. params[PARAM_ANGULAR_LIMIT_DAMPING] = 0; //1.0;
  378. params[PARAM_ANGULAR_MOTION_SOFTNESS] = 1.0;
  379. params[PARAM_ANGULAR_MOTION_RESTITUTION] = 0.7;
  380. params[PARAM_ANGULAR_MOTION_DAMPING] = 1.0;
  381. params[PARAM_ANGULAR_ORTHOGONAL_SOFTNESS] = 1.0;
  382. params[PARAM_ANGULAR_ORTHOGONAL_RESTITUTION] = 0.7;
  383. params[PARAM_ANGULAR_ORTHOGONAL_DAMPING] = 1.0;
  384. }
  385. //////////////////////////////////
  386. void ConeTwistJoint::_set_swing_span(float p_limit_angular) {
  387. set_param(PARAM_SWING_SPAN, Math::deg2rad(p_limit_angular));
  388. }
  389. float ConeTwistJoint::_get_swing_span() const {
  390. return Math::rad2deg(get_param(PARAM_SWING_SPAN));
  391. }
  392. void ConeTwistJoint::_set_twist_span(float p_limit_angular) {
  393. set_param(PARAM_TWIST_SPAN, Math::deg2rad(p_limit_angular));
  394. }
  395. float ConeTwistJoint::_get_twist_span() const {
  396. return Math::rad2deg(get_param(PARAM_TWIST_SPAN));
  397. }
  398. void ConeTwistJoint::_bind_methods() {
  399. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint::set_param);
  400. ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint::get_param);
  401. ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint::_set_swing_span);
  402. ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint::_get_swing_span);
  403. ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint::_set_twist_span);
  404. ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint::_get_twist_span);
  405. ADD_PROPERTY(PropertyInfo(Variant::REAL, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_swing_span", "_get_swing_span");
  406. ADD_PROPERTY(PropertyInfo(Variant::REAL, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1"), "_set_twist_span", "_get_twist_span");
  407. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_BIAS);
  408. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_SOFTNESS);
  409. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_RELAXATION);
  410. BIND_ENUM_CONSTANT(PARAM_SWING_SPAN);
  411. BIND_ENUM_CONSTANT(PARAM_TWIST_SPAN);
  412. BIND_ENUM_CONSTANT(PARAM_BIAS);
  413. BIND_ENUM_CONSTANT(PARAM_SOFTNESS);
  414. BIND_ENUM_CONSTANT(PARAM_RELAXATION);
  415. BIND_ENUM_CONSTANT(PARAM_MAX);
  416. }
  417. void ConeTwistJoint::set_param(Param p_param, float p_value) {
  418. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  419. params[p_param] = p_value;
  420. if (get_joint().is_valid())
  421. PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer::ConeTwistJointParam(p_param), p_value);
  422. update_gizmo();
  423. }
  424. float ConeTwistJoint::get_param(Param p_param) const {
  425. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  426. return params[p_param];
  427. }
  428. RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
  429. Transform gt = get_global_transform();
  430. //Vector3 cone_twistpos = gt.origin;
  431. //Vector3 cone_twistdir = gt.basis.get_axis(2);
  432. Transform ainv = body_a->get_global_transform().affine_inverse();
  433. Transform local_a = ainv * gt;
  434. local_a.orthonormalize();
  435. Transform local_b = gt;
  436. if (body_b) {
  437. Transform binv = body_b->get_global_transform().affine_inverse();
  438. local_b = binv * gt;
  439. }
  440. local_b.orthonormalize();
  441. RID j = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  442. for (int i = 0; i < PARAM_MAX; i++) {
  443. PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::ConeTwistJointParam(i), params[i]);
  444. }
  445. return j;
  446. }
  447. ConeTwistJoint::ConeTwistJoint() {
  448. params[PARAM_SWING_SPAN] = Math_PI * 0.25;
  449. params[PARAM_TWIST_SPAN] = Math_PI;
  450. params[PARAM_BIAS] = 0.3;
  451. params[PARAM_SOFTNESS] = 0.8;
  452. params[PARAM_RELAXATION] = 1.0;
  453. }
  454. /////////////////////////////////////////////////////////////////////
  455. void Generic6DOFJoint::_set_angular_hi_limit_x(float p_limit_angular) {
  456. set_param_x(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
  457. }
  458. float Generic6DOFJoint::_get_angular_hi_limit_x() const {
  459. return Math::rad2deg(get_param_x(PARAM_ANGULAR_UPPER_LIMIT));
  460. }
  461. void Generic6DOFJoint::_set_angular_lo_limit_x(float p_limit_angular) {
  462. set_param_x(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
  463. }
  464. float Generic6DOFJoint::_get_angular_lo_limit_x() const {
  465. return Math::rad2deg(get_param_x(PARAM_ANGULAR_LOWER_LIMIT));
  466. }
  467. void Generic6DOFJoint::_set_angular_hi_limit_y(float p_limit_angular) {
  468. set_param_y(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
  469. }
  470. float Generic6DOFJoint::_get_angular_hi_limit_y() const {
  471. return Math::rad2deg(get_param_y(PARAM_ANGULAR_UPPER_LIMIT));
  472. }
  473. void Generic6DOFJoint::_set_angular_lo_limit_y(float p_limit_angular) {
  474. set_param_y(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
  475. }
  476. float Generic6DOFJoint::_get_angular_lo_limit_y() const {
  477. return Math::rad2deg(get_param_y(PARAM_ANGULAR_LOWER_LIMIT));
  478. }
  479. void Generic6DOFJoint::_set_angular_hi_limit_z(float p_limit_angular) {
  480. set_param_z(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
  481. }
  482. float Generic6DOFJoint::_get_angular_hi_limit_z() const {
  483. return Math::rad2deg(get_param_z(PARAM_ANGULAR_UPPER_LIMIT));
  484. }
  485. void Generic6DOFJoint::_set_angular_lo_limit_z(float p_limit_angular) {
  486. set_param_z(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
  487. }
  488. float Generic6DOFJoint::_get_angular_lo_limit_z() const {
  489. return Math::rad2deg(get_param_z(PARAM_ANGULAR_LOWER_LIMIT));
  490. }
  491. void Generic6DOFJoint::_bind_methods() {
  492. ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_x);
  493. ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint::_get_angular_hi_limit_x);
  494. ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_x);
  495. ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint::_get_angular_lo_limit_x);
  496. ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_y);
  497. ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint::_get_angular_hi_limit_y);
  498. ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_y);
  499. ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint::_get_angular_lo_limit_y);
  500. ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_z);
  501. ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint::_get_angular_hi_limit_z);
  502. ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_z);
  503. ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint::_get_angular_lo_limit_z);
  504. ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint::set_param_x);
  505. ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint::get_param_x);
  506. ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint::set_param_y);
  507. ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint::get_param_y);
  508. ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint::set_param_z);
  509. ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint::get_param_z);
  510. ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint::set_flag_x);
  511. ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint::get_flag_x);
  512. ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint::set_flag_y);
  513. ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint::get_flag_y);
  514. ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint::set_flag_z);
  515. ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint::get_flag_z);
  516. ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint::set_precision);
  517. ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint::get_precision);
  518. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT);
  519. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT);
  520. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/lower_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_LOWER_LIMIT);
  521. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_LIMIT_SOFTNESS);
  522. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_RESTITUTION);
  523. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_DAMPING);
  524. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_MOTOR);
  525. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_x/target_velocity"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  526. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_x/force_limit"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  527. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_SPRING);
  528. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_x/stiffness"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_STIFFNESS);
  529. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_x/damping"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_DAMPING);
  530. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_x/equilibrium_point"), "set_param_x", "get_param_x", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  531. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_LIMIT);
  532. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_x", "_get_angular_hi_limit_x");
  533. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_x", "_get_angular_lo_limit_x");
  534. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_LIMIT_SOFTNESS);
  535. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_RESTITUTION);
  536. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_DAMPING);
  537. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/force_limit"), "set_param_x", "get_param_x", PARAM_ANGULAR_FORCE_LIMIT);
  538. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/erp"), "set_param_x", "get_param_x", PARAM_ANGULAR_ERP);
  539. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_MOTOR);
  540. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_x/target_velocity"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  541. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_x/force_limit"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  542. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_SPRING);
  543. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_x/stiffness"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_STIFFNESS);
  544. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_x/damping"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_DAMPING);
  545. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_x/equilibrium_point"), "set_param_x", "get_param_x", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  546. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_LIMIT);
  547. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/upper_distance"), "set_param_y", "get_param_y", PARAM_LINEAR_UPPER_LIMIT);
  548. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/lower_distance"), "set_param_y", "get_param_y", PARAM_LINEAR_LOWER_LIMIT);
  549. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_LIMIT_SOFTNESS);
  550. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_RESTITUTION);
  551. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_DAMPING);
  552. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_MOTOR);
  553. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_y/target_velocity"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  554. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_y/force_limit"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  555. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_SPRING);
  556. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_y/stiffness"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_STIFFNESS);
  557. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_y/damping"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_DAMPING);
  558. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_y/equilibrium_point"), "set_param_y", "get_param_y", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  559. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_LIMIT);
  560. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_y", "_get_angular_hi_limit_y");
  561. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_y", "_get_angular_lo_limit_y");
  562. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_LIMIT_SOFTNESS);
  563. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_RESTITUTION);
  564. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_DAMPING);
  565. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/force_limit"), "set_param_y", "get_param_y", PARAM_ANGULAR_FORCE_LIMIT);
  566. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/erp"), "set_param_y", "get_param_y", PARAM_ANGULAR_ERP);
  567. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_MOTOR);
  568. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_y/target_velocity"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  569. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_y/force_limit"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  570. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_SPRING);
  571. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_y/stiffness"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_STIFFNESS);
  572. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_y/damping"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_DAMPING);
  573. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_y/equilibrium_point"), "set_param_y", "get_param_y", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  574. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_LIMIT);
  575. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/upper_distance"), "set_param_z", "get_param_z", PARAM_LINEAR_UPPER_LIMIT);
  576. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/lower_distance"), "set_param_z", "get_param_z", PARAM_LINEAR_LOWER_LIMIT);
  577. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_LIMIT_SOFTNESS);
  578. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_RESTITUTION);
  579. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_DAMPING);
  580. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_MOTOR);
  581. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_z/target_velocity"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  582. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_z/force_limit"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  583. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_spring_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_SPRING);
  584. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_z/stiffness"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_STIFFNESS);
  585. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_z/damping"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_DAMPING);
  586. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_spring_z/equilibrium_point"), "set_param_z", "get_param_z", PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT);
  587. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_LIMIT);
  588. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_z", "_get_angular_hi_limit_z");
  589. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_z", "_get_angular_lo_limit_z");
  590. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_LIMIT_SOFTNESS);
  591. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_RESTITUTION);
  592. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_DAMPING);
  593. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/force_limit"), "set_param_z", "get_param_z", PARAM_ANGULAR_FORCE_LIMIT);
  594. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/erp"), "set_param_z", "get_param_z", PARAM_ANGULAR_ERP);
  595. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_MOTOR);
  596. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_z/target_velocity"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  597. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_z/force_limit"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  598. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_spring_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_SPRING);
  599. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_z/stiffness"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_STIFFNESS);
  600. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_z/damping"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_DAMPING);
  601. ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_spring_z/equilibrium_point"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  602. ADD_PROPERTY(PropertyInfo(Variant::INT, "precision", PROPERTY_HINT_RANGE, "1,99999,1"), "set_precision", "get_precision");
  603. BIND_ENUM_CONSTANT(PARAM_LINEAR_LOWER_LIMIT);
  604. BIND_ENUM_CONSTANT(PARAM_LINEAR_UPPER_LIMIT);
  605. BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
  606. BIND_ENUM_CONSTANT(PARAM_LINEAR_RESTITUTION);
  607. BIND_ENUM_CONSTANT(PARAM_LINEAR_DAMPING);
  608. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_TARGET_VELOCITY);
  609. BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_FORCE_LIMIT);
  610. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LOWER_LIMIT);
  611. BIND_ENUM_CONSTANT(PARAM_ANGULAR_UPPER_LIMIT);
  612. BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
  613. BIND_ENUM_CONSTANT(PARAM_ANGULAR_DAMPING);
  614. BIND_ENUM_CONSTANT(PARAM_ANGULAR_RESTITUTION);
  615. BIND_ENUM_CONSTANT(PARAM_ANGULAR_FORCE_LIMIT);
  616. BIND_ENUM_CONSTANT(PARAM_ANGULAR_ERP);
  617. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
  618. BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
  619. BIND_ENUM_CONSTANT(PARAM_MAX);
  620. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_LIMIT);
  621. BIND_ENUM_CONSTANT(FLAG_ENABLE_ANGULAR_LIMIT);
  622. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_SPRING);
  623. BIND_ENUM_CONSTANT(FLAG_ENABLE_ANGULAR_SPRING);
  624. BIND_ENUM_CONSTANT(FLAG_ENABLE_MOTOR);
  625. BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_MOTOR);
  626. BIND_ENUM_CONSTANT(FLAG_MAX);
  627. }
  628. void Generic6DOFJoint::set_param_x(Param p_param, float p_value) {
  629. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  630. params_x[p_param] = p_value;
  631. if (get_joint().is_valid())
  632. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
  633. update_gizmo();
  634. }
  635. float Generic6DOFJoint::get_param_x(Param p_param) const {
  636. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  637. return params_x[p_param];
  638. }
  639. void Generic6DOFJoint::set_param_y(Param p_param, float p_value) {
  640. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  641. params_y[p_param] = p_value;
  642. if (get_joint().is_valid())
  643. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
  644. update_gizmo();
  645. }
  646. float Generic6DOFJoint::get_param_y(Param p_param) const {
  647. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  648. return params_y[p_param];
  649. }
  650. void Generic6DOFJoint::set_param_z(Param p_param, float p_value) {
  651. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  652. params_z[p_param] = p_value;
  653. if (get_joint().is_valid())
  654. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
  655. update_gizmo();
  656. }
  657. float Generic6DOFJoint::get_param_z(Param p_param) const {
  658. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  659. return params_z[p_param];
  660. }
  661. void Generic6DOFJoint::set_flag_x(Flag p_flag, bool p_enabled) {
  662. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  663. flags_x[p_flag] = p_enabled;
  664. if (get_joint().is_valid())
  665. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
  666. update_gizmo();
  667. }
  668. bool Generic6DOFJoint::get_flag_x(Flag p_flag) const {
  669. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  670. return flags_x[p_flag];
  671. }
  672. void Generic6DOFJoint::set_flag_y(Flag p_flag, bool p_enabled) {
  673. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  674. flags_y[p_flag] = p_enabled;
  675. if (get_joint().is_valid())
  676. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
  677. update_gizmo();
  678. }
  679. bool Generic6DOFJoint::get_flag_y(Flag p_flag) const {
  680. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  681. return flags_y[p_flag];
  682. }
  683. void Generic6DOFJoint::set_flag_z(Flag p_flag, bool p_enabled) {
  684. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  685. flags_z[p_flag] = p_enabled;
  686. if (get_joint().is_valid())
  687. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
  688. update_gizmo();
  689. }
  690. bool Generic6DOFJoint::get_flag_z(Flag p_flag) const {
  691. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  692. return flags_z[p_flag];
  693. }
  694. void Generic6DOFJoint::set_precision(int p_precision) {
  695. precision = p_precision;
  696. PhysicsServer::get_singleton()->generic_6dof_joint_set_precision(
  697. get_joint(),
  698. precision);
  699. }
  700. RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
  701. Transform gt = get_global_transform();
  702. //Vector3 cone_twistpos = gt.origin;
  703. //Vector3 cone_twistdir = gt.basis.get_axis(2);
  704. Transform ainv = body_a->get_global_transform().affine_inverse();
  705. Transform local_a = ainv * gt;
  706. local_a.orthonormalize();
  707. Transform local_b = gt;
  708. if (body_b) {
  709. Transform binv = body_b->get_global_transform().affine_inverse();
  710. local_b = binv * gt;
  711. }
  712. local_b.orthonormalize();
  713. RID j = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
  714. for (int i = 0; i < PARAM_MAX; i++) {
  715. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(i), params_x[i]);
  716. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(i), params_y[i]);
  717. PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(i), params_z[i]);
  718. }
  719. for (int i = 0; i < FLAG_MAX; i++) {
  720. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(i), flags_x[i]);
  721. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(i), flags_y[i]);
  722. PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(i), flags_z[i]);
  723. }
  724. return j;
  725. }
  726. Generic6DOFJoint::Generic6DOFJoint() :
  727. precision(1) {
  728. set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0);
  729. set_param_x(PARAM_LINEAR_UPPER_LIMIT, 0);
  730. set_param_x(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  731. set_param_x(PARAM_LINEAR_RESTITUTION, 0.5);
  732. set_param_x(PARAM_LINEAR_DAMPING, 1.0);
  733. set_param_x(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  734. set_param_x(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  735. set_param_x(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  736. set_param_x(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  737. set_param_x(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  738. set_param_x(PARAM_ANGULAR_LOWER_LIMIT, 0);
  739. set_param_x(PARAM_ANGULAR_UPPER_LIMIT, 0);
  740. set_param_x(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  741. set_param_x(PARAM_ANGULAR_DAMPING, 1.0f);
  742. set_param_x(PARAM_ANGULAR_RESTITUTION, 0);
  743. set_param_x(PARAM_ANGULAR_FORCE_LIMIT, 0);
  744. set_param_x(PARAM_ANGULAR_ERP, 0.5);
  745. set_param_x(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  746. set_param_x(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  747. set_param_x(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  748. set_param_x(PARAM_ANGULAR_SPRING_DAMPING, 0);
  749. set_param_x(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  750. set_flag_x(FLAG_ENABLE_ANGULAR_LIMIT, true);
  751. set_flag_x(FLAG_ENABLE_LINEAR_LIMIT, true);
  752. set_flag_x(FLAG_ENABLE_ANGULAR_SPRING, false);
  753. set_flag_x(FLAG_ENABLE_LINEAR_SPRING, false);
  754. set_flag_x(FLAG_ENABLE_MOTOR, false);
  755. set_flag_x(FLAG_ENABLE_LINEAR_MOTOR, false);
  756. set_param_y(PARAM_LINEAR_LOWER_LIMIT, 0);
  757. set_param_y(PARAM_LINEAR_UPPER_LIMIT, 0);
  758. set_param_y(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  759. set_param_y(PARAM_LINEAR_RESTITUTION, 0.5);
  760. set_param_y(PARAM_LINEAR_DAMPING, 1.0);
  761. set_param_y(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  762. set_param_y(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  763. set_param_y(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  764. set_param_y(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  765. set_param_y(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  766. set_param_y(PARAM_ANGULAR_LOWER_LIMIT, 0);
  767. set_param_y(PARAM_ANGULAR_UPPER_LIMIT, 0);
  768. set_param_y(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  769. set_param_y(PARAM_ANGULAR_DAMPING, 1.0f);
  770. set_param_y(PARAM_ANGULAR_RESTITUTION, 0);
  771. set_param_y(PARAM_ANGULAR_FORCE_LIMIT, 0);
  772. set_param_y(PARAM_ANGULAR_ERP, 0.5);
  773. set_param_y(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  774. set_param_y(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  775. set_param_y(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  776. set_param_y(PARAM_ANGULAR_SPRING_DAMPING, 0);
  777. set_param_y(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  778. set_flag_y(FLAG_ENABLE_ANGULAR_LIMIT, true);
  779. set_flag_y(FLAG_ENABLE_LINEAR_LIMIT, true);
  780. set_flag_y(FLAG_ENABLE_ANGULAR_SPRING, false);
  781. set_flag_y(FLAG_ENABLE_LINEAR_SPRING, false);
  782. set_flag_y(FLAG_ENABLE_MOTOR, false);
  783. set_flag_y(FLAG_ENABLE_LINEAR_MOTOR, false);
  784. set_param_z(PARAM_LINEAR_LOWER_LIMIT, 0);
  785. set_param_z(PARAM_LINEAR_UPPER_LIMIT, 0);
  786. set_param_z(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
  787. set_param_z(PARAM_LINEAR_RESTITUTION, 0.5);
  788. set_param_z(PARAM_LINEAR_DAMPING, 1.0);
  789. set_param_z(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0);
  790. set_param_z(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0);
  791. set_param_z(PARAM_LINEAR_SPRING_STIFFNESS, 0.01);
  792. set_param_z(PARAM_LINEAR_SPRING_DAMPING, 0.01);
  793. set_param_z(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT, 0.0);
  794. set_param_z(PARAM_ANGULAR_LOWER_LIMIT, 0);
  795. set_param_z(PARAM_ANGULAR_UPPER_LIMIT, 0);
  796. set_param_z(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
  797. set_param_z(PARAM_ANGULAR_DAMPING, 1.0f);
  798. set_param_z(PARAM_ANGULAR_RESTITUTION, 0);
  799. set_param_z(PARAM_ANGULAR_FORCE_LIMIT, 0);
  800. set_param_z(PARAM_ANGULAR_ERP, 0.5);
  801. set_param_z(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
  802. set_param_z(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
  803. set_param_z(PARAM_ANGULAR_SPRING_STIFFNESS, 0);
  804. set_param_z(PARAM_ANGULAR_SPRING_DAMPING, 0);
  805. set_param_z(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT, 0);
  806. set_flag_z(FLAG_ENABLE_ANGULAR_LIMIT, true);
  807. set_flag_z(FLAG_ENABLE_LINEAR_LIMIT, true);
  808. set_flag_z(FLAG_ENABLE_ANGULAR_SPRING, false);
  809. set_flag_z(FLAG_ENABLE_LINEAR_SPRING, false);
  810. set_flag_z(FLAG_ENABLE_MOTOR, false);
  811. set_flag_z(FLAG_ENABLE_LINEAR_MOTOR, false);
  812. }