Bone.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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_Bone_h
  30. #define Spine_Bone_h
  31. #include <spine/Updatable.h>
  32. #include <spine/SpineObject.h>
  33. #include <spine/Vector.h>
  34. namespace spine {
  35. class BoneData;
  36. class Skeleton;
  37. /// Stores a bone's current pose.
  38. ///
  39. /// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a
  40. /// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a
  41. /// constraint or application code modifies the world transform after it was computed from the local transform.
  42. class SP_API Bone : public Updatable {
  43. friend class AnimationState;
  44. friend class RotateTimeline;
  45. friend class IkConstraint;
  46. friend class TransformConstraint;
  47. friend class VertexAttachment;
  48. friend class PathConstraint;
  49. friend class Skeleton;
  50. friend class RegionAttachment;
  51. friend class PointAttachment;
  52. friend class ScaleTimeline;
  53. friend class ShearTimeline;
  54. friend class TranslateTimeline;
  55. RTTI_DECL
  56. public:
  57. static void setYDown(bool inValue);
  58. static bool isYDown();
  59. /// @param parent May be NULL.
  60. Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL);
  61. /// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable.
  62. virtual void update();
  63. /// Computes the world transform using the parent bone and this bone's local transform.
  64. void updateWorldTransform();
  65. /// Computes the world transform using the parent bone and the specified local transform.
  66. void updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY);
  67. void setToSetupPose();
  68. void worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY);
  69. void localToWorld(float localX, float localY, float &outWorldX, float &outWorldY);
  70. float worldToLocalRotation(float worldRotation);
  71. float localToWorldRotation(float localRotation);
  72. /// Rotates the world transform the specified amount and sets isAppliedValid to false.
  73. /// @param degrees Degrees.
  74. void rotateWorld(float degrees);
  75. float getWorldToLocalRotationX();
  76. float getWorldToLocalRotationY();
  77. BoneData &getData();
  78. Skeleton &getSkeleton();
  79. Bone *getParent();
  80. Vector<Bone *> &getChildren();
  81. /// The local X translation.
  82. float getX();
  83. void setX(float inValue);
  84. /// The local Y translation.
  85. float getY();
  86. void setY(float inValue);
  87. /// The local rotation.
  88. float getRotation();
  89. void setRotation(float inValue);
  90. /// The local scaleX.
  91. float getScaleX();
  92. void setScaleX(float inValue);
  93. /// The local scaleY.
  94. float getScaleY();
  95. void setScaleY(float inValue);
  96. /// The local shearX.
  97. float getShearX();
  98. void setShearX(float inValue);
  99. /// The local shearY.
  100. float getShearY();
  101. void setShearY(float inValue);
  102. /// The rotation, as calculated by any constraints.
  103. float getAppliedRotation();
  104. void setAppliedRotation(float inValue);
  105. /// The applied local x translation.
  106. float getAX();
  107. void setAX(float inValue);
  108. /// The applied local y translation.
  109. float getAY();
  110. void setAY(float inValue);
  111. /// The applied local scaleX.
  112. float getAScaleX();
  113. void setAScaleX(float inValue);
  114. /// The applied local scaleY.
  115. float getAScaleY();
  116. void setAScaleY(float inValue);
  117. /// The applied local shearX.
  118. float getAShearX();
  119. void setAShearX(float inValue);
  120. /// The applied local shearY.
  121. float getAShearY();
  122. void setAShearY(float inValue);
  123. float getA();
  124. void setA(float inValue);
  125. float getB();
  126. void setB(float inValue);
  127. float getC();
  128. void setC(float inValue);
  129. float getD();
  130. void setD(float inValue);
  131. float getWorldX();
  132. void setWorldX(float inValue);
  133. float getWorldY();
  134. void setWorldY(float inValue);
  135. float getWorldRotationX();
  136. float getWorldRotationY();
  137. /// Returns the magnitide (always positive) of the world scale X.
  138. float getWorldScaleX();
  139. /// Returns the magnitide (always positive) of the world scale Y.
  140. float getWorldScaleY();
  141. bool isAppliedValid();
  142. void setAppliedValid(bool valid);
  143. bool isActive();
  144. void setActive(bool inValue);
  145. private:
  146. static bool yDown;
  147. BoneData &_data;
  148. Skeleton &_skeleton;
  149. Bone *_parent;
  150. Vector<Bone *> _children;
  151. float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY;
  152. float _ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY;
  153. bool _appliedValid;
  154. float _a, _b, _worldX;
  155. float _c, _d, _worldY;
  156. bool _sorted;
  157. bool _active;
  158. /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using
  159. /// the applied transform after the world transform has been modified directly (eg, by a constraint)..
  160. ///
  161. /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation.
  162. void updateAppliedTransform();
  163. };
  164. }
  165. #endif /* Spine_Bone_h */