Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/3d/look_at_modifier_3d.h
9896 views
1
/**************************************************************************/
2
/* look_at_modifier_3d.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/3d/skeleton_modifier_3d.h"
34
#include "scene/animation/tween.h"
35
36
class LookAtModifier3D : public SkeletonModifier3D {
37
GDCLASS(LookAtModifier3D, SkeletonModifier3D);
38
39
public:
40
enum OriginFrom {
41
ORIGIN_FROM_SELF,
42
ORIGIN_FROM_SPECIFIC_BONE,
43
ORIGIN_FROM_EXTERNAL_NODE,
44
};
45
46
private:
47
String bone_name;
48
int bone = -1;
49
50
Vector3 forward_vector;
51
Vector3 forward_vector_nrm;
52
BoneAxis forward_axis = BONE_AXIS_PLUS_Z;
53
Vector3::Axis primary_rotation_axis = Vector3::AXIS_Y;
54
Vector3::Axis secondary_rotation_axis = Vector3::AXIS_X;
55
bool use_secondary_rotation = true;
56
57
OriginFrom origin_from = ORIGIN_FROM_SELF;
58
String origin_bone_name;
59
int origin_bone = -1;
60
NodePath origin_external_node;
61
62
Vector3 origin_offset;
63
float origin_safe_margin = 0.1;
64
65
NodePath target_node;
66
67
float duration = 0;
68
Tween::TransitionType transition_type = Tween::TRANS_LINEAR;
69
Tween::EaseType ease_type = Tween::EASE_IN;
70
71
bool use_angle_limitation = false;
72
bool symmetry_limitation = true;
73
74
float primary_limit_angle = Math::TAU;
75
float primary_damp_threshold = 1.0f;
76
float primary_positive_limit_angle = Math::PI;
77
float primary_positive_damp_threshold = 1.0f;
78
float primary_negative_limit_angle = Math::PI;
79
float primary_negative_damp_threshold = 1.0f;
80
81
float secondary_limit_angle = Math::TAU;
82
float secondary_damp_threshold = 1.0f;
83
float secondary_positive_limit_angle = Math::PI;
84
float secondary_positive_damp_threshold = 1.0f;
85
float secondary_negative_limit_angle = Math::PI;
86
float secondary_negative_damp_threshold = 1.0f;
87
88
bool is_within_limitations = false;
89
90
// For time-based interpolation.
91
Quaternion from_q;
92
Quaternion prev_q;
93
94
float remaining = 0;
95
float time_step = 1.0;
96
97
float remap_damped(float p_from, float p_to, float p_damp_threshold, float p_value) const;
98
double get_bspline_y(const Vector2 &p_from, const Vector2 &p_control, const Vector2 &p_to, double p_x) const;
99
bool is_intersecting_axis(const Vector3 &p_prev, const Vector3 &p_current, Vector3::Axis p_flipping_axis, Vector3::Axis p_check_axis, bool p_check_plane = false) const;
100
101
Transform3D look_at_with_axes(const Transform3D &p_rest);
102
void init_transition();
103
104
protected:
105
virtual PackedStringArray get_configuration_warnings() const override;
106
void _validate_property(PropertyInfo &p_property) const;
107
108
virtual void _validate_bone_names() override;
109
110
static void _bind_methods();
111
112
virtual void _process_modification(double p_delta) override;
113
114
public:
115
void set_bone_name(const String &p_bone_name);
116
String get_bone_name() const;
117
void set_bone(int p_bone);
118
int get_bone() const;
119
120
void set_forward_axis(BoneAxis p_axis);
121
BoneAxis get_forward_axis() const;
122
void set_primary_rotation_axis(Vector3::Axis p_axis);
123
Vector3::Axis get_primary_rotation_axis() const;
124
void set_use_secondary_rotation(bool p_enabled);
125
bool is_using_secondary_rotation() const;
126
127
void set_origin_from(OriginFrom p_origin_from);
128
OriginFrom get_origin_from() const;
129
void set_origin_bone_name(const String &p_bone_name);
130
String get_origin_bone_name() const;
131
void set_origin_bone(int p_bone);
132
int get_origin_bone() const;
133
void set_origin_external_node(const NodePath &p_external_node);
134
NodePath get_origin_external_node() const;
135
136
void set_origin_offset(const Vector3 &p_offset);
137
Vector3 get_origin_offset() const;
138
void set_origin_safe_margin(float p_margin);
139
float get_origin_safe_margin() const;
140
141
void set_target_node(const NodePath &p_target_node);
142
NodePath get_target_node() const;
143
144
void set_duration(float p_duration);
145
float get_duration() const;
146
void set_transition_type(Tween::TransitionType p_transition_type);
147
Tween::TransitionType get_transition_type() const;
148
void set_ease_type(Tween::EaseType p_ease_type);
149
Tween::EaseType get_ease_type() const;
150
151
void set_use_angle_limitation(bool p_enabled);
152
bool is_using_angle_limitation() const;
153
void set_symmetry_limitation(bool p_enabled);
154
bool is_limitation_symmetry() const;
155
156
void set_primary_limit_angle(float p_angle);
157
float get_primary_limit_angle() const;
158
void set_primary_damp_threshold(float p_power);
159
float get_primary_damp_threshold() const;
160
161
void set_primary_positive_limit_angle(float p_angle);
162
float get_primary_positive_limit_angle() const;
163
void set_primary_positive_damp_threshold(float p_power);
164
float get_primary_positive_damp_threshold() const;
165
void set_primary_negative_limit_angle(float p_angle);
166
float get_primary_negative_limit_angle() const;
167
void set_primary_negative_damp_threshold(float p_power);
168
float get_primary_negative_damp_threshold() const;
169
170
void set_secondary_limit_angle(float p_angle);
171
float get_secondary_limit_angle() const;
172
void set_secondary_damp_threshold(float p_power);
173
float get_secondary_damp_threshold() const;
174
175
void set_secondary_positive_limit_angle(float p_angle);
176
float get_secondary_positive_limit_angle() const;
177
void set_secondary_positive_damp_threshold(float p_power);
178
float get_secondary_positive_damp_threshold() const;
179
void set_secondary_negative_limit_angle(float p_angle);
180
float get_secondary_negative_limit_angle() const;
181
void set_secondary_negative_damp_threshold(float p_power);
182
float get_secondary_negative_damp_threshold() const;
183
184
float get_interpolation_remaining() const;
185
bool is_interpolating() const;
186
bool is_target_within_limitation() const;
187
188
static Vector3::Axis get_secondary_rotation_axis(BoneAxis p_forward_axis, Vector3::Axis p_primary_rotation_axis);
189
static Vector3 get_basis_vector_from_bone_axis(const Basis &p_basis, BoneAxis p_axis);
190
static Vector2 get_projection_vector(const Vector3 &p_vector, Vector3::Axis p_axis);
191
};
192
193
VARIANT_ENUM_CAST(LookAtModifier3D::OriginFrom);
194
195