IkConstraint.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef Spine_IkConstraint_h
  30. #define Spine_IkConstraint_h
  31. #include <spine/ConstraintData.h>
  32. #include <spine/Vector.h>
  33. namespace spine {
  34. class IkConstraintData;
  35. class Skeleton;
  36. class Bone;
  37. class SP_API IkConstraint : public Updatable {
  38. friend class Skeleton;
  39. friend class IkConstraintTimeline;
  40. RTTI_DECL
  41. public:
  42. /// Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified
  43. /// in the world coordinate system.
  44. static void apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha);
  45. /// Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as
  46. /// possible. The target is specified in the world coordinate system.
  47. /// @param child A direct descendant of the parent bone.
  48. static void apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, float softness, float alpha);
  49. IkConstraint(IkConstraintData &data, Skeleton &skeleton);
  50. /// Applies the constraint to the constrained bones.
  51. void apply();
  52. virtual void update();
  53. virtual int getOrder();
  54. IkConstraintData &getData();
  55. Vector<Bone *> &getBones();
  56. Bone *getTarget();
  57. void setTarget(Bone *inValue);
  58. int getBendDirection();
  59. void setBendDirection(int inValue);
  60. bool getCompress();
  61. void setCompress(bool inValue);
  62. bool getStretch();
  63. void setStretch(bool inValue);
  64. float getMix();
  65. void setMix(float inValue);
  66. float getSoftness();
  67. void setSoftness(float inValue);
  68. bool isActive();
  69. void setActive(bool inValue);
  70. private:
  71. IkConstraintData &_data;
  72. Vector<Bone *> _bones;
  73. int _bendDirection;
  74. bool _compress;
  75. bool _stretch;
  76. float _mix;
  77. float _softness;
  78. Bone *_target;
  79. bool _active;
  80. };
  81. }
  82. #endif /* Spine_IkConstraint_h */