skeleton_modification_2d_jiggle.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**************************************************************************/
  2. /* skeleton_modification_2d_jiggle.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_MODIFICATION_2D_JIGGLE_H
  31. #define SKELETON_MODIFICATION_2D_JIGGLE_H
  32. #include "scene/2d/skeleton_2d.h"
  33. #include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
  34. ///////////////////////////////////////
  35. // SkeletonModification2DJIGGLE
  36. ///////////////////////////////////////
  37. class SkeletonModification2DJiggle : public SkeletonModification2D {
  38. GDCLASS(SkeletonModification2DJiggle, SkeletonModification2D);
  39. private:
  40. struct Jiggle_Joint_Data2D {
  41. int bone_idx = -1;
  42. NodePath bone2d_node;
  43. ObjectID bone2d_node_cache;
  44. bool override_defaults = false;
  45. float stiffness = 3;
  46. float mass = 0.75;
  47. float damping = 0.75;
  48. bool use_gravity = false;
  49. Vector2 gravity = Vector2(0, 6.0);
  50. Vector2 force = Vector2(0, 0);
  51. Vector2 acceleration = Vector2(0, 0);
  52. Vector2 velocity = Vector2(0, 0);
  53. Vector2 last_position = Vector2(0, 0);
  54. Vector2 dynamic_position = Vector2(0, 0);
  55. Vector2 last_noncollision_position = Vector2(0, 0);
  56. };
  57. Vector<Jiggle_Joint_Data2D> jiggle_data_chain;
  58. NodePath target_node;
  59. ObjectID target_node_cache;
  60. void update_target_cache();
  61. float stiffness = 3;
  62. float mass = 0.75;
  63. float damping = 0.75;
  64. bool use_gravity = false;
  65. Vector2 gravity = Vector2(0, 6);
  66. bool use_colliders = false;
  67. uint32_t collision_mask = 1;
  68. void jiggle_joint_update_bone2d_cache(int p_joint_idx);
  69. void _execute_jiggle_joint(int p_joint_idx, Node2D *p_target, float p_delta);
  70. void _update_jiggle_joint_data();
  71. protected:
  72. static void _bind_methods();
  73. bool _set(const StringName &p_path, const Variant &p_value);
  74. bool _get(const StringName &p_path, Variant &r_ret) const;
  75. void _get_property_list(List<PropertyInfo> *p_list) const;
  76. public:
  77. void _execute(float p_delta) override;
  78. void _setup_modification(SkeletonModificationStack2D *p_stack) override;
  79. void set_target_node(const NodePath &p_target_node);
  80. NodePath get_target_node() const;
  81. void set_stiffness(float p_stiffness);
  82. float get_stiffness() const;
  83. void set_mass(float p_mass);
  84. float get_mass() const;
  85. void set_damping(float p_damping);
  86. float get_damping() const;
  87. void set_use_gravity(bool p_use_gravity);
  88. bool get_use_gravity() const;
  89. void set_gravity(Vector2 p_gravity);
  90. Vector2 get_gravity() const;
  91. void set_use_colliders(bool p_use_colliders);
  92. bool get_use_colliders() const;
  93. void set_collision_mask(int p_mask);
  94. int get_collision_mask() const;
  95. int get_jiggle_data_chain_length();
  96. void set_jiggle_data_chain_length(int p_new_length);
  97. void set_jiggle_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node);
  98. NodePath get_jiggle_joint_bone2d_node(int p_joint_idx) const;
  99. void set_jiggle_joint_bone_index(int p_joint_idx, int p_bone_idx);
  100. int get_jiggle_joint_bone_index(int p_joint_idx) const;
  101. void set_jiggle_joint_override(int p_joint_idx, bool p_override);
  102. bool get_jiggle_joint_override(int p_joint_idx) const;
  103. void set_jiggle_joint_stiffness(int p_joint_idx, float p_stiffness);
  104. float get_jiggle_joint_stiffness(int p_joint_idx) const;
  105. void set_jiggle_joint_mass(int p_joint_idx, float p_mass);
  106. float get_jiggle_joint_mass(int p_joint_idx) const;
  107. void set_jiggle_joint_damping(int p_joint_idx, float p_damping);
  108. float get_jiggle_joint_damping(int p_joint_idx) const;
  109. void set_jiggle_joint_use_gravity(int p_joint_idx, bool p_use_gravity);
  110. bool get_jiggle_joint_use_gravity(int p_joint_idx) const;
  111. void set_jiggle_joint_gravity(int p_joint_idx, Vector2 p_gravity);
  112. Vector2 get_jiggle_joint_gravity(int p_joint_idx) const;
  113. SkeletonModification2DJiggle();
  114. ~SkeletonModification2DJiggle();
  115. };
  116. #endif // SKELETON_MODIFICATION_2D_JIGGLE_H