diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/a_star.cpp | 2 | ||||
-rw-r--r-- | core/math/math_2d.cpp | 63 | ||||
-rw-r--r-- | core/math/math_2d.h | 67 | ||||
-rw-r--r-- | core/math/matrix3.cpp | 9 | ||||
-rw-r--r-- | core/math/matrix3.h | 3 |
5 files changed, 79 insertions, 65 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 4498efeb41..7c5dbc895a 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -459,7 +459,7 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point); ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points); - ClassDB::bind_method(D_METHOD("get_point_connections"), &AStar::get_point_connections); + ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar::get_point_connections); ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true)); ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points); diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 11003c1cd5..8ad164d4dc 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -102,69 +102,6 @@ Vector2 Vector2::cross(real_t p_other) const { return Vector2(p_other * y, -p_other * x); } -Vector2 Vector2::operator+(const Vector2 &p_v) const { - - return Vector2(x + p_v.x, y + p_v.y); -} -void Vector2::operator+=(const Vector2 &p_v) { - - x += p_v.x; - y += p_v.y; -} -Vector2 Vector2::operator-(const Vector2 &p_v) const { - - return Vector2(x - p_v.x, y - p_v.y); -} -void Vector2::operator-=(const Vector2 &p_v) { - - x -= p_v.x; - y -= p_v.y; -} - -Vector2 Vector2::operator*(const Vector2 &p_v1) const { - - return Vector2(x * p_v1.x, y * p_v1.y); -}; - -Vector2 Vector2::operator*(const real_t &rvalue) const { - - return Vector2(x * rvalue, y * rvalue); -}; -void Vector2::operator*=(const real_t &rvalue) { - - x *= rvalue; - y *= rvalue; -}; - -Vector2 Vector2::operator/(const Vector2 &p_v1) const { - - return Vector2(x / p_v1.x, y / p_v1.y); -}; - -Vector2 Vector2::operator/(const real_t &rvalue) const { - - return Vector2(x / rvalue, y / rvalue); -}; - -void Vector2::operator/=(const real_t &rvalue) { - - x /= rvalue; - y /= rvalue; -}; - -Vector2 Vector2::operator-() const { - - return Vector2(-x, -y); -} - -bool Vector2::operator==(const Vector2 &p_vec2) const { - - return x == p_vec2.x && y == p_vec2.y; -} -bool Vector2::operator!=(const Vector2 &p_vec2) const { - - return x != p_vec2.x || y != p_vec2.y; -} Vector2 Vector2::floor() const { return Vector2(Math::floor(x), Math::floor(y)); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 60351445c0..4635a4da55 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -187,6 +187,70 @@ _FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { return p_vec * p_scalar; } +_FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { + + return Vector2(x + p_v.x, y + p_v.y); +} +_FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) { + + x += p_v.x; + y += p_v.y; +} +_FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const { + + return Vector2(x - p_v.x, y - p_v.y); +} +_FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { + + x -= p_v.x; + y -= p_v.y; +} + +_FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const { + + return Vector2(x * p_v1.x, y * p_v1.y); +}; + +_FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const { + + return Vector2(x * rvalue, y * rvalue); +}; +_FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) { + + x *= rvalue; + y *= rvalue; +}; + +_FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const { + + return Vector2(x / p_v1.x, y / p_v1.y); +}; + +_FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const { + + return Vector2(x / rvalue, y / rvalue); +}; + +_FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) { + + x /= rvalue; + y /= rvalue; +}; + +_FORCE_INLINE_ Vector2 Vector2::operator-() const { + + return Vector2(-x, -y); +} + +_FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const { + + return x == p_vec2.x && y == p_vec2.y; +} +_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 res = *this; @@ -336,9 +400,10 @@ struct Rect2 { g.size.height += p_by * 2; return g; } + inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const { Rect2 g = *this; - g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0, + g = g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0, (MARGIN_TOP == p_margin) ? p_amount : 0, (MARGIN_RIGHT == p_margin) ? p_amount : 0, (MARGIN_BOTTOM == p_margin) ? p_amount : 0); diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index ab3bca79ae..5346141470 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -311,6 +311,15 @@ void Basis::rotate(const Vector3 &p_axis, real_t p_phi) { *this = rotated(p_axis, p_phi); } +void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) { + + *this = rotated_local(p_axis, p_phi); +} +Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const { + + return (*this) * Basis(p_axis, p_phi); +} + Basis Basis::rotated(const Vector3 &p_euler) const { return Basis(p_euler) * (*this); } diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 9a33b8203d..9a75308f08 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -75,6 +75,9 @@ public: void rotate(const Vector3 &p_axis, real_t p_phi); Basis rotated(const Vector3 &p_axis, real_t p_phi) const; + void rotate_local(const Vector3 &p_axis, real_t p_phi); + Basis rotated_local(const Vector3 &p_axis, real_t p_phi) const; + void rotate(const Vector3 &p_euler); Basis rotated(const Vector3 &p_euler) const; |