diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2022-09-19 17:57:54 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2022-10-01 21:09:05 -0500 |
commit | fc879c04c898e8992958133e338efe4cea9ffcc8 (patch) | |
tree | 8a57922daf29889565d230d07ae8354406b78f5d /include/godot_cpp | |
parent | d479208a8fe9c3c1b0f2b0acbc94635c8005d9b8 (diff) | |
download | redot-cpp-fc879c04c898e8992958133e338efe4cea9ffcc8.tar.gz |
Update Vector4/4i to match the engine
Diffstat (limited to 'include/godot_cpp')
-rw-r--r-- | include/godot_cpp/variant/vector4.hpp | 72 | ||||
-rw-r--r-- | include/godot_cpp/variant/vector4i.hpp | 8 |
2 files changed, 45 insertions, 35 deletions
diff --git a/include/godot_cpp/variant/vector4.hpp b/include/godot_cpp/variant/vector4.hpp index 4ad3eec..2c1403c 100644 --- a/include/godot_cpp/variant/vector4.hpp +++ b/include/godot_cpp/variant/vector4.hpp @@ -44,6 +44,8 @@ class Vector4 { friend class Variant; public: + static const int AXIS_COUNT = 4; + enum Axis { AXIS_X, AXIS_Y, @@ -61,30 +63,46 @@ public: 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]; } + + Vector4::Axis min_axis_index() const; + Vector4::Axis max_axis_index() const; + _FORCE_INLINE_ real_t length_squared() const; bool is_equal_approx(const Vector4 &p_vec4) const; + bool is_zero_approx() const; real_t length() const; void normalize(); Vector4 normalized() const; bool is_normalized() const; + + real_t distance_to(const Vector4 &p_to) const; + real_t distance_squared_to(const Vector4 &p_to) const; + Vector4 direction_to(const Vector4 &p_to) 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 cubic_interpolate(const Vector4 &p_b, const Vector4 &p_pre_a, const Vector4 &p_post_b, const real_t p_weight) const; + Vector4 cubic_interpolate_in_time(const Vector4 &p_b, const Vector4 &p_pre_a, const Vector4 &p_post_b, const real_t p_weight, const real_t &p_b_t, const real_t &p_pre_a_t, const real_t &p_post_b_t) const; - Vector4::Axis min_axis_index() const; - Vector4::Axis max_axis_index() const; + Vector4 posmod(const real_t p_mod) const; + Vector4 posmodv(const Vector4 &p_modv) const; + void snap(const Vector4 &p_step); + Vector4 snapped(const Vector4 &p_step) const; Vector4 clamp(const Vector4 &p_min, const Vector4 &p_max) const; Vector4 inverse() const; - Vector4 lerp(const Vector4 &p_to, const real_t p_weight) const; _FORCE_INLINE_ real_t dot(const Vector4 &p_vec4) const; _FORCE_INLINE_ void operator+=(const Vector4 &p_vec4); @@ -197,7 +215,7 @@ Vector4 Vector4::operator/(const Vector4 &p_vec4) const { } Vector4 Vector4::operator-() const { - return Vector4(x, y, z, w); + return Vector4(-x, -y, -z, -w); } Vector4 Vector4::operator*(const real_t &s) const { @@ -221,15 +239,12 @@ bool Vector4::operator<(const Vector4 &p_v) const { if (y == p_v.y) { if (z == p_v.z) { return w < p_v.w; - } else { - return z < p_v.z; } - } else { - return y < p_v.y; + return z < p_v.z; } - } else { - return x < p_v.x; + return y < p_v.y; } + return x < p_v.x; } bool Vector4::operator>(const Vector4 &p_v) const { @@ -237,15 +252,12 @@ bool Vector4::operator>(const Vector4 &p_v) const { if (y == p_v.y) { if (z == p_v.z) { return w > p_v.w; - } else { - return z > p_v.z; } - } else { - return y > p_v.y; + return z > p_v.z; } - } else { - return x > p_v.x; + return y > p_v.y; } + return x > p_v.x; } bool Vector4::operator<=(const Vector4 &p_v) const { @@ -253,15 +265,12 @@ bool Vector4::operator<=(const Vector4 &p_v) const { if (y == p_v.y) { if (z == p_v.z) { return w <= p_v.w; - } else { - return z < p_v.z; } - } else { - return y < p_v.y; + return z < p_v.z; } - } else { - return x < p_v.x; + return y < p_v.y; } + return x < p_v.x; } bool Vector4::operator>=(const Vector4 &p_v) const { @@ -269,15 +278,12 @@ bool Vector4::operator>=(const Vector4 &p_v) const { if (y == p_v.y) { if (z == p_v.z) { return w >= p_v.w; - } else { - return z > p_v.z; } - } else { - return y > p_v.y; + return z > p_v.z; } - } else { - return x > p_v.x; + return y > p_v.y; } + return x > p_v.x; } _FORCE_INLINE_ Vector4 operator*(const float p_scalar, const Vector4 &p_vec) { @@ -298,4 +304,4 @@ _FORCE_INLINE_ Vector4 operator*(const int64_t p_scalar, const Vector4 &p_vec) { } // namespace godot -#endif // GODOT_VECTOR3_HPP +#endif // GODOT_VECTOR4_HPP diff --git a/include/godot_cpp/variant/vector4i.hpp b/include/godot_cpp/variant/vector4i.hpp index ce485c2..979fc83 100644 --- a/include/godot_cpp/variant/vector4i.hpp +++ b/include/godot_cpp/variant/vector4i.hpp @@ -45,6 +45,8 @@ class Vector4i { friend class Variant; public: + static const int AXIS_COUNT = 4; + enum Axis { AXIS_X, AXIS_Y, @@ -64,10 +66,12 @@ public: }; _FORCE_INLINE_ const int32_t &operator[](const int p_axis) const { + DEV_ASSERT((unsigned int)p_axis < 4); return coord[p_axis]; } _FORCE_INLINE_ int32_t &operator[](const int p_axis) { + DEV_ASSERT((unsigned int)p_axis < 4); return coord[p_axis]; } @@ -137,11 +141,11 @@ double Vector4i::length() const { } Vector4i Vector4i::abs() const { - return Vector4i(ABS(x), ABS(y), ABS(z), ABS(w)); + return Vector4i(Math::abs(x), Math::abs(y), Math::abs(z), Math::abs(w)); } Vector4i Vector4i::sign() const { - return Vector4i(SIGN(x), SIGN(y), SIGN(z), SIGN(w)); + return Vector4i(Math::sign(x), Math::sign(y), Math::sign(z), Math::sign(w)); } /* Operators */ |