pin_joint_bullet.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*************************************************************************/
  2. /* pin_joint_bullet.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "pin_joint_bullet.h"
  31. #include "bullet_types_converter.h"
  32. #include "rigid_body_bullet.h"
  33. #include <BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h>
  34. /**
  35. @author AndreaCatania
  36. */
  37. PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b) :
  38. JointBullet() {
  39. if (p_body_b) {
  40. btVector3 btPivotA;
  41. btVector3 btPivotB;
  42. G_TO_B(p_pos_a * p_body_a->get_body_scale(), btPivotA);
  43. G_TO_B(p_pos_b * p_body_b->get_body_scale(), btPivotB);
  44. p2pConstraint = bulletnew(btPoint2PointConstraint(*p_body_a->get_bt_rigid_body(),
  45. *p_body_b->get_bt_rigid_body(),
  46. btPivotA,
  47. btPivotB));
  48. } else {
  49. btVector3 btPivotA;
  50. G_TO_B(p_pos_a, btPivotA);
  51. p2pConstraint = bulletnew(btPoint2PointConstraint(*p_body_a->get_bt_rigid_body(), btPivotA));
  52. }
  53. setup(p2pConstraint);
  54. }
  55. PinJointBullet::~PinJointBullet() {}
  56. void PinJointBullet::set_param(PhysicsServer::PinJointParam p_param, real_t p_value) {
  57. switch (p_param) {
  58. case PhysicsServer::PIN_JOINT_BIAS:
  59. p2pConstraint->m_setting.m_tau = p_value;
  60. break;
  61. case PhysicsServer::PIN_JOINT_DAMPING:
  62. p2pConstraint->m_setting.m_damping = p_value;
  63. break;
  64. case PhysicsServer::PIN_JOINT_IMPULSE_CLAMP:
  65. p2pConstraint->m_setting.m_impulseClamp = p_value;
  66. break;
  67. }
  68. }
  69. real_t PinJointBullet::get_param(PhysicsServer::PinJointParam p_param) const {
  70. switch (p_param) {
  71. case PhysicsServer::PIN_JOINT_BIAS:
  72. return p2pConstraint->m_setting.m_tau;
  73. case PhysicsServer::PIN_JOINT_DAMPING:
  74. return p2pConstraint->m_setting.m_damping;
  75. case PhysicsServer::PIN_JOINT_IMPULSE_CLAMP:
  76. return p2pConstraint->m_setting.m_impulseClamp;
  77. default:
  78. WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated.");
  79. return 0;
  80. }
  81. }
  82. void PinJointBullet::setPivotInA(const Vector3 &p_pos) {
  83. btVector3 btVec;
  84. G_TO_B(p_pos, btVec);
  85. p2pConstraint->setPivotA(btVec);
  86. }
  87. void PinJointBullet::setPivotInB(const Vector3 &p_pos) {
  88. btVector3 btVec;
  89. G_TO_B(p_pos, btVec);
  90. p2pConstraint->setPivotB(btVec);
  91. }
  92. Vector3 PinJointBullet::getPivotInA() {
  93. btVector3 vec = p2pConstraint->getPivotInA();
  94. Vector3 gVec;
  95. B_TO_G(vec, gVec);
  96. return gVec;
  97. }
  98. Vector3 PinJointBullet::getPivotInB() {
  99. btVector3 vec = p2pConstraint->getPivotInB();
  100. Vector3 gVec;
  101. B_TO_G(vec, gVec);
  102. return gVec;
  103. }