IKConstraint.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // Copyright (c) 2008-2016 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 Atomic
  30. {
  31. extern const char* IK_CATEGORY;
  32. // ----------------------------------------------------------------------------
  33. IKConstraint::IKConstraint(Context* context) :
  34. Component(context),
  35. ikConstraintNode_(NULL),
  36. stiffness_(0.0f),
  37. stretchiness_(0.0f)
  38. {
  39. }
  40. // ----------------------------------------------------------------------------
  41. IKConstraint::~IKConstraint()
  42. {
  43. }
  44. // ----------------------------------------------------------------------------
  45. void IKConstraint::RegisterObject(Context* context)
  46. {
  47. context->RegisterFactory<IKConstraint>(IK_CATEGORY);
  48. ATOMIC_ACCESSOR_ATTRIBUTE("Stiffness", GetStiffness, SetStiffness, float, 0.0f, AM_DEFAULT);
  49. ATOMIC_ACCESSOR_ATTRIBUTE("Stretchiness", GetStretchiness, SetStretchiness, float, 0.0f, AM_DEFAULT);
  50. ATOMIC_ACCESSOR_ATTRIBUTE("Length Constraints", GetLengthConstraints, SetLengthConstraints, Vector2, Vector2::ZERO, AM_DEFAULT);
  51. }
  52. // ----------------------------------------------------------------------------
  53. float IKConstraint::GetStiffness() const
  54. {
  55. return stiffness_;
  56. }
  57. // ----------------------------------------------------------------------------
  58. void IKConstraint::SetStiffness(float stiffness)
  59. {
  60. stiffness_ = Clamp(stiffness, 0.0f, 1.0f);
  61. if (ikConstraintNode_ != NULL)
  62. /* TODO ikNode_->stiffness = stiffness_; */
  63. ;
  64. }
  65. // ----------------------------------------------------------------------------
  66. float IKConstraint::GetStretchiness() const
  67. {
  68. return stretchiness_;
  69. }
  70. // ----------------------------------------------------------------------------
  71. void IKConstraint::SetStretchiness(float stretchiness)
  72. {
  73. stretchiness_ = Clamp(stretchiness, 0.0f, 1.0f);
  74. if (ikConstraintNode_)
  75. /* TODO ikNode_->stretchiness = stretchiness_;*/
  76. ;
  77. }
  78. // ----------------------------------------------------------------------------
  79. const Vector2& IKConstraint::GetLengthConstraints() const
  80. {
  81. return lengthConstraints_;
  82. }
  83. // ----------------------------------------------------------------------------
  84. void IKConstraint::SetLengthConstraints(const Vector2& lengthConstraints)
  85. {
  86. lengthConstraints_ = lengthConstraints;
  87. if (ikConstraintNode_ != NULL)
  88. {
  89. /* TODO
  90. ikNode_->min_length = lengthConstraints_.x_;
  91. ikNode_->max_length = lengthConstraints_.y_;*/
  92. }
  93. }
  94. // ----------------------------------------------------------------------------
  95. void IKConstraint::SetIKConstraintNode(ik_node_t* constraintNode)
  96. {
  97. ikConstraintNode_ = constraintNode;
  98. if (constraintNode != NULL)
  99. {
  100. /* TODO
  101. node->stiffness = stiffness_;
  102. node->stretchiness = stretchiness_;
  103. node->min_length = lengthConstraints_.x_;
  104. node->max_length = lengthConstraints_.y_;*/
  105. }
  106. }
  107. } // namespace Atomic