Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_jiggle.h
9903 views
/**************************************************************************/1/* skeleton_modification_2d_jiggle.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/2d/skeleton_2d.h"33#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"3435///////////////////////////////////////36// SkeletonModification2DJIGGLE37///////////////////////////////////////3839class SkeletonModification2DJiggle : public SkeletonModification2D {40GDCLASS(SkeletonModification2DJiggle, SkeletonModification2D);4142private:43struct Jiggle_Joint_Data2D {44int bone_idx = -1;45NodePath bone2d_node;46ObjectID bone2d_node_cache;4748bool override_defaults = false;49float stiffness = 3;50float mass = 0.75;51float damping = 0.75;52bool use_gravity = false;53Vector2 gravity = Vector2(0, 6.0);5455Vector2 force = Vector2(0, 0);56Vector2 acceleration = Vector2(0, 0);57Vector2 velocity = Vector2(0, 0);58Vector2 last_position = Vector2(0, 0);59Vector2 dynamic_position = Vector2(0, 0);6061Vector2 last_noncollision_position = Vector2(0, 0);62};6364Vector<Jiggle_Joint_Data2D> jiggle_data_chain;6566NodePath target_node;67ObjectID target_node_cache;68void update_target_cache();6970float stiffness = 3;71float mass = 0.75;72float damping = 0.75;73bool use_gravity = false;74Vector2 gravity = Vector2(0, 6);7576bool use_colliders = false;77uint32_t collision_mask = 1;7879void jiggle_joint_update_bone2d_cache(int p_joint_idx);80void _execute_jiggle_joint(int p_joint_idx, Node2D *p_target, float p_delta);81void _update_jiggle_joint_data();8283protected:84static void _bind_methods();85bool _set(const StringName &p_path, const Variant &p_value);86bool _get(const StringName &p_path, Variant &r_ret) const;87void _get_property_list(List<PropertyInfo> *p_list) const;8889public:90void _execute(float p_delta) override;91void _setup_modification(SkeletonModificationStack2D *p_stack) override;9293void set_target_node(const NodePath &p_target_node);94NodePath get_target_node() const;9596void set_stiffness(float p_stiffness);97float get_stiffness() const;98void set_mass(float p_mass);99float get_mass() const;100void set_damping(float p_damping);101float get_damping() const;102void set_use_gravity(bool p_use_gravity);103bool get_use_gravity() const;104void set_gravity(Vector2 p_gravity);105Vector2 get_gravity() const;106107void set_use_colliders(bool p_use_colliders);108bool get_use_colliders() const;109void set_collision_mask(int p_mask);110int get_collision_mask() const;111112int get_jiggle_data_chain_length();113void set_jiggle_data_chain_length(int p_new_length);114115void set_jiggle_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node);116NodePath get_jiggle_joint_bone2d_node(int p_joint_idx) const;117void set_jiggle_joint_bone_index(int p_joint_idx, int p_bone_idx);118int get_jiggle_joint_bone_index(int p_joint_idx) const;119120void set_jiggle_joint_override(int p_joint_idx, bool p_override);121bool get_jiggle_joint_override(int p_joint_idx) const;122void set_jiggle_joint_stiffness(int p_joint_idx, float p_stiffness);123float get_jiggle_joint_stiffness(int p_joint_idx) const;124void set_jiggle_joint_mass(int p_joint_idx, float p_mass);125float get_jiggle_joint_mass(int p_joint_idx) const;126void set_jiggle_joint_damping(int p_joint_idx, float p_damping);127float get_jiggle_joint_damping(int p_joint_idx) const;128void set_jiggle_joint_use_gravity(int p_joint_idx, bool p_use_gravity);129bool get_jiggle_joint_use_gravity(int p_joint_idx) const;130void set_jiggle_joint_gravity(int p_joint_idx, Vector2 p_gravity);131Vector2 get_jiggle_joint_gravity(int p_joint_idx) const;132133SkeletonModification2DJiggle();134~SkeletonModification2DJiggle();135};136137138