summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/image.cpp2
-rw-r--r--core/math/math_2d.cpp9
-rw-r--r--core/math/math_defs.h4
-rw-r--r--core/math/math_funcs.h2
-rw-r--r--core/math/matrix3.cpp126
-rw-r--r--core/math/matrix3.h20
-rw-r--r--core/math/quat.cpp4
-rw-r--r--core/math/quat.h3
-rw-r--r--core/math/vector3.h7
-rw-r--r--core/script_language.h1
-rw-r--r--core/ustring.cpp4
-rw-r--r--core/variant_call.cpp18
-rw-r--r--doc/base/classes.xml62
-rw-r--r--editor/editor_name_dialog.cpp6
-rw-r--r--editor/editor_name_dialog.h1
-rw-r--r--editor/editor_settings.cpp1
-rw-r--r--editor/plugins/script_editor_plugin.cpp14
-rw-r--r--editor/plugins/script_text_editor.cpp15
-rw-r--r--editor/script_create_dialog.cpp48
-rw-r--r--editor/script_create_dialog.h4
-rw-r--r--main/tests/test_math.cpp2
-rw-r--r--modules/gdscript/gd_editor.cpp24
-rw-r--r--modules/gdscript/gd_parser.cpp7
-rw-r--r--modules/gdscript/gd_parser.h1
-rw-r--r--modules/gdscript/gd_script.h1
-rw-r--r--scene/2d/physics_body_2d.cpp2
-rw-r--r--scene/3d/physics_body.cpp124
-rw-r--r--scene/3d/physics_body.h17
-rw-r--r--scene/gui/base_button.cpp2
-rw-r--r--scene/resources/animation.cpp4
-rw-r--r--servers/physics/body_sw.cpp4
31 files changed, 469 insertions, 70 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 5fb7cfa812..8a09dc1a8c 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -94,7 +94,7 @@ void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
for (uint32_t i = 0; i < p_pixelsize; i++) {
- p_dst[ofs] = p_src[ofs + i];
+ p_dst[i] = p_src[ofs + i];
}
}
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index 20b916ee3b..962a42acb9 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -63,7 +63,8 @@ Vector2 Vector2::normalized() const {
}
bool Vector2::is_normalized() const {
- return Math::isequal_approx(length(), (real_t)1.0);
+ // use length_squared() instead of length() to avoid sqrt(), makes it more stringent.
+ return Math::is_equal_approx(length_squared(), 1.0);
}
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
@@ -281,7 +282,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2 Vector2::slide(const Vector2 &p_n) const {
-#ifdef DEBUG_ENABLED
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
#endif
return *this - p_n * this->dot(p_n);
@@ -292,7 +293,7 @@ Vector2 Vector2::bounce(const Vector2 &p_n) const {
}
Vector2 Vector2::reflect(const Vector2 &p_n) const {
-#ifdef DEBUG_ENABLED
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
#endif
return 2.0 * p_n * this->dot(p_n) - *this;
@@ -439,7 +440,9 @@ Transform2D Transform2D::inverse() const {
void Transform2D::affine_invert() {
real_t det = basis_determinant();
+#ifdef MATH_CHECKS
ERR_FAIL_COND(det == 0);
+#endif
real_t idet = 1.0 / det;
SWAP(elements[0][0], elements[1][1]);
diff --git a/core/math/math_defs.h b/core/math/math_defs.h
index 1a5768e515..3d9eb63e11 100644
--- a/core/math/math_defs.h
+++ b/core/math/math_defs.h
@@ -35,6 +35,10 @@
#define CMP_NORMALIZE_TOLERANCE 0.000001
#define CMP_POINT_IN_PLANE_EPSILON 0.00001
+#ifdef DEBUG_ENABLED
+#define MATH_CHECKS
+#endif
+
#define USEC_TO_SEC(m_usec) ((m_usec) / 1000000.0)
/**
* "Real" is a type that will be translated to either floats or fixed depending
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index d71d9bd792..5bfbc1005f 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -168,7 +168,7 @@ public:
static float random(float from, float to);
static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
- static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) {
+ static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b) {
// TODO: Comparing floats for approximate-equality is non-trivial.
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index ef368009d1..c733251c3c 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -62,8 +62,9 @@ void Basis::invert() {
real_t det = elements[0][0] * co[0] +
elements[0][1] * co[1] +
elements[0][2] * co[2];
-
+#ifdef MATH_CHECKS
ERR_FAIL_COND(det == 0);
+#endif
real_t s = 1.0 / det;
set(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
@@ -72,8 +73,9 @@ void Basis::invert() {
}
void Basis::orthonormalize() {
+#ifdef MATH_CHECKS
ERR_FAIL_COND(determinant() == 0);
-
+#endif
// Gram-Schmidt Process
Vector3 x = get_axis(0);
@@ -102,20 +104,20 @@ bool Basis::is_orthogonal() const {
Basis id;
Basis m = (*this) * transposed();
- return isequal_approx(id, m);
+ return is_equal_approx(id, m);
}
bool Basis::is_rotation() const {
- return Math::isequal_approx(determinant(), 1) && is_orthogonal();
+ return Math::is_equal_approx(determinant(), 1) && is_orthogonal();
}
bool Basis::is_symmetric() const {
- if (Math::abs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
+ if (!Math::is_equal_approx(elements[0][1], elements[1][0]))
return false;
- if (Math::abs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
+ if (!Math::is_equal_approx(elements[0][2], elements[2][0]))
return false;
- if (Math::abs(elements[1][2] - elements[2][1]) > CMP_EPSILON)
+ if (!Math::is_equal_approx(elements[1][2], elements[2][1]))
return false;
return true;
@@ -123,11 +125,11 @@ bool Basis::is_symmetric() const {
Basis Basis::diagonalize() {
- //NOTE: only implemented for symmetric matrices
- //with the Jacobi iterative method method
-
+//NOTE: only implemented for symmetric matrices
+//with the Jacobi iterative method method
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(!is_symmetric(), Basis());
-
+#endif
const int ite_max = 1024;
real_t off_matrix_norm_2 = elements[0][1] * elements[0][1] + elements[0][2] * elements[0][2] + elements[1][2] * elements[1][2];
@@ -160,7 +162,7 @@ Basis Basis::diagonalize() {
// Compute the rotation angle
real_t angle;
- if (Math::abs(elements[j][j] - elements[i][i]) < CMP_EPSILON) {
+ if (Math::is_equal_approx(elements[j][j], elements[i][i])) {
angle = Math_PI / 4;
} else {
angle = 0.5 * Math::atan(2 * elements[i][j] / (elements[j][j] - elements[i][i]));
@@ -226,11 +228,25 @@ Basis Basis::scaled(const Vector3 &p_scale) const {
}
Vector3 Basis::get_scale() const {
- // We are assuming M = R.S, and performing a polar decomposition to extract R and S.
- // FIXME: We eventually need a proper polar decomposition.
- // As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
- // (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix.
- // As such, it works in conjunction with get_rotation().
+ // FIXME: We are assuming M = R.S (R is rotation and S is scaling), and use polar decomposition to extract R and S.
+ // A polar decomposition is M = O.P, where O is an orthogonal matrix (meaning rotation and reflection) and
+ // P is a positive semi-definite matrix (meaning it contains absolute values of scaling along its diagonal).
+ //
+ // Despite being different from what we want to achieve, we can nevertheless make use of polar decomposition
+ // here as follows. We can split O into a rotation and a reflection as O = R.Q, and obtain M = R.S where
+ // we defined S = Q.P. Now, R is a proper rotation matrix and S is a (signed) scaling matrix,
+ // which can involve negative scalings. However, there is a catch: unlike the polar decomposition of M = O.P,
+ // the decomposition of O into a rotation and reflection matrix as O = R.Q is not unique.
+ // Therefore, we are going to do this decomposition by sticking to a particular convention.
+ // This may lead to confusion for some users though.
+ //
+ // The convention we use here is to absorb the sign flip into the scaling matrix.
+ // The same convention is also used in other similar functions such as set_scale,
+ // get_rotation_axis_angle, get_rotation, set_rotation_axis_angle, set_rotation_euler, ...
+ //
+ // A proper way to get rid of this issue would be to store the scaling values (or at least their signs)
+ // as a part of Basis. However, if we go that path, we need to disable direct (write) access to the
+ // matrix elements.
real_t det_sign = determinant() > 0 ? 1 : -1;
return det_sign * Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
@@ -238,6 +254,17 @@ Vector3 Basis::get_scale() const {
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
}
+// Sets scaling while preserving rotation.
+// This requires some care when working with matrices with negative determinant,
+// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
+// For details, see the explanation in get_scale.
+void Basis::set_scale(const Vector3 &p_scale) {
+ Vector3 e = get_euler();
+ Basis(); // reset to identity
+ scale(p_scale);
+ rotate(e);
+}
+
// Multiplies the matrix from left by the rotation matrix: M -> R.M
// Note that this does *not* rotate the matrix itself.
//
@@ -260,6 +287,7 @@ void Basis::rotate(const Vector3 &p_euler) {
*this = rotated(p_euler);
}
+// TODO: rename this to get_rotation_euler
Vector3 Basis::get_rotation() const {
// Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
// and returns the Euler angles corresponding to the rotation part, complementing get_scale().
@@ -274,6 +302,42 @@ Vector3 Basis::get_rotation() const {
return m.get_euler();
}
+void Basis::get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const {
+ // Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
+ // and returns the Euler angles corresponding to the rotation part, complementing get_scale().
+ // See the comment in get_scale() for further information.
+ Basis m = orthonormalized();
+ real_t det = m.determinant();
+ if (det < 0) {
+ // Ensure that the determinant is 1, such that result is a proper rotation matrix which can be represented by Euler angles.
+ m.scale(Vector3(-1, -1, -1));
+ }
+
+ m.get_axis_angle(p_axis, p_angle);
+}
+
+// Sets rotation while preserving scaling.
+// This requires some care when working with matrices with negative determinant,
+// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
+// For details, see the explanation in get_scale.
+void Basis::set_rotation_euler(const Vector3 &p_euler) {
+ Vector3 s = get_scale();
+ Basis(); // reset to identity
+ scale(s);
+ rotate(p_euler);
+}
+
+// Sets rotation while preserving scaling.
+// This requires some care when working with matrices with negative determinant,
+// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
+// For details, see the explanation in get_scale.
+void Basis::set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle) {
+ Vector3 s = get_scale();
+ Basis(); // reset to identity
+ scale(s);
+ rotate(p_axis, p_angle);
+}
+
// get_euler returns a vector containing the Euler angles in the format
// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last
// (following the convention they are commonly defined in the literature).
@@ -294,9 +358,9 @@ Vector3 Basis::get_euler() const {
// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
Vector3 euler;
-
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(is_rotation() == false, euler);
-
+#endif
euler.y = Math::asin(elements[0][2]);
if (euler.y < Math_PI * 0.5) {
if (euler.y > -Math_PI * 0.5) {
@@ -340,11 +404,11 @@ void Basis::set_euler(const Vector3 &p_euler) {
*this = xmat * (ymat * zmat);
}
-bool Basis::isequal_approx(const Basis &a, const Basis &b) const {
+bool Basis::is_equal_approx(const Basis &a, const Basis &b) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (Math::isequal_approx(a.elements[i][j], b.elements[i][j]) == false)
+ if (Math::is_equal_approx(a.elements[i][j], b.elements[i][j]) == false)
return false;
}
}
@@ -387,8 +451,9 @@ Basis::operator String() const {
}
Basis::operator Quat() const {
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(is_rotation() == false, Quat());
-
+#endif
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
real_t temp[4];
@@ -482,9 +547,10 @@ void Basis::set_orthogonal_index(int p_index) {
*this = _ortho_bases[p_index];
}
-void Basis::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
+void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
+#ifdef MATH_CHECKS
ERR_FAIL_COND(is_rotation() == false);
-
+#endif
real_t angle, x, y, z; // variables for result
real_t epsilon = 0.01; // margin to allow for rounding errors
real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
@@ -573,11 +639,11 @@ Basis::Basis(const Quat &p_quat) {
xz - wy, yz + wx, 1.0 - (xx + yy));
}
-Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
- // Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
-
+void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
+// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_angle
+#ifdef MATH_CHECKS
ERR_FAIL_COND(p_axis.is_normalized() == false);
-
+#endif
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
real_t cosine = Math::cos(p_phi);
@@ -595,3 +661,7 @@ Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
elements[2][1] = p_axis.y * p_axis.z * (1.0 - cosine) + p_axis.x * sine;
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
}
+
+Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
+ set_axis_angle(p_axis, p_phi);
+}
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index 08e963f56e..c3eeb1f705 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -77,15 +77,25 @@ public:
void rotate(const Vector3 &p_euler);
Basis rotated(const Vector3 &p_euler) const;
+
Vector3 get_rotation() const;
+ void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const;
- void scale(const Vector3 &p_scale);
- Basis scaled(const Vector3 &p_scale) const;
- Vector3 get_scale() const;
+ void set_rotation_euler(const Vector3 &p_euler);
+ void set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle);
Vector3 get_euler() const;
void set_euler(const Vector3 &p_euler);
+ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const;
+ void set_axis_angle(const Vector3 &p_axis, real_t p_phi);
+
+ void scale(const Vector3 &p_scale);
+ Basis scaled(const Vector3 &p_scale) const;
+
+ Vector3 get_scale() const;
+ void set_scale(const Vector3 &p_scale);
+
// transposed dot products
_FORCE_INLINE_ real_t tdotx(const Vector3 &v) const {
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2];
@@ -97,7 +107,7 @@ public:
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
}
- bool isequal_approx(const Basis &a, const Basis &b) const;
+ bool is_equal_approx(const Basis &a, const Basis &b) const;
bool operator==(const Basis &p_matrix) const;
bool operator!=(const Basis &p_matrix) const;
@@ -121,8 +131,6 @@ public:
operator String() const;
- void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
-
/* create / set */
_FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 9662542224..0bea97c2e8 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -92,6 +92,10 @@ Quat Quat::normalized() const {
return *this / length();
}
+bool Quat::is_normalized() const {
+ return Math::is_equal_approx(length(), 1.0);
+}
+
Quat Quat::inverse() const {
return Quat(-x, -y, -z, w);
}
diff --git a/core/math/quat.h b/core/math/quat.h
index 76b3cde2a3..f22275b457 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -48,6 +48,7 @@ public:
real_t length() const;
void normalize();
Quat normalized() const;
+ bool is_normalized() const;
Quat inverse() const;
_FORCE_INLINE_ real_t dot(const Quat &q) const;
void set_euler(const Vector3 &p_euler);
@@ -56,7 +57,7 @@ public:
Quat slerpni(const Quat &q, const real_t &t) const;
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
- _FORCE_INLINE_ void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
+ _FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
r_angle = 2 * Math::acos(w);
r_axis.x = x / Math::sqrt(1 - w * w);
r_axis.y = y / Math::sqrt(1 - w * w);
diff --git a/core/math/vector3.h b/core/math/vector3.h
index a6bc20ccb2..5f4390fbd1 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -389,7 +389,8 @@ Vector3 Vector3::normalized() const {
}
bool Vector3::is_normalized() const {
- return Math::isequal_approx(length(), (real_t)1.0);
+ // use length_squared() instead of length() to avoid sqrt(), makes it more stringent.
+ return Math::is_equal_approx(length_squared(), 1.0);
}
Vector3 Vector3::inverse() const {
@@ -404,7 +405,7 @@ void Vector3::zero() {
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector3 Vector3::slide(const Vector3 &p_n) const {
-#ifdef DEBUG_ENABLED
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3());
#endif
return *this - p_n * this->dot(p_n);
@@ -415,7 +416,7 @@ Vector3 Vector3::bounce(const Vector3 &p_n) const {
}
Vector3 Vector3::reflect(const Vector3 &p_n) const {
-#ifdef DEBUG_ENABLED
+#ifdef MATH_CHECKS
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3());
#endif
return 2.0 * p_n * this->dot(p_n) - *this;
diff --git a/core/script_language.h b/core/script_language.h
index 1ec02f5845..115ab59dca 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -199,6 +199,7 @@ public:
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const = 0;
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
+ virtual bool can_inherit_from_file() { return false; }
virtual int find_function(const String &p_function, const String &p_code) const = 0;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const = 0;
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d2d4b6507f..b01f680dd6 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -513,14 +513,16 @@ String String::camelcase_to_underscore(bool lowercase) const {
for (size_t i = 1; i < this->size(); i++) {
bool is_upper = cstr[i] >= A && cstr[i] <= Z;
+ bool is_number = cstr[i] >= '0' && cstr[i] <= '9';
bool are_next_2_lower = false;
bool was_precedent_upper = cstr[i - 1] >= A && cstr[i - 1] <= Z;
+ bool was_precedent_number = cstr[i - 1] >= '0' && cstr[i - 1] <= '9';
if (i + 2 < this->size()) {
are_next_2_lower = cstr[i + 1] >= a && cstr[i + 1] <= z && cstr[i + 2] >= a && cstr[i + 2] <= z;
}
- bool should_split = ((is_upper && !was_precedent_upper) || (was_precedent_upper && is_upper && are_next_2_lower));
+ bool should_split = ((is_upper && !was_precedent_upper && !was_precedent_number) || (was_precedent_upper && is_upper && are_next_2_lower) || (is_number && !was_precedent_number));
if (should_split) {
new_string += this->substr(start_index, i - start_index) + "_";
start_index = i;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index e87dfd2768..beaee188eb 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -328,6 +328,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Vector2, normalized);
VCALL_LOCALMEM0R(Vector2, length);
VCALL_LOCALMEM0R(Vector2, length_squared);
+ VCALL_LOCALMEM0R(Vector2, is_normalized);
VCALL_LOCALMEM1R(Vector2, distance_to);
VCALL_LOCALMEM1R(Vector2, distance_squared_to);
VCALL_LOCALMEM1R(Vector2, angle_to);
@@ -362,6 +363,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Vector3, max_axis);
VCALL_LOCALMEM0R(Vector3, length);
VCALL_LOCALMEM0R(Vector3, length_squared);
+ VCALL_LOCALMEM0R(Vector3, is_normalized);
VCALL_LOCALMEM0R(Vector3, normalized);
VCALL_LOCALMEM0R(Vector3, inverse);
VCALL_LOCALMEM1R(Vector3, snapped);
@@ -418,6 +420,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Quat, length);
VCALL_LOCALMEM0R(Quat, length_squared);
VCALL_LOCALMEM0R(Quat, normalized);
+ VCALL_LOCALMEM0R(Quat, is_normalized);
VCALL_LOCALMEM0R(Quat, inverse);
VCALL_LOCALMEM1R(Quat, dot);
VCALL_LOCALMEM1R(Quat, xform);
@@ -704,6 +707,9 @@ struct _VariantCall {
VCALL_PTR1R(Basis, scaled);
VCALL_PTR0R(Basis, get_scale);
VCALL_PTR0R(Basis, get_euler);
+ VCALL_PTR1(Basis, set_scale);
+ VCALL_PTR1(Basis, set_rotation_euler);
+ VCALL_PTR2(Basis, set_rotation_axis_angle);
VCALL_PTR1R(Basis, tdotx);
VCALL_PTR1R(Basis, tdoty);
VCALL_PTR1R(Basis, tdotz);
@@ -875,6 +881,11 @@ struct _VariantCall {
r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
}
+ static void Basis_init3(Variant &r_ret, const Variant **p_args) {
+
+ r_ret = Basis(p_args[0]->operator Vector3());
+ }
+
static void Transform_init1(Variant &r_ret, const Variant **p_args) {
Transform t;
@@ -1429,6 +1440,7 @@ void register_variant_methods() {
ADDFUNC0(VECTOR2, REAL, Vector2, length, varray());
ADDFUNC0(VECTOR2, REAL, Vector2, angle, varray());
ADDFUNC0(VECTOR2, REAL, Vector2, length_squared, varray());
+ ADDFUNC0(VECTOR2, BOOL, Vector2, is_normalized, varray());
ADDFUNC1(VECTOR2, REAL, Vector2, distance_to, VECTOR2, "to", varray());
ADDFUNC1(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray());
ADDFUNC1(VECTOR2, REAL, Vector2, angle_to, VECTOR2, "to", varray());
@@ -1462,6 +1474,7 @@ void register_variant_methods() {
ADDFUNC0(VECTOR3, INT, Vector3, max_axis, varray());
ADDFUNC0(VECTOR3, REAL, Vector3, length, varray());
ADDFUNC0(VECTOR3, REAL, Vector3, length_squared, varray());
+ ADDFUNC0(VECTOR3, BOOL, Vector3, is_normalized, varray());
ADDFUNC0(VECTOR3, VECTOR3, Vector3, normalized, varray());
ADDFUNC0(VECTOR3, VECTOR3, Vector3, inverse, varray());
ADDFUNC1(VECTOR3, VECTOR3, Vector3, snapped, REAL, "by", varray());
@@ -1497,6 +1510,7 @@ void register_variant_methods() {
ADDFUNC0(QUAT, REAL, Quat, length, varray());
ADDFUNC0(QUAT, REAL, Quat, length_squared, varray());
ADDFUNC0(QUAT, QUAT, Quat, normalized, varray());
+ ADDFUNC0(QUAT, BOOL, Quat, is_normalized, varray());
ADDFUNC0(QUAT, QUAT, Quat, inverse, varray());
ADDFUNC1(QUAT, REAL, Quat, dot, QUAT, "b", varray());
ADDFUNC1(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray());
@@ -1692,6 +1706,9 @@ void register_variant_methods() {
ADDFUNC0(BASIS, REAL, Basis, determinant, varray());
ADDFUNC2(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", REAL, "phi", varray());
ADDFUNC1(BASIS, BASIS, Basis, scaled, VECTOR3, "scale", varray());
+ ADDFUNC1(BASIS, NIL, Basis, set_scale, VECTOR3, "scale", varray());
+ ADDFUNC1(BASIS, NIL, Basis, set_rotation_euler, VECTOR3, "euler", varray());
+ ADDFUNC2(BASIS, NIL, Basis, set_rotation_axis_angle, VECTOR3, "axis", REAL, "angle", varray());
ADDFUNC0(BASIS, VECTOR3, Basis, get_scale, varray());
ADDFUNC0(BASIS, VECTOR3, Basis, get_euler, varray());
ADDFUNC1(BASIS, REAL, Basis, tdotx, VECTOR3, "with", varray());
@@ -1749,6 +1766,7 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL);
+ _VariantCall::add_constructor(_VariantCall::Basis_init3, Variant::BASIS, "euler", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3);
diff --git a/doc/base/classes.xml b/doc/base/classes.xml
index 9b1f8c788b..e0e88ef348 100644
--- a/doc/base/classes.xml
+++ b/doc/base/classes.xml
@@ -6868,6 +6868,15 @@
<method name="Basis">
<return type="Basis">
</return>
+ <argument index="0" name="euler" type="Vector3">
+ </argument>
+ <description>
+ Create a rotation matrix (in the XYZ convention: first Z, then Y, and X last) from the specified Euler angles, given in the vector format as (third,second,first).
+ </description>
+ </method>
+ <method name="Basis">
+ <return type="Basis">
+ </return>
<argument index="0" name="x_axis" type="Vector3">
</argument>
<argument index="1" name="y_axis" type="Vector3">
@@ -6889,8 +6898,7 @@
<return type="Vector3">
</return>
<description>
- Return Euler angles (in the XYZ convention: first Z, then Y, and X last) from the matrix. Returned vector contains the rotation angles in the format (third,second,first).
- This function only works if the matrix represents a proper rotation.
+ Assuming that the matrix is a proper rotation matrix (orthonormal matrix with determinant +1), return Euler angles (in the XYZ convention: first Z, then Y, and X last). Returned vector contains the rotation angles in the format (third,second,first).
</description>
</method>
<method name="get_orthogonal_index">
@@ -6932,6 +6940,26 @@
Introduce an additional rotation around the given axis by phi (radians). Only relevant when the matrix is being used as a part of [Transform]. The axis must be a normalized vector.
</description>
</method>
+ <method name="set_rotation_euler">
+ <return type="Basis">
+ </return>
+ <argument index="0" name="euler" type="Vector3">
+ </argument>
+ <description>
+ Changes only the rotation part of the [Basis] to a rotation corresponding to given Euler angles, while preserving the scaling part (as determined by get_scale).
+ </description>
+ </method>
+ <method name="set_rotation_axis_angle">
+ <return type="Basis">
+ </return>
+ <argument index="0" name="axis" type="Vector3">
+ </argument>
+ <argument index="1" name="phi" type="float">
+ </argument>
+ <description>
+ Changes only the rotation part of the [Basis] to a rotation around given axis by phi, while preserving the scaling part (as determined by get_scale).
+ </description>
+ </method>
<method name="scaled">
<return type="Basis">
</return>
@@ -6941,6 +6969,15 @@
Introduce an additional scaling specified by the given 3D scaling factor. Only relevant when the matrix is being used as a part of [Transform].
</description>
</method>
+ <method name="set_scale">
+ <return type="Basis">
+ </return>
+ <argument index="0" name="scale" type="Vector3">
+ </argument>
+ <description>
+ Changes only the scaling part of the Basis to the specified scaling, while preserving the rotation part (as determined by get_rotation).
+ </description>
+ </method>
<method name="tdotx">
<return type="float">
</return>
@@ -35148,6 +35185,13 @@
Returns a copy of the quaternion, normalized to unit length.
</description>
</method>
+ <method name="is_normalized">
+ <return type="bool">
+ </return>
+ <description>
+ Returns whether the quaternion is normalized or not.
+ </description>
+ </method>
<method name="slerp">
<return type="Quat">
</return>
@@ -48048,6 +48092,13 @@ do_property].
Returns a normalized vector to unit length.
</description>
</method>
+ <method name="is_normalized">
+ <return type="bool">
+ </return>
+ <description>
+ Returns whether the vector is normalized or not.
+ </description>
+ </method>
<method name="reflect">
<return type="Vector2">
</return>
@@ -48272,6 +48323,13 @@ do_property].
Return a copy of the normalized vector to unit length. This is the same as v / v.length().
</description>
</method>
+ <method name="is_normalized">
+ <return type="bool">
+ </return>
+ <description>
+ Returns whether the vector is normalized or not.
+ </description>
+ </method>
<method name="outer">
<return type="Basis">
</return>
diff --git a/editor/editor_name_dialog.cpp b/editor/editor_name_dialog.cpp
index 972857fd88..29d5dda658 100644
--- a/editor/editor_name_dialog.cpp
+++ b/editor/editor_name_dialog.cpp
@@ -79,9 +79,11 @@ void EditorNameDialog::_bind_methods() {
}
EditorNameDialog::EditorNameDialog() {
+ makevb = memnew(VBoxContainer);
+ add_child(makevb);
name = memnew(LineEdit);
- add_child(name);
- move_child(name, get_label()->get_index() + 1);
+ makevb->add_child(name);
+ makevb->move_child(name, get_label()->get_index() + 1);
name->set_margin(MARGIN_TOP, 5);
name->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5);
name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5);
diff --git a/editor/editor_name_dialog.h b/editor/editor_name_dialog.h
index a98db4ffe6..eeeee34d7e 100644
--- a/editor/editor_name_dialog.h
+++ b/editor/editor_name_dialog.h
@@ -38,6 +38,7 @@ class EditorNameDialog : public ConfirmationDialog {
GDCLASS(EditorNameDialog, ConfirmationDialog);
+ VBoxContainer *makevb;
LineEdit *name;
void _line_gui_input(const InputEvent &p_event);
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index bec4fdadc7..9beffa3c67 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -557,6 +557,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["text_editor/theme/font"] = PropertyInfo(Variant::STRING, "text_editor/theme/font", PROPERTY_HINT_GLOBAL_FILE, "*.fnt");
set("text_editor/completion/auto_brace_complete", false);
set("text_editor/files/restore_scripts_on_load", true);
+ set("text_editor/completion/complete_file_paths", true);
//set("docks/scene_tree/display_old_action_buttons",false);
set("docks/scene_tree/start_create_dialog_fully_expanded", false);
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index a99cd7a2d6..cdcc0a0855 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1534,13 +1534,6 @@ void ScriptEditor::save_all_scripts() {
if (!se)
continue;
- if (!se->is_unsaved())
- continue;
-
- if (trim_trailing_whitespace_on_save) {
- se->trim_trailing_whitespace();
- }
-
if (convert_indent_on_save) {
if (use_space_indentation) {
se->convert_indent_to_spaces();
@@ -1549,6 +1542,13 @@ void ScriptEditor::save_all_scripts() {
}
}
+ if (trim_trailing_whitespace_on_save) {
+ se->trim_trailing_whitespace();
+ }
+
+ if (!se->is_unsaved())
+ continue;
+
Ref<Script> script = se->get_edited_script();
if (script.is_valid())
se->apply_code();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 052c19f34e..e942d6cebd 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -285,6 +285,9 @@ void ScriptTextEditor::convert_indent_to_spaces() {
indent += " ";
}
+ int cursor_line = tx->cursor_get_line();
+ int cursor_column = tx->cursor_get_column();
+
bool changed_indentation = false;
for (int i = 0; i < tx->get_line_count(); i++) {
String line = tx->get_line(i);
@@ -300,6 +303,9 @@ void ScriptTextEditor::convert_indent_to_spaces() {
tx->begin_complex_operation();
changed_indentation = true;
}
+ if (cursor_line == i && cursor_column > j) {
+ cursor_column += indent_size - 1;
+ }
line = line.left(j) + indent + line.right(j + 1);
}
j++;
@@ -307,6 +313,7 @@ void ScriptTextEditor::convert_indent_to_spaces() {
tx->set_line(i, line);
}
if (changed_indentation) {
+ tx->cursor_set_column(cursor_column);
tx->end_complex_operation();
tx->update();
}
@@ -323,6 +330,9 @@ void ScriptTextEditor::convert_indent_to_tabs() {
int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size");
indent_size -= 1;
+ int cursor_line = tx->cursor_get_line();
+ int cursor_column = tx->cursor_get_column();
+
bool changed_indentation = false;
for (int i = 0; i < tx->get_line_count(); i++) {
String line = tx->get_line(i);
@@ -342,7 +352,9 @@ void ScriptTextEditor::convert_indent_to_tabs() {
tx->begin_complex_operation();
changed_indentation = true;
}
-
+ if (cursor_line == i && cursor_column > j) {
+ cursor_column -= indent_size;
+ }
line = line.left(j - indent_size) + "\t" + line.right(j + 1);
j = 0;
space_count = -1;
@@ -355,6 +367,7 @@ void ScriptTextEditor::convert_indent_to_tabs() {
tx->set_line(i, line);
}
if (changed_indentation) {
+ tx->cursor_set_column(cursor_column);
tx->end_complex_operation();
tx->update();
}
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 7808cae0cd..15c540e132 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -55,6 +55,8 @@ bool ScriptCreateDialog::_validate(const String &p_string) {
if (p_string.length() == 0)
return false;
+ String path_chars = "\"res://";
+ bool is_val_path = ScriptServer::get_language(language_menu->get_selected())->can_inherit_from_file();
for (int i = 0; i < p_string.length(); i++) {
if (i == 0) {
@@ -62,7 +64,17 @@ bool ScriptCreateDialog::_validate(const String &p_string) {
return false; // no start with number plz
}
- bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_';
+ if (i == p_string.length() - 1 && is_val_path)
+ return p_string[i] == '\"';
+
+ if (is_val_path && i < path_chars.length()) {
+ if (p_string[i] != path_chars[i])
+ is_val_path = false;
+ else
+ continue;
+ }
+
+ bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || (is_val_path && (p_string[i] == '/' || p_string[i] == '.'));
if (!valid_char)
return false;
@@ -74,7 +86,7 @@ bool ScriptCreateDialog::_validate(const String &p_string) {
void ScriptCreateDialog::_class_name_changed(const String &p_name) {
if (!_validate(parent_name->get_text())) {
- error_label->set_text(TTR("Invalid parent class name"));
+ error_label->set_text(TTR("Invalid parent class name or path"));
error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
} else if (class_name->is_editable()) {
if (class_name->get_text() == "") {
@@ -175,6 +187,12 @@ void ScriptCreateDialog::_lang_changed(int l) {
class_name->set_editable(false);
}
+ if (ScriptServer::get_language(l)->can_inherit_from_file()) {
+ parent_browse_button->show();
+ } else {
+ parent_browse_button->hide();
+ }
+
String selected_ext = "." + ScriptServer::get_language(l)->get_extension();
String path = file_path->get_text();
String extension = "";
@@ -215,7 +233,9 @@ void ScriptCreateDialog::_built_in_pressed() {
}
}
-void ScriptCreateDialog::_browse_path() {
+void ScriptCreateDialog::_browse_path(bool browse_parent) {
+
+ is_browsing_parent = browse_parent;
file_browse->set_mode(EditorFileDialog::MODE_SAVE_FILE);
file_browse->set_disable_overwrite_warning(true);
@@ -238,8 +258,13 @@ void ScriptCreateDialog::_browse_path() {
void ScriptCreateDialog::_file_selected(const String &p_file) {
String p = GlobalConfig::get_singleton()->localize_path(p_file);
- file_path->set_text(p);
- _path_changed(p);
+ if (is_browsing_parent) {
+ parent_name->set_text("\"" + p + "\"");
+ _class_name_changed("\"" + p + "\"");
+ } else {
+ file_path->set_text(p);
+ _path_changed(p);
+ }
}
void ScriptCreateDialog::_path_changed(const String &p_path) {
@@ -353,9 +378,18 @@ ScriptCreateDialog::ScriptCreateDialog() {
vb2->add_child(error_label);
vb->add_margin_child(TTR("Class Name:"), vb2);
+ HBoxContainer *hb1 = memnew(HBoxContainer);
parent_name = memnew(LineEdit);
- vb->add_margin_child(TTR("Inherits:"), parent_name);
parent_name->connect("text_changed", this, "_class_name_changed");
+ parent_name->set_h_size_flags(SIZE_EXPAND_FILL);
+ hb1->add_child(parent_name);
+ parent_browse_button = memnew(Button);
+ parent_browse_button->set_text(" .. ");
+ parent_browse_button->connect("pressed", this, "_browse_path", varray(true));
+ hb1->add_child(parent_browse_button);
+ parent_browse_button->hide();
+ vb->add_margin_child(TTR("Inherits:"), hb1);
+ is_browsing_parent = false;
language_menu = memnew(OptionButton);
vb->add_margin_child(TTR("Language"), language_menu);
@@ -398,7 +432,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
file_path->set_h_size_flags(SIZE_EXPAND_FILL);
Button *b = memnew(Button);
b->set_text(" .. ");
- b->connect("pressed", this, "_browse_path");
+ b->connect("pressed", this, "_browse_path", varray(false));
hbc->add_child(b);
path_vb->add_child(hbc);
path_error_label = memnew(Label);
diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h
index 499886facd..113d4a468c 100644
--- a/editor/script_create_dialog.h
+++ b/editor/script_create_dialog.h
@@ -44,6 +44,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
Label *error_label;
Label *path_error_label;
LineEdit *parent_name;
+ Button *parent_browse_button;
OptionButton *language_menu;
LineEdit *file_path;
EditorFileDialog *file_browse;
@@ -52,6 +53,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
AcceptDialog *alert;
bool path_valid;
bool create_new;
+ bool is_browsing_parent;
String initial_bp;
EditorSettings *editor_settings;
@@ -60,7 +62,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
void _built_in_pressed();
bool _validate(const String &p_strin);
void _class_name_changed(const String &p_name);
- void _browse_path();
+ void _browse_path(bool browse_parent);
void _file_selected(const String &p_file);
virtual void ok_pressed();
void _create_new();
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index cb75dcec13..95a1672e67 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -602,7 +602,7 @@ MainLoop *test() {
print_line(q3);
print_line("before v: " + v + " a: " + rtos(a));
- q.get_axis_and_angle(v, a);
+ q.get_axis_angle(v, a);
print_line("after v: " + v + " a: " + rtos(a));
}
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index c2f14f5466..2a3015c185 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -32,6 +32,10 @@
#include "gd_script.h"
#include "global_config.h"
#include "os/file_access.h"
+#ifdef TOOLS_ENABLED
+#include "editor/editor_file_system.h"
+#include "editor/editor_settings.h"
+#endif
void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
@@ -1406,6 +1410,17 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi
arghint += ")";
}
+void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_list) {
+
+ for (int i = 0; i < p_dir->get_subdir_count(); i++) {
+ get_directory_contents(p_dir->get_subdir(i), r_list);
+ }
+
+ for (int i = 0; i < p_dir->get_file_count(); i++) {
+ r_list.insert("\"" + p_dir->get_file_path(i) + "\"");
+ }
+}
+
static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) {
//print_line("find type arguments?");
@@ -1754,6 +1769,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N
const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
MethodInfo mi = GDFunctions::get_info(fn->function);
+ if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) {
+ get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result);
+ }
+
arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("(");
for (int i = 0; i < mi.arguments.size(); i++) {
if (i > 0)
@@ -2375,6 +2394,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
}
} break;
+ case GDParser::COMPLETION_PRELOAD: {
+
+ if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))
+ get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options);
+ } break;
}
for (Set<String>::Element *E = options.front(); E; E = E->next()) {
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index cd16fef6b3..b02d7f713b 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -387,6 +387,13 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
_set_error("Expected '(' after 'preload'");
return NULL;
}
+ completion_cursor = StringName();
+ completion_type = COMPLETION_PRELOAD;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_block = current_block;
+ completion_found = true;
tokenizer->advance();
String path;
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 445ad7361c..4f3ca0dc5f 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -437,6 +437,7 @@ public:
COMPLETION_PARENT_FUNCTION,
COMPLETION_METHOD,
COMPLETION_CALL_ARGUMENTS,
+ COMPLETION_PRELOAD,
COMPLETION_INDEX,
COMPLETION_VIRTUAL_FUNC,
COMPLETION_YIELD,
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h
index f92c11b9e0..00ae136790 100644
--- a/modules/gdscript/gd_script.h
+++ b/modules/gdscript/gd_script.h
@@ -384,6 +384,7 @@ public:
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
+ virtual bool can_inherit_from_file() { return true; }
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index f752cbf6b6..626ea10515 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1199,7 +1199,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
revert_motion();
return Vector2();
}
- } else if (get_collision_normal().dot(-p_floor_direction) <= Math::cos(p_floor_max_angle)) { //ceiling
+ } else if (get_collision_normal().dot(-p_floor_direction) >= Math::cos(p_floor_max_angle)) { //ceiling
move_and_slide_on_ceiling = true;
} else {
move_and_slide_on_wall = true;
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 94f34d6fb3..98babedf0d 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "physics_body.h"
+#include "method_bind_ext.inc"
#include "scene/scene_string_names.h"
void PhysicsBody::_notification(int p_what) {
@@ -907,6 +908,19 @@ bool KinematicBody::_ignores_mode(PhysicsServer::BodyMode p_mode) const {
return true;
}
+void KinematicBody::revert_motion() {
+
+ Transform gt = get_global_transform();
+ gt.origin -= travel; //I do hope this is correct.
+ travel = Vector3();
+ set_global_transform(gt);
+}
+
+Vector3 KinematicBody::get_travel() const {
+
+ return travel;
+}
+
Vector3 KinematicBody::move(const Vector3 &p_motion) {
//give me back regular physics engine logic
@@ -1097,10 +1111,111 @@ Vector3 KinematicBody::move(const Vector3 &p_motion) {
Transform gt = get_global_transform();
gt.origin += motion;
set_global_transform(gt);
+ travel = motion;
return p_motion - motion;
}
+Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, const Vector3 &p_ceil_direction, float p_slope_stop_min_velocity, int p_max_bounces, float p_floor_max_angle, float p_ceil_max_angle) {
+
+ /*
+ Things to note:
+ 1. This function is basically the KinematicBody2D function ported over.
+ 2. The 'travel' variable and stuff relating to it exists more or less for this function's sake.
+ 3. Someone is going to have to document this, so here's an example for them:
+ vel = move_and_slide(vel, Vector3(0, 1, 0), Vector3(0, -1, 0), 0.1);
+ Very useful for FPS controllers so long as you control horizontal motion properly - even for Quake-style AABB colliders.
+ The slope stop system is... rather weird, and it's correct operation depends on what scale your game is built on,
+ but as far as I can tell in theory it's suppposed to be a way of turning impassable slopes into invisible walls.
+ It can also be a pain, since there's a better-known way of defining such things: "let gravity do the work".
+ If you don't like it, set it to positive infinity.
+ 4. Might be a bug somewhere else in physics: When there are two CollisionShape nodes with a shared Shape, only one is considered, I think.
+ Test this further.
+ */
+
+ Vector3 motion = (move_and_slide_floor_velocity + p_linear_velocity) * get_fixed_process_delta_time();
+ Vector3 lv = p_linear_velocity;
+
+ move_and_slide_on_floor = false;
+ move_and_slide_on_ceiling = false;
+ move_and_slide_on_wall = false;
+ move_and_slide_colliders.clear();
+ move_and_slide_floor_velocity = Vector3();
+
+ while (p_max_bounces) {
+
+ motion = move(motion);
+
+ if (is_colliding()) {
+
+ bool hit_horizontal = false; //hit floor or ceiling
+
+ if (p_floor_direction != Vector3()) {
+ if (get_collision_normal().dot(p_floor_direction) >= Math::cos(p_floor_max_angle)) { //floor
+
+ hit_horizontal = true;
+ move_and_slide_on_floor = true;
+ move_and_slide_floor_velocity = get_collider_velocity();
+
+ //Note: These two lines are the only lines that really changed between 3D/2D, see if it can't be reused somehow???
+ Vector2 hz_velocity = Vector2(lv.x - move_and_slide_floor_velocity.x, lv.z - move_and_slide_floor_velocity.z);
+ if (get_travel().length() < 1 && hz_velocity.length() < p_slope_stop_min_velocity) {
+ revert_motion();
+ return Vector3();
+ }
+ }
+ }
+
+ if (p_ceil_direction != Vector3()) {
+ if (get_collision_normal().dot(p_ceil_direction) >= Math::cos(p_ceil_max_angle)) { //ceiling
+ hit_horizontal = true;
+ move_and_slide_on_ceiling = true;
+ }
+ }
+
+ //if it hit something but didn't hit a floor or ceiling, it is by default a wall
+ //(this imitates the pre-specifiable-ceiling logic more or less, except ceiling is optional)
+ if (!hit_horizontal) {
+ move_and_slide_on_wall = true;
+ }
+
+ Vector3 n = get_collision_normal();
+ motion = motion.slide(n);
+ lv = lv.slide(n);
+ Variant collider = _get_collider();
+ if (collider.get_type() != Variant::NIL) {
+ move_and_slide_colliders.push_back(collider);
+ }
+
+ } else {
+ break;
+ }
+
+ p_max_bounces--;
+ if (motion == Vector3())
+ break;
+ }
+
+ return lv;
+}
+
+bool KinematicBody::is_move_and_slide_on_floor() const {
+
+ return move_and_slide_on_floor;
+}
+bool KinematicBody::is_move_and_slide_on_wall() const {
+
+ return move_and_slide_on_wall;
+}
+bool KinematicBody::is_move_and_slide_on_ceiling() const {
+
+ return move_and_slide_on_ceiling;
+}
+Array KinematicBody::get_move_and_slide_colliders() const {
+
+ return move_and_slide_colliders;
+}
+
Vector3 KinematicBody::move_to(const Vector3 &p_position) {
return move(p_position - get_global_transform().origin);
@@ -1223,6 +1338,7 @@ void KinematicBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("move", "rel_vec"), &KinematicBody::move);
ClassDB::bind_method(D_METHOD("move_to", "position"), &KinematicBody::move_to);
+ ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "ceil_normal", "slope_stop_min_velocity", "max_bounces", "floor_max_angle", "ceil_max_angle"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(Vector3(0, 0, 0)), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(Math::deg2rad((float)45)));
ClassDB::bind_method(D_METHOD("can_teleport_to", "position"), &KinematicBody::can_teleport_to);
@@ -1249,6 +1365,14 @@ void KinematicBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_margin", "pixels"), &KinematicBody::set_collision_margin);
ClassDB::bind_method(D_METHOD("get_collision_margin", "pixels"), &KinematicBody::get_collision_margin);
+ ClassDB::bind_method(D_METHOD("get_travel"), &KinematicBody::get_travel);
+ ClassDB::bind_method(D_METHOD("revert_motion"), &KinematicBody::revert_motion);
+
+ ClassDB::bind_method(D_METHOD("get_move_and_slide_colliders"), &KinematicBody::get_move_and_slide_colliders);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_floor"), &KinematicBody::is_move_and_slide_on_floor);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_ceiling"), &KinematicBody::is_move_and_slide_on_ceiling);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_wall"), &KinematicBody::is_move_and_slide_on_wall);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/static"), "set_collide_with_static_bodies", "can_collide_with_static_bodies");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/kinematic"), "set_collide_with_kinematic_bodies", "can_collide_with_kinematic_bodies");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/rigid"), "set_collide_with_rigid_bodies", "can_collide_with_rigid_bodies");
diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h
index c62f6be13f..d13f84dc15 100644
--- a/scene/3d/physics_body.h
+++ b/scene/3d/physics_body.h
@@ -275,6 +275,13 @@ class KinematicBody : public PhysicsBody {
Vector3 collider_vel;
ObjectID collider;
int collider_shape;
+ Vector3 travel;
+
+ Vector3 move_and_slide_floor_velocity;
+ bool move_and_slide_on_floor;
+ bool move_and_slide_on_ceiling;
+ bool move_and_slide_on_wall;
+ Array move_and_slide_colliders;
Variant _get_collider() const;
@@ -295,6 +302,10 @@ public:
bool can_teleport_to(const Vector3 &p_position);
bool is_colliding() const;
+
+ Vector3 get_travel() const; // Set by move and others. Consider unreliable except immediately after a move call.
+ void revert_motion();
+
Vector3 get_collision_pos() const;
Vector3 get_collision_normal() const;
Vector3 get_collider_velocity() const;
@@ -316,6 +327,12 @@ public:
void set_collision_margin(float p_margin);
float get_collision_margin() const;
+ Vector3 move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction = Vector3(0, 0, 0), const Vector3 &p_ceil_direction = Vector3(0, 0, 0), float p_slope_stop_min_velocity = 5, int p_max_bounces = 4, float p_floor_max_angle = Math::deg2rad((float)45), float p_ceil_max_angle = Math::deg2rad((float)45));
+ bool is_move_and_slide_on_floor() const;
+ bool is_move_and_slide_on_wall() const;
+ bool is_move_and_slide_on_ceiling() const;
+ Array get_move_and_slide_colliders() const;
+
KinematicBody();
~KinematicBody();
};
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index ee4f8736d7..839dcc3678 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -38,6 +38,8 @@ void BaseButton::_unpress_group() {
if (!button_group.is_valid())
return;
+ status.pressed = true;
+
for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
if (E->get() == this)
continue;
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index cebec379e6..545c700354 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -1761,8 +1761,8 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
Vector3 v02, v01;
real_t a02, a01;
- r02.get_axis_and_angle(v02, a02);
- r01.get_axis_and_angle(v01, a01);
+ r02.get_axis_angle(v02, a02);
+ r01.get_axis_angle(v01, a01);
if (Math::abs(a02) > p_max_optimizable_angle)
return false;
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp
index 9def425f28..715f93c1c1 100644
--- a/servers/physics/body_sw.cpp
+++ b/servers/physics/body_sw.cpp
@@ -495,7 +495,7 @@ void BodySW::integrate_forces(real_t p_step) {
Vector3 axis;
real_t angle;
- rot.get_axis_and_angle(axis, angle);
+ rot.get_axis_angle(axis, angle);
axis.normalize();
angular_velocity = axis.normalized() * (angle / p_step);
@@ -638,7 +638,7 @@ void BodySW::simulate_motion(const Transform& p_xform,real_t p_step) {
Vector3 axis;
real_t angle;
- rot.get_axis_and_angle(axis,angle);
+ rot.get_axis_angle(axis,angle);
axis.normalize();
angular_velocity=axis.normalized() * (angle/p_step);
linear_velocity = (p_xform.origin - get_transform().origin)/p_step;