Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_jiggle.h
9903 views
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
31
#pragma once
32
33
#include "scene/2d/skeleton_2d.h"
34
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
35
36
///////////////////////////////////////
37
// SkeletonModification2DJIGGLE
38
///////////////////////////////////////
39
40
class SkeletonModification2DJiggle : public SkeletonModification2D {
41
GDCLASS(SkeletonModification2DJiggle, SkeletonModification2D);
42
43
private:
44
struct Jiggle_Joint_Data2D {
45
int bone_idx = -1;
46
NodePath bone2d_node;
47
ObjectID bone2d_node_cache;
48
49
bool override_defaults = false;
50
float stiffness = 3;
51
float mass = 0.75;
52
float damping = 0.75;
53
bool use_gravity = false;
54
Vector2 gravity = Vector2(0, 6.0);
55
56
Vector2 force = Vector2(0, 0);
57
Vector2 acceleration = Vector2(0, 0);
58
Vector2 velocity = Vector2(0, 0);
59
Vector2 last_position = Vector2(0, 0);
60
Vector2 dynamic_position = Vector2(0, 0);
61
62
Vector2 last_noncollision_position = Vector2(0, 0);
63
};
64
65
Vector<Jiggle_Joint_Data2D> jiggle_data_chain;
66
67
NodePath target_node;
68
ObjectID target_node_cache;
69
void update_target_cache();
70
71
float stiffness = 3;
72
float mass = 0.75;
73
float damping = 0.75;
74
bool use_gravity = false;
75
Vector2 gravity = Vector2(0, 6);
76
77
bool use_colliders = false;
78
uint32_t collision_mask = 1;
79
80
void jiggle_joint_update_bone2d_cache(int p_joint_idx);
81
void _execute_jiggle_joint(int p_joint_idx, Node2D *p_target, float p_delta);
82
void _update_jiggle_joint_data();
83
84
protected:
85
static void _bind_methods();
86
bool _set(const StringName &p_path, const Variant &p_value);
87
bool _get(const StringName &p_path, Variant &r_ret) const;
88
void _get_property_list(List<PropertyInfo> *p_list) const;
89
90
public:
91
void _execute(float p_delta) override;
92
void _setup_modification(SkeletonModificationStack2D *p_stack) override;
93
94
void set_target_node(const NodePath &p_target_node);
95
NodePath get_target_node() const;
96
97
void set_stiffness(float p_stiffness);
98
float get_stiffness() const;
99
void set_mass(float p_mass);
100
float get_mass() const;
101
void set_damping(float p_damping);
102
float get_damping() const;
103
void set_use_gravity(bool p_use_gravity);
104
bool get_use_gravity() const;
105
void set_gravity(Vector2 p_gravity);
106
Vector2 get_gravity() const;
107
108
void set_use_colliders(bool p_use_colliders);
109
bool get_use_colliders() const;
110
void set_collision_mask(int p_mask);
111
int get_collision_mask() const;
112
113
int get_jiggle_data_chain_length();
114
void set_jiggle_data_chain_length(int p_new_length);
115
116
void set_jiggle_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node);
117
NodePath get_jiggle_joint_bone2d_node(int p_joint_idx) const;
118
void set_jiggle_joint_bone_index(int p_joint_idx, int p_bone_idx);
119
int get_jiggle_joint_bone_index(int p_joint_idx) const;
120
121
void set_jiggle_joint_override(int p_joint_idx, bool p_override);
122
bool get_jiggle_joint_override(int p_joint_idx) const;
123
void set_jiggle_joint_stiffness(int p_joint_idx, float p_stiffness);
124
float get_jiggle_joint_stiffness(int p_joint_idx) const;
125
void set_jiggle_joint_mass(int p_joint_idx, float p_mass);
126
float get_jiggle_joint_mass(int p_joint_idx) const;
127
void set_jiggle_joint_damping(int p_joint_idx, float p_damping);
128
float get_jiggle_joint_damping(int p_joint_idx) const;
129
void set_jiggle_joint_use_gravity(int p_joint_idx, bool p_use_gravity);
130
bool get_jiggle_joint_use_gravity(int p_joint_idx) const;
131
void set_jiggle_joint_gravity(int p_joint_idx, Vector2 p_gravity);
132
Vector2 get_jiggle_joint_gravity(int p_joint_idx) const;
133
134
SkeletonModification2DJiggle();
135
~SkeletonModification2DJiggle();
136
};
137
138