summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/audio_frame.h2
-rw-r--r--core/math/geometry.cpp4
-rw-r--r--core/math/geometry.h4
-rw-r--r--core/math/transform.cpp4
-rw-r--r--core/math/transform_2d.cpp6
-rw-r--r--core/math/vector2.cpp10
-rw-r--r--core/math/vector2.h21
-rw-r--r--core/math/vector3.h4
8 files changed, 19 insertions, 36 deletions
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
index e1dbb385e4..4665311059 100644
--- a/core/math/audio_frame.h
+++ b/core/math/audio_frame.h
@@ -104,7 +104,7 @@ struct AudioFrame {
r = ::undenormalise(r);
}
- _FORCE_INLINE_ AudioFrame linear_interpolate(const AudioFrame &p_b, float p_t) const {
+ _FORCE_INLINE_ AudioFrame lerp(const AudioFrame &p_b, float p_t) const {
AudioFrame res = *this;
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 3e07e9253e..4733c27cbc 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -911,7 +911,7 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l
for (int j = 1; j <= p_lats; j++) {
// FIXME: This is stupid.
- Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized();
+ Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = angle * p_radius;
planes.push_back(Plane(pos, angle));
planes.push_back(Plane(pos * axis_neg, angle * axis_neg));
@@ -943,7 +943,7 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i
for (int j = 1; j <= p_lats; j++) {
- Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized();
+ Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = axis * p_height * 0.5 + angle * p_radius;
planes.push_back(Plane(pos, angle));
planes.push_back(Plane(pos * axis_neg, angle * axis_neg));
diff --git a/core/math/geometry.h b/core/math/geometry.h
index e47d18b056..a86db6e395 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -117,8 +117,8 @@ public:
if (mub < 0) mub = 0;
if (mua > 1) mua = 1;
if (mub > 1) mub = 1;
- c1 = p1.linear_interpolate(p2, mua);
- c2 = q1.linear_interpolate(q2, mub);
+ c1 = p1.lerp(p2, mua);
+ c2 = q1.lerp(q2, mub);
}
static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) {
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 9dad3262d2..82e4005d3e 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -129,8 +129,8 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
Vector3 dst_loc = p_transform.origin;
Transform interp;
- interp.basis.set_quat_scale(src_rot.slerp(dst_rot, p_c).normalized(), src_scale.linear_interpolate(dst_scale, p_c));
- interp.origin = src_loc.linear_interpolate(dst_loc, p_c);
+ interp.basis.set_quat_scale(src_rot.slerp(dst_rot, p_c).normalized(), src_scale.lerp(dst_scale, p_c));
+ interp.origin = src_loc.lerp(dst_loc, p_c);
return interp;
}
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index f28b664e46..97a9216a5a 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -267,7 +267,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
Vector2 v;
if (dot > 0.9995) {
- v = Vector2::linear_interpolate(v1, v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
+ v = v1.lerp(v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
} else {
real_t angle = p_c * Math::acos(dot);
Vector2 v3 = (v2 - v1 * dot).normalized();
@@ -275,8 +275,8 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
}
//construct matrix
- Transform2D res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
- res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
+ Transform2D res(Math::atan2(v.y, v.x), p1.lerp(p2, p_c));
+ res.scale_basis(s1.lerp(s2, p_c));
return res;
}
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index f4259e388b..f46badd19e 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -119,11 +119,11 @@ Vector2 Vector2::round() const {
}
Vector2 Vector2::rotated(real_t p_by) const {
-
- Vector2 v;
- v.set_rotation(angle() + p_by);
- v *= length();
- return v;
+ real_t sine = Math::sin(p_by);
+ real_t cosi = Math::cos(p_by);
+ return Vector2(
+ x * cosi - y * sine,
+ x * sine + y * cosi);
}
Vector2 Vector2::posmod(const real_t p_mod) const {
diff --git a/core/math/vector2.h b/core/math/vector2.h
index ba5558102f..c0057f2543 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -82,8 +82,7 @@ struct Vector2 {
Vector2 clamped(real_t p_len) const;
- _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t);
- _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
+ _FORCE_INLINE_ Vector2 lerp(const Vector2 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector2 slerp(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
@@ -123,12 +122,6 @@ struct Vector2 {
real_t angle() const;
- void set_rotation(real_t p_radians) {
-
- x = Math::cos(p_radians);
- y = Math::sin(p_radians);
- }
-
_FORCE_INLINE_ Vector2 abs() const {
return Vector2(Math::abs(x), Math::abs(y));
@@ -230,7 +223,7 @@ _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}
-Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
+Vector2 Vector2::lerp(const Vector2 &p_b, real_t p_t) const {
Vector2 res = *this;
@@ -254,16 +247,6 @@ Vector2 Vector2::direction_to(const Vector2 &p_b) const {
return ret;
}
-Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {
-
- Vector2 res = p_a;
-
- res.x += (p_t * (p_b.x - p_a.x));
- res.y += (p_t * (p_b.y - p_a.y));
-
- return res;
-}
-
typedef Vector2 Size2;
typedef Vector2 Point2;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 3bf8644af9..a5e9d09208 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -89,7 +89,7 @@ struct Vector3 {
/* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const;
+ _FORCE_INLINE_ Vector3 lerp(const Vector3 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
@@ -206,7 +206,7 @@ Vector3 Vector3::round() const {
return Vector3(Math::round(x), Math::round(y), Math::round(z));
}
-Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
+Vector3 Vector3::lerp(const Vector3 &p_b, real_t p_t) const {
return Vector3(
x + (p_t * (p_b.x - x)),