IKConstraint.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Core/Context.h"
  23. #include "../IK/IK.h"
  24. #include "../IK/IKConstraint.h"
  25. #include "../Scene/Node.h"
  26. #include "../Scene/SceneEvents.h"
  27. #include <ik/constraint.h>
  28. #include <ik/node.h>
  29. namespace Urho3D
  30. {
  31. extern const char* IK_CATEGORY;
  32. // ----------------------------------------------------------------------------
  33. IKConstraint::IKConstraint(Context* context) :
  34. Component(context),
  35. ikConstraintNode_(nullptr),
  36. stiffness_(0.0f),
  37. stretchiness_(0.0f)
  38. {
  39. }
  40. // ----------------------------------------------------------------------------
  41. IKConstraint::~IKConstraint() = default;
  42. // ----------------------------------------------------------------------------
  43. void IKConstraint::RegisterObject(Context* context)
  44. {
  45. context->RegisterFactory<IKConstraint>(IK_CATEGORY);
  46. URHO3D_ACCESSOR_ATTRIBUTE("Stiffness", GetStiffness, SetStiffness, float, 0.0f, AM_DEFAULT);
  47. URHO3D_ACCESSOR_ATTRIBUTE("Stretchiness", GetStretchiness, SetStretchiness, float, 0.0f, AM_DEFAULT);
  48. URHO3D_ACCESSOR_ATTRIBUTE("Length Constraints", GetLengthConstraints, SetLengthConstraints, Vector2, Vector2::ZERO, AM_DEFAULT);
  49. }
  50. // ----------------------------------------------------------------------------
  51. float IKConstraint::GetStiffness() const
  52. {
  53. return stiffness_;
  54. }
  55. // ----------------------------------------------------------------------------
  56. void IKConstraint::SetStiffness(float stiffness)
  57. {
  58. stiffness_ = Clamp(stiffness, 0.0f, 1.0f);
  59. // TODO
  60. //if (ikConstraintNode_ != nullptr)
  61. // ikNode_->stiffness = stiffness_;
  62. }
  63. // ----------------------------------------------------------------------------
  64. float IKConstraint::GetStretchiness() const
  65. {
  66. return stretchiness_;
  67. }
  68. // ----------------------------------------------------------------------------
  69. void IKConstraint::SetStretchiness(float stretchiness)
  70. {
  71. stretchiness_ = Clamp(stretchiness, 0.0f, 1.0f);
  72. // TODO
  73. //if (ikConstraintNode_)
  74. // ikNode_->stretchiness = stretchiness_;
  75. }
  76. // ----------------------------------------------------------------------------
  77. const Vector2& IKConstraint::GetLengthConstraints() const
  78. {
  79. return lengthConstraints_;
  80. }
  81. // ----------------------------------------------------------------------------
  82. void IKConstraint::SetLengthConstraints(const Vector2& lengthConstraints)
  83. {
  84. lengthConstraints_ = lengthConstraints;
  85. if (ikConstraintNode_ != nullptr)
  86. {
  87. /* TODO
  88. ikNode_->min_length = lengthConstraints_.x_;
  89. ikNode_->max_length = lengthConstraints_.y_;*/
  90. }
  91. }
  92. // ----------------------------------------------------------------------------
  93. void IKConstraint::SetIKConstraintNode(ik_node_t* constraintNode)
  94. {
  95. ikConstraintNode_ = constraintNode;
  96. if (constraintNode != nullptr)
  97. {
  98. /* TODO
  99. node->stiffness = stiffness_;
  100. node->stretchiness = stretchiness_;
  101. node->min_length = lengthConstraints_.x_;
  102. node->max_length = lengthConstraints_.y_;*/
  103. }
  104. }
  105. } // namespace Urho3D