Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_lookat.h
9903 views
1
/**************************************************************************/
2
/* skeleton_modification_2d_lookat.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
// SkeletonModification2DLookAt
38
///////////////////////////////////////
39
40
class SkeletonModification2DLookAt : public SkeletonModification2D {
41
GDCLASS(SkeletonModification2DLookAt, SkeletonModification2D);
42
43
private:
44
int bone_idx = -1;
45
NodePath bone2d_node;
46
ObjectID bone2d_node_cache;
47
48
NodePath target_node;
49
ObjectID target_node_cache;
50
Node2D *target_node_reference = nullptr;
51
52
float additional_rotation = 0;
53
bool enable_constraint = false;
54
float constraint_angle_min = 0;
55
float constraint_angle_max = (2.0 * Math::PI);
56
bool constraint_angle_invert = false;
57
bool constraint_in_localspace = true;
58
59
void update_bone2d_cache();
60
void update_target_cache();
61
62
protected:
63
static void _bind_methods();
64
bool _set(const StringName &p_path, const Variant &p_value);
65
bool _get(const StringName &p_path, Variant &r_ret) const;
66
void _get_property_list(List<PropertyInfo> *p_list) const;
67
68
public:
69
void _execute(float p_delta) override;
70
void _setup_modification(SkeletonModificationStack2D *p_stack) override;
71
void _draw_editor_gizmo() override;
72
73
void set_bone2d_node(const NodePath &p_target_node);
74
NodePath get_bone2d_node() const;
75
void set_bone_index(int p_idx);
76
int get_bone_index() const;
77
78
void set_target_node(const NodePath &p_target_node);
79
NodePath get_target_node() const;
80
81
void set_additional_rotation(float p_rotation);
82
float get_additional_rotation() const;
83
84
void set_enable_constraint(bool p_constraint);
85
bool get_enable_constraint() const;
86
void set_constraint_angle_min(float p_angle_min);
87
float get_constraint_angle_min() const;
88
void set_constraint_angle_max(float p_angle_max);
89
float get_constraint_angle_max() const;
90
void set_constraint_angle_invert(bool p_invert);
91
bool get_constraint_angle_invert() const;
92
void set_constraint_in_localspace(bool p_constraint_in_localspace);
93
bool get_constraint_in_localspace() const;
94
95
SkeletonModification2DLookAt();
96
~SkeletonModification2DLookAt();
97
};
98
99