diff options
author | reduz <reduzio@gmail.com> | 2020-11-04 23:01:55 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2020-11-06 12:45:50 -0300 |
commit | f2397809a84c2bf0d41e6cb2092fa8f3c5a17850 (patch) | |
tree | 1eb1930e9124c5ecf77840e80ebed64cbb85608c /core/math | |
parent | 391d29f558d122798416b5957660d9eeceecd0f5 (diff) |
Refactored Variant Operators.
-Using classes to call and a table
-For typed code (GDS or GDNative), can obtain functions to call prevalidated or ptr.
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/quat.h | 4 | ||||
-rw-r--r-- | core/math/vector2.cpp | 13 | ||||
-rw-r--r-- | core/math/vector2.h | 6 | ||||
-rw-r--r-- | core/math/vector3i.h | 26 |
4 files changed, 47 insertions, 2 deletions
diff --git a/core/math/quat.h b/core/math/quat.h index 3152b7d233..617bffd908 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -91,6 +91,10 @@ public: return v + ((uv * w) + u.cross(uv)) * ((real_t)2); } + _FORCE_INLINE_ Vector3 xform_inv(const Vector3 &v) const { + return inverse().xform(v); + } + _FORCE_INLINE_ void operator+=(const Quat &q); _FORCE_INLINE_ void operator-=(const Quat &q); _FORCE_INLINE_ void operator*=(const real_t &s); diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 233421e070..75e742a5f1 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -233,6 +233,19 @@ void Vector2i::operator/=(const int &rvalue) { y /= rvalue; } +Vector2i Vector2i::operator%(const Vector2i &p_v1) const { + return Vector2i(x % p_v1.x, y % p_v1.y); +} + +Vector2i Vector2i::operator%(const int &rvalue) const { + return Vector2i(x % rvalue, y % rvalue); +} + +void Vector2i::operator%=(const int &rvalue) { + x %= rvalue; + y %= rvalue; +} + Vector2i Vector2i::operator-() const { return Vector2i(-x, -y); } diff --git a/core/math/vector2.h b/core/math/vector2.h index c2a2656e72..31bb7208d3 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -290,11 +290,13 @@ struct Vector2i { void operator*=(const int &rvalue); Vector2i operator/(const Vector2i &p_v1) const; - Vector2i operator/(const int &rvalue) const; - void operator/=(const int &rvalue); + Vector2i operator%(const Vector2i &p_v1) const; + Vector2i operator%(const int &rvalue) const; + void operator%=(const int &rvalue); + Vector2i operator-() const; bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); } diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 08729ad056..89774e9395 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -80,11 +80,15 @@ struct Vector3i { _FORCE_INLINE_ Vector3i operator*(const Vector3i &p_v) const; _FORCE_INLINE_ Vector3i &operator/=(const Vector3i &p_v); _FORCE_INLINE_ Vector3i operator/(const Vector3i &p_v) const; + _FORCE_INLINE_ Vector3i &operator%=(const Vector3i &p_v); + _FORCE_INLINE_ Vector3i operator%(const Vector3i &p_v) const; _FORCE_INLINE_ Vector3i &operator*=(int32_t p_scalar); _FORCE_INLINE_ Vector3i operator*(int32_t p_scalar) const; _FORCE_INLINE_ Vector3i &operator/=(int32_t p_scalar); _FORCE_INLINE_ Vector3i operator/(int32_t p_scalar) const; + _FORCE_INLINE_ Vector3i &operator%=(int32_t p_scalar); + _FORCE_INLINE_ Vector3i operator%(int32_t p_scalar) const; _FORCE_INLINE_ Vector3i operator-() const; @@ -159,6 +163,17 @@ Vector3i Vector3i::operator/(const Vector3i &p_v) const { return Vector3i(x / p_v.x, y / p_v.y, z / p_v.z); } +Vector3i &Vector3i::operator%=(const Vector3i &p_v) { + x %= p_v.x; + y %= p_v.y; + z %= p_v.z; + return *this; +} + +Vector3i Vector3i::operator%(const Vector3i &p_v) const { + return Vector3i(x % p_v.x, y % p_v.y, z % p_v.z); +} + Vector3i &Vector3i::operator*=(int32_t p_scalar) { x *= p_scalar; y *= p_scalar; @@ -185,6 +200,17 @@ Vector3i Vector3i::operator/(int32_t p_scalar) const { return Vector3i(x / p_scalar, y / p_scalar, z / p_scalar); } +Vector3i &Vector3i::operator%=(int32_t p_scalar) { + x %= p_scalar; + y %= p_scalar; + z %= p_scalar; + return *this; +} + +Vector3i Vector3i::operator%(int32_t p_scalar) const { + return Vector3i(x % p_scalar, y % p_scalar, z % p_scalar); +} + Vector3i Vector3i::operator-() const { return Vector3i(-x, -y, -z); } |