cone_twist_joint_bullet.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**************************************************************************/
  2. /* cone_twist_joint_bullet.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 "cone_twist_joint_bullet.h"
  31. #include "bullet_types_converter.h"
  32. #include "bullet_utilities.h"
  33. #include "rigid_body_bullet.h"
  34. #include <BulletDynamics/ConstraintSolver/btConeTwistConstraint.h>
  35. /**
  36. @author AndreaCatania
  37. */
  38. ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame) :
  39. JointBullet() {
  40. Transform scaled_AFrame(rbAFrame.scaled(rbA->get_body_scale()));
  41. _ALLOW_DISCARD_ scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis);
  42. btTransform btFrameA;
  43. G_TO_B(scaled_AFrame, btFrameA);
  44. if (rbB) {
  45. Transform scaled_BFrame(rbBFrame.scaled(rbB->get_body_scale()));
  46. _ALLOW_DISCARD_ scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis);
  47. btTransform btFrameB;
  48. G_TO_B(scaled_BFrame, btFrameB);
  49. coneConstraint = bulletnew(btConeTwistConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB));
  50. } else {
  51. coneConstraint = bulletnew(btConeTwistConstraint(*rbA->get_bt_rigid_body(), btFrameA));
  52. }
  53. setup(coneConstraint);
  54. }
  55. void ConeTwistJointBullet::set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value) {
  56. switch (p_param) {
  57. case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN:
  58. coneConstraint->setLimit(5, p_value);
  59. coneConstraint->setLimit(4, p_value);
  60. break;
  61. case PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN:
  62. coneConstraint->setLimit(3, p_value);
  63. break;
  64. case PhysicsServer::CONE_TWIST_JOINT_BIAS:
  65. coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), coneConstraint->getLimitSoftness(), p_value, coneConstraint->getRelaxationFactor());
  66. break;
  67. case PhysicsServer::CONE_TWIST_JOINT_SOFTNESS:
  68. coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), p_value, coneConstraint->getBiasFactor(), coneConstraint->getRelaxationFactor());
  69. break;
  70. case PhysicsServer::CONE_TWIST_JOINT_RELAXATION:
  71. coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), coneConstraint->getLimitSoftness(), coneConstraint->getBiasFactor(), p_value);
  72. break;
  73. default:
  74. WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated.");
  75. break;
  76. }
  77. }
  78. real_t ConeTwistJointBullet::get_param(PhysicsServer::ConeTwistJointParam p_param) const {
  79. switch (p_param) {
  80. case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN:
  81. return coneConstraint->getSwingSpan1();
  82. case PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN:
  83. return coneConstraint->getTwistSpan();
  84. case PhysicsServer::CONE_TWIST_JOINT_BIAS:
  85. return coneConstraint->getBiasFactor();
  86. case PhysicsServer::CONE_TWIST_JOINT_SOFTNESS:
  87. return coneConstraint->getLimitSoftness();
  88. case PhysicsServer::CONE_TWIST_JOINT_RELAXATION:
  89. return coneConstraint->getRelaxationFactor();
  90. default:
  91. WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated.");
  92. return 0;
  93. }
  94. }