godot_hinge_joint_3d.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/
  2. /* godot_hinge_joint_3d.h */
  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. #ifndef GODOT_HINGE_JOINT_3D_H
  31. #define GODOT_HINGE_JOINT_3D_H
  32. /*
  33. Adapted to Godot from the Bullet library.
  34. */
  35. #include "../godot_joint_3d.h"
  36. #include "godot_jacobian_entry_3d.h"
  37. /*
  38. Bullet Continuous Collision Detection and Physics Library
  39. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  40. This software is provided 'as-is', without any express or implied warranty.
  41. In no event will the authors be held liable for any damages arising from the use of this software.
  42. Permission is granted to anyone to use this software for any purpose,
  43. including commercial applications, and to alter it and redistribute it freely,
  44. subject to the following restrictions:
  45. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  46. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  47. 3. This notice may not be removed or altered from any source distribution.
  48. */
  49. class GodotHingeJoint3D : public GodotJoint3D {
  50. union {
  51. struct {
  52. GodotBody3D *A;
  53. GodotBody3D *B;
  54. };
  55. GodotBody3D *_arr[2] = {};
  56. };
  57. GodotJacobianEntry3D m_jac[3]; //3 orthogonal linear constraints
  58. GodotJacobianEntry3D m_jacAng[3]; //2 orthogonal angular constraints+ 1 for limit/motor
  59. Transform3D m_rbAFrame; // constraint axii. Assumes z is hinge axis.
  60. Transform3D m_rbBFrame;
  61. real_t m_motorTargetVelocity = 0.0;
  62. real_t m_maxMotorImpulse = 0.0;
  63. real_t m_limitSoftness = 0.9;
  64. real_t m_biasFactor = 0.3;
  65. real_t m_relaxationFactor = 1.0;
  66. real_t m_lowerLimit = Math_PI;
  67. real_t m_upperLimit = -Math_PI;
  68. real_t m_kHinge = 0.0;
  69. real_t m_limitSign = 0.0;
  70. real_t m_correction = 0.0;
  71. real_t m_accLimitImpulse = 0.0;
  72. real_t tau = 0.3;
  73. bool m_useLimit = false;
  74. bool m_angularOnly = false;
  75. bool m_enableAngularMotor = false;
  76. bool m_solveLimit = false;
  77. real_t m_appliedImpulse = 0.0;
  78. public:
  79. virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_HINGE; }
  80. virtual bool setup(real_t p_step) override;
  81. virtual void solve(real_t p_step) override;
  82. real_t get_hinge_angle();
  83. void set_param(PhysicsServer3D::HingeJointParam p_param, real_t p_value);
  84. real_t get_param(PhysicsServer3D::HingeJointParam p_param) const;
  85. void set_flag(PhysicsServer3D::HingeJointFlag p_flag, bool p_value);
  86. bool get_flag(PhysicsServer3D::HingeJointFlag p_flag) const;
  87. GodotHingeJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Transform3D &frameA, const Transform3D &frameB);
  88. GodotHingeJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB);
  89. };
  90. #endif // GODOT_HINGE_JOINT_3D_H