diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-07-27 10:45:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-27 10:45:39 +0200 |
commit | 1c57d90e856c72022ee699e72122717c196ee317 (patch) | |
tree | fcb15b2f4f55bde2166331f29aeb6a13fbcf5cb6 /core/math | |
parent | 0065fcc947f7dee49ca04070f53fcd7f1dd81ab9 (diff) | |
parent | d7b30b23278b21710fcccf4f3b58f8981fe82438 (diff) |
Merge pull request #63463 from KoBeWi/Vector5
Add some missing Vector4 methods
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/vector4.cpp | 22 | ||||
-rw-r--r-- | core/math/vector4.h | 15 |
2 files changed, 32 insertions, 5 deletions
diff --git a/core/math/vector4.cpp b/core/math/vector4.cpp index c2a6f8ead2..ed42d8bfb9 100644 --- a/core/math/vector4.cpp +++ b/core/math/vector4.cpp @@ -50,7 +50,7 @@ Vector4 Vector4::normalized() const { } bool Vector4::is_normalized() const { - return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); //use less epsilon + return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); // Use less epsilon. } Vector4 Vector4::abs() const { @@ -61,6 +61,26 @@ Vector4 Vector4::sign() const { return Vector4(SIGN(x), SIGN(y), SIGN(z), SIGN(w)); } +Vector4 Vector4::floor() const { + return Vector4(Math::floor(x), Math::floor(y), Math::floor(z), Math::floor(w)); +} + +Vector4 Vector4::ceil() const { + return Vector4(Math::ceil(x), Math::ceil(y), Math::ceil(z), Math::ceil(w)); +} + +Vector4 Vector4::round() const { + return Vector4(Math::round(x), Math::round(y), Math::round(z), Math::round(w)); +} + +Vector4 Vector4::lerp(const Vector4 &p_to, const real_t p_weight) const { + return Vector4( + x + (p_weight * (p_to.x - x)), + y + (p_weight * (p_to.y - y)), + z + (p_weight * (p_to.z - z)), + w + (p_weight * (p_to.w - w))); +} + Vector4 Vector4::inverse() const { return Vector4(1.0f / x, 1.0f / y, 1.0f / z, 1.0f / w); } diff --git a/core/math/vector4.h b/core/math/vector4.h index 645c51db87..37ddb509d6 100644 --- a/core/math/vector4.h +++ b/core/math/vector4.h @@ -54,11 +54,13 @@ struct _NO_DISCARD_ Vector4 { real_t components[4] = { 0, 0, 0, 0 }; }; - _FORCE_INLINE_ real_t &operator[](int idx) { - return components[idx]; + _FORCE_INLINE_ real_t &operator[](const int p_axis) { + DEV_ASSERT((unsigned int)p_axis < 4); + return components[p_axis]; } - _FORCE_INLINE_ const real_t &operator[](int idx) const { - return components[idx]; + _FORCE_INLINE_ const real_t &operator[](const int p_axis) const { + DEV_ASSERT((unsigned int)p_axis < 4); + return components[p_axis]; } _FORCE_INLINE_ real_t length_squared() const; bool is_equal_approx(const Vector4 &p_vec4) const; @@ -66,8 +68,13 @@ struct _NO_DISCARD_ Vector4 { void normalize(); Vector4 normalized() const; bool is_normalized() const; + Vector4 abs() const; Vector4 sign() const; + Vector4 floor() const; + Vector4 ceil() const; + Vector4 round() const; + Vector4 lerp(const Vector4 &p_to, const real_t p_weight) const; Vector4::Axis min_axis_index() const; Vector4::Axis max_axis_index() const; |