skeleton_2d.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* skeleton_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 SKELETON_2D_H
  31. #define SKELETON_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class Skeleton2D;
  34. class Bone2D : public Node2D {
  35. GDCLASS(Bone2D, Node2D)
  36. friend class Skeleton2D;
  37. Bone2D *parent_bone;
  38. Skeleton2D *skeleton;
  39. Transform2D rest;
  40. float default_length;
  41. int skeleton_index;
  42. protected:
  43. void _notification(int p_what);
  44. static void _bind_methods();
  45. public:
  46. void set_rest(const Transform2D &p_rest);
  47. Transform2D get_rest() const;
  48. void apply_rest();
  49. Transform2D get_skeleton_rest() const;
  50. String get_configuration_warning() const;
  51. void set_default_length(float p_length);
  52. float get_default_length() const;
  53. int get_index_in_skeleton() const;
  54. Bone2D();
  55. };
  56. class Skeleton2D : public Node2D {
  57. GDCLASS(Skeleton2D, Node2D);
  58. friend class Bone2D;
  59. struct Bone {
  60. bool operator<(const Bone &p_bone) const {
  61. return p_bone.bone->is_greater_than(bone);
  62. }
  63. Bone2D *bone;
  64. int parent_index;
  65. Transform2D accum_transform;
  66. Transform2D rest_inverse;
  67. };
  68. Vector<Bone> bones;
  69. bool bone_setup_dirty;
  70. void _make_bone_setup_dirty();
  71. void _update_bone_setup();
  72. bool transform_dirty;
  73. void _make_transform_dirty();
  74. void _update_transform();
  75. RID skeleton;
  76. protected:
  77. void _notification(int p_what);
  78. static void _bind_methods();
  79. public:
  80. int get_bone_count() const;
  81. Bone2D *get_bone(int p_idx);
  82. RID get_skeleton() const;
  83. Skeleton2D();
  84. ~Skeleton2D();
  85. };
  86. #endif // SKELETON_2D_H